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