Creating a right click menu?
I am creating an app and need the functionality that would allow the user to right click a div element and then produce a little menu. For this i am trying to use the
wdContextMenu to create it as it looks really impressive.
The problem i have is assigning the functionality to a div element when using an the initialize() of a MooTools class.
With my app i first create an object that during initialization creates two seperate div elements. I would then like to assign them two seperate menus when each is clicked. The problem is that for some reason whichever of the two divs is right-clicked, the same menu appears. Below is the code i use:
- this.leftpanelDiv= document.createElement("div");
- this.leftpanelDiv.id = "leftPanel";
- this.leftpanelDiv.style.width = "800px";
- this.leftpanelDiv.style.height = "800px";
- this.leftpanelDiv.style.border = "thin black solid";
- this.mainAppDiv.appendChild(this.leftpanelDiv);
- $(this.leftpanelDiv).contextmenu(document_Options); //the right-click menu
- //----------------------------------------------------//
- this.rightpanelDiv= document.createElement("div");
- this.rightpanelDiv.id = "rightPanel";
- this.rightpanelDiv.style.width = "200px";
- this.rightpanelDiv.style.height = "800px";
- this.rightpanelDiv.style.border = "thin black solid";
- this.mainAppDiv.appendChild(this.rightpanelDiv);
- $(this.rightpanelDiv).contextmenu(panel_Options);
Now it has created two divs and assigned the context menu to it. This works fine in that the screen has two divs displayed and when they are right clicked a menu does appear. But for some reason it displays the same menu. It always shows the document_Options menu. I have no idea why?
Below are the options that i created:
- var document_Options =
- {
- width: 150,
- items:
- [
- {text: "Create Element", icon: "add.gif", alias: "1-1", action: examplefunc01 }
- ]
};
- var panel_Options =
- {
- width: 150,
- items:
- [
- { text: "Delete Element", icon: "remove.gif", alias: "1-1", action: examplefunc02 }
- ]
};
I believe it could be because there are nested divs. The final document DOM looks like this:
- <div id="mainDiv">
- <div id="leftPanel">
- </div>
- <div id="rightPanel">
- </div>
- </div>
Can anyone think of a reason why both divs show the same menu?