@@ -5,42 +5,42 var observingContextMenuClick; | |||||
5 |
|
5 | |||
6 | ContextMenu = Class.create(); |
|
6 | ContextMenu = Class.create(); | |
7 | ContextMenu.prototype = { |
|
7 | ContextMenu.prototype = { | |
8 |
|
|
8 | initialize: function (url) { | |
9 |
|
|
9 | this.url = url; | |
10 |
|
|
10 | this.createMenu(); | |
11 |
|
11 | |||
12 |
|
|
12 | if (!observingContextMenuClick) { | |
13 |
|
|
13 | Event.observe(document, 'click', this.Click.bindAsEventListener(this)); | |
14 |
|
|
14 | Event.observe(document, 'contextmenu', this.RightClick.bindAsEventListener(this)); | |
15 |
|
|
15 | observingContextMenuClick = true; | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 |
|
|
18 | this.unselectAll(); | |
19 |
|
|
19 | this.lastSelected = null; | |
20 | }, |
|
20 | }, | |
21 |
|
21 | |||
22 |
|
|
22 | RightClick: function(e) { | |
23 |
|
|
23 | this.hideMenu(); | |
24 |
|
|
24 | // do not show the context menu on links | |
25 |
|
|
25 | if (Event.element(e).tagName == 'A') { return; } | |
26 |
|
|
26 | var tr = Event.findElement(e, 'tr'); | |
27 |
|
|
27 | if (tr == document || tr == undefined || !tr.hasClassName('hascontextmenu')) { return; } | |
28 |
|
|
28 | Event.stop(e); | |
29 |
|
|
29 | if (!this.isSelected(tr)) { | |
30 |
|
|
30 | this.unselectAll(); | |
31 |
|
|
31 | this.addSelection(tr); | |
32 |
|
|
32 | this.lastSelected = tr; | |
33 | } |
|
33 | } | |
34 |
|
|
34 | this.showMenu(e); | |
35 | }, |
|
35 | }, | |
36 |
|
36 | |||
37 | Click: function(e) { |
|
37 | Click: function(e) { | |
38 |
|
|
38 | if (Event.element(e).tagName == 'A' && Event.element(e).hasClassName('submenu')) { | |
39 |
|
|
39 | Event.stop(e) | |
40 |
|
|
40 | return; | |
41 | } |
|
41 | } | |
42 |
|
|
42 | this.hideMenu(); | |
43 |
|
|
43 | if (Event.element(e).tagName == 'A' || Event.element(e).tagName == 'IMG') { return; } | |
44 | if (Event.isLeftClick(e) || (navigator.appVersion.match(/\bMSIE\b/))) { |
|
44 | if (Event.isLeftClick(e) || (navigator.appVersion.match(/\bMSIE\b/))) { | |
45 | var tr = Event.findElement(e, 'tr'); |
|
45 | var tr = Event.findElement(e, 'tr'); | |
46 | if (tr!=null && tr!=document && tr.hasClassName('hascontextmenu')) { |
|
46 | if (tr!=null && tr!=document && tr.hasClassName('hascontextmenu')) { | |
@@ -114,7 +114,7 ContextMenu.prototype = { | |||||
114 | var max_height; |
|
114 | var max_height; | |
115 |
|
115 | |||
116 | $('context-menu').style['left'] = (render_x + 'px'); |
|
116 | $('context-menu').style['left'] = (render_x + 'px'); | |
117 |
$('context-menu').style['top'] = (render_y + 'px'); |
|
117 | $('context-menu').style['top'] = (render_y + 'px'); | |
118 | Element.update('context-menu', ''); |
|
118 | Element.update('context-menu', ''); | |
119 |
|
119 | |||
120 | new Ajax.Updater({success:'context-menu'}, this.url, |
|
120 | new Ajax.Updater({success:'context-menu'}, this.url, | |
@@ -123,34 +123,34 ContextMenu.prototype = { | |||||
123 | evalScripts:true, |
|
123 | evalScripts:true, | |
124 | parameters:Form.serialize(Event.findElement(e, 'form')), |
|
124 | parameters:Form.serialize(Event.findElement(e, 'form')), | |
125 | onComplete:function(request){ |
|
125 | onComplete:function(request){ | |
126 |
|
|
126 | dims = $('context-menu').getDimensions(); | |
127 |
|
|
127 | menu_width = dims.width; | |
128 |
|
|
128 | menu_height = dims.height; | |
129 |
|
|
129 | max_width = mouse_x + 2*menu_width; | |
130 |
|
|
130 | max_height = mouse_y + menu_height; | |
131 |
|
131 | |||
132 |
|
|
132 | var ws = window_size(); | |
133 |
|
|
133 | window_width = ws.width; | |
134 |
|
|
134 | window_height = ws.height; | |
135 |
|
135 | |||
136 |
|
|
136 | /* display the menu above and/or to the left of the click if needed */ | |
137 |
|
|
137 | if (max_width > window_width) { | |
138 |
|
|
138 | render_x -= menu_width; | |
139 |
|
|
139 | $('context-menu').addClassName('reverse-x'); | |
140 |
|
|
140 | } else { | |
141 |
|
|
141 | $('context-menu').removeClassName('reverse-x'); | |
142 | } |
|
142 | } | |
143 |
|
|
143 | if (max_height > window_height) { | |
144 |
|
|
144 | render_y -= menu_height; | |
145 |
|
|
145 | $('context-menu').addClassName('reverse-y'); | |
146 |
|
|
146 | } else { | |
147 |
|
|
147 | $('context-menu').removeClassName('reverse-y'); | |
148 | } |
|
148 | } | |
149 |
|
|
149 | if (render_x <= 0) render_x = 1; | |
150 |
|
|
150 | if (render_y <= 0) render_y = 1; | |
151 |
|
|
151 | $('context-menu').style['left'] = (render_x + 'px'); | |
152 |
|
|
152 | $('context-menu').style['top'] = (render_y + 'px'); | |
153 |
|
153 | |||
154 | Effect.Appear('context-menu', {duration: 0.20}); |
|
154 | Effect.Appear('context-menu', {duration: 0.20}); | |
155 | if (window.parseStylesheets) { window.parseStylesheets(); } // IE |
|
155 | if (window.parseStylesheets) { window.parseStylesheets(); } // IE | |
156 | }}) |
|
156 | }}) | |
@@ -187,8 +187,8 ContextMenu.prototype = { | |||||
187 | }, |
|
187 | }, | |
188 |
|
188 | |||
189 | checkSelectionBox: function(tr, checked) { |
|
189 | checkSelectionBox: function(tr, checked) { | |
190 |
|
|
190 | var inputs = Element.getElementsBySelector(tr, 'input'); | |
191 |
|
|
191 | if (inputs.length > 0) { inputs[0].checked = checked; } | |
192 | }, |
|
192 | }, | |
193 |
|
193 | |||
194 | isSelected: function(tr) { |
|
194 | isSelected: function(tr) { | |
@@ -205,32 +205,32 ContextMenu.prototype = { | |||||
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | function toggleIssuesSelection(el) { |
|
207 | function toggleIssuesSelection(el) { | |
208 |
|
|
208 | var boxes = el.getElementsBySelector('input[type=checkbox]'); | |
209 |
|
|
209 | var all_checked = true; | |
210 |
|
|
210 | for (i = 0; i < boxes.length; i++) { if (boxes[i].checked == false) { all_checked = false; } } | |
211 |
|
|
211 | for (i = 0; i < boxes.length; i++) { | |
212 |
|
|
212 | if (all_checked) { | |
213 |
|
|
213 | boxes[i].checked = false; | |
214 |
|
|
214 | boxes[i].up('tr').removeClassName('context-menu-selection'); | |
215 |
|
|
215 | } else if (boxes[i].checked == false) { | |
216 |
|
|
216 | boxes[i].checked = true; | |
217 |
|
|
217 | boxes[i].up('tr').addClassName('context-menu-selection'); | |
218 | } |
|
218 | } | |
219 | } |
|
219 | } | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | function window_size() { |
|
222 | function window_size() { | |
223 |
|
|
223 | var w; | |
224 |
|
|
224 | var h; | |
225 |
|
|
225 | if (window.innerWidth) { | |
226 |
|
|
226 | w = window.innerWidth; | |
227 |
|
|
227 | h = window.innerHeight; | |
228 |
|
|
228 | } else if (document.documentElement) { | |
229 |
|
|
229 | w = document.documentElement.clientWidth; | |
230 |
|
|
230 | h = document.documentElement.clientHeight; | |
231 |
|
|
231 | } else { | |
232 |
|
|
232 | w = document.body.clientWidth; | |
233 |
|
|
233 | h = document.body.clientHeight; | |
234 |
|
|
234 | } | |
235 |
|
|
235 | return {width: w, height: h}; | |
236 | } |
|
236 | } |
General Comments 0
You need to be logged in to leave comments.
Login now