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