[IMP] Disable right click on m2o button
[odoo/odoo.git] / addons / web / static / lib / jquery.contextmenu / jquery.contextmenu.r2.packed.js
1 (function($) {
2     var menu,shadow,trigger,content,hash,currentTarget;
3     var defaults= {
4         menuStyle: {
5             listStyle:'none',
6             padding:'1px',
7             margin:'0px',
8             backgroundColor:'#fff',
9             border:'1px solid #999',
10             width:'100px'
11         },
12         itemStyle: {
13             margin:'0px',
14             color:'#000',
15             display:'block',
16             cursor:'default',
17             padding:'3px',
18             border:'1px solid #fff',
19             backgroundColor:'transparent'
20         },
21         itemHoverStyle: {
22             border:'1px solid #0a246a',
23             backgroundColor:'#b6bdd2'
24         },
25         eventPosX:'pageX',
26         eventPosY:'pageY',
27         shadow:true,
28         onContextMenu:null,
29         onShowMenu:null
30     };
31     $.fn.contextMenu= function(id,options) {
32         if(!menu) {
33             menu=$('<div id="jqContextMenu"></div>').hide().css({
34                 position:'absolute',
35                 zIndex:'2000'
36             }).appendTo('body').bind('click', function(e) {
37                 e.stopPropagation()
38             })
39         }
40         if(!shadow) {
41             shadow=$('<div></div>').css({
42                 backgroundColor:'#000',
43                 position:'absolute',
44                 opacity:0.2,
45                 zIndex:499
46             }).appendTo('body').hide()
47         }
48         hash=hash||[];
49         hash.push({
50             id:id,
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
60         });
61         var index=hash.length-1;
62         var callback = function(e) {
63             var bShowContext=(!!hash[index].onContextMenu)?hash[index].onContextMenu(e):true;
64             if(bShowContext)
65                 display(index,this,e,options);
66             return false;
67         };
68         if (!options.noRightClick) {
69             $(this).bind('contextmenu', callback);
70         }
71         if (options.leftClickToo || options.noRightClick) {
72             $(this).click(callback);
73         }
74         return this
75     };
76     function display(index,trigger,e,options) {
77         var cur=hash[index];
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)
81         }, function() {
82             $(this).css(cur.itemStyle)
83         }).find('img').css({
84             verticalAlign:'middle',
85             paddingRight:'2px'
86         });
87         menu.html(content);
88         if(!!cur.onShowMenu)
89             menu=cur.onShowMenu(e,menu);
90         $.each(cur.bindings, function(id,func) {
91             $('#'+id,menu).bind('click', function(e) {
92                 hide();
93                 func(trigger,currentTarget)
94             })
95         });
96         menu.css({
97             'left':e[cur.eventPosX],
98             'top':e[cur.eventPosY]
99         }).show();
100         if(cur.shadow)
101             shadow.css({
102                 width:menu.width(),
103                 height:menu.height(),
104                 left:e.pageX+2,
105                 top:e.pageY+2
106             }).show();
107         $(document).one('click',hide)
108     }
109
110     function hide() {
111         menu.hide();
112         shadow.hide()
113     }
114
115     $.contextMenu= {
116         defaults: function(userDefaults) {
117             $.each(userDefaults, function(i,val) {
118                 if(typeof val=='object'&&defaults[i]) {
119                     $.extend(defaults[i],val)
120                 } else
121                     defaults[i]=val
122             })
123         }
124     }
125 })(jQuery);
126 $( function() {
127     $('div.contextMenu').hide()
128 });