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