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