2
* ContextMenu - jQuery plugin for right-click context menus
4
* Author: Chris Domigan
5
* Contributors: Dan G. Switzer, II
6
* Parts of this plugin are inspired by Joern Zaefferer's Tooltip plugin
8
* Dual licensed under the MIT and GPL licenses:
9
* http://www.opensource.org/licenses/mit-license.php
10
* http://www.gnu.org/licenses/gpl.html
15
* For documentation visit http://www.trendskitchens.co.nz/jquery/contextmenu/
21
var menu, shadow, trigger, content, hash, currentTarget;
27
backgroundColor: '#fff',
28
border: '1px solid #999',
37
border: '1px solid #fff',
38
backgroundColor: 'transparent'
41
border: '1px solid #0a246a',
42
backgroundColor: '#b6bdd2'
51
$.fn.contextMenu = function(id, options) {
52
if (!menu) { // Create singleton menu
53
menu = $('<div id="jqContextMenu"></div>')
55
.css({position:'absolute', zIndex:'500'})
57
.bind('click', function(e) {
62
shadow = $('<div></div>')
63
.css({backgroundColor:'#000',position:'absolute',opacity:0.2,zIndex:499})
70
menuStyle: $.extend({}, defaults.menuStyle, options.menuStyle || {}),
71
itemStyle: $.extend({}, defaults.itemStyle, options.itemStyle || {}),
72
itemHoverStyle: $.extend({}, defaults.itemHoverStyle, options.itemHoverStyle || {}),
73
bindings: options.bindings || {},
74
shadow: options.shadow || options.shadow === false ? options.shadow : defaults.shadow,
75
onContextMenu: options.onContextMenu || defaults.onContextMenu,
76
onShowMenu: options.onShowMenu || defaults.onShowMenu,
77
eventPosX: options.eventPosX || defaults.eventPosX,
78
eventPosY: options.eventPosY || defaults.eventPosY
81
var index = hash.length - 1;
82
$(this).bind('contextmenu', function(e) {
83
// Check if onContextMenu() defined
84
var bShowContext = (!!hash[index].onContextMenu) ? hash[index].onContextMenu(e) : true;
85
if (bShowContext) display(index, this, e, options);
91
function display(index, trigger, e, options) {
92
var cur = hash[index];
93
content = $('#'+cur.id).find('ul:first').clone(true);
94
content.css(cur.menuStyle).find('li').css(cur.itemStyle).hover(
96
$(this).css(cur.itemHoverStyle);
99
$(this).css(cur.itemStyle);
101
).find('img').css({verticalAlign:'middle',paddingRight:'2px'});
103
// Send the content to the menu
106
// if there's an onShowMenu, run it now -- must run after content has been added
107
// if you try to alter the content variable before the menu.html(), IE6 has issues
108
// updating the content
109
if (!!cur.onShowMenu) menu = cur.onShowMenu(e, menu);
111
$.each(cur.bindings, function(id, func) {
112
$('#'+id, menu).bind('click', function(e) {
114
func(trigger, currentTarget);
118
menu.css({'left':e[cur.eventPosX],'top':e[cur.eventPosY]}).show();
119
if (cur.shadow) shadow.css({width:menu.width(),height:menu.height(),left:e.pageX+2,top:e.pageY+2}).show();
120
$(document).one('click', hide);
130
defaults : function(userDefaults) {
131
$.each(userDefaults, function(i, val) {
132
if (typeof val == 'object' && defaults[i]) {
133
$.extend(defaults[i], val);
135
else defaults[i] = val;
143
$('div.contextMenu').hide();
b'\\ No newline at end of file'