This repository was archived by the owner on Aug 14, 2021. It is now read-only.
This repository was archived by the owner on Aug 14, 2021. It is now read-only.
'replaceMenu' in beforeOpen causing select: to lose ui.target #58
Closed
Description
Thanks in advance for your attention.
I am having an issue with trying to re-define the $menu
array in the beforeOpen function. The code below works fine until the select:
, where the ui.target
property is null; ui.cmd
, however, is properly set.
Commenting out the replaceMenu
call causes the ui.target
to bind just fine.
Not sure how, but in line 149, this.currentTarget
is null
with the replaceMenu
call uncommented, and set properly (I get the alert
in select:
) when commented-out:
ui.target = $(this.currentTarget);
Let me know if can provide any further code or other context.
$("#treePane").contextmenu({
delegate: "span.fancytree-title",
menu: [
{
title: "New ",
cmd: "new_",
uiIcon: "ui-icon-document"
}, {
title: "Edit ",
cmd: "edit_",
uiIcon: "ui-icon-pencil"
}, {
title: "Remove ",
cmd: "remove_",
uiIcon: "ui-icon-close"
}, {
title: "----"
}, {
title: "Launch ",
cmd: "launch_",
uiIcon: "ui-icon-arrowreturnthick-1-n",
disabled: true
}
],
select: function(event, ui) {
var $target, node;
node = $.ui.fancytree.getNode(ui.target);
console.log("In select:");
console.log(ui.cmd + " " + ui.target);
alert(node.key + " " + node.title); // error here -> node is undefined
},
beforeOpen: function(event, ui) {
var $menu, $target, extraData, node;
node = $.ui.fancytree.getNode(ui.target);
node.type = node.data.type;
$menu = ui.menu;
$target = ui.target;
extraData = ui.extraData;
// vvv commenting-out makes ui.target bind
$("#treePane").contextmenu("replaceMenu", [
{
title: "New " + node.type,
cmd: "new_" + node.type,
uiIcon: "ui-icon-document"
}, {
title: "Edit " + node.type,
cmd: "edit_" + node.type,
uiIcon: "ui-icon-pencil"
}, {
title: "Remove " + node.type,
cmd: "remove_" + node.type,
uiIcon: "ui-icon-close"
}, {
title: "----"
}, {
title: "Launch " + node.type,
cmd: "launch_" + node.type,
uiIcon: "ui-icon-arrowreturnthick-1-n",
disabled: true
}
]);
return node.setActive();
}
});