From 7490cde0d7416d4911f187df7186180d7d14d0bb Mon Sep 17 00:00:00 2001 From: Pilskalns Date: Tue, 30 Sep 2014 11:16:47 +0300 Subject: [PATCH 1/3] Menu item class addition method Class to menu items are being added more friendly for styling (for other calls to add class) --- jquery.contextMenu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.contextMenu.js b/jquery.contextMenu.js index 394f2f9..cce3fa7 100644 --- a/jquery.contextMenu.js +++ b/jquery.contextMenu.js @@ -51,7 +51,7 @@ var menuItem = $('
  • ' + link + '
  • '); if (itemOptions.klass) { - menuItem.attr("class", itemOptions.klass); + menuItem.addClass(itemOptions.klass); } menuItem.appendTo(menu).bind('click', function(e) { From 1abde10a9ed8bbf50fac157f2fe36aa71910f583 Mon Sep 17 00:00:00 2001 From: Pilskalns Date: Tue, 30 Sep 2014 12:35:59 +0300 Subject: [PATCH 2/3] Update jquery.contextMenu.js --- jquery.contextMenu.js | 223 ++++++++++++++++++++++-------------------- 1 file changed, 115 insertions(+), 108 deletions(-) diff --git a/jquery.contextMenu.js b/jquery.contextMenu.js index cce3fa7..068ef09 100644 --- a/jquery.contextMenu.js +++ b/jquery.contextMenu.js @@ -6,118 +6,125 @@ * @author Jonas Arnklint * @version 1.7 * -*/ + */ // Making a local '$' alias of jQuery to support jQuery.noConflict (function($) { - jQuery.fn.contextMenu = function ( name, actions, options ) { - var me = this, - win = $(window), - menu = $('').hide().appendTo('body'), - activeElement = null, // last clicked element that responds with contextMenu - originalEvent = null, // the original contextmenu event - hideMenu = function() { - $('.context-menu:visible').each(function() { - $(this).trigger("closed"); - $(this).hide(); - $('body').unbind('click', hideMenu); - menu.unbind('closed'); - }); - }, - default_options = { - shiftDisable : false, // Allow access to native contextMenu by rightclick + shift - disable_native_context_menu: false, // disables the native contextmenu everywhere you click - leftClick: false // show menu on left mouse click instead of right - }, - options = $.extend(default_options, options); - - $(document).bind('contextmenu', function(e) { - if (options.disable_native_context_menu) { - e.preventDefault(); - } - hideMenu(); - }); - - $(window).bind('blur', function () { - hideMenu(); - }); - - $.each(actions, function(me, itemOptions) { - if (itemOptions.link) { - var link = itemOptions.link; - } else { - var link = ''+me+''; - } - - var menuItem = $('
  • ' + link + '
  • '); - - if (itemOptions.klass) { - menuItem.addClass(itemOptions.klass); - } - - menuItem.appendTo(menu).bind('click', function(e) { - itemOptions.click(activeElement, originalEvent); - e.preventDefault(); - }); - }); - - if (options.leftClick) { - var mouseEvent = 'click'; - } else { - var mouseEvent = 'contextmenu'; - } + jQuery.fn.contextMenu = function(name, actions, options) { + var me = this, + win = $(window), + menu = $('').hide().appendTo('body'), + activeElement = null, // last clicked element that responds with contextMenu + originalEvent = null, // the original contextmenu event + hideMenu = function() { + $('.context-menu:visible').each(function() { + $(this).trigger("closed"); + $(this).hide(); + $('body').unbind('click', hideMenu); + menu.unbind('closed'); + }); + }, + default_options = { + shiftDisable: false, // Allow access to native contextMenu by rightclick + shift + disable_native_context_menu: false, // disables the native contextmenu everywhere you click + leftClick: false, // show menu on left mouse click instead of right + jqui: false // enable integration with jQuery-UI + }, + options = $.extend(default_options, options); + + $(document).bind('contextmenu', function(e) { + if (options.disable_native_context_menu) { + e.preventDefault(); + } + hideMenu(); + }); - var mouseEventFunc = function(e){ - - if (options.shiftDisable && e.shiftKey) { - return true - } - - // Hide any existing context menus - hideMenu(); - - activeElement = $(this); // set clicked element - originalEvent = e; // Store the original context menu event - - if (options.showMenu) { - options.showMenu.call(menu, activeElement); - } - - // Bind to the closed event if there is a hideMenu handler specified - if (options.hideMenu) { - menu.bind("closed", function() { - options.hideMenu.call(menu, activeElement); + $(window).bind('blur', function() { + hideMenu(); }); - } - - menu.css({ - visibility: 'hidden', - position: 'absolute', - zIndex: 1000 - }); - - // include margin so it can be used to offset from page border. - var mWidth = menu.outerWidth(true), - mHeight = menu.outerHeight(true), - xPos = ((e.pageX - win.scrollLeft()) + mWidth < win.width()) ? e.pageX : e.pageX - mWidth, - yPos = ((e.pageY - win.scrollTop()) + mHeight < win.height()) ? e.pageY : e.pageY - mHeight; - - menu.show(0, function() { - $('body').bind('click', hideMenu); - }).css({ - visibility: 'visible', - top: yPos + 'px', - left: xPos + 'px', - zIndex: 1000 - }); - - return false; - } - if (options.delegateEventTo) { - return me.on(mouseEvent, options.delegateEventTo, mouseEventFunc) - } else { - return me.bind(mouseEvent, mouseEventFunc); + $.each(actions, function(me, itemOptions) { + if (itemOptions.link) { + var link = itemOptions.link; + } else { + var link = '' + me + ''; + } + + if (itemOptions.icon && options.jqui) { + link = '' + link; + } + + console.log(link); + var menuItem = $('
  • ' + link + '
  • '); + + if (itemOptions.klass) { + menuItem.addClass(itemOptions.klass); + } + + + menuItem.appendTo(menu).bind('click', function(e) { + itemOptions.click(activeElement, originalEvent); + e.preventDefault(); + }); + }); + + if (options.leftClick) { + var mouseEvent = 'click'; + } else { + var mouseEvent = 'contextmenu'; + } + + var mouseEventFunc = function(e) { + + if (options.shiftDisable && e.shiftKey) { + return true + } + + // Hide any existing context menus + hideMenu(); + + activeElement = $(this); // set clicked element + originalEvent = e; // Store the original context menu event + + if (options.showMenu) { + options.showMenu.call(menu, activeElement); + } + + // Bind to the closed event if there is a hideMenu handler specified + if (options.hideMenu) { + menu.bind("closed", function() { + options.hideMenu.call(menu, activeElement); + }); + } + + menu.css({ + visibility: 'hidden', + position: 'absolute', + zIndex: 1000 + }); + + // include margin so it can be used to offset from page border. + var mWidth = menu.outerWidth(true), + mHeight = menu.outerHeight(true), + xPos = ((e.pageX - win.scrollLeft()) + mWidth < win.width()) ? e.pageX : e.pageX - mWidth, + yPos = ((e.pageY - win.scrollTop()) + mHeight < win.height()) ? e.pageY : e.pageY - mHeight; + + menu.show(0, function() { + $('body').bind('click', hideMenu); + if (options.jqui){$('.context-menu').menu();} + }).css({ + visibility: 'visible', + top: yPos + 'px', + left: xPos + 'px', + zIndex: 1000 + }); + + return false; + } + + if (options.delegateEventTo) { + return me.on(mouseEvent, options.delegateEventTo, mouseEventFunc) + } else { + return me.bind(mouseEvent, mouseEventFunc); + } } - } })(jQuery); - From c330e3a9acd77c66437b5be80f6f6e9fe3b10501 Mon Sep 17 00:00:00 2001 From: Pilskalns Date: Tue, 30 Sep 2014 12:39:12 +0300 Subject: [PATCH 3/3] Update jquery.contextMenu.js --- jquery.contextMenu.js | 221 +++++++++++++++++++++--------------------- 1 file changed, 110 insertions(+), 111 deletions(-) diff --git a/jquery.contextMenu.js b/jquery.contextMenu.js index 068ef09..bf43275 100644 --- a/jquery.contextMenu.js +++ b/jquery.contextMenu.js @@ -6,125 +6,124 @@ * @author Jonas Arnklint * @version 1.7 * - */ +*/ // Making a local '$' alias of jQuery to support jQuery.noConflict (function($) { - jQuery.fn.contextMenu = function(name, actions, options) { - var me = this, - win = $(window), - menu = $('
      ').hide().appendTo('body'), - activeElement = null, // last clicked element that responds with contextMenu - originalEvent = null, // the original contextmenu event - hideMenu = function() { - $('.context-menu:visible').each(function() { - $(this).trigger("closed"); - $(this).hide(); - $('body').unbind('click', hideMenu); - menu.unbind('closed'); - }); - }, - default_options = { - shiftDisable: false, // Allow access to native contextMenu by rightclick + shift - disable_native_context_menu: false, // disables the native contextmenu everywhere you click - leftClick: false, // show menu on left mouse click instead of right - jqui: false // enable integration with jQuery-UI - }, - options = $.extend(default_options, options); - - $(document).bind('contextmenu', function(e) { - if (options.disable_native_context_menu) { - e.preventDefault(); - } - hideMenu(); - }); - - $(window).bind('blur', function() { - hideMenu(); - }); - - $.each(actions, function(me, itemOptions) { - if (itemOptions.link) { - var link = itemOptions.link; - } else { - var link = '' + me + ''; - } + jQuery.fn.contextMenu = function ( name, actions, options ) { + var me = this, + win = $(window), + menu = $('
        ').hide().appendTo('body'), + activeElement = null, // last clicked element that responds with contextMenu + originalEvent = null, // the original contextmenu event + hideMenu = function() { + $('.context-menu:visible').each(function() { + $(this).trigger("closed"); + $(this).hide(); + $('body').unbind('click', hideMenu); + menu.unbind('closed'); + }); + }, + default_options = { + shiftDisable : false, // Allow access to native contextMenu by rightclick + shift + disable_native_context_menu: false, // disables the native contextmenu everywhere you click + leftClick: false, // show menu on left mouse click instead of right + jqui: false // enable integration with jQuery-UI + }, + options = $.extend(default_options, options); + + $(document).bind('contextmenu', function(e) { + if (options.disable_native_context_menu) { + e.preventDefault(); + } + hideMenu(); + }); + + $(window).bind('blur', function () { + hideMenu(); + }); + + $.each(actions, function(me, itemOptions) { + if (itemOptions.link) { + var link = itemOptions.link; + } else { + var link = ''+me+''; + } + + if (itemOptions.icon && options.jqui) { + link = '' + link; + } - if (itemOptions.icon && options.jqui) { - link = '' + link; - } + var menuItem = $('
      • ' + link + '
      • '); - console.log(link); - var menuItem = $('
      • ' + link + '
      • '); + if (itemOptions.klass) { + menuItem.addClass(itemOptions.klass); + } - if (itemOptions.klass) { - menuItem.addClass(itemOptions.klass); - } + menuItem.appendTo(menu).bind('click', function(e) { + itemOptions.click(activeElement, originalEvent); + e.preventDefault(); + }); + }); + if (options.leftClick) { + var mouseEvent = 'click'; + } else { + var mouseEvent = 'contextmenu'; + } - menuItem.appendTo(menu).bind('click', function(e) { - itemOptions.click(activeElement, originalEvent); - e.preventDefault(); - }); + var mouseEventFunc = function(e){ + + if (options.shiftDisable && e.shiftKey) { + return true + } + + // Hide any existing context menus + hideMenu(); + + activeElement = $(this); // set clicked element + originalEvent = e; // Store the original context menu event + + if (options.showMenu) { + options.showMenu.call(menu, activeElement); + } + + // Bind to the closed event if there is a hideMenu handler specified + if (options.hideMenu) { + menu.bind("closed", function() { + options.hideMenu.call(menu, activeElement); }); + } + + menu.css({ + visibility: 'hidden', + position: 'absolute', + zIndex: 1000 + }); + + // include margin so it can be used to offset from page border. + var mWidth = menu.outerWidth(true), + mHeight = menu.outerHeight(true), + xPos = ((e.pageX - win.scrollLeft()) + mWidth < win.width()) ? e.pageX : e.pageX - mWidth, + yPos = ((e.pageY - win.scrollTop()) + mHeight < win.height()) ? e.pageY : e.pageY - mHeight; + + menu.show(0, function() { + $('body').bind('click', hideMenu); + if (options.jqui){$('.context-menu').menu();} + }).css({ + visibility: 'visible', + top: yPos + 'px', + left: xPos + 'px', + zIndex: 1000 + }); + + return false; + } - if (options.leftClick) { - var mouseEvent = 'click'; - } else { - var mouseEvent = 'contextmenu'; - } - - var mouseEventFunc = function(e) { - - if (options.shiftDisable && e.shiftKey) { - return true - } - - // Hide any existing context menus - hideMenu(); - - activeElement = $(this); // set clicked element - originalEvent = e; // Store the original context menu event - - if (options.showMenu) { - options.showMenu.call(menu, activeElement); - } - - // Bind to the closed event if there is a hideMenu handler specified - if (options.hideMenu) { - menu.bind("closed", function() { - options.hideMenu.call(menu, activeElement); - }); - } - - menu.css({ - visibility: 'hidden', - position: 'absolute', - zIndex: 1000 - }); - - // include margin so it can be used to offset from page border. - var mWidth = menu.outerWidth(true), - mHeight = menu.outerHeight(true), - xPos = ((e.pageX - win.scrollLeft()) + mWidth < win.width()) ? e.pageX : e.pageX - mWidth, - yPos = ((e.pageY - win.scrollTop()) + mHeight < win.height()) ? e.pageY : e.pageY - mHeight; - - menu.show(0, function() { - $('body').bind('click', hideMenu); - if (options.jqui){$('.context-menu').menu();} - }).css({ - visibility: 'visible', - top: yPos + 'px', - left: xPos + 'px', - zIndex: 1000 - }); - - return false; - } - - if (options.delegateEventTo) { - return me.on(mouseEvent, options.delegateEventTo, mouseEventFunc) - } else { - return me.bind(mouseEvent, mouseEventFunc); - } + if (options.delegateEventTo) { + return me.on(mouseEvent, options.delegateEventTo, mouseEventFunc) + } else { + return me.bind(mouseEvent, mouseEventFunc); } + } })(jQuery); +