3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.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 (100 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 resizeTask.delay(100);
62 * 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.
63 * @param {Function} fn The function the event invokes.
64 * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
65 * @param {boolean} options Options object as passed to {@link Ext.Element#addListener}
67 onTextResize : function(fn, scope, options){
69 textEvent = new Ext.util.Event();
70 var textEl = new Ext.Element(document.createElement('div'));
71 textEl.dom.className = 'x-text-resize';
72 textEl.dom.innerHTML = 'X';
73 textEl.appendTo(document.body);
74 textSize = textEl.dom.offsetHeight;
75 setInterval(function(){
76 if(textEl.dom.offsetHeight != textSize){
77 textEvent.fire(textSize, textSize = textEl.dom.offsetHeight);
79 }, this.textResizeInterval);
81 textEvent.addListener(fn, scope, options);
85 * Removes the passed window resize listener.
86 * @param {Function} fn The method the event invokes
87 * @param {Object} scope The scope of handler
89 removeResizeListener : function(fn, scope){
91 resizeEvent.removeListener(fn, scope);
96 fireResize : function(){
98 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
103 * The frequency, in milliseconds, to check for text resize events (defaults to 50)
105 textResizeInterval : 50,
108 * Url used for onDocumentReady with using SSL (defaults to Ext.SSL_SECURE_URL)
112 // protected, short accessor for useKeydown
113 getKeyEvent : function(){
114 return useKeydown ? 'keydown' : 'keypress';
117 // protected for use inside the framework
118 // detects whether we should use keydown or keypress based on the browser.
119 useKeydown: useKeydown
123 Ext.EventManager.on = Ext.EventManager.addListener;
126 Ext.apply(Ext.EventObjectImpl.prototype, {
127 /** Key constant @type Number */
129 /** Key constant @type Number */
131 /** Key constant @type Number */
133 /** Key constant @type Number */
135 /** Key constant @type Number */
137 /** Key constant @type Number */
139 /** Key constant @type Number */
141 CONTROL : 17, // legacy
142 /** Key constant @type Number */
144 /** Key constant @type Number */
146 /** Key constant @type Number */
148 /** Key constant @type Number */
150 /** Key constant @type Number */
152 /** Key constant @type Number */
154 PAGEUP : 33, // legacy
155 /** Key constant @type Number */
157 PAGEDOWN : 34, // legacy
158 /** Key constant @type Number */
160 /** Key constant @type Number */
162 /** Key constant @type Number */
164 /** Key constant @type Number */
166 /** Key constant @type Number */
168 /** Key constant @type Number */
170 /** Key constant @type Number */
172 /** Key constant @type Number */
174 /** Key constant @type Number */
176 /** Key constant @type Number */
178 /** Key constant @type Number */
180 /** Key constant @type Number */
182 /** Key constant @type Number */
184 /** Key constant @type Number */
186 /** Key constant @type Number */
188 /** Key constant @type Number */
190 /** Key constant @type Number */
192 /** Key constant @type Number */
194 /** Key constant @type Number */
196 /** Key constant @type Number */
198 /** Key constant @type Number */
200 /** Key constant @type Number */
202 /** Key constant @type Number */
204 /** Key constant @type Number */
206 /** Key constant @type Number */
208 /** Key constant @type Number */
210 /** Key constant @type Number */
212 /** Key constant @type Number */
214 /** Key constant @type Number */
216 /** Key constant @type Number */
218 /** Key constant @type Number */
220 /** Key constant @type Number */
222 /** Key constant @type Number */
224 /** Key constant @type Number */
226 /** Key constant @type Number */
228 /** Key constant @type Number */
230 /** Key constant @type Number */
232 /** Key constant @type Number */
234 /** Key constant @type Number */
236 /** Key constant @type Number */
238 /** Key constant @type Number */
240 /** Key constant @type Number */
242 /** Key constant @type Number */
244 /** Key constant @type Number */
246 /** Key constant @type Number */
248 /** Key constant @type Number */
250 /** Key constant @type Number */
252 /** Key constant @type Number */
254 /** Key constant @type Number */
256 /** Key constant @type Number */
258 /** Key constant @type Number */
260 /** Key constant @type Number */
262 /** Key constant @type Number */
264 /** Key constant @type Number */
266 /** Key constant @type Number */
268 /** Key constant @type Number */
270 /** Key constant @type Number */
272 /** Key constant @type Number */
274 /** Key constant @type Number */
276 /** Key constant @type Number */
278 /** Key constant @type Number */
280 /** Key constant @type Number */
282 /** Key constant @type Number */
284 /** Key constant @type Number */
286 /** Key constant @type Number */
288 /** Key constant @type Number */
290 /** Key constant @type Number */
292 /** Key constant @type Number */
294 /** Key constant @type Number */
296 /** Key constant @type Number */
298 /** Key constant @type Number */
300 /** Key constant @type Number */
302 /** Key constant @type Number */
306 isNavKeyPress : function(){
308 k = this.normalizeKey(me.keyCode);
309 return (k >= 33 && k <= 40) || // Page Up/Down, End, Home, Left, Up, Right, Down
315 isSpecialKey : function(){
316 var k = this.normalizeKey(this.keyCode);
317 return (this.type == 'keypress' && this.ctrlKey) ||
318 this.isNavKeyPress() ||
319 (k == this.BACKSPACE) || // Backspace
320 (k >= 16 && k <= 20) || // Shift, Ctrl, Alt, Pause, Caps Lock
321 (k >= 44 && k <= 46); // Print Screen, Insert, Delete
324 getPoint : function(){
325 return new Ext.lib.Point(this.xy[0], this.xy[1]);
329 * Returns true if the control, meta, shift or alt key was pressed during this event.
332 hasModifier : function(){
333 return ((this.ctrlKey || this.altKey) || this.shiftKey);