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