/** * Copyright (c)2005-2009 Matt Kruse (javascripttoolbox.com) * * Dual licensed under the MIT and GPL licenses. * This basically means you can use this code however you want for * free, but don't claim to have written it yourself! * Donations always accepted: http://www.JavascriptToolbox.com/donate/ * * Please do not link to the .js files on javascripttoolbox.com from * your site. Copy the files locally to your server instead. * */ /** * jquery.contextmenu.js * jQuery Plugin for Context Menus * http://www.JavascriptToolbox.com/lib/contextmenu/ * * Copyright (c) 2008 Matt Kruse (javascripttoolbox.com) * Dual licensed under the MIT and GPL licenses. * * @version 1.0 * @history 1.0 2008-10-20 Initial Release * @todo slideUp doesn't work in IE - because of iframe? * @todo Hide all other menus when contextmenu is shown? * @todo More themes * @todo Nested context menus */ ;(function($){ $.contextMenu = { shadow:true, shadowOffset:0, shadowOffsetX:5, shadowOffsetY:5, shadowWidthAdjust:-3, shadowHeightAdjust:-3, shadowOpacity:.2, shadowClass:'context-menu-shadow', shadowColor:'black', offsetX:0, offsetY:0, appendTo:'body', direction:'down', constrainToScreen:true, showTransition:'show', hideTransition:'hide', showSpeed:'', hideSpeed:'', showCallback:null, hideCallback:null, className:'context-menu', itemClassName:'context-menu-item', itemHoverClassName:'context-menu-item-hover', disabledItemClassName:'context-menu-item-disabled', disabledItemHoverClassName:'context-menu-item-disabled-hover', separatorClassName:'context-menu-separator', innerDivClassName:'context-menu-item-inner', themePrefix:'context-menu-theme-', theme:'default', separator:'context-menu-separator', // A specific key to identify a separator target:null, // The target of the context click, to be populated when triggered menu:null, // The jQuery object containing the HTML object that is the menu itself shadowObj:null, // Shadow object bgiframe:null, // The iframe object for IE6 shown:false, // Currently being shown? useIframe:/*@cc_on @*//*@if (@_win32) true, @else @*/false,/*@end @*/ // This is a better check than looking at userAgent! bindTarget: 'contextmenu', // Create the menu instance create: function(menu,opts) { var cmenu = $.extend({},this,opts); // Clone all default properties to created object // If a selector has been passed in, then use that as the menu if (typeof menu=="string") { cmenu.menu = $(menu); } // If a function has been passed in, call it each time the menu is shown to create the menu else if (typeof menu=="function") { cmenu.menuFunction = menu; } // Otherwise parse the Array passed in else { cmenu.menu = cmenu.createMenu(menu,cmenu); } if (cmenu.menu) { cmenu.menu.css({display:'none'}); $(cmenu.appendTo).append(cmenu.menu); } // Create the shadow object if shadow is enabled if (cmenu.shadow) { cmenu.createShadow(cmenu); // Extracted to method for extensibility if (cmenu.shadowOffset) { cmenu.shadowOffsetX = cmenu.shadowOffsetY = cmenu.shadowOffset; } } // when to hide the menu: // click anywhere in the body: $('body').bind('click',function(){cmenu.hide();}); // right-click anywhere in the body: $('body').bind('contextmenu',function(){cmenu.hide();}); // escape key: $(document).keyup(function(e) { if (e.keyCode == 27) { cmenu.hide(); } }); return cmenu; }, // Create an iframe object to go behind the menu createIframe: function() { return $('