3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.EventManager
10 Ext.apply(Ext.EventManager, function(){
16 propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/,
19 // note 1: IE fires ONLY the keydown event on specialkey autorepeat
20 // note 2: Safari < 3.1, Gecko (Mac/Linux) & Opera fire only the keypress event on specialkey autorepeat
21 // (research done by @Jan Wolter at http://unixpapa.com/js/key.html)
22 useKeydown = Ext.isWebKit ?
23 Ext.num(navigator.userAgent.match(/AppleWebKit\/(\d+)/)[1]) >= 525 :
24 !((Ext.isGecko && !Ext.isWindows) || Ext.isOpera);
28 doResizeEvent: function(){
29 var h = D.getViewHeight(),
32 //whacky problem in IE where the resize event will fire even though the w/h are the same.
33 if(curHeight != h || curWidth != w){
34 resizeEvent.fire(curWidth = w, curHeight = h);
39 * Adds a listener to be notified when the browser window is resized and provides resize event buffering (50 milliseconds),
40 * passes new viewport width and height to handlers.
41 * @param {Function} fn The handler function the window resize event invokes.
42 * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
43 * @param {boolean} options Options object as passed to {@link Ext.Element#addListener}
45 onWindowResize : function(fn, scope, options){
47 resizeEvent = new Ext.util.Event();
48 resizeTask = new Ext.util.DelayedTask(this.doResizeEvent);
49 Ext.EventManager.on(window, "resize", this.fireWindowResize, this);
51 resizeEvent.addListener(fn, scope, options);
54 // exposed only to allow manual firing
55 fireWindowResize : function(){
57 if((Ext.isIE||Ext.isAir) && resizeTask){
60 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
66 * Adds a listener to be notified when the user changes the active text size. Handler gets called with 2 params, the old size and the new size.
67 * @param {Function} fn The function the event invokes.
68 * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
69 * @param {boolean} options Options object as passed to {@link Ext.Element#addListener}
71 onTextResize : function(fn, scope, options){
73 textEvent = new Ext.util.Event();
74 var textEl = new Ext.Element(document.createElement('div'));
75 textEl.dom.className = 'x-text-resize';
76 textEl.dom.innerHTML = 'X';
77 textEl.appendTo(document.body);
78 textSize = textEl.dom.offsetHeight;
79 setInterval(function(){
80 if(textEl.dom.offsetHeight != textSize){
81 textEvent.fire(textSize, textSize = textEl.dom.offsetHeight);
83 }, this.textResizeInterval);
85 textEvent.addListener(fn, scope, options);
89 * Removes the passed window resize listener.
90 * @param {Function} fn The method the event invokes
91 * @param {Object} scope The scope of handler
93 removeResizeListener : function(fn, scope){
95 resizeEvent.removeListener(fn, scope);
100 fireResize : function(){
102 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
107 * The frequency, in milliseconds, to check for text resize events (defaults to 50)
109 textResizeInterval : 50,
112 * Url used for onDocumentReady with using SSL (defaults to Ext.SSL_SECURE_URL)
116 // protected for use inside the framework
117 // detects whether we should use keydown or keypress based on the browser.
118 useKeydown: useKeydown
122 Ext.EventManager.on = Ext.EventManager.addListener;
125 Ext.apply(Ext.EventObjectImpl.prototype, {
126 /** Key constant @type Number */
128 /** Key constant @type Number */
130 /** Key constant @type Number */
132 /** Key constant @type Number */
134 /** Key constant @type Number */
136 /** Key constant @type Number */
138 /** Key constant @type Number */
140 CONTROL : 17, // legacy
141 /** Key constant @type Number */
143 /** Key constant @type Number */
145 /** Key constant @type Number */
147 /** Key constant @type Number */
149 /** Key constant @type Number */
151 /** Key constant @type Number */
153 PAGEUP : 33, // legacy
154 /** Key constant @type Number */
156 PAGEDOWN : 34, // legacy
157 /** Key constant @type Number */
159 /** Key constant @type Number */
161 /** Key constant @type Number */
163 /** Key constant @type Number */
165 /** Key constant @type Number */
167 /** Key constant @type Number */
169 /** Key constant @type Number */
171 /** Key constant @type Number */
173 /** Key constant @type Number */
175 /** Key constant @type Number */
177 /** Key constant @type Number */
179 /** Key constant @type Number */
181 /** Key constant @type Number */
183 /** Key constant @type Number */
185 /** Key constant @type Number */
187 /** Key constant @type Number */
189 /** Key constant @type Number */
191 /** Key constant @type Number */
193 /** Key constant @type Number */
195 /** Key constant @type Number */
197 /** Key constant @type Number */
199 /** Key constant @type Number */
201 /** Key constant @type Number */
203 /** Key constant @type Number */
205 /** Key constant @type Number */
207 /** Key constant @type Number */
209 /** Key constant @type Number */
211 /** Key constant @type Number */
213 /** Key constant @type Number */
215 /** Key constant @type Number */
217 /** Key constant @type Number */
219 /** Key constant @type Number */
221 /** Key constant @type Number */
223 /** Key constant @type Number */
225 /** Key constant @type Number */
227 /** Key constant @type Number */
229 /** Key constant @type Number */
231 /** Key constant @type Number */
233 /** Key constant @type Number */
235 /** Key constant @type Number */
237 /** Key constant @type Number */
239 /** Key constant @type Number */
241 /** Key constant @type Number */
243 /** Key constant @type Number */
245 /** Key constant @type Number */
247 /** Key constant @type Number */
249 /** Key constant @type Number */
251 /** Key constant @type Number */
253 /** Key constant @type Number */
255 /** Key constant @type Number */
257 /** Key constant @type Number */
259 /** Key constant @type Number */
261 /** Key constant @type Number */
263 /** Key constant @type Number */
265 /** Key constant @type Number */
267 /** Key constant @type Number */
269 /** Key constant @type Number */
271 /** Key constant @type Number */
273 /** Key constant @type Number */
275 /** Key constant @type Number */
277 /** Key constant @type Number */
279 /** Key constant @type Number */
281 /** Key constant @type Number */
283 /** Key constant @type Number */
285 /** Key constant @type Number */
287 /** Key constant @type Number */
289 /** Key constant @type Number */
291 /** Key constant @type Number */
293 /** Key constant @type Number */
295 /** Key constant @type Number */
297 /** Key constant @type Number */
299 /** Key constant @type Number */
301 /** Key constant @type Number */
305 isNavKeyPress : function(){
307 k = this.normalizeKey(me.keyCode);
308 return (k >= 33 && k <= 40) || // Page Up/Down, End, Home, Left, Up, Right, Down
314 isSpecialKey : function(){
315 var k = this.normalizeKey(this.keyCode);
316 return (this.type == 'keypress' && this.ctrlKey) ||
317 this.isNavKeyPress() ||
318 (k == this.BACKSPACE) || // Backspace
319 (k >= 16 && k <= 20) || // Shift, Ctrl, Alt, Pause, Caps Lock
320 (k >= 44 && k <= 45); // Print Screen, Insert
323 getPoint : function(){
324 return new Ext.lib.Point(this.xy[0], this.xy[1]);
328 * Returns true if the control, meta, shift or alt key was pressed during this event.
331 hasModifier : function(){
332 return ((this.ctrlKey || this.altKey) || this.shiftKey);