3 * Copyright(c) 2006-2010 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 (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 for use inside the framework
113 // detects whether we should use keydown or keypress based on the browser.
114 useKeydown: useKeydown
118 Ext.EventManager.on = Ext.EventManager.addListener;
121 Ext.apply(Ext.EventObjectImpl.prototype, {
122 /** Key constant @type Number */
124 /** Key constant @type Number */
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 CONTROL : 17, // legacy
137 /** Key constant @type Number */
139 /** Key constant @type Number */
141 /** Key constant @type Number */
143 /** Key constant @type Number */
145 /** Key constant @type Number */
147 /** Key constant @type Number */
149 PAGEUP : 33, // legacy
150 /** Key constant @type Number */
152 PAGEDOWN : 34, // legacy
153 /** Key constant @type Number */
155 /** Key constant @type Number */
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 */
301 isNavKeyPress : function(){
303 k = this.normalizeKey(me.keyCode);
304 return (k >= 33 && k <= 40) || // Page Up/Down, End, Home, Left, Up, Right, Down
310 isSpecialKey : function(){
311 var k = this.normalizeKey(this.keyCode);
312 return (this.type == 'keypress' && this.ctrlKey) ||
313 this.isNavKeyPress() ||
314 (k == this.BACKSPACE) || // Backspace
315 (k >= 16 && k <= 20) || // Shift, Ctrl, Alt, Pause, Caps Lock
316 (k >= 44 && k <= 45); // Print Screen, Insert
319 getPoint : function(){
320 return new Ext.lib.Point(this.xy[0], this.xy[1]);
324 * Returns true if the control, meta, shift or alt key was pressed during this event.
327 hasModifier : function(){
328 return ((this.ctrlKey || this.altKey) || this.shiftKey);