Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / EventManager-more.html
1 <html>\r
2 <head>\r
3   <title>The source code</title>\r
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js">/**\r
9  * @class Ext.EventManager\r
10  */\r
11 Ext.apply(Ext.EventManager, function(){\r
12         var resizeEvent, \r
13         resizeTask, \r
14         textEvent, \r
15         textSize,\r
16         D = Ext.lib.Dom,\r
17         E = Ext.lib.Event,\r
18         propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/,\r
19         curWidth = 0,\r
20         curHeight = 0,\r
21         // note 1: IE fires ONLY the keydown event on specialkey autorepeat\r
22         // note 2: Safari < 3.1, Gecko (Mac/Linux) & Opera fire only the keypress event on specialkey autorepeat\r
23         // (research done by @Jan Wolter at http://unixpapa.com/js/key.html)\r
24         useKeydown = Ext.isSafari ? \r
25                     Ext.num(navigator.userAgent.toLowerCase().match(/version\/(\d+\.\d)/)[1] || 2) >= 3.1 :\r
26                     !((Ext.isGecko && !Ext.isWindows) || Ext.isOpera);\r
27         \r
28         return { \r
29                 // private\r
30             doResizeEvent: function(){\r
31             var h = D.getViewHeight(),\r
32                 w = D.getViewWidth();\r
33             \r
34             //whacky problem in IE where the resize event will fire even though the w/h are the same.\r
35             if(curHeight != h || curWidth != w){\r
36                 resizeEvent.fire(curWidth = w, curHeight = h);\r
37             }\r
38             },\r
39             \r
40             <div id="method-Ext.EventManager-onWindowResize"></div>/**\r
41              * Fires when the window is resized and provides resize event buffering (50 milliseconds), passes new viewport width and height to handlers.\r
42              * @param {Function} fn        The method the event invokes\r
43              * @param {Object}   scope    An object that becomes the scope of the handler\r
44              * @param {boolean}  options\r
45              */\r
46             onWindowResize : function(fn, scope, options){\r
47                 if(!resizeEvent){\r
48                     resizeEvent = new Ext.util.Event();\r
49                     resizeTask = new Ext.util.DelayedTask(this.doResizeEvent);\r
50                     E.on(window, "resize", this.fireWindowResize, this);\r
51                 }\r
52                 resizeEvent.addListener(fn, scope, options);\r
53             },\r
54         \r
55             // exposed only to allow manual firing\r
56             fireWindowResize : function(){\r
57                 if(resizeEvent){\r
58                     if((Ext.isIE||Ext.isAir) && resizeTask){\r
59                         resizeTask.delay(50);\r
60                     }else{\r
61                         resizeEvent.fire(D.getViewWidth(), D.getViewHeight());\r
62                     }\r
63                 }\r
64             },\r
65         \r
66             <div id="method-Ext.EventManager-onTextResize"></div>/**\r
67              * Fires when the user changes the active text size. Handler gets called with 2 params, the old size and the new size.\r
68              * @param {Function} fn        The method the event invokes\r
69              * @param {Object}   scope    An object that becomes the scope of the handler\r
70              * @param {boolean}  options\r
71              */\r
72             onTextResize : function(fn, scope, options){\r
73                 if(!textEvent){\r
74                     textEvent = new Ext.util.Event();\r
75                     var textEl = new Ext.Element(document.createElement('div'));\r
76                     textEl.dom.className = 'x-text-resize';\r
77                     textEl.dom.innerHTML = 'X';\r
78                     textEl.appendTo(document.body);\r
79                     textSize = textEl.dom.offsetHeight;\r
80                     setInterval(function(){\r
81                         if(textEl.dom.offsetHeight != textSize){\r
82                             textEvent.fire(textSize, textSize = textEl.dom.offsetHeight);\r
83                         }\r
84                     }, this.textResizeInterval);\r
85                 }\r
86                 textEvent.addListener(fn, scope, options);\r
87             },\r
88         \r
89             <div id="method-Ext.EventManager-removeResizeListener"></div>/**\r
90              * Removes the passed window resize listener.\r
91              * @param {Function} fn        The method the event invokes\r
92              * @param {Object}   scope    The scope of handler\r
93              */\r
94             removeResizeListener : function(fn, scope){\r
95                 if(resizeEvent){\r
96                     resizeEvent.removeListener(fn, scope);\r
97                 }\r
98             },\r
99         \r
100             // private\r
101             fireResize : function(){\r
102                 if(resizeEvent){\r
103                     resizeEvent.fire(D.getViewWidth(), D.getViewHeight());\r
104                 }\r
105             },\r
106             \r
107              <div id="prop-Ext.EventManager-textResizeInterval"></div>/**\r
108              * The frequency, in milliseconds, to check for text resize events (defaults to 50)\r
109              */\r
110             textResizeInterval : 50,\r
111             \r
112             <div id="prop-Ext.EventManager-ieDeferSrc"></div>/**\r
113          * Url used for onDocumentReady with using SSL (defaults to Ext.SSL_SECURE_URL)\r
114          */\r
115         ieDeferSrc : false,\r
116         \r
117         // protected for use inside the framework\r
118         // detects whether we should use keydown or keypress based on the browser.\r
119         useKeydown: useKeydown\r
120     };\r
121 }());\r
122 \r
123 Ext.EventManager.on = Ext.EventManager.addListener;\r
124 \r
125 \r
126 Ext.apply(Ext.EventObjectImpl.prototype, {\r
127     <div id="prop-Ext.EventManager-BACKSPACE"></div>/** Key constant @type Number */\r
128     BACKSPACE: 8,\r
129     <div id="prop-Ext.EventManager-TAB"></div>/** Key constant @type Number */\r
130     TAB: 9,\r
131     <div id="prop-Ext.EventManager-NUM_CENTER"></div>/** Key constant @type Number */\r
132     NUM_CENTER: 12,\r
133     <div id="prop-Ext.EventManager-ENTER"></div>/** Key constant @type Number */\r
134     ENTER: 13,\r
135     <div id="prop-Ext.EventManager-RETURN"></div>/** Key constant @type Number */\r
136     RETURN: 13,\r
137     <div id="prop-Ext.EventManager-SHIFT"></div>/** Key constant @type Number */\r
138     SHIFT: 16,\r
139     <div id="prop-Ext.EventManager-CTRL"></div>/** Key constant @type Number */\r
140     CTRL: 17,\r
141     CONTROL : 17, // legacy\r
142     <div id="prop-Ext.EventManager-ALT"></div>/** Key constant @type Number */\r
143     ALT: 18,\r
144     <div id="prop-Ext.EventManager-PAUSE"></div>/** Key constant @type Number */\r
145     PAUSE: 19,\r
146     <div id="prop-Ext.EventManager-CAPS_LOCK"></div>/** Key constant @type Number */\r
147     CAPS_LOCK: 20,\r
148     <div id="prop-Ext.EventManager-ESC"></div>/** Key constant @type Number */\r
149     ESC: 27,\r
150     <div id="prop-Ext.EventManager-SPACE"></div>/** Key constant @type Number */\r
151     SPACE: 32,\r
152     <div id="prop-Ext.EventManager-PAGE_UP"></div>/** Key constant @type Number */\r
153     PAGE_UP: 33,\r
154     PAGEUP : 33, // legacy\r
155     <div id="prop-Ext.EventManager-PAGE_DOWN"></div>/** Key constant @type Number */\r
156     PAGE_DOWN: 34,\r
157     PAGEDOWN : 34, // legacy\r
158     <div id="prop-Ext.EventManager-END"></div>/** Key constant @type Number */\r
159     END: 35,\r
160     <div id="prop-Ext.EventManager-HOME"></div>/** Key constant @type Number */\r
161     HOME: 36,\r
162     <div id="prop-Ext.EventManager-LEFT"></div>/** Key constant @type Number */\r
163     LEFT: 37,\r
164     <div id="prop-Ext.EventManager-UP"></div>/** Key constant @type Number */\r
165     UP: 38,\r
166     <div id="prop-Ext.EventManager-RIGHT"></div>/** Key constant @type Number */\r
167     RIGHT: 39,\r
168     <div id="prop-Ext.EventManager-DOWN"></div>/** Key constant @type Number */\r
169     DOWN: 40,\r
170     <div id="prop-Ext.EventManager-PRINT_SCREEN"></div>/** Key constant @type Number */\r
171     PRINT_SCREEN: 44,\r
172     <div id="prop-Ext.EventManager-INSERT"></div>/** Key constant @type Number */\r
173     INSERT: 45,\r
174     <div id="prop-Ext.EventManager-DELETE"></div>/** Key constant @type Number */\r
175     DELETE: 46,\r
176     <div id="prop-Ext.EventManager-ZERO"></div>/** Key constant @type Number */\r
177     ZERO: 48,\r
178     <div id="prop-Ext.EventManager-ONE"></div>/** Key constant @type Number */\r
179     ONE: 49,\r
180     <div id="prop-Ext.EventManager-TWO"></div>/** Key constant @type Number */\r
181     TWO: 50,\r
182     <div id="prop-Ext.EventManager-THREE"></div>/** Key constant @type Number */\r
183     THREE: 51,\r
184     <div id="prop-Ext.EventManager-FOUR"></div>/** Key constant @type Number */\r
185     FOUR: 52,\r
186     <div id="prop-Ext.EventManager-FIVE"></div>/** Key constant @type Number */\r
187     FIVE: 53,\r
188     <div id="prop-Ext.EventManager-SIX"></div>/** Key constant @type Number */\r
189     SIX: 54,\r
190     <div id="prop-Ext.EventManager-SEVEN"></div>/** Key constant @type Number */\r
191     SEVEN: 55,\r
192     <div id="prop-Ext.EventManager-EIGHT"></div>/** Key constant @type Number */\r
193     EIGHT: 56,\r
194     <div id="prop-Ext.EventManager-NINE"></div>/** Key constant @type Number */\r
195     NINE: 57,\r
196     <div id="prop-Ext.EventManager-A"></div>/** Key constant @type Number */\r
197     A: 65,\r
198     <div id="prop-Ext.EventManager-B"></div>/** Key constant @type Number */\r
199     B: 66,\r
200     <div id="prop-Ext.EventManager-C"></div>/** Key constant @type Number */\r
201     C: 67,\r
202     <div id="prop-Ext.EventManager-D"></div>/** Key constant @type Number */\r
203     D: 68,\r
204     <div id="prop-Ext.EventManager-E"></div>/** Key constant @type Number */\r
205     E: 69,\r
206     <div id="prop-Ext.EventManager-F"></div>/** Key constant @type Number */\r
207     F: 70,\r
208     <div id="prop-Ext.EventManager-G"></div>/** Key constant @type Number */\r
209     G: 71,\r
210     <div id="prop-Ext.EventManager-H"></div>/** Key constant @type Number */\r
211     H: 72,\r
212     <div id="prop-Ext.EventManager-I"></div>/** Key constant @type Number */\r
213     I: 73,\r
214     <div id="prop-Ext.EventManager-J"></div>/** Key constant @type Number */\r
215     J: 74,\r
216     <div id="prop-Ext.EventManager-K"></div>/** Key constant @type Number */\r
217     K: 75,\r
218     <div id="prop-Ext.EventManager-L"></div>/** Key constant @type Number */\r
219     L: 76,\r
220     <div id="prop-Ext.EventManager-M"></div>/** Key constant @type Number */\r
221     M: 77,\r
222     <div id="prop-Ext.EventManager-N"></div>/** Key constant @type Number */\r
223     N: 78,\r
224     <div id="prop-Ext.EventManager-O"></div>/** Key constant @type Number */\r
225     O: 79,\r
226     <div id="prop-Ext.EventManager-P"></div>/** Key constant @type Number */\r
227     P: 80,\r
228     <div id="prop-Ext.EventManager-Q"></div>/** Key constant @type Number */\r
229     Q: 81,\r
230     <div id="prop-Ext.EventManager-R"></div>/** Key constant @type Number */\r
231     R: 82,\r
232     <div id="prop-Ext.EventManager-S"></div>/** Key constant @type Number */\r
233     S: 83,\r
234     <div id="prop-Ext.EventManager-T"></div>/** Key constant @type Number */\r
235     T: 84,\r
236     <div id="prop-Ext.EventManager-U"></div>/** Key constant @type Number */\r
237     U: 85,\r
238     <div id="prop-Ext.EventManager-V"></div>/** Key constant @type Number */\r
239     V: 86,\r
240     <div id="prop-Ext.EventManager-W"></div>/** Key constant @type Number */\r
241     W: 87,\r
242     <div id="prop-Ext.EventManager-X"></div>/** Key constant @type Number */\r
243     X: 88,\r
244     <div id="prop-Ext.EventManager-Y"></div>/** Key constant @type Number */\r
245     Y: 89,\r
246     <div id="prop-Ext.EventManager-Z"></div>/** Key constant @type Number */\r
247     Z: 90,\r
248     <div id="prop-Ext.EventManager-CONTEXT_MENU"></div>/** Key constant @type Number */\r
249     CONTEXT_MENU: 93,\r
250     <div id="prop-Ext.EventManager-NUM_ZERO"></div>/** Key constant @type Number */\r
251     NUM_ZERO: 96,\r
252     <div id="prop-Ext.EventManager-NUM_ONE"></div>/** Key constant @type Number */\r
253     NUM_ONE: 97,\r
254     <div id="prop-Ext.EventManager-NUM_TWO"></div>/** Key constant @type Number */\r
255     NUM_TWO: 98,\r
256     <div id="prop-Ext.EventManager-NUM_THREE"></div>/** Key constant @type Number */\r
257     NUM_THREE: 99,\r
258     <div id="prop-Ext.EventManager-NUM_FOUR"></div>/** Key constant @type Number */\r
259     NUM_FOUR: 100,\r
260     <div id="prop-Ext.EventManager-NUM_FIVE"></div>/** Key constant @type Number */\r
261     NUM_FIVE: 101,\r
262     <div id="prop-Ext.EventManager-NUM_SIX"></div>/** Key constant @type Number */\r
263     NUM_SIX: 102,\r
264     <div id="prop-Ext.EventManager-NUM_SEVEN"></div>/** Key constant @type Number */\r
265     NUM_SEVEN: 103,\r
266     <div id="prop-Ext.EventManager-NUM_EIGHT"></div>/** Key constant @type Number */\r
267     NUM_EIGHT: 104,\r
268     <div id="prop-Ext.EventManager-NUM_NINE"></div>/** Key constant @type Number */\r
269     NUM_NINE: 105,\r
270     <div id="prop-Ext.EventManager-NUM_MULTIPLY"></div>/** Key constant @type Number */\r
271     NUM_MULTIPLY: 106,\r
272     <div id="prop-Ext.EventManager-NUM_PLUS"></div>/** Key constant @type Number */\r
273     NUM_PLUS: 107,\r
274     <div id="prop-Ext.EventManager-NUM_MINUS"></div>/** Key constant @type Number */\r
275     NUM_MINUS: 109,\r
276     <div id="prop-Ext.EventManager-NUM_PERIOD"></div>/** Key constant @type Number */\r
277     NUM_PERIOD: 110,\r
278     <div id="prop-Ext.EventManager-NUM_DIVISION"></div>/** Key constant @type Number */\r
279     NUM_DIVISION: 111,\r
280     <div id="prop-Ext.EventManager-F1"></div>/** Key constant @type Number */\r
281     F1: 112,\r
282     <div id="prop-Ext.EventManager-F2"></div>/** Key constant @type Number */\r
283     F2: 113,\r
284     <div id="prop-Ext.EventManager-F3"></div>/** Key constant @type Number */\r
285     F3: 114,\r
286     <div id="prop-Ext.EventManager-F4"></div>/** Key constant @type Number */\r
287     F4: 115,\r
288     <div id="prop-Ext.EventManager-F5"></div>/** Key constant @type Number */\r
289     F5: 116,\r
290     <div id="prop-Ext.EventManager-F6"></div>/** Key constant @type Number */\r
291     F6: 117,\r
292     <div id="prop-Ext.EventManager-F7"></div>/** Key constant @type Number */\r
293     F7: 118,\r
294     <div id="prop-Ext.EventManager-F8"></div>/** Key constant @type Number */\r
295     F8: 119,\r
296     <div id="prop-Ext.EventManager-F9"></div>/** Key constant @type Number */\r
297     F9: 120,\r
298     <div id="prop-Ext.EventManager-F10"></div>/** Key constant @type Number */\r
299     F10: 121,\r
300     <div id="prop-Ext.EventManager-F11"></div>/** Key constant @type Number */\r
301     F11: 122,\r
302     <div id="prop-Ext.EventManager-F12"></div>/** Key constant @type Number */\r
303     F12: 123,   \r
304     \r
305     /** @private */\r
306     isNavKeyPress : function(){\r
307         var me = this,\r
308                 k = this.normalizeKey(me.keyCode);              \r
309         return (k >= 33 && k <= 40) ||  // Page Up/Down, End, Home, Left, Up, Right, Down\r
310                 k == me.RETURN ||\r
311                 k == me.TAB ||\r
312                 k == me.ESC;\r
313     },\r
314 \r
315     isSpecialKey : function(){\r
316         var k = this.normalizeKey(this.keyCode);\r
317         return (this.type == 'keypress' && this.ctrlKey) ||\r
318                 this.isNavKeyPress() ||\r
319         (k == this.BACKSPACE) || // Backspace\r
320                 (k >= 16 && k <= 20) || // Shift, Ctrl, Alt, Pause, Caps Lock\r
321                 (k >= 44 && k <= 45);   // Print Screen, Insert\r
322     },\r
323         \r
324         getPoint : function(){\r
325             return new Ext.lib.Point(this.xy[0], this.xy[1]);\r
326         },\r
327 \r
328     <div id="method-Ext.EventManager-hasModifier"></div>/**\r
329      * Returns true if the control, meta, shift or alt key was pressed during this event.\r
330      * @return {Boolean}\r
331      */\r
332     hasModifier : function(){\r
333         return ((this.ctrlKey || this.altKey) || this.shiftKey);\r
334     }\r
335 });</pre>    \r
336 </body>\r
337 </html>