PDA

View Full Version : contextmenu not working



jeanluca
14 Jun 2010, 2:22 AM
Hi All

I've written the following test code


<html>
<head>
<title>Getting Started Example</title>
<link rel="stylesheet" type="text/css" href="lib/extjs/resources/css/ext-all.css" />

<script src="js/yui/2/build/utilities/utilities.js"></script>
<script src="lib/extjs/adapter/yui/ext-yui-adapter.js"></script>
<script src="lib/extjs/ext-all-debug.js"></script>

<script>
Ext.onReady(function(){
Ext.get('myDiv').on('contextmenu', function(eventObj, elRef) {
alert('myDiv contextmenu Handler, source elment ID: ' + elRef.id);
});
</script>
</head>
<body>
<div id="myDiv" style="background-color:green"> MyDiv Text
<br/>
<a href="#" oncontextmenu="alert('test'); Ext.stopEvent();">skdhksjdfkjsdhfh</a>
</body>
</html>

When I right-click the anchor, the alert message is shown. However, when I do the same thing with the div, nothing happens. Any suggestions why ?

cheers

CrazyEnigma
14 Jun 2010, 6:50 PM
Even though this is not an really EXT JS, does oncontextmenu work on div directly? If it does, you still need to use "oncontextmenu" even though you are calling the on() method. The event that fires will be "oncontextmenu", not "contextmenu"

Animal
14 Jun 2010, 9:27 PM
Event names do not contain "on". Think about it. The event is, logically, "contextmenu".

The handler might be called onContextMenu, but how can an event contain "on"? It's not logical. Oh! McSoft did it, so....

CrazyEnigma
15 Jun 2010, 6:16 AM
I know they don't contain "on" in the context of EXT JS. Neither is it past tense. You are right Animal, it makes no sense to have "on".

Sorry that was the wrong help.

You are getting some syntax errors... Namely, you didn't close off onReady(), and I am not sure if you need to reference "ext-base.js"

jeanluca
15 Jun 2010, 12:27 PM
you're right. It was an syntax error which I missed, sorry!