Updates the plugin so that it can support multiple instances.
Multiple instances need to be applied to different elements in the DOM otherwise multiple menus will be called for each click/right click. e.g. jQuery(document).ContextMenu(url); would work for any form on a page. Using this would mean that multiple instances couldn't be used though jQuery('#content form').eq(0).ContextMenu(url); jQuery('#content form').eq(3).ContextMenu(url); Using the above 2 menus will be created for the first and 4th forms on the page. Any of forms won't response to menu clicks. jQuery(docuemnt).ContextMenu(url); jQuery('#content form').eq(0).ContextMenu(url); With the above any form on the page will respond to menu clicks but the first form will send 2 requests for the context menu.
This commit is contained in:
parent
2b640f76ec
commit
a510f0a85f
@ -1,7 +1,9 @@
|
||||
(function($) {
|
||||
var ContextMenuClass = function(el, options) {
|
||||
var element = el;
|
||||
var opts = options;
|
||||
var observingContextMenuClick;
|
||||
var url;
|
||||
var lastSelected;
|
||||
var lastSelected = null;
|
||||
var menu;
|
||||
var menuId = 'context-menu';
|
||||
var selectorName = 'hascontextmenu';
|
||||
@ -135,7 +137,7 @@
|
||||
var renderY = mouseY;
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
url: opts.url,
|
||||
data: params,
|
||||
success: function(response, success) {
|
||||
menu.html(response);
|
||||
@ -195,18 +197,21 @@
|
||||
}
|
||||
};
|
||||
|
||||
$.fn.ContextMenu = function(u) {
|
||||
url = u;
|
||||
methods.createMenu();
|
||||
|
||||
if(!observingContextMenuClick) {
|
||||
$(document).bind('click.contextMenu', methods.click);
|
||||
$(document).bind('contextmenu.contextMenu', methods.click);
|
||||
element.bind('click.contextMenu', methods.click);
|
||||
element.bind('contextmenu.contextMenu', methods.click);
|
||||
observingContextMenuClick = true;
|
||||
}
|
||||
|
||||
methods.unselectAll();
|
||||
lastSelected = null;
|
||||
};
|
||||
|
||||
$.fn.ContextMenu = function(u) {
|
||||
return this.each(function() {
|
||||
new ContextMenuClass($(this), {url: u});
|
||||
});
|
||||
};
|
||||
})(jQuery);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user