-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.rightClick.js
116 lines (109 loc) · 2.54 KB
/
jquery.rightClick.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// jQuery Right-Click Plugin
//
// Version 1.01
//
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
// 20 December 2008
//
// Visit http://abeautifulsite.net/notebook/68 for more information
//
// Usage:
//
// // Capture right click
// $("#selector").rightClick( function(e) {
// // Do something
// });
//
// // Capture right mouse down
// $("#selector").rightMouseDown( function(e) {
// // Do something
// });
//
// // Capture right mouseup
// $("#selector").rightMouseUp( function(e) {
// // Do something
// });
//
// // Disable context menu on an element
// $("#selector").noContext();
//
// History:
//
// 1.01 - Updated (20 December 2008)
// - References to 'this' now work the same way as other jQuery plugins, thus
// the el parameter has been deprecated. Use this or $(this) instead
// - The mouse event is now passed to the callback function
// - Changed license to GNU GPL
//
// 1.00 - Released (13 May 2008)
//
// License:
//
// This plugin is dual-licensed under the GNU General Public License and the MIT License
// and is copyright 2008 A Beautiful Site, LLC.
//
if(jQuery) (function(){
$.extend($.fn, {
rightClick: function(handler) {
$(this).each( function() {
$(this).mousedown( function(e) {
var evt = e;
$(this).mouseup( function() {
$(this).unbind('mouseup');
if( evt.button == 2 ) {
handler.call( $(this), evt );
return false;
} else {
return true;
}
});
});
$(this)[0].oncontextmenu = function() {
return false;
}
});
return $(this);
},
rightMouseDown: function(handler) {
$(this).each( function() {
$(this).mousedown( function(e) {
if( e.button == 2 ) {
handler.call( $(this), e );
return false;
} else {
return true;
}
});
$(this)[0].oncontextmenu = function() {
return false;
}
});
return $(this);
},
rightMouseUp: function(handler) {
$(this).each( function() {
$(this).mouseup( function(e) {
if( e.button == 2 ) {
handler.call( $(this), e );
return false;
} else {
return true;
}
});
$(this)[0].oncontextmenu = function() {
return false;
}
});
return $(this);
},
noContext: function() {
$(this).each( function() {
$(this)[0].oncontextmenu = function() {
return false;
}
});
return $(this);
}
});
})(jQuery);