+// jQuery Context Menu Plugin\r
+//\r
+// Version 1.01\r
+//\r
+// Cory S.N. LaViska\r
+// A Beautiful Site (http://abeautifulsite.net/)\r
+//\r
+// More info: http://abeautifulsite.net/2008/09/jquery-context-menu-plugin/\r
+//\r
+// Terms of Use\r
+//\r
+// This plugin is dual-licensed under the GNU General Public License\r
+// and the MIT License and is copyright A Beautiful Site, LLC.\r
+//\r
+if(jQuery)( function() {\r
+ $.extend($.fn, {\r
+ \r
+ contextMenu: function(o, callback) {\r
+ // Defaults\r
+ if( o.menu == undefined ) return false;\r
+ if( o.inSpeed == undefined ) o.inSpeed = 150;\r
+ if( o.outSpeed == undefined ) o.outSpeed = 75;\r
+ // 0 needs to be -1 for expected results (no fade)\r
+ if( o.inSpeed == 0 ) o.inSpeed = -1;\r
+ if( o.outSpeed == 0 ) o.outSpeed = -1;\r
+ // Loop each context menu\r
+ $(this).each( function() {\r
+ var el = $(this);\r
+ var offset = $(el).offset();\r
+ // Add contextMenu class\r
+ $('#' + o.menu).addClass('contextMenu');\r
+ // Simulate a true right click\r
+ $(this).mousedown( function(e) {\r
+ var evt = e;\r
+ evt.stopPropagation();\r
+ $(this).mouseup( function(e) {\r
+ e.stopPropagation();\r
+ var srcElement = $(this);\r
+ $(this).unbind('mouseup');\r
+ if( evt.button == 2 ) {\r
+ // Hide context menus that may be showing\r
+ $(".contextMenu").hide();\r
+ // Get this context menu\r
+ var menu = $('#' + o.menu);\r
+ \r
+ if( $(el).hasClass('disabled') ) return false;\r
+ \r
+ // Detect mouse position\r
+ var d = {}, x, y;\r
+ if( self.innerHeight ) {\r
+ d.pageYOffset = self.pageYOffset;\r
+ d.pageXOffset = self.pageXOffset;\r
+ d.innerHeight = self.innerHeight;\r
+ d.innerWidth = self.innerWidth;\r
+ } else if( document.documentElement &&\r
+ document.documentElement.clientHeight ) {\r
+ d.pageYOffset = document.documentElement.scrollTop;\r
+ d.pageXOffset = document.documentElement.scrollLeft;\r
+ d.innerHeight = document.documentElement.clientHeight;\r
+ d.innerWidth = document.documentElement.clientWidth;\r
+ } else if( document.body ) {\r
+ d.pageYOffset = document.body.scrollTop;\r
+ d.pageXOffset = document.body.scrollLeft;\r
+ d.innerHeight = document.body.clientHeight;\r
+ d.innerWidth = document.body.clientWidth;\r
+ }\r
+ (e.pageX) ? x = e.pageX : x = e.clientX + d.scrollLeft;\r
+ (e.pageY) ? y = e.pageY : y = e.clientY + d.scrollTop;\r
+ \r
+ // Show the menu\r
+ $(document).unbind('click');\r
+ $(menu).css({ top: y, left: x }).fadeIn(o.inSpeed);\r
+ // Hover events\r
+ $(menu).find('A').mouseover( function() {\r
+ $(menu).find('LI.hover').removeClass('hover');\r
+ $(this).parent().addClass('hover');\r
+ }).mouseout( function() {\r
+ $(menu).find('LI.hover').removeClass('hover');\r
+ });\r
+ \r
+ // Keyboard\r
+ $(document).keypress( function(e) {\r
+ switch( e.keyCode ) {\r
+ case 38: // up\r
+ if( $(menu).find('LI.hover').size() == 0 ) {\r
+ $(menu).find('LI:last').addClass('hover');\r
+ } else {\r
+ $(menu).find('LI.hover').removeClass('hover').prevAll('LI:not(.disabled)').eq(0).addClass('hover');\r
+ if( $(menu).find('LI.hover').size() == 0 ) $(menu).find('LI:last').addClass('hover');\r
+ }\r
+ break;\r
+ case 40: // down\r
+ if( $(menu).find('LI.hover').size() == 0 ) {\r
+ $(menu).find('LI:first').addClass('hover');\r
+ } else {\r
+ $(menu).find('LI.hover').removeClass('hover').nextAll('LI:not(.disabled)').eq(0).addClass('hover');\r
+ if( $(menu).find('LI.hover').size() == 0 ) $(menu).find('LI:first').addClass('hover');\r
+ }\r
+ break;\r
+ case 13: // enter\r
+ $(menu).find('LI.hover A').trigger('click');\r
+ break;\r
+ case 27: // esc\r
+ $(document).trigger('click');\r
+ break\r
+ }\r
+ });\r
+ \r
+ // When items are selected\r
+ $('#' + o.menu).find('A').unbind('click');\r
+ $('#' + o.menu).find('LI:not(.disabled) A').click( function() {\r
+ $(document).unbind('click').unbind('keypress');\r
+ $(".contextMenu").hide();\r
+ // Callback\r
+ if( callback ) callback( $(this).attr('href').substr(1), $(srcElement), {x: x - offset.left, y: y - offset.top, docX: x, docY: y} );\r
+ return false;\r
+ });\r
+ \r
+ // Hide bindings\r
+ setTimeout( function() { // Delay for Mozilla\r
+ $(document).click( function() {\r
+ $(document).unbind('click').unbind('keypress');\r
+ $(menu).fadeOut(o.outSpeed);\r
+ return false;\r
+ });\r
+ }, 0);\r
+ }\r
+ });\r
+ });\r
+ \r
+ // Disable text selection\r
+ if( $.browser.mozilla ) {\r
+ $('#' + o.menu).each( function() { $(this).css({ 'MozUserSelect' : 'none' }); });\r
+ } else if( $.browser.msie ) {\r
+ $('#' + o.menu).each( function() { $(this).bind('selectstart.disableTextSelect', function() { return false; }); });\r
+ } else {\r
+ $('#' + o.menu).each(function() { $(this).bind('mousedown.disableTextSelect', function() { return false; }); });\r
+ }\r
+ // Disable browser context menu (requires both selectors to work in IE/Safari + FF/Chrome)\r
+ $(el).add($('UL.contextMenu')).bind('contextmenu', function() { return false; });\r
+ \r
+ });\r
+ return $(this);\r
+ },\r
+ \r
+ // Disable context menu items on the fly\r
+ disableContextMenuItems: function(o) {\r
+ if( o == undefined ) {\r
+ // Disable all\r
+ $(this).find('LI').addClass('disabled');\r
+ return( $(this) );\r
+ }\r
+ $(this).each( function() {\r
+ if( o != undefined ) {\r
+ var d = o.split(',');\r
+ for( var i = 0; i < d.length; i++ ) {\r
+ $(this).find('A[href="' + d[i] + '"]').parent().addClass('disabled');\r
+ \r
+ }\r
+ }\r
+ });\r
+ return( $(this) );\r
+ },\r
+ \r
+ // Enable context menu items on the fly\r
+ enableContextMenuItems: function(o) {\r
+ if( o == undefined ) {\r
+ // Enable all\r
+ $(this).find('LI.disabled').removeClass('disabled');\r
+ return( $(this) );\r
+ }\r
+ $(this).each( function() {\r
+ if( o != undefined ) {\r
+ var d = o.split(',');\r
+ for( var i = 0; i < d.length; i++ ) {\r
+ $(this).find('A[href="' + d[i] + '"]').parent().removeClass('disabled');\r
+ \r
+ }\r
+ }\r
+ });\r
+ return( $(this) );\r
+ },\r
+ \r
+ // Disable context menu(s)\r
+ disableContextMenu: function() {\r
+ $(this).each( function() {\r
+ $(this).addClass('disabled');\r
+ });\r
+ return( $(this) );\r
+ },\r
+ \r
+ // Enable context menu(s)\r
+ enableContextMenu: function() {\r
+ $(this).each( function() {\r
+ $(this).removeClass('disabled');\r
+ });\r
+ return( $(this) );\r
+ },\r
+ \r
+ // Destroy context menu(s)\r
+ destroyContextMenu: function() {\r
+ // Destroy specified context menus\r
+ $(this).each( function() {\r
+ // Disable action\r
+ $(this).unbind('mousedown').unbind('mouseup');\r
+ });\r
+ return( $(this) );\r
+ }\r
+ \r
+ });\r
+})(jQuery);
\ No newline at end of file