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