2 var menu,shadow,trigger,content,hash,currentTarget;
8 backgroundColor:'#fff',
9 border:'1px solid #999',
18 border:'1px solid #fff',
19 backgroundColor:'transparent'
22 border:'1px solid #0a246a',
23 backgroundColor:'#b6bdd2'
31 $.fn.contextMenu= function(id,options) {
33 menu=$('<div id="jqContextMenu"></div>').hide().css({
36 }).appendTo('body').bind('click', function(e) {
41 shadow=$('<div></div>').css({
42 backgroundColor:'#000',
46 }).appendTo('body').hide()
51 menuStyle:$.extend({},defaults.menuStyle,options.menuStyle|| {}),
52 itemStyle:$.extend({},defaults.itemStyle,options.itemStyle|| {}),
53 itemHoverStyle:$.extend({},defaults.itemHoverStyle,options.itemHoverStyle|| {}),
54 bindings:options.bindings|| {},
55 shadow:options.shadow||options.shadow===false?options.shadow:defaults.shadow,
56 onContextMenu:options.onContextMenu||defaults.onContextMenu,
57 onShowMenu:options.onShowMenu||defaults.onShowMenu,
58 eventPosX:options.eventPosX||defaults.eventPosX,
59 eventPosY:options.eventPosY||defaults.eventPosY
61 var index=hash.length-1;
62 var callback = function(e) {
63 var bShowContext=(!!hash[index].onContextMenu)?hash[index].onContextMenu(e):true;
65 display(index,this,e,options);
68 if (!options.noRightClick) {
69 $(this).bind('contextmenu', callback);
71 if (options.leftClickToo || options.noRightClick) {
72 $(this).click(callback);
76 function display(index,trigger,e,options) {
78 content=$('#'+cur.id).find('ul:first').clone(true);
79 content.css(cur.menuStyle).find('li').css(cur.itemStyle).hover( function() {
80 $(this).css(cur.itemHoverStyle)
82 $(this).css(cur.itemStyle)
84 verticalAlign:'middle',
89 menu=cur.onShowMenu(e,menu);
90 $.each(cur.bindings, function(id,func) {
91 $('#'+id,menu).bind('click', function(e) {
93 func(trigger,currentTarget)
97 'left':e[cur.eventPosX],
98 'top':e[cur.eventPosY]
103 height:menu.height(),
107 $(document).one('click',hide)
116 defaults: function(userDefaults) {
117 $.each(userDefaults, function(i,val) {
118 if(typeof val=='object'&&defaults[i]) {
119 $.extend(defaults[i],val)
127 $('div.contextMenu').hide()