@@ -1,236 +1,236 | |||
|
1 |
/* |
|
|
2 |
Copyright (C) 2006-20 |
|
|
1 | /* Redmine - project management software | |
|
2 | Copyright (C) 2006-2012 Jean-Philippe Lang */ | |
|
3 | 3 | |
|
4 | 4 | var observingContextMenuClick; |
|
5 | 5 | |
|
6 | 6 | ContextMenu = Class.create(); |
|
7 | 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 | 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 | 45 | var tr = Event.findElement(e, 'tr'); |
|
46 | 46 | if (tr!=null && tr!=document && tr.hasClassName('hascontextmenu')) { |
|
47 | 47 | // a row was clicked, check if the click was on checkbox |
|
48 | 48 | var box = Event.findElement(e, 'input'); |
|
49 | 49 | if (box!=document && box!=undefined) { |
|
50 | 50 | // a checkbox may be clicked |
|
51 | 51 | if (box.checked) { |
|
52 | 52 | tr.addClassName('context-menu-selection'); |
|
53 | 53 | } else { |
|
54 | 54 | tr.removeClassName('context-menu-selection'); |
|
55 | 55 | } |
|
56 | 56 | } else { |
|
57 | 57 | if (e.ctrlKey || e.metaKey) { |
|
58 | 58 | this.toggleSelection(tr); |
|
59 | 59 | } else if (e.shiftKey) { |
|
60 | 60 | if (this.lastSelected != null) { |
|
61 | 61 | var toggling = false; |
|
62 | 62 | var rows = $$('.hascontextmenu'); |
|
63 | 63 | for (i=0; i<rows.length; i++) { |
|
64 | 64 | if (toggling || rows[i]==tr) { |
|
65 | 65 | this.addSelection(rows[i]); |
|
66 | 66 | } |
|
67 | 67 | if (rows[i]==tr || rows[i]==this.lastSelected) { |
|
68 | 68 | toggling = !toggling; |
|
69 | 69 | } |
|
70 | 70 | } |
|
71 | 71 | } else { |
|
72 | 72 | this.addSelection(tr); |
|
73 | 73 | } |
|
74 | 74 | } else { |
|
75 | 75 | this.unselectAll(); |
|
76 | 76 | this.addSelection(tr); |
|
77 | 77 | } |
|
78 | 78 | this.lastSelected = tr; |
|
79 | 79 | } |
|
80 | 80 | } else { |
|
81 | 81 | // click is outside the rows |
|
82 | 82 | var t = Event.findElement(e, 'a'); |
|
83 | 83 | if (t == document || t == undefined) { |
|
84 | 84 | this.unselectAll(); |
|
85 | 85 | } else { |
|
86 | 86 | if (Element.hasClassName(t, 'disabled') || Element.hasClassName(t, 'submenu')) { |
|
87 | 87 | Event.stop(e); |
|
88 | 88 | } |
|
89 | 89 | } |
|
90 | 90 | } |
|
91 | 91 | } |
|
92 | 92 | }, |
|
93 | ||
|
93 | ||
|
94 | 94 | createMenu: function() { |
|
95 | 95 | if (!$('context-menu')) { |
|
96 | 96 | var menu = document.createElement("div"); |
|
97 | 97 | menu.setAttribute("id", "context-menu"); |
|
98 | 98 | menu.setAttribute("style", "display:none;"); |
|
99 | 99 | document.getElementById("content").appendChild(menu); |
|
100 | 100 | } |
|
101 | 101 | }, |
|
102 | ||
|
102 | ||
|
103 | 103 | showMenu: function(e) { |
|
104 | 104 | var mouse_x = Event.pointerX(e); |
|
105 | 105 | var mouse_y = Event.pointerY(e); |
|
106 | 106 | var render_x = mouse_x; |
|
107 | 107 | var render_y = mouse_y; |
|
108 | 108 | var dims; |
|
109 | 109 | var menu_width; |
|
110 | 110 | var menu_height; |
|
111 | 111 | var window_width; |
|
112 | 112 | var window_height; |
|
113 | 113 | var max_width; |
|
114 | 114 | var max_height; |
|
115 | 115 | |
|
116 | 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 | 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, | |
|
121 | 121 | {asynchronous:true, |
|
122 | 122 | method: 'get', |
|
123 | 123 | evalScripts:true, |
|
124 | 124 | parameters:Form.serialize(Event.findElement(e, 'form')), |
|
125 | 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 | 154 | Effect.Appear('context-menu', {duration: 0.20}); |
|
155 | 155 | if (window.parseStylesheets) { window.parseStylesheets(); } // IE |
|
156 | 156 | }}) |
|
157 | 157 | }, |
|
158 | ||
|
158 | ||
|
159 | 159 | hideMenu: function() { |
|
160 | 160 | Element.hide('context-menu'); |
|
161 | 161 | }, |
|
162 | ||
|
162 | ||
|
163 | 163 | addSelection: function(tr) { |
|
164 | 164 | tr.addClassName('context-menu-selection'); |
|
165 | 165 | this.checkSelectionBox(tr, true); |
|
166 | 166 | this.clearDocumentSelection(); |
|
167 | 167 | }, |
|
168 | ||
|
168 | ||
|
169 | 169 | toggleSelection: function(tr) { |
|
170 | 170 | if (this.isSelected(tr)) { |
|
171 | 171 | this.removeSelection(tr); |
|
172 | 172 | } else { |
|
173 | 173 | this.addSelection(tr); |
|
174 | 174 | } |
|
175 | 175 | }, |
|
176 | ||
|
176 | ||
|
177 | 177 | removeSelection: function(tr) { |
|
178 | 178 | tr.removeClassName('context-menu-selection'); |
|
179 | 179 | this.checkSelectionBox(tr, false); |
|
180 | 180 | }, |
|
181 | ||
|
181 | ||
|
182 | 182 | unselectAll: function() { |
|
183 | 183 | var rows = $$('.hascontextmenu'); |
|
184 | 184 | for (i=0; i<rows.length; i++) { |
|
185 | 185 | this.removeSelection(rows[i]); |
|
186 | 186 | } |
|
187 | 187 | }, |
|
188 | ||
|
188 | ||
|
189 | 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 | 194 | isSelected: function(tr) { |
|
195 | 195 | return Element.hasClassName(tr, 'context-menu-selection'); |
|
196 | 196 | }, |
|
197 | ||
|
197 | ||
|
198 | 198 | clearDocumentSelection: function() { |
|
199 | 199 | if (document.selection) { |
|
200 | 200 | document.selection.clear(); // IE |
|
201 | 201 | } else { |
|
202 | 202 | window.getSelection().removeAllRanges(); |
|
203 | 203 | } |
|
204 | 204 | } |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 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 | 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