PDA

View Full Version : Another simple contextmenu



youds
23 May 2014, 12:06 PM
Hi

I previously posted a thread asking about a contextmenu, however, here's another for you.

<!-- Begin ExtJS-->
<script type="text/javascript" charset="utf-8" async defer>
Ext.BLANK_IMAGE_URL = 'ext-4.2.1.883/resources/images/default/s.gif';
Ext.onReady(function(){
console.log("Congratulations! You have Ext configured correctly!");
var removeAction = Ext.create('Ext.Action', {
icon:'img/star_red.png',
text: 'Remove this element, because I don\'t like it',
handler: function(widget, event) {
if(confirm("This element will be removed from DOM. You will need to refresh your browser to make it reappear. Continue?")) {
Ext.get("elementContextMenu").remove();
}
return false;
}
});

var contextMenu = Ext.create('Ext.menu.Menu', {
items: [
removeAction
]
});
Ext.get("elementContextMenu").on("contextmenu", function(event,element){
event.stopEvent();
console.log(contextMenu.showAt(event.getXY()));
return false;
})
}); //end onReady
</script><div style="padding:15px;background:#EEE;border:3px solid #AAA;border-radius:10px;color:#000;width:500px;margin:50px" id="elementContextMenu">Right click here</div>

When I right click the div, nothing happens??

skirtle
23 May 2014, 12:42 PM
Literally nothing? Not even the default browser menu? No error messages?

Try using a simpler event (e.g. click) and a simpler acceptance test (just do some console logging, don't try to show a menu). Add some breakpoints to confirm exactly which lines get hit.

youds
26 May 2014, 11:09 AM
Literally, nothing. Not even the default browser menu, or error messages.

skirtle
26 May 2014, 11:25 AM
Works for me:

https://fiddle.sencha.com/#fiddle/64q