3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
15 * @class Ext.EventManager
\r
17 Ext.apply(Ext.EventManager, function(){
\r
24 propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/,
\r
27 // note 1: IE fires ONLY the keydown event on specialkey autorepeat
\r
28 // note 2: Safari < 3.1, Gecko (Mac/Linux) & Opera fire only the keypress event on specialkey autorepeat
\r
29 // (research done by @Jan Wolter at http://unixpapa.com/js/key.html)
\r
30 useKeydown = Ext.isWebKit ?
\r
31 Ext.num(navigator.userAgent.match(/AppleWebKit\/(\d+)/)[1]) >= 525 :
\r
32 !((Ext.isGecko && !Ext.isWindows) || Ext.isOpera);
\r
36 doResizeEvent: function(){
\r
37 var h = D.getViewHeight(),
\r
38 w = D.getViewWidth();
\r
40 //whacky problem in IE where the resize event will fire even though the w/h are the same.
\r
41 if(curHeight != h || curWidth != w){
\r
42 resizeEvent.fire(curWidth = w, curHeight = h);
\r
46 <div id="method-Ext.EventManager-onWindowResize"></div>/**
\r
47 * Fires when the window is resized and provides resize event buffering (50 milliseconds), passes new viewport width and height to handlers.
\r
48 * @param {Function} fn The method the event invokes
\r
49 * @param {Object} scope An object that becomes the scope of the handler
\r
50 * @param {boolean} options
\r
52 onWindowResize : function(fn, scope, options){
\r
54 resizeEvent = new Ext.util.Event();
\r
55 resizeTask = new Ext.util.DelayedTask(this.doResizeEvent);
\r
56 E.on(window, "resize", this.fireWindowResize, this);
\r
58 resizeEvent.addListener(fn, scope, options);
\r
61 // exposed only to allow manual firing
\r
62 fireWindowResize : function(){
\r
64 if((Ext.isIE||Ext.isAir) && resizeTask){
\r
65 resizeTask.delay(50);
\r
67 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
\r
72 <div id="method-Ext.EventManager-onTextResize"></div>/**
\r
73 * Fires when the user changes the active text size. Handler gets called with 2 params, the old size and the new size.
\r
74 * @param {Function} fn The method the event invokes
\r
75 * @param {Object} scope An object that becomes the scope of the handler
\r
76 * @param {boolean} options
\r
78 onTextResize : function(fn, scope, options){
\r
80 textEvent = new Ext.util.Event();
\r
81 var textEl = new Ext.Element(document.createElement('div'));
\r
82 textEl.dom.className = 'x-text-resize';
\r
83 textEl.dom.innerHTML = 'X';
\r
84 textEl.appendTo(document.body);
\r
85 textSize = textEl.dom.offsetHeight;
\r
86 setInterval(function(){
\r
87 if(textEl.dom.offsetHeight != textSize){
\r
88 textEvent.fire(textSize, textSize = textEl.dom.offsetHeight);
\r
90 }, this.textResizeInterval);
\r
92 textEvent.addListener(fn, scope, options);
\r
95 <div id="method-Ext.EventManager-removeResizeListener"></div>/**
\r
96 * Removes the passed window resize listener.
\r
97 * @param {Function} fn The method the event invokes
\r
98 * @param {Object} scope The scope of handler
\r
100 removeResizeListener : function(fn, scope){
\r
102 resizeEvent.removeListener(fn, scope);
\r
107 fireResize : function(){
\r
109 resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
\r
113 <div id="prop-Ext.EventManager-textResizeInterval"></div>/**
\r
114 * The frequency, in milliseconds, to check for text resize events (defaults to 50)
\r
116 textResizeInterval : 50,
\r
118 <div id="prop-Ext.EventManager-ieDeferSrc"></div>/**
\r
119 * Url used for onDocumentReady with using SSL (defaults to Ext.SSL_SECURE_URL)
\r
121 ieDeferSrc : false,
\r
123 // protected for use inside the framework
\r
124 // detects whether we should use keydown or keypress based on the browser.
\r
125 useKeydown: useKeydown
\r
129 Ext.EventManager.on = Ext.EventManager.addListener;
\r
132 Ext.apply(Ext.EventObjectImpl.prototype, {
\r
133 <div id="prop-Ext.EventManager-BACKSPACE"></div>/** Key constant @type Number */
\r
135 <div id="prop-Ext.EventManager-TAB"></div>/** Key constant @type Number */
\r
137 <div id="prop-Ext.EventManager-NUM_CENTER"></div>/** Key constant @type Number */
\r
139 <div id="prop-Ext.EventManager-ENTER"></div>/** Key constant @type Number */
\r
141 <div id="prop-Ext.EventManager-RETURN"></div>/** Key constant @type Number */
\r
143 <div id="prop-Ext.EventManager-SHIFT"></div>/** Key constant @type Number */
\r
145 <div id="prop-Ext.EventManager-CTRL"></div>/** Key constant @type Number */
\r
147 CONTROL : 17, // legacy
\r
148 <div id="prop-Ext.EventManager-ALT"></div>/** Key constant @type Number */
\r
150 <div id="prop-Ext.EventManager-PAUSE"></div>/** Key constant @type Number */
\r
152 <div id="prop-Ext.EventManager-CAPS_LOCK"></div>/** Key constant @type Number */
\r
154 <div id="prop-Ext.EventManager-ESC"></div>/** Key constant @type Number */
\r
156 <div id="prop-Ext.EventManager-SPACE"></div>/** Key constant @type Number */
\r
158 <div id="prop-Ext.EventManager-PAGE_UP"></div>/** Key constant @type Number */
\r
160 PAGEUP : 33, // legacy
\r
161 <div id="prop-Ext.EventManager-PAGE_DOWN"></div>/** Key constant @type Number */
\r
163 PAGEDOWN : 34, // legacy
\r
164 <div id="prop-Ext.EventManager-END"></div>/** Key constant @type Number */
\r
166 <div id="prop-Ext.EventManager-HOME"></div>/** Key constant @type Number */
\r
168 <div id="prop-Ext.EventManager-LEFT"></div>/** Key constant @type Number */
\r
170 <div id="prop-Ext.EventManager-UP"></div>/** Key constant @type Number */
\r
172 <div id="prop-Ext.EventManager-RIGHT"></div>/** Key constant @type Number */
\r
174 <div id="prop-Ext.EventManager-DOWN"></div>/** Key constant @type Number */
\r
176 <div id="prop-Ext.EventManager-PRINT_SCREEN"></div>/** Key constant @type Number */
\r
178 <div id="prop-Ext.EventManager-INSERT"></div>/** Key constant @type Number */
\r
180 <div id="prop-Ext.EventManager-DELETE"></div>/** Key constant @type Number */
\r
182 <div id="prop-Ext.EventManager-ZERO"></div>/** Key constant @type Number */
\r
184 <div id="prop-Ext.EventManager-ONE"></div>/** Key constant @type Number */
\r
186 <div id="prop-Ext.EventManager-TWO"></div>/** Key constant @type Number */
\r
188 <div id="prop-Ext.EventManager-THREE"></div>/** Key constant @type Number */
\r
190 <div id="prop-Ext.EventManager-FOUR"></div>/** Key constant @type Number */
\r
192 <div id="prop-Ext.EventManager-FIVE"></div>/** Key constant @type Number */
\r
194 <div id="prop-Ext.EventManager-SIX"></div>/** Key constant @type Number */
\r
196 <div id="prop-Ext.EventManager-SEVEN"></div>/** Key constant @type Number */
\r
198 <div id="prop-Ext.EventManager-EIGHT"></div>/** Key constant @type Number */
\r
200 <div id="prop-Ext.EventManager-NINE"></div>/** Key constant @type Number */
\r
202 <div id="prop-Ext.EventManager-A"></div>/** Key constant @type Number */
\r
204 <div id="prop-Ext.EventManager-B"></div>/** Key constant @type Number */
\r
206 <div id="prop-Ext.EventManager-C"></div>/** Key constant @type Number */
\r
208 <div id="prop-Ext.EventManager-D"></div>/** Key constant @type Number */
\r
210 <div id="prop-Ext.EventManager-E"></div>/** Key constant @type Number */
\r
212 <div id="prop-Ext.EventManager-F"></div>/** Key constant @type Number */
\r
214 <div id="prop-Ext.EventManager-G"></div>/** Key constant @type Number */
\r
216 <div id="prop-Ext.EventManager-H"></div>/** Key constant @type Number */
\r
218 <div id="prop-Ext.EventManager-I"></div>/** Key constant @type Number */
\r
220 <div id="prop-Ext.EventManager-J"></div>/** Key constant @type Number */
\r
222 <div id="prop-Ext.EventManager-K"></div>/** Key constant @type Number */
\r
224 <div id="prop-Ext.EventManager-L"></div>/** Key constant @type Number */
\r
226 <div id="prop-Ext.EventManager-M"></div>/** Key constant @type Number */
\r
228 <div id="prop-Ext.EventManager-N"></div>/** Key constant @type Number */
\r
230 <div id="prop-Ext.EventManager-O"></div>/** Key constant @type Number */
\r
232 <div id="prop-Ext.EventManager-P"></div>/** Key constant @type Number */
\r
234 <div id="prop-Ext.EventManager-Q"></div>/** Key constant @type Number */
\r
236 <div id="prop-Ext.EventManager-R"></div>/** Key constant @type Number */
\r
238 <div id="prop-Ext.EventManager-S"></div>/** Key constant @type Number */
\r
240 <div id="prop-Ext.EventManager-T"></div>/** Key constant @type Number */
\r
242 <div id="prop-Ext.EventManager-U"></div>/** Key constant @type Number */
\r
244 <div id="prop-Ext.EventManager-V"></div>/** Key constant @type Number */
\r
246 <div id="prop-Ext.EventManager-W"></div>/** Key constant @type Number */
\r
248 <div id="prop-Ext.EventManager-X"></div>/** Key constant @type Number */
\r
250 <div id="prop-Ext.EventManager-Y"></div>/** Key constant @type Number */
\r
252 <div id="prop-Ext.EventManager-Z"></div>/** Key constant @type Number */
\r
254 <div id="prop-Ext.EventManager-CONTEXT_MENU"></div>/** Key constant @type Number */
\r
256 <div id="prop-Ext.EventManager-NUM_ZERO"></div>/** Key constant @type Number */
\r
258 <div id="prop-Ext.EventManager-NUM_ONE"></div>/** Key constant @type Number */
\r
260 <div id="prop-Ext.EventManager-NUM_TWO"></div>/** Key constant @type Number */
\r
262 <div id="prop-Ext.EventManager-NUM_THREE"></div>/** Key constant @type Number */
\r
264 <div id="prop-Ext.EventManager-NUM_FOUR"></div>/** Key constant @type Number */
\r
266 <div id="prop-Ext.EventManager-NUM_FIVE"></div>/** Key constant @type Number */
\r
268 <div id="prop-Ext.EventManager-NUM_SIX"></div>/** Key constant @type Number */
\r
270 <div id="prop-Ext.EventManager-NUM_SEVEN"></div>/** Key constant @type Number */
\r
272 <div id="prop-Ext.EventManager-NUM_EIGHT"></div>/** Key constant @type Number */
\r
274 <div id="prop-Ext.EventManager-NUM_NINE"></div>/** Key constant @type Number */
\r
276 <div id="prop-Ext.EventManager-NUM_MULTIPLY"></div>/** Key constant @type Number */
\r
278 <div id="prop-Ext.EventManager-NUM_PLUS"></div>/** Key constant @type Number */
\r
280 <div id="prop-Ext.EventManager-NUM_MINUS"></div>/** Key constant @type Number */
\r
282 <div id="prop-Ext.EventManager-NUM_PERIOD"></div>/** Key constant @type Number */
\r
284 <div id="prop-Ext.EventManager-NUM_DIVISION"></div>/** Key constant @type Number */
\r
286 <div id="prop-Ext.EventManager-F1"></div>/** Key constant @type Number */
\r
288 <div id="prop-Ext.EventManager-F2"></div>/** Key constant @type Number */
\r
290 <div id="prop-Ext.EventManager-F3"></div>/** Key constant @type Number */
\r
292 <div id="prop-Ext.EventManager-F4"></div>/** Key constant @type Number */
\r
294 <div id="prop-Ext.EventManager-F5"></div>/** Key constant @type Number */
\r
296 <div id="prop-Ext.EventManager-F6"></div>/** Key constant @type Number */
\r
298 <div id="prop-Ext.EventManager-F7"></div>/** Key constant @type Number */
\r
300 <div id="prop-Ext.EventManager-F8"></div>/** Key constant @type Number */
\r
302 <div id="prop-Ext.EventManager-F9"></div>/** Key constant @type Number */
\r
304 <div id="prop-Ext.EventManager-F10"></div>/** Key constant @type Number */
\r
306 <div id="prop-Ext.EventManager-F11"></div>/** Key constant @type Number */
\r
308 <div id="prop-Ext.EventManager-F12"></div>/** Key constant @type Number */
\r
312 isNavKeyPress : function(){
\r
314 k = this.normalizeKey(me.keyCode);
\r
315 return (k >= 33 && k <= 40) || // Page Up/Down, End, Home, Left, Up, Right, Down
\r
321 isSpecialKey : function(){
\r
322 var k = this.normalizeKey(this.keyCode);
\r
323 return (this.type == 'keypress' && this.ctrlKey) ||
\r
324 this.isNavKeyPress() ||
\r
325 (k == this.BACKSPACE) || // Backspace
\r
326 (k >= 16 && k <= 20) || // Shift, Ctrl, Alt, Pause, Caps Lock
\r
327 (k >= 44 && k <= 45); // Print Screen, Insert
\r
330 getPoint : function(){
\r
331 return new Ext.lib.Point(this.xy[0], this.xy[1]);
\r
334 <div id="method-Ext.EventManager-hasModifier"></div>/**
\r
335 * Returns true if the control, meta, shift or alt key was pressed during this event.
\r
336 * @return {Boolean}
\r
338 hasModifier : function(){
\r
339 return ((this.ctrlKey || this.altKey) || this.shiftKey);
\r