@@ -1,231 +1,233 | |||||
1 | /* redMine - project management software |
|
1 | /* redMine - project management software | |
2 | Copyright (C) 2006-2008 Jean-Philippe Lang */ |
|
2 | Copyright (C) 2006-2008 Jean-Philippe Lang */ | |
3 |
|
3 | |||
4 | var observingContextMenuClick; |
|
4 | var observingContextMenuClick; | |
5 |
|
5 | |||
6 | ContextMenu = Class.create(); |
|
6 | ContextMenu = Class.create(); | |
7 | ContextMenu.prototype = { |
|
7 | ContextMenu.prototype = { | |
8 | initialize: function (url) { |
|
8 | initialize: function (url) { | |
9 | this.url = url; |
|
9 | this.url = url; | |
10 | this.createMenu(); |
|
10 | this.createMenu(); | |
11 |
|
11 | |||
12 | // prevent text selection in the issue list |
|
|||
13 | var tables = $$('table.issues'); |
|
|||
14 | for (i=0; i<tables.length; i++) { |
|
|||
15 | tables[i].onselectstart = function () { return false; } // ie |
|
|||
16 | tables[i].onmousedown = function () { return false; } // mozilla |
|
|||
17 | } |
|
|||
18 |
|
||||
19 | if (!observingContextMenuClick) { |
|
12 | if (!observingContextMenuClick) { | |
20 | Event.observe(document, 'click', this.Click.bindAsEventListener(this)); |
|
13 | Event.observe(document, 'click', this.Click.bindAsEventListener(this)); | |
21 | Event.observe(document, (window.opera ? 'click' : 'contextmenu'), this.RightClick.bindAsEventListener(this)); |
|
14 | Event.observe(document, (window.opera ? 'click' : 'contextmenu'), this.RightClick.bindAsEventListener(this)); | |
22 | observingContextMenuClick = true; |
|
15 | observingContextMenuClick = true; | |
23 | } |
|
16 | } | |
24 |
|
17 | |||
25 | this.unselectAll(); |
|
18 | this.unselectAll(); | |
26 | this.lastSelected = null; |
|
19 | this.lastSelected = null; | |
27 | }, |
|
20 | }, | |
28 |
|
21 | |||
29 | RightClick: function(e) { |
|
22 | RightClick: function(e) { | |
30 | this.hideMenu(); |
|
23 | this.hideMenu(); | |
31 | // do not show the context menu on links |
|
24 | // do not show the context menu on links | |
32 | if (Event.element(e).tagName == 'A') { return; } |
|
25 | if (Event.element(e).tagName == 'A') { return; } | |
33 | // right-click simulated by Alt+Click with Opera |
|
26 | // right-click simulated by Alt+Click with Opera | |
34 | if (window.opera && !e.altKey) { return; } |
|
27 | if (window.opera && !e.altKey) { return; } | |
35 | var tr = Event.findElement(e, 'tr'); |
|
28 | var tr = Event.findElement(e, 'tr'); | |
36 | if (tr == document || tr == undefined || !tr.hasClassName('hascontextmenu')) { return; } |
|
29 | if (tr == document || tr == undefined || !tr.hasClassName('hascontextmenu')) { return; } | |
37 | Event.stop(e); |
|
30 | Event.stop(e); | |
38 | if (!this.isSelected(tr)) { |
|
31 | if (!this.isSelected(tr)) { | |
39 | this.unselectAll(); |
|
32 | this.unselectAll(); | |
40 | this.addSelection(tr); |
|
33 | this.addSelection(tr); | |
41 | this.lastSelected = tr; |
|
34 | this.lastSelected = tr; | |
42 | } |
|
35 | } | |
43 | this.showMenu(e); |
|
36 | this.showMenu(e); | |
44 | }, |
|
37 | }, | |
45 |
|
38 | |||
46 | Click: function(e) { |
|
39 | Click: function(e) { | |
47 | this.hideMenu(); |
|
40 | this.hideMenu(); | |
48 | if (Event.element(e).tagName == 'A') { return; } |
|
41 | if (Event.element(e).tagName == 'A') { return; } | |
49 | if (window.opera && e.altKey) { return; } |
|
42 | if (window.opera && e.altKey) { return; } | |
50 | if (Event.isLeftClick(e) || (navigator.appVersion.match(/\bMSIE\b/))) { |
|
43 | if (Event.isLeftClick(e) || (navigator.appVersion.match(/\bMSIE\b/))) { | |
51 | var tr = Event.findElement(e, 'tr'); |
|
44 | var tr = Event.findElement(e, 'tr'); | |
52 | if (tr!=null && tr!=document && tr.hasClassName('hascontextmenu')) { |
|
45 | if (tr!=null && tr!=document && tr.hasClassName('hascontextmenu')) { | |
53 | // a row was clicked, check if the click was on checkbox |
|
46 | // a row was clicked, check if the click was on checkbox | |
54 | var box = Event.findElement(e, 'input'); |
|
47 | var box = Event.findElement(e, 'input'); | |
55 | if (box!=document && box!=undefined) { |
|
48 | if (box!=document && box!=undefined) { | |
56 | // a checkbox may be clicked |
|
49 | // a checkbox may be clicked | |
57 | if (box.checked) { |
|
50 | if (box.checked) { | |
58 | tr.addClassName('context-menu-selection'); |
|
51 | tr.addClassName('context-menu-selection'); | |
59 | } else { |
|
52 | } else { | |
60 | tr.removeClassName('context-menu-selection'); |
|
53 | tr.removeClassName('context-menu-selection'); | |
61 | } |
|
54 | } | |
62 | } else { |
|
55 | } else { | |
63 | if (e.ctrlKey) { |
|
56 | if (e.ctrlKey) { | |
64 | this.toggleSelection(tr); |
|
57 | this.toggleSelection(tr); | |
65 | } else if (e.shiftKey) { |
|
58 | } else if (e.shiftKey) { | |
66 | if (this.lastSelected != null) { |
|
59 | if (this.lastSelected != null) { | |
67 | var toggling = false; |
|
60 | var toggling = false; | |
68 | var rows = $$('.hascontextmenu'); |
|
61 | var rows = $$('.hascontextmenu'); | |
69 | for (i=0; i<rows.length; i++) { |
|
62 | for (i=0; i<rows.length; i++) { | |
70 | if (toggling || rows[i]==tr) { |
|
63 | if (toggling || rows[i]==tr) { | |
71 | this.addSelection(rows[i]); |
|
64 | this.addSelection(rows[i]); | |
72 | } |
|
65 | } | |
73 | if (rows[i]==tr || rows[i]==this.lastSelected) { |
|
66 | if (rows[i]==tr || rows[i]==this.lastSelected) { | |
74 | toggling = !toggling; |
|
67 | toggling = !toggling; | |
75 | } |
|
68 | } | |
76 | } |
|
69 | } | |
77 | } else { |
|
70 | } else { | |
78 | this.addSelection(tr); |
|
71 | this.addSelection(tr); | |
79 | } |
|
72 | } | |
80 | } else { |
|
73 | } else { | |
81 | this.unselectAll(); |
|
74 | this.unselectAll(); | |
82 | this.addSelection(tr); |
|
75 | this.addSelection(tr); | |
83 | } |
|
76 | } | |
84 | this.lastSelected = tr; |
|
77 | this.lastSelected = tr; | |
85 | } |
|
78 | } | |
86 | } else { |
|
79 | } else { | |
87 | // click is outside the rows |
|
80 | // click is outside the rows | |
88 | var t = Event.findElement(e, 'a'); |
|
81 | var t = Event.findElement(e, 'a'); | |
89 | if ((t != document) && (Element.hasClassName(t, 'disabled') || Element.hasClassName(t, 'submenu'))) { |
|
82 | if ((t != document) && (Element.hasClassName(t, 'disabled') || Element.hasClassName(t, 'submenu'))) { | |
90 | Event.stop(e); |
|
83 | Event.stop(e); | |
91 | } |
|
84 | } | |
92 | } |
|
85 | } | |
93 | } |
|
86 | } | |
94 | else{ |
|
87 | else{ | |
95 | this.RightClick(e); |
|
88 | this.RightClick(e); | |
96 | } |
|
89 | } | |
97 | }, |
|
90 | }, | |
98 |
|
91 | |||
99 | createMenu: function() { |
|
92 | createMenu: function() { | |
100 | if (!$('context-menu')) { |
|
93 | if (!$('context-menu')) { | |
101 | var menu = document.createElement("div"); |
|
94 | var menu = document.createElement("div"); | |
102 | menu.setAttribute("id", "context-menu"); |
|
95 | menu.setAttribute("id", "context-menu"); | |
103 | menu.setAttribute("style", "display:none;"); |
|
96 | menu.setAttribute("style", "display:none;"); | |
104 | document.getElementById("content").appendChild(menu); |
|
97 | document.getElementById("content").appendChild(menu); | |
105 | } |
|
98 | } | |
106 | }, |
|
99 | }, | |
107 |
|
100 | |||
108 | showMenu: function(e) { |
|
101 | showMenu: function(e) { | |
109 | var mouse_x = Event.pointerX(e); |
|
102 | var mouse_x = Event.pointerX(e); | |
110 | var mouse_y = Event.pointerY(e); |
|
103 | var mouse_y = Event.pointerY(e); | |
111 | var render_x = mouse_x; |
|
104 | var render_x = mouse_x; | |
112 | var render_y = mouse_y; |
|
105 | var render_y = mouse_y; | |
113 | var dims; |
|
106 | var dims; | |
114 | var menu_width; |
|
107 | var menu_width; | |
115 | var menu_height; |
|
108 | var menu_height; | |
116 | var window_width; |
|
109 | var window_width; | |
117 | var window_height; |
|
110 | var window_height; | |
118 | var max_width; |
|
111 | var max_width; | |
119 | var max_height; |
|
112 | var max_height; | |
120 |
|
113 | |||
121 | $('context-menu').style['left'] = (render_x + 'px'); |
|
114 | $('context-menu').style['left'] = (render_x + 'px'); | |
122 | $('context-menu').style['top'] = (render_y + 'px'); |
|
115 | $('context-menu').style['top'] = (render_y + 'px'); | |
123 | Element.update('context-menu', ''); |
|
116 | Element.update('context-menu', ''); | |
124 |
|
117 | |||
125 | new Ajax.Updater({success:'context-menu'}, this.url, |
|
118 | new Ajax.Updater({success:'context-menu'}, this.url, | |
126 | {asynchronous:true, |
|
119 | {asynchronous:true, | |
127 | evalScripts:true, |
|
120 | evalScripts:true, | |
128 | parameters:Form.serialize(Event.findElement(e, 'form')), |
|
121 | parameters:Form.serialize(Event.findElement(e, 'form')), | |
129 | onComplete:function(request){ |
|
122 | onComplete:function(request){ | |
130 | dims = $('context-menu').getDimensions(); |
|
123 | dims = $('context-menu').getDimensions(); | |
131 | menu_width = dims.width; |
|
124 | menu_width = dims.width; | |
132 | menu_height = dims.height; |
|
125 | menu_height = dims.height; | |
133 | max_width = mouse_x + 2*menu_width; |
|
126 | max_width = mouse_x + 2*menu_width; | |
134 | max_height = mouse_y + menu_height; |
|
127 | max_height = mouse_y + menu_height; | |
135 |
|
128 | |||
136 | var ws = window_size(); |
|
129 | var ws = window_size(); | |
137 | window_width = ws.width; |
|
130 | window_width = ws.width; | |
138 | window_height = ws.height; |
|
131 | window_height = ws.height; | |
139 |
|
132 | |||
140 | /* display the menu above and/or to the left of the click if needed */ |
|
133 | /* display the menu above and/or to the left of the click if needed */ | |
141 | if (max_width > window_width) { |
|
134 | if (max_width > window_width) { | |
142 | render_x -= menu_width; |
|
135 | render_x -= menu_width; | |
143 | $('context-menu').addClassName('reverse-x'); |
|
136 | $('context-menu').addClassName('reverse-x'); | |
144 | } else { |
|
137 | } else { | |
145 | $('context-menu').removeClassName('reverse-x'); |
|
138 | $('context-menu').removeClassName('reverse-x'); | |
146 | } |
|
139 | } | |
147 | if (max_height > window_height) { |
|
140 | if (max_height > window_height) { | |
148 | render_y -= menu_height; |
|
141 | render_y -= menu_height; | |
149 | $('context-menu').addClassName('reverse-y'); |
|
142 | $('context-menu').addClassName('reverse-y'); | |
150 | } else { |
|
143 | } else { | |
151 | $('context-menu').removeClassName('reverse-y'); |
|
144 | $('context-menu').removeClassName('reverse-y'); | |
152 | } |
|
145 | } | |
153 | if (render_x <= 0) render_x = 1; |
|
146 | if (render_x <= 0) render_x = 1; | |
154 | if (render_y <= 0) render_y = 1; |
|
147 | if (render_y <= 0) render_y = 1; | |
155 | $('context-menu').style['left'] = (render_x + 'px'); |
|
148 | $('context-menu').style['left'] = (render_x + 'px'); | |
156 | $('context-menu').style['top'] = (render_y + 'px'); |
|
149 | $('context-menu').style['top'] = (render_y + 'px'); | |
157 |
|
150 | |||
158 | Effect.Appear('context-menu', {duration: 0.20}); |
|
151 | Effect.Appear('context-menu', {duration: 0.20}); | |
159 | if (window.parseStylesheets) { window.parseStylesheets(); } // IE |
|
152 | if (window.parseStylesheets) { window.parseStylesheets(); } // IE | |
160 | }}) |
|
153 | }}) | |
161 | }, |
|
154 | }, | |
162 |
|
155 | |||
163 | hideMenu: function() { |
|
156 | hideMenu: function() { | |
164 | Element.hide('context-menu'); |
|
157 | Element.hide('context-menu'); | |
165 | }, |
|
158 | }, | |
166 |
|
159 | |||
167 | addSelection: function(tr) { |
|
160 | addSelection: function(tr) { | |
168 | tr.addClassName('context-menu-selection'); |
|
161 | tr.addClassName('context-menu-selection'); | |
169 | this.checkSelectionBox(tr, true); |
|
162 | this.checkSelectionBox(tr, true); | |
|
163 | this.clearDocumentSelection(); | |||
170 | }, |
|
164 | }, | |
171 |
|
165 | |||
172 | toggleSelection: function(tr) { |
|
166 | toggleSelection: function(tr) { | |
173 | if (this.isSelected(tr)) { |
|
167 | if (this.isSelected(tr)) { | |
174 | this.removeSelection(tr); |
|
168 | this.removeSelection(tr); | |
175 | } else { |
|
169 | } else { | |
176 | this.addSelection(tr); |
|
170 | this.addSelection(tr); | |
177 | } |
|
171 | } | |
178 | }, |
|
172 | }, | |
179 |
|
173 | |||
180 | removeSelection: function(tr) { |
|
174 | removeSelection: function(tr) { | |
181 | tr.removeClassName('context-menu-selection'); |
|
175 | tr.removeClassName('context-menu-selection'); | |
182 | this.checkSelectionBox(tr, false); |
|
176 | this.checkSelectionBox(tr, false); | |
183 | }, |
|
177 | }, | |
184 |
|
178 | |||
185 | unselectAll: function() { |
|
179 | unselectAll: function() { | |
186 | var rows = $$('.hascontextmenu'); |
|
180 | var rows = $$('.hascontextmenu'); | |
187 | for (i=0; i<rows.length; i++) { |
|
181 | for (i=0; i<rows.length; i++) { | |
188 | this.removeSelection(rows[i]); |
|
182 | this.removeSelection(rows[i]); | |
189 | } |
|
183 | } | |
190 | }, |
|
184 | }, | |
191 |
|
185 | |||
192 | checkSelectionBox: function(tr, checked) { |
|
186 | checkSelectionBox: function(tr, checked) { | |
193 | var inputs = Element.getElementsBySelector(tr, 'input'); |
|
187 | var inputs = Element.getElementsBySelector(tr, 'input'); | |
194 | if (inputs.length > 0) { inputs[0].checked = checked; } |
|
188 | if (inputs.length > 0) { inputs[0].checked = checked; } | |
195 | }, |
|
189 | }, | |
196 |
|
190 | |||
197 | isSelected: function(tr) { |
|
191 | isSelected: function(tr) { | |
198 | return Element.hasClassName(tr, 'context-menu-selection'); |
|
192 | return Element.hasClassName(tr, 'context-menu-selection'); | |
|
193 | }, | |||
|
194 | ||||
|
195 | clearDocumentSelection: function() { | |||
|
196 | if (document.selection) { | |||
|
197 | document.selection.clear(); // IE | |||
|
198 | } else { | |||
|
199 | window.getSelection().removeAllRanges(); | |||
|
200 | } | |||
199 | } |
|
201 | } | |
200 | } |
|
202 | } | |
201 |
|
203 | |||
202 | function toggleIssuesSelection(el) { |
|
204 | function toggleIssuesSelection(el) { | |
203 | var boxes = el.getElementsBySelector('input[type=checkbox]'); |
|
205 | var boxes = el.getElementsBySelector('input[type=checkbox]'); | |
204 | var all_checked = true; |
|
206 | var all_checked = true; | |
205 | for (i = 0; i < boxes.length; i++) { if (boxes[i].checked == false) { all_checked = false; } } |
|
207 | for (i = 0; i < boxes.length; i++) { if (boxes[i].checked == false) { all_checked = false; } } | |
206 | for (i = 0; i < boxes.length; i++) { |
|
208 | for (i = 0; i < boxes.length; i++) { | |
207 | if (all_checked) { |
|
209 | if (all_checked) { | |
208 | boxes[i].checked = false; |
|
210 | boxes[i].checked = false; | |
209 | boxes[i].up('tr').removeClassName('context-menu-selection'); |
|
211 | boxes[i].up('tr').removeClassName('context-menu-selection'); | |
210 | } else if (boxes[i].checked == false) { |
|
212 | } else if (boxes[i].checked == false) { | |
211 | boxes[i].checked = true; |
|
213 | boxes[i].checked = true; | |
212 | boxes[i].up('tr').addClassName('context-menu-selection'); |
|
214 | boxes[i].up('tr').addClassName('context-menu-selection'); | |
213 | } |
|
215 | } | |
214 | } |
|
216 | } | |
215 | } |
|
217 | } | |
216 |
|
218 | |||
217 | function window_size() { |
|
219 | function window_size() { | |
218 | var w; |
|
220 | var w; | |
219 | var h; |
|
221 | var h; | |
220 | if (window.innerWidth) { |
|
222 | if (window.innerWidth) { | |
221 | w = window.innerWidth; |
|
223 | w = window.innerWidth; | |
222 | h = window.innerHeight; |
|
224 | h = window.innerHeight; | |
223 | } else if (document.documentElement) { |
|
225 | } else if (document.documentElement) { | |
224 | w = document.documentElement.clientWidth; |
|
226 | w = document.documentElement.clientWidth; | |
225 | h = document.documentElement.clientHeight; |
|
227 | h = document.documentElement.clientHeight; | |
226 | } else { |
|
228 | } else { | |
227 | w = document.body.clientWidth; |
|
229 | w = document.body.clientWidth; | |
228 | h = document.body.clientHeight; |
|
230 | h = document.body.clientHeight; | |
229 | } |
|
231 | } | |
230 | return {width: w, height: h}; |
|
232 | return {width: w, height: h}; | |
231 | } |
|
233 | } |
General Comments 0
You need to be logged in to leave comments.
Login now