Upgrade to ExtJS 3.1.1 - Released 02/08/2010
[extjs.git] / src / core / core / Ext.js
1 /*!
2  * Ext JS Library 3.1.1
3  * Copyright(c) 2006-2010 Ext JS, LLC
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7
8 // for old browsers
9 window.undefined = window.undefined;
10
11 /**
12  * @class Ext
13  * Ext core utilities and functions.
14  * @singleton
15  */
16
17 Ext = {
18     /**
19      * The version of the framework
20      * @type String
21      */
22     version : '3.1.1'
23 };
24
25 /**
26  * Copies all the properties of config to obj.
27  * @param {Object} obj The receiver of the properties
28  * @param {Object} config The source of the properties
29  * @param {Object} defaults A different object that will also be applied for default values
30  * @return {Object} returns obj
31  * @member Ext apply
32  */
33 Ext.apply = function(o, c, defaults){
34     // no "this" reference for friendly out of scope calls
35     if(defaults){
36         Ext.apply(o, defaults);
37     }
38     if(o && c && typeof c == 'object'){
39         for(var p in c){
40             o[p] = c[p];
41         }
42     }
43     return o;
44 };
45
46 (function(){
47     var idSeed = 0,
48         toString = Object.prototype.toString,
49         ua = navigator.userAgent.toLowerCase(),
50         check = function(r){
51             return r.test(ua);
52         },
53         DOC = document,
54         isStrict = DOC.compatMode == "CSS1Compat",
55         isOpera = check(/opera/),
56         isChrome = check(/\bchrome\b/),
57         isWebKit = check(/webkit/),
58         isSafari = !isChrome && check(/safari/),
59         isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
60         isSafari3 = isSafari && check(/version\/3/),
61         isSafari4 = isSafari && check(/version\/4/),
62         isIE = !isOpera && check(/msie/),
63         isIE7 = isIE && check(/msie 7/),
64         isIE8 = isIE && check(/msie 8/),
65         isIE6 = isIE && !isIE7 && !isIE8,
66         isGecko = !isWebKit && check(/gecko/),
67         isGecko2 = isGecko && check(/rv:1\.8/),
68         isGecko3 = isGecko && check(/rv:1\.9/),
69         isBorderBox = isIE && !isStrict,
70         isWindows = check(/windows|win32/),
71         isMac = check(/macintosh|mac os x/),
72         isAir = check(/adobeair/),
73         isLinux = check(/linux/),
74         isSecure = /^https/i.test(window.location.protocol);
75
76     // remove css image flicker
77     if(isIE6){
78         try{
79             DOC.execCommand("BackgroundImageCache", false, true);
80         }catch(e){}
81     }
82
83     Ext.apply(Ext, {
84         /**
85          * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent
86          * the IE insecure content warning (<tt>'about:blank'</tt>, except for IE in secure mode, which is <tt>'javascript:""'</tt>).
87          * @type String
88          */
89         SSL_SECURE_URL : isSecure && isIE ? 'javascript:""' : 'about:blank',
90         /**
91          * True if the browser is in strict (standards-compliant) mode, as opposed to quirks mode
92          * @type Boolean
93          */
94         isStrict : isStrict,
95         /**
96          * True if the page is running over SSL
97          * @type Boolean
98          */
99         isSecure : isSecure,
100         /**
101          * True when the document is fully initialized and ready for action
102          * @type Boolean
103          */
104         isReady : false,
105
106         /**
107          * True if the {@link Ext.Fx} Class is available
108          * @type Boolean
109          * @property enableFx
110          */
111
112         /**
113          * True to automatically uncache orphaned Ext.Elements periodically (defaults to true)
114          * @type Boolean
115          */
116         enableGarbageCollector : true,
117
118         /**
119          * True to automatically purge event listeners during garbageCollection (defaults to false).
120          * @type Boolean
121          */
122         enableListenerCollection : false,
123
124         /**
125          * EXPERIMENTAL - True to cascade listener removal to child elements when an element is removed.
126          * Currently not optimized for performance.
127          * @type Boolean
128          */
129         enableNestedListenerRemoval : false,
130
131         /**
132          * Indicates whether to use native browser parsing for JSON methods.
133          * This option is ignored if the browser does not support native JSON methods.
134          * <b>Note: Native JSON methods will not work with objects that have functions.
135          * Also, property names must be quoted, otherwise the data will not parse.</b> (Defaults to false)
136          * @type Boolean
137          */
138         USE_NATIVE_JSON : false,
139
140         /**
141          * Copies all the properties of config to obj if they don't already exist.
142          * @param {Object} obj The receiver of the properties
143          * @param {Object} config The source of the properties
144          * @return {Object} returns obj
145          */
146         applyIf : function(o, c){
147             if(o){
148                 for(var p in c){
149                     if(!Ext.isDefined(o[p])){
150                         o[p] = c[p];
151                     }
152                 }
153             }
154             return o;
155         },
156
157         /**
158          * Generates unique ids. If the element already has an id, it is unchanged
159          * @param {Mixed} el (optional) The element to generate an id for
160          * @param {String} prefix (optional) Id prefix (defaults "ext-gen")
161          * @return {String} The generated Id.
162          */
163         id : function(el, prefix){
164             el = Ext.getDom(el, true) || {};
165             if (!el.id) {
166                 el.id = (prefix || "ext-gen") + (++idSeed);
167             }
168             return el.id;
169         },
170
171         /**
172          * <p>Extends one class to create a subclass and optionally overrides members with the passed literal. This method
173          * also adds the function "override()" to the subclass that can be used to override members of the class.</p>
174          * For example, to create a subclass of Ext GridPanel:
175          * <pre><code>
176 MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
177     constructor: function(config) {
178
179 //      Create configuration for this Grid.
180         var store = new Ext.data.Store({...});
181         var colModel = new Ext.grid.ColumnModel({...});
182
183 //      Create a new config object containing our computed properties
184 //      *plus* whatever was in the config parameter.
185         config = Ext.apply({
186             store: store,
187             colModel: colModel
188         }, config);
189
190         MyGridPanel.superclass.constructor.call(this, config);
191
192 //      Your postprocessing here
193     },
194
195     yourMethod: function() {
196         // etc.
197     }
198 });
199 </code></pre>
200          *
201          * <p>This function also supports a 3-argument call in which the subclass's constructor is
202          * passed as an argument. In this form, the parameters are as follows:</p>
203          * <div class="mdetail-params"><ul>
204          * <li><code>subclass</code> : Function <div class="sub-desc">The subclass constructor.</div></li>
205          * <li><code>superclass</code> : Function <div class="sub-desc">The constructor of class being extended</div></li>
206          * <li><code>overrides</code> : Object <div class="sub-desc">A literal with members which are copied into the subclass's
207          * prototype, and are therefore shared among all instances of the new class.</div></li>
208          * </ul></div>
209          *
210          * @param {Function} superclass The constructor of class being extended.
211          * @param {Object} overrides <p>A literal with members which are copied into the subclass's
212          * prototype, and are therefore shared between all instances of the new class.</p>
213          * <p>This may contain a special member named <tt><b>constructor</b></tt>. This is used
214          * to define the constructor of the new class, and is returned. If this property is
215          * <i>not</i> specified, a constructor is generated and returned which just calls the
216          * superclass's constructor passing on its parameters.</p>
217          * <p><b>It is essential that you call the superclass constructor in any provided constructor. See example code.</b></p>
218          * @return {Function} The subclass constructor from the <code>overrides</code> parameter, or a generated one if not provided.
219          */
220         extend : function(){
221             // inline overrides
222             var io = function(o){
223                 for(var m in o){
224                     this[m] = o[m];
225                 }
226             };
227             var oc = Object.prototype.constructor;
228
229             return function(sb, sp, overrides){
230                 if(Ext.isObject(sp)){
231                     overrides = sp;
232                     sp = sb;
233                     sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
234                 }
235                 var F = function(){},
236                     sbp,
237                     spp = sp.prototype;
238
239                 F.prototype = spp;
240                 sbp = sb.prototype = new F();
241                 sbp.constructor=sb;
242                 sb.superclass=spp;
243                 if(spp.constructor == oc){
244                     spp.constructor=sp;
245                 }
246                 sb.override = function(o){
247                     Ext.override(sb, o);
248                 };
249                 sbp.superclass = sbp.supr = (function(){
250                     return spp;
251                 });
252                 sbp.override = io;
253                 Ext.override(sb, overrides);
254                 sb.extend = function(o){return Ext.extend(sb, o);};
255                 return sb;
256             };
257         }(),
258
259         /**
260          * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
261          * Usage:<pre><code>
262 Ext.override(MyClass, {
263     newMethod1: function(){
264         // etc.
265     },
266     newMethod2: function(foo){
267         // etc.
268     }
269 });
270 </code></pre>
271          * @param {Object} origclass The class to override
272          * @param {Object} overrides The list of functions to add to origClass.  This should be specified as an object literal
273          * containing one or more methods.
274          * @method override
275          */
276         override : function(origclass, overrides){
277             if(overrides){
278                 var p = origclass.prototype;
279                 Ext.apply(p, overrides);
280                 if(Ext.isIE && overrides.hasOwnProperty('toString')){
281                     p.toString = overrides.toString;
282                 }
283             }
284         },
285
286         /**
287          * Creates namespaces to be used for scoping variables and classes so that they are not global.
288          * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
289          * <pre><code>
290 Ext.namespace('Company', 'Company.data');
291 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
292 Company.Widget = function() { ... }
293 Company.data.CustomStore = function(config) { ... }
294 </code></pre>
295          * @param {String} namespace1
296          * @param {String} namespace2
297          * @param {String} etc
298          * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
299          * @method namespace
300          */
301         namespace : function(){
302             var o, d;
303             Ext.each(arguments, function(v) {
304                 d = v.split(".");
305                 o = window[d[0]] = window[d[0]] || {};
306                 Ext.each(d.slice(1), function(v2){
307                     o = o[v2] = o[v2] || {};
308                 });
309             });
310             return o;
311         },
312
313         /**
314          * Takes an object and converts it to an encoded URL. e.g. Ext.urlEncode({foo: 1, bar: 2}); would return "foo=1&bar=2".  Optionally, property values can be arrays, instead of keys and the resulting string that's returned will contain a name/value pair for each array value.
315          * @param {Object} o
316          * @param {String} pre (optional) A prefix to add to the url encoded string
317          * @return {String}
318          */
319         urlEncode : function(o, pre){
320             var empty,
321                 buf = [],
322                 e = encodeURIComponent;
323
324             Ext.iterate(o, function(key, item){
325                 empty = Ext.isEmpty(item);
326                 Ext.each(empty ? key : item, function(val){
327                     buf.push('&', e(key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : '');
328                 });
329             });
330             if(!pre){
331                 buf.shift();
332                 pre = '';
333             }
334             return pre + buf.join('');
335         },
336
337         /**
338          * Takes an encoded URL and and converts it to an object. Example: <pre><code>
339 Ext.urlDecode("foo=1&bar=2"); // returns {foo: "1", bar: "2"}
340 Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2", "3", "4"]}
341 </code></pre>
342          * @param {String} string
343          * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
344          * @return {Object} A literal with members
345          */
346         urlDecode : function(string, overwrite){
347             if(Ext.isEmpty(string)){
348                 return {};
349             }
350             var obj = {},
351                 pairs = string.split('&'),
352                 d = decodeURIComponent,
353                 name,
354                 value;
355             Ext.each(pairs, function(pair) {
356                 pair = pair.split('=');
357                 name = d(pair[0]);
358                 value = d(pair[1]);
359                 obj[name] = overwrite || !obj[name] ? value :
360                             [].concat(obj[name]).concat(value);
361             });
362             return obj;
363         },
364
365         /**
366          * Appends content to the query string of a URL, handling logic for whether to place
367          * a question mark or ampersand.
368          * @param {String} url The URL to append to.
369          * @param {String} s The content to append to the URL.
370          * @return (String) The resulting URL
371          */
372         urlAppend : function(url, s){
373             if(!Ext.isEmpty(s)){
374                 return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
375             }
376             return url;
377         },
378
379         /**
380          * Converts any iterable (numeric indices and a length property) into a true array
381          * Don't use this on strings. IE doesn't support "abc"[0] which this implementation depends on.
382          * For strings, use this instead: "abc".match(/./g) => [a,b,c];
383          * @param {Iterable} the iterable object to be turned into a true Array.
384          * @return (Array) array
385          */
386          toArray : function(){
387              return isIE ?
388                  function(a, i, j, res){
389                      res = [];
390                      for(var x = 0, len = a.length; x < len; x++) {
391                          res.push(a[x]);
392                      }
393                      return res.slice(i || 0, j || res.length);
394                  } :
395                  function(a, i, j){
396                      return Array.prototype.slice.call(a, i || 0, j || a.length);
397                  }
398          }(),
399
400         isIterable : function(v){
401             //check for array or arguments
402             if(Ext.isArray(v) || v.callee){
403                 return true;
404             }
405             //check for node list type
406             if(/NodeList|HTMLCollection/.test(toString.call(v))){
407                 return true;
408             }
409             //NodeList has an item and length property
410             //IXMLDOMNodeList has nextNode method, needs to be checked first.
411             return ((typeof v.nextNode != 'undefined' || v.item) && Ext.isNumber(v.length));
412         },
413
414         /**
415          * Iterates an array calling the supplied function.
416          * @param {Array/NodeList/Mixed} array The array to be iterated. If this
417          * argument is not really an array, the supplied function is called once.
418          * @param {Function} fn The function to be called with each item. If the
419          * supplied function returns false, iteration stops and this method returns
420          * the current <code>index</code>. This function is called with
421          * the following arguments:
422          * <div class="mdetail-params"><ul>
423          * <li><code>item</code> : <i>Mixed</i>
424          * <div class="sub-desc">The item at the current <code>index</code>
425          * in the passed <code>array</code></div></li>
426          * <li><code>index</code> : <i>Number</i>
427          * <div class="sub-desc">The current index within the array</div></li>
428          * <li><code>allItems</code> : <i>Array</i>
429          * <div class="sub-desc">The <code>array</code> passed as the first
430          * argument to <code>Ext.each</code>.</div></li>
431          * </ul></div>
432          * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed.
433          * Defaults to the <code>item</code> at the current <code>index</code>
434          * within the passed <code>array</code>.
435          * @return See description for the fn parameter.
436          */
437         each : function(array, fn, scope){
438             if(Ext.isEmpty(array, true)){
439                 return;
440             }
441             if(!Ext.isIterable(array) || Ext.isPrimitive(array)){
442                 array = [array];
443             }
444             for(var i = 0, len = array.length; i < len; i++){
445                 if(fn.call(scope || array[i], array[i], i, array) === false){
446                     return i;
447                 };
448             }
449         },
450
451         /**
452          * Iterates either the elements in an array, or each of the properties in an object.
453          * <b>Note</b>: If you are only iterating arrays, it is better to call {@link #each}.
454          * @param {Object/Array} object The object or array to be iterated
455          * @param {Function} fn The function to be called for each iteration.
456          * The iteration will stop if the supplied function returns false, or
457          * all array elements / object properties have been covered. The signature
458          * varies depending on the type of object being interated:
459          * <div class="mdetail-params"><ul>
460          * <li>Arrays : <tt>(Object item, Number index, Array allItems)</tt>
461          * <div class="sub-desc">
462          * When iterating an array, the supplied function is called with each item.</div></li>
463          * <li>Objects : <tt>(String key, Object value, Object)</tt>
464          * <div class="sub-desc">
465          * When iterating an object, the supplied function is called with each key-value pair in
466          * the object, and the iterated object</div></li>
467          * </ul></div>
468          * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed. Defaults to
469          * the <code>object</code> being iterated.
470          */
471         iterate : function(obj, fn, scope){
472             if(Ext.isEmpty(obj)){
473                 return;
474             }
475             if(Ext.isIterable(obj)){
476                 Ext.each(obj, fn, scope);
477                 return;
478             }else if(Ext.isObject(obj)){
479                 for(var prop in obj){
480                     if(obj.hasOwnProperty(prop)){
481                         if(fn.call(scope || obj, prop, obj[prop], obj) === false){
482                             return;
483                         };
484                     }
485                 }
486             }
487         },
488
489         /**
490          * Return the dom node for the passed String (id), dom node, or Ext.Element.
491          * Optional 'strict' flag is needed for IE since it can return 'name' and
492          * 'id' elements by using getElementById.
493          * Here are some examples:
494          * <pre><code>
495 // gets dom node based on id
496 var elDom = Ext.getDom('elId');
497 // gets dom node based on the dom node
498 var elDom1 = Ext.getDom(elDom);
499
500 // If we don&#39;t know if we are working with an
501 // Ext.Element or a dom node use Ext.getDom
502 function(el){
503     var dom = Ext.getDom(el);
504     // do something with the dom node
505 }
506          * </code></pre>
507          * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc)
508          * when this method is called to be successful.
509          * @param {Mixed} el
510          * @return HTMLElement
511          */
512         getDom : function(el, strict){
513             if(!el || !DOC){
514                 return null;
515             }
516             if (el.dom){
517                 return el.dom;
518             } else {
519                 if (Ext.isString(el)) {
520                     var e = DOC.getElementById(el);
521                     // IE returns elements with the 'name' and 'id' attribute.
522                     // we do a strict check to return the element with only the id attribute
523                     if (e && isIE && strict) {
524                         if (el == e.getAttribute('id')) {
525                             return e;
526                         } else {
527                             return null;
528                         }
529                     }
530                     return e;
531                 } else {
532                     return el;
533                 }
534             }
535         },
536
537         /**
538          * Returns the current document body as an {@link Ext.Element}.
539          * @return Ext.Element The document body
540          */
541         getBody : function(){
542             return Ext.get(DOC.body || DOC.documentElement);
543         },
544
545         /**
546          * Removes a DOM node from the document.
547          */
548         /**
549          * <p>Removes this element from the document, removes all DOM event listeners, and deletes the cache reference.
550          * All DOM event listeners are removed from this element. If {@link Ext#enableNestedListenerRemoval} is
551          * <code>true</code>, then DOM event listeners are also removed from all child nodes. The body node
552          * will be ignored if passed in.</p>
553          * @param {HTMLElement} node The node to remove
554          */
555         removeNode : isIE && !isIE8 ? function(){
556             var d;
557             return function(n){
558                 if(n && n.tagName != 'BODY'){
559                     (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
560                     d = d || DOC.createElement('div');
561                     d.appendChild(n);
562                     d.innerHTML = '';
563                     delete Ext.elCache[n.id];
564                 }
565             }
566         }() : function(n){
567             if(n && n.parentNode && n.tagName != 'BODY'){
568                 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
569                 n.parentNode.removeChild(n);
570                 delete Ext.elCache[n.id];
571             }
572         },
573
574         /**
575          * <p>Returns true if the passed value is empty.</p>
576          * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
577          * <li>null</li>
578          * <li>undefined</li>
579          * <li>an empty array</li>
580          * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
581          * </ul></div>
582          * @param {Mixed} value The value to test
583          * @param {Boolean} allowBlank (optional) true to allow empty strings (defaults to false)
584          * @return {Boolean}
585          */
586         isEmpty : function(v, allowBlank){
587             return v === null || v === undefined || ((Ext.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false);
588         },
589
590         /**
591          * Returns true if the passed value is a JavaScript array, otherwise false.
592          * @param {Mixed} value The value to test
593          * @return {Boolean}
594          */
595         isArray : function(v){
596             return toString.apply(v) === '[object Array]';
597         },
598
599         /**
600          * Returns true if the passed object is a JavaScript date object, otherwise false.
601          * @param {Object} object The object to test
602          * @return {Boolean}
603          */
604         isDate : function(v){
605             return toString.apply(v) === '[object Date]';
606         },
607
608         /**
609          * Returns true if the passed value is a JavaScript Object, otherwise false.
610          * @param {Mixed} value The value to test
611          * @return {Boolean}
612          */
613         isObject : function(v){
614             return !!v && Object.prototype.toString.call(v) === '[object Object]';
615         },
616
617         /**
618          * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean.
619          * @param {Mixed} value The value to test
620          * @return {Boolean}
621          */
622         isPrimitive : function(v){
623             return Ext.isString(v) || Ext.isNumber(v) || Ext.isBoolean(v);
624         },
625
626         /**
627          * Returns true if the passed value is a JavaScript Function, otherwise false.
628          * @param {Mixed} value The value to test
629          * @return {Boolean}
630          */
631         isFunction : function(v){
632             return toString.apply(v) === '[object Function]';
633         },
634
635         /**
636          * Returns true if the passed value is a number. Returns false for non-finite numbers.
637          * @param {Mixed} value The value to test
638          * @return {Boolean}
639          */
640         isNumber : function(v){
641             return typeof v === 'number' && isFinite(v);
642         },
643
644         /**
645          * Returns true if the passed value is a string.
646          * @param {Mixed} value The value to test
647          * @return {Boolean}
648          */
649         isString : function(v){
650             return typeof v === 'string';
651         },
652
653         /**
654          * Returns true if the passed value is a boolean.
655          * @param {Mixed} value The value to test
656          * @return {Boolean}
657          */
658         isBoolean : function(v){
659             return typeof v === 'boolean';
660         },
661
662         /**
663          * Returns true if the passed value is an HTMLElement
664          * @param {Mixed} value The value to test
665          * @return {Boolean}
666          */
667         isElement : function(v) {
668             return !!v && v.tagName;
669         },
670
671         /**
672          * Returns true if the passed value is not undefined.
673          * @param {Mixed} value The value to test
674          * @return {Boolean}
675          */
676         isDefined : function(v){
677             return typeof v !== 'undefined';
678         },
679
680         /**
681          * True if the detected browser is Opera.
682          * @type Boolean
683          */
684         isOpera : isOpera,
685         /**
686          * True if the detected browser uses WebKit.
687          * @type Boolean
688          */
689         isWebKit : isWebKit,
690         /**
691          * True if the detected browser is Chrome.
692          * @type Boolean
693          */
694         isChrome : isChrome,
695         /**
696          * True if the detected browser is Safari.
697          * @type Boolean
698          */
699         isSafari : isSafari,
700         /**
701          * True if the detected browser is Safari 3.x.
702          * @type Boolean
703          */
704         isSafari3 : isSafari3,
705         /**
706          * True if the detected browser is Safari 4.x.
707          * @type Boolean
708          */
709         isSafari4 : isSafari4,
710         /**
711          * True if the detected browser is Safari 2.x.
712          * @type Boolean
713          */
714         isSafari2 : isSafari2,
715         /**
716          * True if the detected browser is Internet Explorer.
717          * @type Boolean
718          */
719         isIE : isIE,
720         /**
721          * True if the detected browser is Internet Explorer 6.x.
722          * @type Boolean
723          */
724         isIE6 : isIE6,
725         /**
726          * True if the detected browser is Internet Explorer 7.x.
727          * @type Boolean
728          */
729         isIE7 : isIE7,
730         /**
731          * True if the detected browser is Internet Explorer 8.x.
732          * @type Boolean
733          */
734         isIE8 : isIE8,
735         /**
736          * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
737          * @type Boolean
738          */
739         isGecko : isGecko,
740         /**
741          * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x).
742          * @type Boolean
743          */
744         isGecko2 : isGecko2,
745         /**
746          * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
747          * @type Boolean
748          */
749         isGecko3 : isGecko3,
750         /**
751          * True if the detected browser is Internet Explorer running in non-strict mode.
752          * @type Boolean
753          */
754         isBorderBox : isBorderBox,
755         /**
756          * True if the detected platform is Linux.
757          * @type Boolean
758          */
759         isLinux : isLinux,
760         /**
761          * True if the detected platform is Windows.
762          * @type Boolean
763          */
764         isWindows : isWindows,
765         /**
766          * True if the detected platform is Mac OS.
767          * @type Boolean
768          */
769         isMac : isMac,
770         /**
771          * True if the detected platform is Adobe Air.
772          * @type Boolean
773          */
774         isAir : isAir
775     });
776
777     /**
778      * Creates namespaces to be used for scoping variables and classes so that they are not global.
779      * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
780      * <pre><code>
781 Ext.namespace('Company', 'Company.data');
782 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
783 Company.Widget = function() { ... }
784 Company.data.CustomStore = function(config) { ... }
785 </code></pre>
786      * @param {String} namespace1
787      * @param {String} namespace2
788      * @param {String} etc
789      * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
790      * @method ns
791      */
792     Ext.ns = Ext.namespace;
793 })();
794
795 Ext.ns("Ext.util", "Ext.lib", "Ext.data");
796
797 Ext.elCache = {};
798
799 /**
800  * @class Function
801  * These functions are available on every Function object (any JavaScript function).
802  */
803 Ext.apply(Function.prototype, {
804      /**
805      * Creates an interceptor function. The passed function is called before the original one. If it returns false,
806      * the original one is not called. The resulting function returns the results of the original function.
807      * The passed function is called with the parameters of the original function. Example usage:
808      * <pre><code>
809 var sayHi = function(name){
810     alert('Hi, ' + name);
811 }
812
813 sayHi('Fred'); // alerts "Hi, Fred"
814
815 // create a new function that validates input without
816 // directly modifying the original function:
817 var sayHiToFriend = sayHi.createInterceptor(function(name){
818     return name == 'Brian';
819 });
820
821 sayHiToFriend('Fred');  // no alert
822 sayHiToFriend('Brian'); // alerts "Hi, Brian"
823 </code></pre>
824      * @param {Function} fcn The function to call before the original
825      * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
826      * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
827      * @return {Function} The new function
828      */
829     createInterceptor : function(fcn, scope){
830         var method = this;
831         return !Ext.isFunction(fcn) ?
832                 this :
833                 function() {
834                     var me = this,
835                         args = arguments;
836                     fcn.target = me;
837                     fcn.method = method;
838                     return (fcn.apply(scope || me || window, args) !== false) ?
839                             method.apply(me || window, args) :
840                             null;
841                 };
842     },
843
844      /**
845      * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
846      * Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code>
847      * Will create a function that is bound to those 2 args. <b>If a specific scope is required in the
848      * callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always
849      * executes in the window scope.
850      * <p>This method is required when you want to pass arguments to a callback function.  If no arguments
851      * are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn).
852      * However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function
853      * would simply execute immediately when the code is parsed. Example usage:
854      * <pre><code>
855 var sayHi = function(name){
856     alert('Hi, ' + name);
857 }
858
859 // clicking the button alerts "Hi, Fred"
860 new Ext.Button({
861     text: 'Say Hi',
862     renderTo: Ext.getBody(),
863     handler: sayHi.createCallback('Fred')
864 });
865 </code></pre>
866      * @return {Function} The new function
867     */
868     createCallback : function(/*args...*/){
869         // make args available, in function below
870         var args = arguments,
871             method = this;
872         return function() {
873             return method.apply(window, args);
874         };
875     },
876
877     /**
878      * Creates a delegate (callback) that sets the scope to obj.
879      * Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code>
880      * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
881      * callback points to obj. Example usage:
882      * <pre><code>
883 var sayHi = function(name){
884     // Note this use of "this.text" here.  This function expects to
885     // execute within a scope that contains a text property.  In this
886     // example, the "this" variable is pointing to the btn object that
887     // was passed in createDelegate below.
888     alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
889 }
890
891 var btn = new Ext.Button({
892     text: 'Say Hi',
893     renderTo: Ext.getBody()
894 });
895
896 // This callback will execute in the scope of the
897 // button instance. Clicking the button alerts
898 // "Hi, Fred. You clicked the "Say Hi" button."
899 btn.on('click', sayHi.createDelegate(btn, ['Fred']));
900 </code></pre>
901      * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
902      * <b>If omitted, defaults to the browser window.</b>
903      * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
904      * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
905      * if a number the args are inserted at the specified position
906      * @return {Function} The new function
907      */
908     createDelegate : function(obj, args, appendArgs){
909         var method = this;
910         return function() {
911             var callArgs = args || arguments;
912             if (appendArgs === true){
913                 callArgs = Array.prototype.slice.call(arguments, 0);
914                 callArgs = callArgs.concat(args);
915             }else if (Ext.isNumber(appendArgs)){
916                 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
917                 var applyArgs = [appendArgs, 0].concat(args); // create method call params
918                 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
919             }
920             return method.apply(obj || window, callArgs);
921         };
922     },
923
924     /**
925      * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
926      * <pre><code>
927 var sayHi = function(name){
928     alert('Hi, ' + name);
929 }
930
931 // executes immediately:
932 sayHi('Fred');
933
934 // executes after 2 seconds:
935 sayHi.defer(2000, this, ['Fred']);
936
937 // this syntax is sometimes useful for deferring
938 // execution of an anonymous function:
939 (function(){
940     alert('Anonymous');
941 }).defer(100);
942 </code></pre>
943      * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
944      * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
945      * <b>If omitted, defaults to the browser window.</b>
946      * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
947      * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
948      * if a number the args are inserted at the specified position
949      * @return {Number} The timeout id that can be used with clearTimeout
950      */
951     defer : function(millis, obj, args, appendArgs){
952         var fn = this.createDelegate(obj, args, appendArgs);
953         if(millis > 0){
954             return setTimeout(fn, millis);
955         }
956         fn();
957         return 0;
958     }
959 });
960
961 /**
962  * @class String
963  * These functions are available on every String object.
964  */
965 Ext.applyIf(String, {
966     /**
967      * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens.  Each
968      * token must be unique, and must increment in the format {0}, {1}, etc.  Example usage:
969      * <pre><code>
970 var cls = 'my-class', text = 'Some text';
971 var s = String.format('&lt;div class="{0}">{1}&lt;/div>', cls, text);
972 // s now contains the string: '&lt;div class="my-class">Some text&lt;/div>'
973      * </code></pre>
974      * @param {String} string The tokenized string to be formatted
975      * @param {String} value1 The value to replace token {0}
976      * @param {String} value2 Etc...
977      * @return {String} The formatted string
978      * @static
979      */
980     format : function(format){
981         var args = Ext.toArray(arguments, 1);
982         return format.replace(/\{(\d+)\}/g, function(m, i){
983             return args[i];
984         });
985     }
986 });
987
988 /**
989  * @class Array
990  */
991 Ext.applyIf(Array.prototype, {
992     /**
993      * Checks whether or not the specified object exists in the array.
994      * @param {Object} o The object to check for
995      * @param {Number} from (Optional) The index at which to begin the search
996      * @return {Number} The index of o in the array (or -1 if it is not found)
997      */
998     indexOf : function(o, from){
999         var len = this.length;
1000         from = from || 0;
1001         from += (from < 0) ? len : 0;
1002         for (; from < len; ++from){
1003             if(this[from] === o){
1004                 return from;
1005             }
1006         }
1007         return -1;
1008     },
1009
1010     /**
1011      * Removes the specified object from the array.  If the object is not found nothing happens.
1012      * @param {Object} o The object to remove
1013      * @return {Array} this array
1014      */
1015     remove : function(o){
1016         var index = this.indexOf(o);
1017         if(index != -1){
1018             this.splice(index, 1);
1019         }
1020         return this;
1021     }
1022 });