##// END OF EJS Templates
replace tabs to spaces and fix indents public/javascripts/context_menu.js...
Toshi MARUYAMA -
r8769:fc7b71b334a4
parent child
Show More
@@ -5,42 +5,42 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 this.createMenu();
10 this.createMenu();
11
11
12 if (!observingContextMenuClick) {
12 if (!observingContextMenuClick) {
13 Event.observe(document, 'click', this.Click.bindAsEventListener(this));
13 Event.observe(document, 'click', this.Click.bindAsEventListener(this));
14 Event.observe(document, 'contextmenu', this.RightClick.bindAsEventListener(this));
14 Event.observe(document, 'contextmenu', this.RightClick.bindAsEventListener(this));
15 observingContextMenuClick = true;
15 observingContextMenuClick = true;
16 }
16 }
17
17
18 this.unselectAll();
18 this.unselectAll();
19 this.lastSelected = null;
19 this.lastSelected = null;
20 },
20 },
21
21
22 RightClick: function(e) {
22 RightClick: function(e) {
23 this.hideMenu();
23 this.hideMenu();
24 // do not show the context menu on links
24 // do not show the context menu on links
25 if (Event.element(e).tagName == 'A') { return; }
25 if (Event.element(e).tagName == 'A') { return; }
26 var tr = Event.findElement(e, 'tr');
26 var tr = Event.findElement(e, 'tr');
27 if (tr == document || tr == undefined || !tr.hasClassName('hascontextmenu')) { return; }
27 if (tr == document || tr == undefined || !tr.hasClassName('hascontextmenu')) { return; }
28 Event.stop(e);
28 Event.stop(e);
29 if (!this.isSelected(tr)) {
29 if (!this.isSelected(tr)) {
30 this.unselectAll();
30 this.unselectAll();
31 this.addSelection(tr);
31 this.addSelection(tr);
32 this.lastSelected = tr;
32 this.lastSelected = tr;
33 }
33 }
34 this.showMenu(e);
34 this.showMenu(e);
35 },
35 },
36
36
37 Click: function(e) {
37 Click: function(e) {
38 if (Event.element(e).tagName == 'A' && Event.element(e).hasClassName('submenu')) {
38 if (Event.element(e).tagName == 'A' && Event.element(e).hasClassName('submenu')) {
39 Event.stop(e)
39 Event.stop(e)
40 return;
40 return;
41 }
41 }
42 this.hideMenu();
42 this.hideMenu();
43 if (Event.element(e).tagName == 'A' || Event.element(e).tagName == 'IMG') { return; }
43 if (Event.element(e).tagName == 'A' || Event.element(e).tagName == 'IMG') { return; }
44 if (Event.isLeftClick(e) || (navigator.appVersion.match(/\bMSIE\b/))) {
44 if (Event.isLeftClick(e) || (navigator.appVersion.match(/\bMSIE\b/))) {
45 var tr = Event.findElement(e, 'tr');
45 var tr = Event.findElement(e, 'tr');
46 if (tr!=null && tr!=document && tr.hasClassName('hascontextmenu')) {
46 if (tr!=null && tr!=document && tr.hasClassName('hascontextmenu')) {
@@ -114,7 +114,7 ContextMenu.prototype = {
114 var max_height;
114 var max_height;
115
115
116 $('context-menu').style['left'] = (render_x + 'px');
116 $('context-menu').style['left'] = (render_x + 'px');
117 $('context-menu').style['top'] = (render_y + 'px');
117 $('context-menu').style['top'] = (render_y + 'px');
118 Element.update('context-menu', '');
118 Element.update('context-menu', '');
119
119
120 new Ajax.Updater({success:'context-menu'}, this.url,
120 new Ajax.Updater({success:'context-menu'}, this.url,
@@ -123,34 +123,34 ContextMenu.prototype = {
123 evalScripts:true,
123 evalScripts:true,
124 parameters:Form.serialize(Event.findElement(e, 'form')),
124 parameters:Form.serialize(Event.findElement(e, 'form')),
125 onComplete:function(request){
125 onComplete:function(request){
126 dims = $('context-menu').getDimensions();
126 dims = $('context-menu').getDimensions();
127 menu_width = dims.width;
127 menu_width = dims.width;
128 menu_height = dims.height;
128 menu_height = dims.height;
129 max_width = mouse_x + 2*menu_width;
129 max_width = mouse_x + 2*menu_width;
130 max_height = mouse_y + menu_height;
130 max_height = mouse_y + menu_height;
131
131
132 var ws = window_size();
132 var ws = window_size();
133 window_width = ws.width;
133 window_width = ws.width;
134 window_height = ws.height;
134 window_height = ws.height;
135
135
136 /* display the menu above and/or to the left of the click if needed */
136 /* display the menu above and/or to the left of the click if needed */
137 if (max_width > window_width) {
137 if (max_width > window_width) {
138 render_x -= menu_width;
138 render_x -= menu_width;
139 $('context-menu').addClassName('reverse-x');
139 $('context-menu').addClassName('reverse-x');
140 } else {
140 } else {
141 $('context-menu').removeClassName('reverse-x');
141 $('context-menu').removeClassName('reverse-x');
142 }
142 }
143 if (max_height > window_height) {
143 if (max_height > window_height) {
144 render_y -= menu_height;
144 render_y -= menu_height;
145 $('context-menu').addClassName('reverse-y');
145 $('context-menu').addClassName('reverse-y');
146 } else {
146 } else {
147 $('context-menu').removeClassName('reverse-y');
147 $('context-menu').removeClassName('reverse-y');
148 }
148 }
149 if (render_x <= 0) render_x = 1;
149 if (render_x <= 0) render_x = 1;
150 if (render_y <= 0) render_y = 1;
150 if (render_y <= 0) render_y = 1;
151 $('context-menu').style['left'] = (render_x + 'px');
151 $('context-menu').style['left'] = (render_x + 'px');
152 $('context-menu').style['top'] = (render_y + 'px');
152 $('context-menu').style['top'] = (render_y + 'px');
153
153
154 Effect.Appear('context-menu', {duration: 0.20});
154 Effect.Appear('context-menu', {duration: 0.20});
155 if (window.parseStylesheets) { window.parseStylesheets(); } // IE
155 if (window.parseStylesheets) { window.parseStylesheets(); } // IE
156 }})
156 }})
@@ -187,8 +187,8 ContextMenu.prototype = {
187 },
187 },
188
188
189 checkSelectionBox: function(tr, checked) {
189 checkSelectionBox: function(tr, checked) {
190 var inputs = Element.getElementsBySelector(tr, 'input');
190 var inputs = Element.getElementsBySelector(tr, 'input');
191 if (inputs.length > 0) { inputs[0].checked = checked; }
191 if (inputs.length > 0) { inputs[0].checked = checked; }
192 },
192 },
193
193
194 isSelected: function(tr) {
194 isSelected: function(tr) {
@@ -205,32 +205,32 ContextMenu.prototype = {
205 }
205 }
206
206
207 function toggleIssuesSelection(el) {
207 function toggleIssuesSelection(el) {
208 var boxes = el.getElementsBySelector('input[type=checkbox]');
208 var boxes = el.getElementsBySelector('input[type=checkbox]');
209 var all_checked = true;
209 var all_checked = true;
210 for (i = 0; i < boxes.length; i++) { if (boxes[i].checked == false) { all_checked = false; } }
210 for (i = 0; i < boxes.length; i++) { if (boxes[i].checked == false) { all_checked = false; } }
211 for (i = 0; i < boxes.length; i++) {
211 for (i = 0; i < boxes.length; i++) {
212 if (all_checked) {
212 if (all_checked) {
213 boxes[i].checked = false;
213 boxes[i].checked = false;
214 boxes[i].up('tr').removeClassName('context-menu-selection');
214 boxes[i].up('tr').removeClassName('context-menu-selection');
215 } else if (boxes[i].checked == false) {
215 } else if (boxes[i].checked == false) {
216 boxes[i].checked = true;
216 boxes[i].checked = true;
217 boxes[i].up('tr').addClassName('context-menu-selection');
217 boxes[i].up('tr').addClassName('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