これをWindowsのexplorer.exeのように機能させたいのですが、それは、貼り付けアイテムが表示される要素をカットまたはコピーした場合のみです..これは時々機能しますが、おそらく何かが欠けている..常に機能するように改善する方法について、ご意見をお聞かせください。
jQuery.noConflict();
jQuery(document).ready(function ($) {
// This is for the context menu to bind with operations on the right clicked node
function customMenu(node) {
// The default set of all items
var control;
var items = {
createItem: {
label: "Create",
action: function (node) { return {createItem: this.create(node) }; }
},
renameItem: {
label: "Rename",
action: function (node) { return {renameItem: this.rename(node) }; }
},
deleteItem: {
label: "Delete",
action: function (node) { return {deleteItem: this.remove(node) }; },
"separator_after": true
},
copyItem: {
label: "Copy",
action: function (node) { $(node).addClass("copy"); return {copyItem: this.copy(node) }; }
},
cutItem: {
label: "Cut",
action: function (node) { $(node).addClass("cut"); return {cutItem: this.cut(node) }; }
},
pasteItem: {
label: "Paste",
action: function (node) { $(node).addClass("paste"); return {pasteItem: this.paste(node) }; }
}
};
// We go over all the selected items as the context menu only takes action on the one that is right clicked
$.jstree._reference("#{$id_arr[$k]}").get_selected(false, true).each(function(index,element){
if ( $(element).attr("id") != $(node).attr("id") )
{
// Let's deselect all nodes that are unrelated to the context menu -- selected but are not the one right clicked
$("#{$id_arr[$k]}").jstree("deselect_node", '#'+$(element).attr("id") );
}
});
// Let's loop through all elements and try to find if the paste operation was done already
$("#{$id_arr[$k]}").find("li").each(function(index,element){
if($(node).hasClass("paste") )
{
//We are asumming that the current event is pasted so remove the Paste from the context menu
control =0;
// and from any node that has the class for cut or copy.. there is no other way as dnd, move and copy, cut are a move operation for jstree
if( $(element).hasClass("copy") ) $(element).removeClass("copy");
if ( $(element).hasClass("cut") ) $(element).removeClass("cut");
}
if( ($(element).hasClass("copy") || $(element).hasClass("cut") ) )
{
control =1;
}
//we already pasted the node
if( $(element).hasClass("paste") )
{
$(this).removeClass("paste");
}
});
switch (control)
{
case 1:
switch ($(node).attr("rel"))
{
case "drive":
delete items.renameItem;
delete items.deleteItem;
delete items.cutItem;
delete items.copyItem;
break;
}
break;
case 0:
switch ($(node).attr("rel"))
{
case "drive":
delete items.renameItem;
delete items.deleteItem;
delete items.cutItem;
delete items.copyItem;
delete items.pasteItem;
break;
case "default":
delete items.pasteItem;
break;
}
break;
default: switch ($(node).attr("rel"))
{
case "drive":
delete items.renameItem;
delete items.deleteItem;
delete items.cutItem;
delete items.copyItem;
delete items.pasteItem;
break;
case "default":
delete items.pasteItem;
break;
}
break;
}
return items;
}