Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / docs / source / EventManager-more.html
1 <html>
2 <head>
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>
6 </head>
7 <body  onload="prettyPrint();">
8     <pre class="prettyprint lang-js">/*!
9  * Ext JS Library 3.0.3
10  * Copyright(c) 2006-2009 Ext JS, LLC
11  * licensing@extjs.com
12  * http://www.extjs.com/license
13  */
14 /**\r
15  * @class Ext.EventManager\r
16  */\r
17 Ext.apply(Ext.EventManager, function(){\r
18         var resizeEvent, \r
19         resizeTask, \r
20         textEvent, \r
21         textSize,\r
22         D = Ext.lib.Dom,\r
23         E = Ext.lib.Event,\r
24         propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/,\r
25         curWidth = 0,\r
26         curHeight = 0,\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
33         \r
34         return { \r
35                 // private\r
36             doResizeEvent: function(){\r
37             var h = D.getViewHeight(),\r
38                 w = D.getViewWidth();\r
39             \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
43             }\r
44             },\r
45             \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
51              */\r
52             onWindowResize : function(fn, scope, options){\r
53                 if(!resizeEvent){\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
57                 }\r
58                 resizeEvent.addListener(fn, scope, options);\r
59             },\r
60         \r
61             // exposed only to allow manual firing\r
62             fireWindowResize : function(){\r
63                 if(resizeEvent){\r
64                     if((Ext.isIE||Ext.isAir) && resizeTask){\r
65                         resizeTask.delay(50);\r
66                     }else{\r
67                         resizeEvent.fire(D.getViewWidth(), D.getViewHeight());\r
68                     }\r
69                 }\r
70             },\r
71         \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
77              */\r
78             onTextResize : function(fn, scope, options){\r
79                 if(!textEvent){\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
89                         }\r
90                     }, this.textResizeInterval);\r
91                 }\r
92                 textEvent.addListener(fn, scope, options);\r
93             },\r
94         \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
99              */\r
100             removeResizeListener : function(fn, scope){\r
101                 if(resizeEvent){\r
102                     resizeEvent.removeListener(fn, scope);\r
103                 }\r
104             },\r
105         \r
106             // private\r
107             fireResize : function(){\r
108                 if(resizeEvent){\r
109                     resizeEvent.fire(D.getViewWidth(), D.getViewHeight());\r
110                 }\r
111             },\r
112             \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
115              */\r
116             textResizeInterval : 50,\r
117             \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
120          */\r
121         ieDeferSrc : false,\r
122         \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
126     };\r
127 }());\r
128 \r
129 Ext.EventManager.on = Ext.EventManager.addListener;\r
130 \r
131 \r
132 Ext.apply(Ext.EventObjectImpl.prototype, {\r
133     <div id="prop-Ext.EventManager-BACKSPACE"></div>/** Key constant @type Number */\r
134     BACKSPACE: 8,\r
135     <div id="prop-Ext.EventManager-TAB"></div>/** Key constant @type Number */\r
136     TAB: 9,\r
137     <div id="prop-Ext.EventManager-NUM_CENTER"></div>/** Key constant @type Number */\r
138     NUM_CENTER: 12,\r
139     <div id="prop-Ext.EventManager-ENTER"></div>/** Key constant @type Number */\r
140     ENTER: 13,\r
141     <div id="prop-Ext.EventManager-RETURN"></div>/** Key constant @type Number */\r
142     RETURN: 13,\r
143     <div id="prop-Ext.EventManager-SHIFT"></div>/** Key constant @type Number */\r
144     SHIFT: 16,\r
145     <div id="prop-Ext.EventManager-CTRL"></div>/** Key constant @type Number */\r
146     CTRL: 17,\r
147     CONTROL : 17, // legacy\r
148     <div id="prop-Ext.EventManager-ALT"></div>/** Key constant @type Number */\r
149     ALT: 18,\r
150     <div id="prop-Ext.EventManager-PAUSE"></div>/** Key constant @type Number */\r
151     PAUSE: 19,\r
152     <div id="prop-Ext.EventManager-CAPS_LOCK"></div>/** Key constant @type Number */\r
153     CAPS_LOCK: 20,\r
154     <div id="prop-Ext.EventManager-ESC"></div>/** Key constant @type Number */\r
155     ESC: 27,\r
156     <div id="prop-Ext.EventManager-SPACE"></div>/** Key constant @type Number */\r
157     SPACE: 32,\r
158     <div id="prop-Ext.EventManager-PAGE_UP"></div>/** Key constant @type Number */\r
159     PAGE_UP: 33,\r
160     PAGEUP : 33, // legacy\r
161     <div id="prop-Ext.EventManager-PAGE_DOWN"></div>/** Key constant @type Number */\r
162     PAGE_DOWN: 34,\r
163     PAGEDOWN : 34, // legacy\r
164     <div id="prop-Ext.EventManager-END"></div>/** Key constant @type Number */\r
165     END: 35,\r
166     <div id="prop-Ext.EventManager-HOME"></div>/** Key constant @type Number */\r
167     HOME: 36,\r
168     <div id="prop-Ext.EventManager-LEFT"></div>/** Key constant @type Number */\r
169     LEFT: 37,\r
170     <div id="prop-Ext.EventManager-UP"></div>/** Key constant @type Number */\r
171     UP: 38,\r
172     <div id="prop-Ext.EventManager-RIGHT"></div>/** Key constant @type Number */\r
173     RIGHT: 39,\r
174     <div id="prop-Ext.EventManager-DOWN"></div>/** Key constant @type Number */\r
175     DOWN: 40,\r
176     <div id="prop-Ext.EventManager-PRINT_SCREEN"></div>/** Key constant @type Number */\r
177     PRINT_SCREEN: 44,\r
178     <div id="prop-Ext.EventManager-INSERT"></div>/** Key constant @type Number */\r
179     INSERT: 45,\r
180     <div id="prop-Ext.EventManager-DELETE"></div>/** Key constant @type Number */\r
181     DELETE: 46,\r
182     <div id="prop-Ext.EventManager-ZERO"></div>/** Key constant @type Number */\r
183     ZERO: 48,\r
184     <div id="prop-Ext.EventManager-ONE"></div>/** Key constant @type Number */\r
185     ONE: 49,\r
186     <div id="prop-Ext.EventManager-TWO"></div>/** Key constant @type Number */\r
187     TWO: 50,\r
188     <div id="prop-Ext.EventManager-THREE"></div>/** Key constant @type Number */\r
189     THREE: 51,\r
190     <div id="prop-Ext.EventManager-FOUR"></div>/** Key constant @type Number */\r
191     FOUR: 52,\r
192     <div id="prop-Ext.EventManager-FIVE"></div>/** Key constant @type Number */\r
193     FIVE: 53,\r
194     <div id="prop-Ext.EventManager-SIX"></div>/** Key constant @type Number */\r
195     SIX: 54,\r
196     <div id="prop-Ext.EventManager-SEVEN"></div>/** Key constant @type Number */\r
197     SEVEN: 55,\r
198     <div id="prop-Ext.EventManager-EIGHT"></div>/** Key constant @type Number */\r
199     EIGHT: 56,\r
200     <div id="prop-Ext.EventManager-NINE"></div>/** Key constant @type Number */\r
201     NINE: 57,\r
202     <div id="prop-Ext.EventManager-A"></div>/** Key constant @type Number */\r
203     A: 65,\r
204     <div id="prop-Ext.EventManager-B"></div>/** Key constant @type Number */\r
205     B: 66,\r
206     <div id="prop-Ext.EventManager-C"></div>/** Key constant @type Number */\r
207     C: 67,\r
208     <div id="prop-Ext.EventManager-D"></div>/** Key constant @type Number */\r
209     D: 68,\r
210     <div id="prop-Ext.EventManager-E"></div>/** Key constant @type Number */\r
211     E: 69,\r
212     <div id="prop-Ext.EventManager-F"></div>/** Key constant @type Number */\r
213     F: 70,\r
214     <div id="prop-Ext.EventManager-G"></div>/** Key constant @type Number */\r
215     G: 71,\r
216     <div id="prop-Ext.EventManager-H"></div>/** Key constant @type Number */\r
217     H: 72,\r
218     <div id="prop-Ext.EventManager-I"></div>/** Key constant @type Number */\r
219     I: 73,\r
220     <div id="prop-Ext.EventManager-J"></div>/** Key constant @type Number */\r
221     J: 74,\r
222     <div id="prop-Ext.EventManager-K"></div>/** Key constant @type Number */\r
223     K: 75,\r
224     <div id="prop-Ext.EventManager-L"></div>/** Key constant @type Number */\r
225     L: 76,\r
226     <div id="prop-Ext.EventManager-M"></div>/** Key constant @type Number */\r
227     M: 77,\r
228     <div id="prop-Ext.EventManager-N"></div>/** Key constant @type Number */\r
229     N: 78,\r
230     <div id="prop-Ext.EventManager-O"></div>/** Key constant @type Number */\r
231     O: 79,\r
232     <div id="prop-Ext.EventManager-P"></div>/** Key constant @type Number */\r
233     P: 80,\r
234     <div id="prop-Ext.EventManager-Q"></div>/** Key constant @type Number */\r
235     Q: 81,\r
236     <div id="prop-Ext.EventManager-R"></div>/** Key constant @type Number */\r
237     R: 82,\r
238     <div id="prop-Ext.EventManager-S"></div>/** Key constant @type Number */\r
239     S: 83,\r
240     <div id="prop-Ext.EventManager-T"></div>/** Key constant @type Number */\r
241     T: 84,\r
242     <div id="prop-Ext.EventManager-U"></div>/** Key constant @type Number */\r
243     U: 85,\r
244     <div id="prop-Ext.EventManager-V"></div>/** Key constant @type Number */\r
245     V: 86,\r
246     <div id="prop-Ext.EventManager-W"></div>/** Key constant @type Number */\r
247     W: 87,\r
248     <div id="prop-Ext.EventManager-X"></div>/** Key constant @type Number */\r
249     X: 88,\r
250     <div id="prop-Ext.EventManager-Y"></div>/** Key constant @type Number */\r
251     Y: 89,\r
252     <div id="prop-Ext.EventManager-Z"></div>/** Key constant @type Number */\r
253     Z: 90,\r
254     <div id="prop-Ext.EventManager-CONTEXT_MENU"></div>/** Key constant @type Number */\r
255     CONTEXT_MENU: 93,\r
256     <div id="prop-Ext.EventManager-NUM_ZERO"></div>/** Key constant @type Number */\r
257     NUM_ZERO: 96,\r
258     <div id="prop-Ext.EventManager-NUM_ONE"></div>/** Key constant @type Number */\r
259     NUM_ONE: 97,\r
260     <div id="prop-Ext.EventManager-NUM_TWO"></div>/** Key constant @type Number */\r
261     NUM_TWO: 98,\r
262     <div id="prop-Ext.EventManager-NUM_THREE"></div>/** Key constant @type Number */\r
263     NUM_THREE: 99,\r
264     <div id="prop-Ext.EventManager-NUM_FOUR"></div>/** Key constant @type Number */\r
265     NUM_FOUR: 100,\r
266     <div id="prop-Ext.EventManager-NUM_FIVE"></div>/** Key constant @type Number */\r
267     NUM_FIVE: 101,\r
268     <div id="prop-Ext.EventManager-NUM_SIX"></div>/** Key constant @type Number */\r
269     NUM_SIX: 102,\r
270     <div id="prop-Ext.EventManager-NUM_SEVEN"></div>/** Key constant @type Number */\r
271     NUM_SEVEN: 103,\r
272     <div id="prop-Ext.EventManager-NUM_EIGHT"></div>/** Key constant @type Number */\r
273     NUM_EIGHT: 104,\r
274     <div id="prop-Ext.EventManager-NUM_NINE"></div>/** Key constant @type Number */\r
275     NUM_NINE: 105,\r
276     <div id="prop-Ext.EventManager-NUM_MULTIPLY"></div>/** Key constant @type Number */\r
277     NUM_MULTIPLY: 106,\r
278     <div id="prop-Ext.EventManager-NUM_PLUS"></div>/** Key constant @type Number */\r
279     NUM_PLUS: 107,\r
280     <div id="prop-Ext.EventManager-NUM_MINUS"></div>/** Key constant @type Number */\r
281     NUM_MINUS: 109,\r
282     <div id="prop-Ext.EventManager-NUM_PERIOD"></div>/** Key constant @type Number */\r
283     NUM_PERIOD: 110,\r
284     <div id="prop-Ext.EventManager-NUM_DIVISION"></div>/** Key constant @type Number */\r
285     NUM_DIVISION: 111,\r
286     <div id="prop-Ext.EventManager-F1"></div>/** Key constant @type Number */\r
287     F1: 112,\r
288     <div id="prop-Ext.EventManager-F2"></div>/** Key constant @type Number */\r
289     F2: 113,\r
290     <div id="prop-Ext.EventManager-F3"></div>/** Key constant @type Number */\r
291     F3: 114,\r
292     <div id="prop-Ext.EventManager-F4"></div>/** Key constant @type Number */\r
293     F4: 115,\r
294     <div id="prop-Ext.EventManager-F5"></div>/** Key constant @type Number */\r
295     F5: 116,\r
296     <div id="prop-Ext.EventManager-F6"></div>/** Key constant @type Number */\r
297     F6: 117,\r
298     <div id="prop-Ext.EventManager-F7"></div>/** Key constant @type Number */\r
299     F7: 118,\r
300     <div id="prop-Ext.EventManager-F8"></div>/** Key constant @type Number */\r
301     F8: 119,\r
302     <div id="prop-Ext.EventManager-F9"></div>/** Key constant @type Number */\r
303     F9: 120,\r
304     <div id="prop-Ext.EventManager-F10"></div>/** Key constant @type Number */\r
305     F10: 121,\r
306     <div id="prop-Ext.EventManager-F11"></div>/** Key constant @type Number */\r
307     F11: 122,\r
308     <div id="prop-Ext.EventManager-F12"></div>/** Key constant @type Number */\r
309     F12: 123,   \r
310     \r
311     /** @private */\r
312     isNavKeyPress : function(){\r
313         var me = this,\r
314                 k = this.normalizeKey(me.keyCode);              \r
315         return (k >= 33 && k <= 40) ||  // Page Up/Down, End, Home, Left, Up, Right, Down\r
316                 k == me.RETURN ||\r
317                 k == me.TAB ||\r
318                 k == me.ESC;\r
319     },\r
320 \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
328     },\r
329         \r
330         getPoint : function(){\r
331             return new Ext.lib.Point(this.xy[0], this.xy[1]);\r
332         },\r
333 \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
337      */\r
338     hasModifier : function(){\r
339         return ((this.ctrlKey || this.altKey) || this.shiftKey);\r
340     }\r
341 });</pre>
342 </body>
343 </html>