This is a very good solution but there is a little error.
Attaching the menù with:
function treeRightClick(NODE, TREE_OBJ, EV) {
// lazily create contextmenu
initContextMenu(NODE);
// now force trigger for contextmenu event - first time around
$(NODE).trigger('contextmenu', EV);
}
function initContextMenu(NODE) {
....
....
// attach to node
if(menu) {
$(NODE).contextMenu(menu,{theme:'xp'});
}
}
does not work well (almost using the async ajax feature).
If I right click in a parent node a context menu appears, with the
correct NODE object parameter passed to initContextMenu(). But left
clicking that node and loading his children with ajax and then right
clicking in any of the children, a context menu appears but the NODE
parameter refers to the parent, not to the selected child.
I do not know the exact cause of this problem but I have solved
binding to the A element of the LI node instead of the LI element
itself.
function treeRightClick(NODE, TREE_OBJ, EV) {
// lazily create contextmenu
initContextMenu(NODE);
// now force trigger for contextmenu event - first time around
$(NODE).children("a").trigger('contextmenu', EV);
}
function initContextMenu(NODE) {
....
....
// attach to node
if(menu) {
$(NODE).children("a").contextMenu(menu,{theme:'xp'});
}
}