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