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