Closed manhbui21 closed 7 years ago
Simply remove the contextmenu plugin. Or unbind the event handler using .off
on the tree container - check how it is bound in the contextmenu plugin and unbind in your own code (for example in a jstree.ready handler)
Do you have any sample code about the way to unbind that event handler? I'm new to jstree so there is something I've not clearly understood.
I tried like this
$('#jstree_div_id').jstree({ \\tree definition }).on('ready.jstree', function(e, data){ this.get_container().delegate("a", "contextmenu.jstree", $.proxy(function(e){ e.preventDefault(); }))});
And it thrown an exception at this line "this.get_container() is not a function"
Here is my own context menu plugin that I created to active context menu from a button
(function ($, undefined) { \"use strict\"; var btn = document.createElement('button'); btn.className = "jstree-contextmenubtn"; var btnIcon = document.createElement('span'); btnIcon.className = "icon_className"; btn.appendChild(btnIcon); $.jstree.plugins.contextmenubtn = function (options, parent) { this.bind = function () { parent.bind.call(this); this.element.on("click.jstree", ".jstree-contextmenubtn", $.proxy(function (e) { e.preventDefault(); e.stopPropagation(); $(e.target).closest('.jstree-node').children('.jstree-anchor').trigger('contextmenu'); }, this)); }; this.teardown = function () { this.element.find(".jstree-contextmenubtn").remove(); parent.teardown.call(this); }; this.redraw_node = function(obj, deep, callback, force_draw) { obj = parent.redraw_node.call(this, obj, deep, callback, force_draw); if(obj) { var tmp = btn.cloneNode(true); obj.appendChild(tmp); } return obj; }; }; })(jQuery);
I am currently importing both default "contextmenu" plugin and this customized plugin. When I try removing the default "contextmenu" plugin it also thrown an exception. Did I do anything wrong? How should I edit my code to do this requirement?
$('#jstree_div_id').off("contextmenu.jstree", ".jstree-anchor");
This is what you need provided you use a current version of jstree and jQuery.
I customized a new way to display context menu so I do not need it's default right click event anymore. How can I disable it?