Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Steve Boulay on Nov 23, 2009 06:16
open dhtmlx forum
contextmenu

Hello,

I want to have a contextmenu for all my screen but i don't know how make it.

My HTML sources are like that :

<body>
    <div id="menuObj"></div>
    <div id='ContextArea' style="position:absolute;width:100%;height:100%;top:0;left:0;background-color:green;">
....... BODY HTML .......
</div>
</body>

And my init script is :

var menuCtxt = new dhtmlXMenuObject();
menuCtxt.renderAsContextMenu();
menuCtxt.attachEvent("onBeforeContextMenu", function(zoneId){alert(zoneId);});
menuCtxt.addContextZone("ContextArea");

and i try too the HTML sources :

<body id='ContextArea' >
    <div id="menuObj"></div>
....... BODY HTML .......
</div>
</body>

But in these two cases, it doesn't work. Why?

Regards
Answer posted by Alex (support) on Nov 24, 2009 07:53

Hello,

we have added abiltity to attach context menu to the document body. 

Please have a look at the attached sample. This sample contains modified dhtmlxmenu.js, so please use this file in your application

Attachments (1)
Answer posted by Steve Boulay on Nov 24, 2009 08:12
Thanks,

But i use a full compressed version of DHTMLX.js how can i use it and your version of dhtmlxmenu.js ???

Regards
Answer posted by Alex (support) on Nov 24, 2009 08:25

You can either generate the new dhtmlx.js (in this case it is necessary replace dhtmlxMenu/codebase/dhtmlxmenu.js with the new one) or include this file after dhtmlx.js in a page.

 

Answer posted by Steve Boulay on Nov 24, 2009 08:29
Thanks

But how can i generate the new dhtmlx.js ?
Answer posted by Alex (support) on Nov 24, 2009 08:45

it can be done using libCompliler. It is included in the Suite package. 

Answer posted by Steve Boulay on Nov 25, 2009 08:08
Thanks for all.

i want use a dynamic context menu in my page. After attach my contet menu to my body, i use the onBeforeContextMenu Event to load the content of my menu. In this event how i can know on which object is the target of my right click ??

Regards
Answer posted by Alex (support) on Nov 25, 2009 08:55

You can make the following modification in the dhtmlxmenu.js to get target from onBeforeContextMenu event:

please locate this line in the dhtmlxmenu.js

if (this.callEvent("onBeforeContextMenu", [cZone.id])) {

and replace it with

if (this.callEvent("onBeforeContextMenu", [cZone.id,e])) {

(just add e into the array)

After that you can apply the following method:

menu.attachEvent("onBeforeContextMenu",function(zoneId,ev){
    var target_element = ev.srcElement||ev.target;
    /*your code here*/
    return true
})

Answer posted by Steve Boulay on Nov 25, 2009 09:04
Thanks