/** * jQuery.contextMenu - Show a custom context when right clicking something * Jonas Arnklint, http://github.com/arnklint/jquery-contextMenu * Released into the public domain * Date: Jan 14, 2011 * @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); // fix for ie mouse button bug var mouseEvent = 'contextmenu'; var mouseEventFunc = function(e){ var name = e.data.name; var actions = e.data.actions; var options = e.data.options; var correctButton = ( (options.leftClick && e.button == 0) || (!options.leftClick && e.button == 2) ); if( correctButton ){ activeElement = $(this); // set clicked element if (options.showMenu) { options.showMenu.call(menu, activeElement); } var menu = $('
').hide().appendTo('body'), activeElement = null, // last clicked element that responds with contextMenu hideMenu = function() { $('.context-menu:visible').each(function() { $(this).trigger("closed"); $(this).hide(); $('body').unbind('click', hideMenu); }); if (options.hideMenu) { options.hideMenu.call(menu, activeElement); } }, default_options = { 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(); }); $.each(actions, function(me, itemOptions) { if (itemOptions.link) { var link = itemOptions.link; } else { var link = ''+me+''; } var menuItem = $('