##// END OF EJS Templates
Merged r11750 from trunk (#12650)....
Jean-Philippe Lang -
r11521:606762dcadbc
parent child
Show More
@@ -1,236 +1,236
1 1 var contextMenuObserving;
2 2 var contextMenuUrl;
3 3
4 4 function contextMenuRightClick(event) {
5 5 var target = $(event.target);
6 6 if (target.is('a')) {return;}
7 7 var tr = target.parents('tr').first();
8 8 if (!tr.hasClass('hascontextmenu')) {return;}
9 9 event.preventDefault();
10 10 if (!contextMenuIsSelected(tr)) {
11 11 contextMenuUnselectAll();
12 12 contextMenuAddSelection(tr);
13 13 contextMenuSetLastSelected(tr);
14 14 }
15 15 contextMenuShow(event);
16 16 }
17 17
18 18 function contextMenuClick(event) {
19 19 var target = $(event.target);
20 20 var lastSelected;
21 21
22 22 if (target.is('a') && target.hasClass('submenu')) {
23 23 event.preventDefault();
24 24 return;
25 25 }
26 26 contextMenuHide();
27 27 if (target.is('a') || target.is('img')) { return; }
28 28 if (event.which == 1 || (navigator.appVersion.match(/\bMSIE\b/))) {
29 29 var tr = target.parents('tr').first();
30 30 if (tr.length && tr.hasClass('hascontextmenu')) {
31 31 // a row was clicked, check if the click was on checkbox
32 32 if (target.is('input')) {
33 33 // a checkbox may be clicked
34 34 if (target.attr('checked')) {
35 35 tr.addClass('context-menu-selection');
36 36 } else {
37 37 tr.removeClass('context-menu-selection');
38 38 }
39 39 } else {
40 40 if (event.ctrlKey || event.metaKey) {
41 41 contextMenuToggleSelection(tr);
42 42 } else if (event.shiftKey) {
43 43 lastSelected = contextMenuLastSelected();
44 44 if (lastSelected.length) {
45 45 var toggling = false;
46 46 $('.hascontextmenu').each(function(){
47 47 if (toggling || $(this).is(tr)) {
48 48 contextMenuAddSelection($(this));
49 49 }
50 50 if ($(this).is(tr) || $(this).is(lastSelected)) {
51 51 toggling = !toggling;
52 52 }
53 53 });
54 54 } else {
55 55 contextMenuAddSelection(tr);
56 56 }
57 57 } else {
58 58 contextMenuUnselectAll();
59 59 contextMenuAddSelection(tr);
60 60 }
61 61 contextMenuSetLastSelected(tr);
62 62 }
63 63 } else {
64 64 // click is outside the rows
65 65 if (target.is('a') && (target.hasClass('disabled') || target.hasClass('submenu'))) {
66 66 event.preventDefault();
67 67 } else {
68 68 contextMenuUnselectAll();
69 69 }
70 70 }
71 71 }
72 72 }
73 73
74 74 function contextMenuCreate() {
75 75 if ($('#context-menu').length < 1) {
76 76 var menu = document.createElement("div");
77 77 menu.setAttribute("id", "context-menu");
78 78 menu.setAttribute("style", "display:none;");
79 79 document.getElementById("content").appendChild(menu);
80 80 }
81 81 }
82 82
83 83 function contextMenuShow(event) {
84 84 var mouse_x = event.pageX;
85 85 var mouse_y = event.pageY;
86 86 var render_x = mouse_x;
87 87 var render_y = mouse_y;
88 88 var dims;
89 89 var menu_width;
90 90 var menu_height;
91 91 var window_width;
92 92 var window_height;
93 93 var max_width;
94 94 var max_height;
95 95
96 96 $('#context-menu').css('left', (render_x + 'px'));
97 97 $('#context-menu').css('top', (render_y + 'px'));
98 98 $('#context-menu').html('');
99 99
100 100 $.ajax({
101 101 url: contextMenuUrl,
102 102 data: $(event.target).parents('form').first().serialize(),
103 103 success: function(data, textStatus, jqXHR) {
104 104 $('#context-menu').html(data);
105 105 menu_width = $('#context-menu').width();
106 106 menu_height = $('#context-menu').height();
107 107 max_width = mouse_x + 2*menu_width;
108 108 max_height = mouse_y + menu_height;
109 109
110 110 var ws = window_size();
111 111 window_width = ws.width;
112 112 window_height = ws.height;
113 113
114 114 /* display the menu above and/or to the left of the click if needed */
115 115 if (max_width > window_width) {
116 116 render_x -= menu_width;
117 117 $('#context-menu').addClass('reverse-x');
118 118 } else {
119 119 $('#context-menu').removeClass('reverse-x');
120 120 }
121 121 if (max_height > window_height) {
122 122 render_y -= menu_height;
123 123 $('#context-menu').addClass('reverse-y');
124 124 } else {
125 125 $('#context-menu').removeClass('reverse-y');
126 126 }
127 127 if (render_x <= 0) render_x = 1;
128 128 if (render_y <= 0) render_y = 1;
129 129 $('#context-menu').css('left', (render_x + 'px'));
130 130 $('#context-menu').css('top', (render_y + 'px'));
131 131 $('#context-menu').show();
132 132
133 133 //if (window.parseStylesheets) { window.parseStylesheets(); } // IE
134 134
135 135 }
136 136 });
137 137 }
138 138
139 139 function contextMenuSetLastSelected(tr) {
140 140 $('.cm-last').removeClass('cm-last');
141 141 tr.addClass('cm-last');
142 142 }
143 143
144 144 function contextMenuLastSelected() {
145 145 return $('.cm-last').first();
146 146 }
147 147
148 148 function contextMenuUnselectAll() {
149 149 $('.hascontextmenu').each(function(){
150 150 contextMenuRemoveSelection($(this));
151 151 });
152 152 $('.cm-last').removeClass('cm-last');
153 153 }
154 154
155 155 function contextMenuHide() {
156 156 $('#context-menu').hide();
157 157 }
158 158
159 159 function contextMenuToggleSelection(tr) {
160 160 if (contextMenuIsSelected(tr)) {
161 161 contextMenuRemoveSelection(tr);
162 162 } else {
163 163 contextMenuAddSelection(tr);
164 164 }
165 165 }
166 166
167 167 function contextMenuAddSelection(tr) {
168 168 tr.addClass('context-menu-selection');
169 169 contextMenuCheckSelectionBox(tr, true);
170 170 contextMenuClearDocumentSelection();
171 171 }
172 172
173 173 function contextMenuRemoveSelection(tr) {
174 174 tr.removeClass('context-menu-selection');
175 175 contextMenuCheckSelectionBox(tr, false);
176 176 }
177 177
178 178 function contextMenuIsSelected(tr) {
179 179 return tr.hasClass('context-menu-selection');
180 180 }
181 181
182 182 function contextMenuCheckSelectionBox(tr, checked) {
183 183 tr.find('input[type=checkbox]').attr('checked', checked);
184 184 }
185 185
186 186 function contextMenuClearDocumentSelection() {
187 187 // TODO
188 188 if (document.selection) {
189 document.selection.clear(); // IE
189 document.selection.empty(); // IE
190 190 } else {
191 191 window.getSelection().removeAllRanges();
192 192 }
193 193 }
194 194
195 195 function contextMenuInit(url) {
196 196 contextMenuUrl = url;
197 197 contextMenuCreate();
198 198 contextMenuUnselectAll();
199 199
200 200 if (!contextMenuObserving) {
201 201 $(document).click(contextMenuClick);
202 202 $(document).contextmenu(contextMenuRightClick);
203 203 contextMenuObserving = true;
204 204 }
205 205 }
206 206
207 207 function toggleIssuesSelection(el) {
208 208 var boxes = $(el).parents('form').find('input[type=checkbox]');
209 209 var all_checked = true;
210 210 boxes.each(function(){ if (!$(this).attr('checked')) { all_checked = false; } });
211 211 boxes.each(function(){
212 212 if (all_checked) {
213 213 $(this).removeAttr('checked');
214 214 $(this).parents('tr').removeClass('context-menu-selection');
215 215 } else if (!$(this).attr('checked')) {
216 216 $(this).attr('checked', true);
217 217 $(this).parents('tr').addClass('context-menu-selection');
218 218 }
219 219 });
220 220 }
221 221
222 222 function window_size() {
223 223 var w;
224 224 var h;
225 225 if (window.innerWidth) {
226 226 w = window.innerWidth;
227 227 h = window.innerHeight;
228 228 } else if (document.documentElement) {
229 229 w = document.documentElement.clientWidth;
230 230 h = document.documentElement.clientHeight;
231 231 } else {
232 232 w = document.body.clientWidth;
233 233 h = document.body.clientHeight;
234 234 }
235 235 return {width: w, height: h};
236 236 }
General Comments 0
You need to be logged in to leave comments. Login now