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