Project

General

Profile

Defect #960 » context_menu_patch.diff

the patch - Mike Duchene, 2008-04-03 03:42

View differences:

context_menu.js 2008-04-02 21:25:48.000000000 -0400
93 93
  },
94 94
  
95 95
  showMenu: function(e) {
96
		$('context-menu').style['left'] = (Event.pointerX(e) + 'px');
97
		$('context-menu').style['top'] = (Event.pointerY(e) + 'px');		
98
		Element.update('context-menu', '');
99
		new Ajax.Updater({success:'context-menu'}, this.url, 
96
    var mouse_x = Event.pointerX(e);
97
    var mouse_y = Event.pointerY(e);
98
    var render_x = mouse_x;
99
    var render_y = mouse_y;
100
    var dims;
101
    var menu_width;
102
    var menu_height;
103
    var window_width;
104
    var window_height;
105
    var max_width;
106
    var max_height;
107

  
108
    $('context-menu').style['left'] = (render_x + 'px');
109
    $('context-menu').style['top'] = (render_y + 'px');		
110
    Element.update('context-menu', '');
111

  
112
    new Ajax.Updater({success:'context-menu'}, this.url, 
100 113
      {asynchronous:true,
101 114
       evalScripts:true,
102 115
       parameters:Form.serialize(Event.findElement(e, 'form')),
103 116
       onComplete:function(request){
117
	 dims = $('context-menu').getDimensions();
118
	 menu_width = dims.width;
119
	 menu_height = dims.height;
120

  
121
	 max_width = mouse_x + 2*menu_width;
122
	 max_height = mouse_y + menu_height;
123

  
124
	 var ws = window_size();
125
	 window_width = ws.width;
126
	 window_height = ws.height;
127

  
128
	 if (max_width > window_width) {
129
	   render_x -= menu_width;
130
	 }
131
	 if (max_height > window_height) {
132
	   render_y -= menu_height;
133
	 }
134
	 if (render_x <= 0) render_x = 1;
135
	 if (render_y <= 0) render_y = 1;
136
	 $('context-menu').style['left'] = (render_x + 'px');
137
	 $('context-menu').style['top'] = (render_y + 'px');		
138

  
139
// this code can be used for debugging
140
//	 alert("menu_width=" + menu_width + "\nmenu_height=" + menu_height + "\nmouse_x=" + mouse_x + "\nmouse_y=" + mouse_y +
141
//	 "\nwindow_width=" + window_width + "\nwindow_height=" + window_height + "\nrender_x=" + render_x + "\nrender_y=" + render_y);
142

  
104 143
         Effect.Appear('context-menu', {duration: 0.20});
105 144
         if (window.parseStylesheets) { window.parseStylesheets(); } // IE
106 145
      }})
......
159 198
		}
160 199
	}
161 200
}
201

  
202
function window_size() {
203
    var w;
204
    var h;
205
    if (window.innerWidth) {
206
	w = window.innerWidth;
207
	h = window.innerHeight;
208
    } else if (document.documentElement) {
209
	w = document.documentElement.clientWidth;
210
	h = document.documentElement.clientHeight;
211
    } else {
212
	w = document.body.clientWidth;
213
	h = document.body.clientHeight;
214
    }
215
    return {width: w, height: h};
216
}
(1-1/2)