zfben_rails_assets 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,144 @@
1
+ /*
2
+ * ContextMenu - jQuery plugin for right-click context menus
3
+ *
4
+ * Author: Chris Domigan
5
+ * Contributors: Dan G. Switzer, II
6
+ * Parts of this plugin are inspired by Joern Zaefferer's Tooltip plugin
7
+ *
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
11
+ *
12
+ * Version: r2
13
+ * Date: 16 July 2007
14
+ *
15
+ * For documentation visit http://www.trendskitchens.co.nz/jquery/contextmenu/
16
+ *
17
+ */
18
+
19
+ (function($) {
20
+
21
+ var menu, shadow, trigger, content, hash, currentTarget;
22
+ var defaults = {
23
+ menuStyle: {
24
+ listStyle: 'none',
25
+ padding: '1px',
26
+ margin: '0px',
27
+ backgroundColor: '#fff',
28
+ border: '1px solid #999',
29
+ width: '100px'
30
+ },
31
+ itemStyle: {
32
+ margin: '0px',
33
+ color: '#000',
34
+ display: 'block',
35
+ cursor: 'default',
36
+ padding: '3px',
37
+ border: '1px solid #fff',
38
+ backgroundColor: 'transparent'
39
+ },
40
+ itemHoverStyle: {
41
+ border: '1px solid #0a246a',
42
+ backgroundColor: '#b6bdd2'
43
+ },
44
+ eventPosX: 'pageX',
45
+ eventPosY: 'pageY',
46
+ shadow : true,
47
+ onContextMenu: null,
48
+ onShowMenu: null
49
+ };
50
+
51
+ $.fn.contextMenu = function(id, options) {
52
+ if (!menu) { // Create singleton menu
53
+ menu = $('<div id="jqContextMenu"></div>')
54
+ .hide()
55
+ .css({position:'absolute', zIndex:'500'})
56
+ .appendTo('body')
57
+ .bind('click', function(e) {
58
+ e.stopPropagation();
59
+ });
60
+ }
61
+ if (!shadow) {
62
+ shadow = $('<div></div>')
63
+ .css({backgroundColor:'#000',position:'absolute',opacity:0.2,zIndex:499})
64
+ .appendTo('body')
65
+ .hide();
66
+ }
67
+ hash = hash || [];
68
+ hash.push({
69
+ id : id,
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
79
+ });
80
+
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);
86
+ return false;
87
+ });
88
+ return this;
89
+ };
90
+
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(
95
+ function() {
96
+ $(this).css(cur.itemHoverStyle);
97
+ },
98
+ function(){
99
+ $(this).css(cur.itemStyle);
100
+ }
101
+ ).find('img').css({verticalAlign:'middle',paddingRight:'2px'});
102
+
103
+ // Send the content to the menu
104
+ menu.html(content);
105
+
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);
110
+
111
+ $.each(cur.bindings, function(id, func) {
112
+ $('#'+id, menu).bind('click', function(e) {
113
+ hide();
114
+ func(trigger, currentTarget);
115
+ });
116
+ });
117
+
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);
121
+ }
122
+
123
+ function hide() {
124
+ menu.hide();
125
+ shadow.hide();
126
+ }
127
+
128
+ // Apply defaults
129
+ $.contextMenu = {
130
+ defaults : function(userDefaults) {
131
+ $.each(userDefaults, function(i, val) {
132
+ if (typeof val == 'object' && defaults[i]) {
133
+ $.extend(defaults[i], val);
134
+ }
135
+ else defaults[i] = val;
136
+ });
137
+ }
138
+ };
139
+
140
+ })(jQuery);
141
+
142
+ $(function() {
143
+ $('div.contextMenu').hide();
144
+ });