3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
8 window.undefined = window.undefined;
12 * Ext core utilities and functions.
18 * The version of the framework
30 * Copies all the properties of config to obj.
31 * @param {Object} obj The receiver of the properties
32 * @param {Object} config The source of the properties
33 * @param {Object} defaults A different object that will also be applied for default values
34 * @return {Object} returns obj
37 Ext.apply = function(o, c, defaults){
38 // no "this" reference for friendly out of scope calls
40 Ext.apply(o, defaults);
42 if(o && c && typeof c == 'object'){
52 toString = Object.prototype.toString,
53 ua = navigator.userAgent.toLowerCase(),
58 docMode = DOC.documentMode,
59 isStrict = DOC.compatMode == "CSS1Compat",
60 isOpera = check(/opera/),
61 isChrome = check(/\bchrome\b/),
62 isWebKit = check(/webkit/),
63 isSafari = !isChrome && check(/safari/),
64 isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
65 isSafari3 = isSafari && check(/version\/3/),
66 isSafari4 = isSafari && check(/version\/4/),
67 isIE = !isOpera && check(/msie/),
68 isIE7 = isIE && (check(/msie 7/) || docMode == 7),
69 isIE8 = isIE && (check(/msie 8/) && docMode != 7),
70 isIE6 = isIE && !isIE7 && !isIE8,
71 isGecko = !isWebKit && check(/gecko/),
72 isGecko2 = isGecko && check(/rv:1\.8/),
73 isGecko3 = isGecko && check(/rv:1\.9/),
74 isBorderBox = isIE && !isStrict,
75 isWindows = check(/windows|win32/),
76 isMac = check(/macintosh|mac os x/),
77 isAir = check(/adobeair/),
78 isLinux = check(/linux/),
79 isSecure = /^https/i.test(window.location.protocol);
81 // remove css image flicker
84 DOC.execCommand("BackgroundImageCache", false, true);
90 * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent
91 * the IE insecure content warning (<tt>'about:blank'</tt>, except for IE in secure mode, which is <tt>'javascript:""'</tt>).
94 SSL_SECURE_URL : isSecure && isIE ? 'javascript:""' : 'about:blank',
96 * True if the browser is in strict (standards-compliant) mode, as opposed to quirks mode
101 * True if the page is running over SSL
106 * True when the document is fully initialized and ready for action
112 * True if the {@link Ext.Fx} Class is available
118 * HIGHLY EXPERIMENTAL
119 * True to force css based border-box model override and turning off javascript based adjustments. This is a
120 * runtime configuration and must be set before onReady.
123 enableForcedBoxModel : false,
126 * True to automatically uncache orphaned Ext.Elements periodically (defaults to true)
129 enableGarbageCollector : true,
132 * True to automatically purge event listeners during garbageCollection (defaults to false).
135 enableListenerCollection : false,
138 * EXPERIMENTAL - True to cascade listener removal to child elements when an element is removed.
139 * Currently not optimized for performance.
142 enableNestedListenerRemoval : false,
145 * Indicates whether to use native browser parsing for JSON methods.
146 * This option is ignored if the browser does not support native JSON methods.
147 * <b>Note: Native JSON methods will not work with objects that have functions.
148 * Also, property names must be quoted, otherwise the data will not parse.</b> (Defaults to false)
151 USE_NATIVE_JSON : false,
154 * Copies all the properties of config to obj if they don't already exist.
155 * @param {Object} obj The receiver of the properties
156 * @param {Object} config The source of the properties
157 * @return {Object} returns obj
159 applyIf : function(o, c){
162 if(!Ext.isDefined(o[p])){
171 * Generates unique ids. If the element already has an id, it is unchanged
172 * @param {Mixed} el (optional) The element to generate an id for
173 * @param {String} prefix (optional) Id prefix (defaults "ext-gen")
174 * @return {String} The generated Id.
176 id : function(el, prefix){
177 el = Ext.getDom(el, true) || {};
179 el.id = (prefix || "ext-gen") + (++idSeed);
185 * <p>Extends one class to create a subclass and optionally overrides members with the passed literal. This method
186 * also adds the function "override()" to the subclass that can be used to override members of the class.</p>
187 * For example, to create a subclass of Ext GridPanel:
189 MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
190 constructor: function(config) {
192 // Create configuration for this Grid.
193 var store = new Ext.data.Store({...});
194 var colModel = new Ext.grid.ColumnModel({...});
196 // Create a new config object containing our computed properties
197 // *plus* whatever was in the config parameter.
203 MyGridPanel.superclass.constructor.call(this, config);
205 // Your postprocessing here
208 yourMethod: function() {
214 * <p>This function also supports a 3-argument call in which the subclass's constructor is
215 * passed as an argument. In this form, the parameters are as follows:</p>
216 * <div class="mdetail-params"><ul>
217 * <li><code>subclass</code> : Function <div class="sub-desc">The subclass constructor.</div></li>
218 * <li><code>superclass</code> : Function <div class="sub-desc">The constructor of class being extended</div></li>
219 * <li><code>overrides</code> : Object <div class="sub-desc">A literal with members which are copied into the subclass's
220 * prototype, and are therefore shared among all instances of the new class.</div></li>
223 * @param {Function} superclass The constructor of class being extended.
224 * @param {Object} overrides <p>A literal with members which are copied into the subclass's
225 * prototype, and are therefore shared between all instances of the new class.</p>
226 * <p>This may contain a special member named <tt><b>constructor</b></tt>. This is used
227 * to define the constructor of the new class, and is returned. If this property is
228 * <i>not</i> specified, a constructor is generated and returned which just calls the
229 * superclass's constructor passing on its parameters.</p>
230 * <p><b>It is essential that you call the superclass constructor in any provided constructor. See example code.</b></p>
231 * @return {Function} The subclass constructor from the <code>overrides</code> parameter, or a generated one if not provided.
235 var io = function(o){
240 var oc = Object.prototype.constructor;
242 return function(sb, sp, overrides){
243 if(typeof sp == 'object'){
246 sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
248 var F = function(){},
253 sbp = sb.prototype = new F();
256 if(spp.constructor == oc){
259 sb.override = function(o){
262 sbp.superclass = sbp.supr = (function(){
266 Ext.override(sb, overrides);
267 sb.extend = function(o){return Ext.extend(sb, o);};
273 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
275 Ext.override(MyClass, {
276 newMethod1: function(){
279 newMethod2: function(foo){
284 * @param {Object} origclass The class to override
285 * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
286 * containing one or more methods.
289 override : function(origclass, overrides){
291 var p = origclass.prototype;
292 Ext.apply(p, overrides);
293 if(Ext.isIE && overrides.hasOwnProperty('toString')){
294 p.toString = overrides.toString;
300 * Creates namespaces to be used for scoping variables and classes so that they are not global.
301 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
303 Ext.namespace('Company', 'Company.data');
304 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
305 Company.Widget = function() { ... }
306 Company.data.CustomStore = function(config) { ... }
308 * @param {String} namespace1
309 * @param {String} namespace2
310 * @param {String} etc
311 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
314 namespace : function(){
316 Ext.each(arguments, function(v) {
318 o = window[d[0]] = window[d[0]] || {};
319 Ext.each(d.slice(1), function(v2){
320 o = o[v2] = o[v2] || {};
327 * 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.
329 * @param {String} pre (optional) A prefix to add to the url encoded string
332 urlEncode : function(o, pre){
335 e = encodeURIComponent;
337 Ext.iterate(o, function(key, item){
338 empty = Ext.isEmpty(item);
339 Ext.each(empty ? key : item, function(val){
340 buf.push('&', e(key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : '');
347 return pre + buf.join('');
351 * Takes an encoded URL and and converts it to an object. Example: <pre><code>
352 Ext.urlDecode("foo=1&bar=2"); // returns {foo: "1", bar: "2"}
353 Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2", "3", "4"]}
355 * @param {String} string
356 * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
357 * @return {Object} A literal with members
359 urlDecode : function(string, overwrite){
360 if(Ext.isEmpty(string)){
364 pairs = string.split('&'),
365 d = decodeURIComponent,
368 Ext.each(pairs, function(pair) {
369 pair = pair.split('=');
372 obj[name] = overwrite || !obj[name] ? value :
373 [].concat(obj[name]).concat(value);
379 * Appends content to the query string of a URL, handling logic for whether to place
380 * a question mark or ampersand.
381 * @param {String} url The URL to append to.
382 * @param {String} s The content to append to the URL.
383 * @return (String) The resulting URL
385 urlAppend : function(url, s){
387 return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
393 * Converts any iterable (numeric indices and a length property) into a true array
394 * Don't use this on strings. IE doesn't support "abc"[0] which this implementation depends on.
395 * For strings, use this instead: "abc".match(/./g) => [a,b,c];
396 * @param {Iterable} the iterable object to be turned into a true Array.
397 * @return (Array) array
399 toArray : function(){
401 function(a, i, j, res){
403 for(var x = 0, len = a.length; x < len; x++) {
406 return res.slice(i || 0, j || res.length);
409 return Array.prototype.slice.call(a, i || 0, j || a.length);
413 isIterable : function(v){
414 //check for array or arguments
415 if(Ext.isArray(v) || v.callee){
418 //check for node list type
419 if(/NodeList|HTMLCollection/.test(toString.call(v))){
422 //NodeList has an item and length property
423 //IXMLDOMNodeList has nextNode method, needs to be checked first.
424 return ((typeof v.nextNode != 'undefined' || v.item) && Ext.isNumber(v.length));
428 * Iterates an array calling the supplied function.
429 * @param {Array/NodeList/Mixed} array The array to be iterated. If this
430 * argument is not really an array, the supplied function is called once.
431 * @param {Function} fn The function to be called with each item. If the
432 * supplied function returns false, iteration stops and this method returns
433 * the current <code>index</code>. This function is called with
434 * the following arguments:
435 * <div class="mdetail-params"><ul>
436 * <li><code>item</code> : <i>Mixed</i>
437 * <div class="sub-desc">The item at the current <code>index</code>
438 * in the passed <code>array</code></div></li>
439 * <li><code>index</code> : <i>Number</i>
440 * <div class="sub-desc">The current index within the array</div></li>
441 * <li><code>allItems</code> : <i>Array</i>
442 * <div class="sub-desc">The <code>array</code> passed as the first
443 * argument to <code>Ext.each</code>.</div></li>
445 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed.
446 * Defaults to the <code>item</code> at the current <code>index</code>
447 * within the passed <code>array</code>.
448 * @return See description for the fn parameter.
450 each : function(array, fn, scope){
451 if(Ext.isEmpty(array, true)){
454 if(!Ext.isIterable(array) || Ext.isPrimitive(array)){
457 for(var i = 0, len = array.length; i < len; i++){
458 if(fn.call(scope || array[i], array[i], i, array) === false){
465 * Iterates either the elements in an array, or each of the properties in an object.
466 * <b>Note</b>: If you are only iterating arrays, it is better to call {@link #each}.
467 * @param {Object/Array} object The object or array to be iterated
468 * @param {Function} fn The function to be called for each iteration.
469 * The iteration will stop if the supplied function returns false, or
470 * all array elements / object properties have been covered. The signature
471 * varies depending on the type of object being interated:
472 * <div class="mdetail-params"><ul>
473 * <li>Arrays : <tt>(Object item, Number index, Array allItems)</tt>
474 * <div class="sub-desc">
475 * When iterating an array, the supplied function is called with each item.</div></li>
476 * <li>Objects : <tt>(String key, Object value, Object)</tt>
477 * <div class="sub-desc">
478 * When iterating an object, the supplied function is called with each key-value pair in
479 * the object, and the iterated object</div></li>
481 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed. Defaults to
482 * the <code>object</code> being iterated.
484 iterate : function(obj, fn, scope){
485 if(Ext.isEmpty(obj)){
488 if(Ext.isIterable(obj)){
489 Ext.each(obj, fn, scope);
491 }else if(typeof obj == 'object'){
492 for(var prop in obj){
493 if(obj.hasOwnProperty(prop)){
494 if(fn.call(scope || obj, prop, obj[prop], obj) === false){
503 * Return the dom node for the passed String (id), dom node, or Ext.Element.
504 * Optional 'strict' flag is needed for IE since it can return 'name' and
505 * 'id' elements by using getElementById.
506 * Here are some examples:
508 // gets dom node based on id
509 var elDom = Ext.getDom('elId');
510 // gets dom node based on the dom node
511 var elDom1 = Ext.getDom(elDom);
513 // If we don't know if we are working with an
514 // Ext.Element or a dom node use Ext.getDom
516 var dom = Ext.getDom(el);
517 // do something with the dom node
520 * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc)
521 * when this method is called to be successful.
523 * @return HTMLElement
525 getDom : function(el, strict){
532 if (typeof el == 'string') {
533 var e = DOC.getElementById(el);
534 // IE returns elements with the 'name' and 'id' attribute.
535 // we do a strict check to return the element with only the id attribute
536 if (e && isIE && strict) {
537 if (el == e.getAttribute('id')) {
551 * Returns the current document body as an {@link Ext.Element}.
552 * @return Ext.Element The document body
554 getBody : function(){
555 return Ext.get(DOC.body || DOC.documentElement);
559 * Returns the current document body as an {@link Ext.Element}.
560 * @return Ext.Element The document body
562 getHead : function() {
566 if (head == undefined) {
567 head = Ext.get(DOC.getElementsByTagName("head")[0]);
575 * Removes a DOM node from the document.
578 * <p>Removes this element from the document, removes all DOM event listeners, and deletes the cache reference.
579 * All DOM event listeners are removed from this element. If {@link Ext#enableNestedListenerRemoval} is
580 * <code>true</code>, then DOM event listeners are also removed from all child nodes. The body node
581 * will be ignored if passed in.</p>
582 * @param {HTMLElement} node The node to remove
584 removeNode : isIE && !isIE8 ? function(){
587 if(n && n.tagName != 'BODY'){
588 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
589 d = d || DOC.createElement('div');
592 delete Ext.elCache[n.id];
596 if(n && n.parentNode && n.tagName != 'BODY'){
597 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
598 n.parentNode.removeChild(n);
599 delete Ext.elCache[n.id];
604 * <p>Returns true if the passed value is empty.</p>
605 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
608 * <li>an empty array</li>
609 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
611 * @param {Mixed} value The value to test
612 * @param {Boolean} allowBlank (optional) true to allow empty strings (defaults to false)
615 isEmpty : function(v, allowBlank){
616 return v === null || v === undefined || ((Ext.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false);
620 * Returns true if the passed value is a JavaScript array, otherwise false.
621 * @param {Mixed} value The value to test
624 isArray : function(v){
625 return toString.apply(v) === '[object Array]';
629 * Returns true if the passed object is a JavaScript date object, otherwise false.
630 * @param {Object} object The object to test
633 isDate : function(v){
634 return toString.apply(v) === '[object Date]';
638 * Returns true if the passed value is a JavaScript Object, otherwise false.
639 * @param {Mixed} value The value to test
642 isObject : function(v){
643 return !!v && Object.prototype.toString.call(v) === '[object Object]';
647 * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean.
648 * @param {Mixed} value The value to test
651 isPrimitive : function(v){
652 return Ext.isString(v) || Ext.isNumber(v) || Ext.isBoolean(v);
656 * Returns true if the passed value is a JavaScript Function, otherwise false.
657 * @param {Mixed} value The value to test
660 isFunction : function(v){
661 return toString.apply(v) === '[object Function]';
665 * Returns true if the passed value is a number. Returns false for non-finite numbers.
666 * @param {Mixed} value The value to test
669 isNumber : function(v){
670 return typeof v === 'number' && isFinite(v);
674 * Returns true if the passed value is a string.
675 * @param {Mixed} value The value to test
678 isString : function(v){
679 return typeof v === 'string';
683 * Returns true if the passed value is a boolean.
684 * @param {Mixed} value The value to test
687 isBoolean : function(v){
688 return typeof v === 'boolean';
692 * Returns true if the passed value is an HTMLElement
693 * @param {Mixed} value The value to test
696 isElement : function(v) {
697 return v ? !!v.tagName : false;
701 * Returns true if the passed value is not undefined.
702 * @param {Mixed} value The value to test
705 isDefined : function(v){
706 return typeof v !== 'undefined';
710 * True if the detected browser is Opera.
715 * True if the detected browser uses WebKit.
720 * True if the detected browser is Chrome.
725 * True if the detected browser is Safari.
730 * True if the detected browser is Safari 3.x.
733 isSafari3 : isSafari3,
735 * True if the detected browser is Safari 4.x.
738 isSafari4 : isSafari4,
740 * True if the detected browser is Safari 2.x.
743 isSafari2 : isSafari2,
745 * True if the detected browser is Internet Explorer.
750 * True if the detected browser is Internet Explorer 6.x.
755 * True if the detected browser is Internet Explorer 7.x.
760 * True if the detected browser is Internet Explorer 8.x.
765 * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
770 * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x).
775 * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
780 * True if the detected browser is Internet Explorer running in non-strict mode.
783 isBorderBox : isBorderBox,
785 * True if the detected platform is Linux.
790 * True if the detected platform is Windows.
793 isWindows : isWindows,
795 * True if the detected platform is Mac OS.
800 * True if the detected platform is Adobe Air.
807 * Creates namespaces to be used for scoping variables and classes so that they are not global.
808 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
810 Ext.namespace('Company', 'Company.data');
811 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
812 Company.Widget = function() { ... }
813 Company.data.CustomStore = function(config) { ... }
815 * @param {String} namespace1
816 * @param {String} namespace2
817 * @param {String} etc
818 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
821 Ext.ns = Ext.namespace;
824 Ext.ns('Ext.util', 'Ext.lib', 'Ext.data', 'Ext.supports');
830 * These functions are available on every Function object (any JavaScript function).
832 Ext.apply(Function.prototype, {
834 * Creates an interceptor function. The passed function is called before the original one. If it returns false,
835 * the original one is not called. The resulting function returns the results of the original function.
836 * The passed function is called with the parameters of the original function. Example usage:
838 var sayHi = function(name){
839 alert('Hi, ' + name);
842 sayHi('Fred'); // alerts "Hi, Fred"
844 // create a new function that validates input without
845 // directly modifying the original function:
846 var sayHiToFriend = sayHi.createInterceptor(function(name){
847 return name == 'Brian';
850 sayHiToFriend('Fred'); // no alert
851 sayHiToFriend('Brian'); // alerts "Hi, Brian"
853 * @param {Function} fcn The function to call before the original
854 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
855 * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
856 * @return {Function} The new function
858 createInterceptor : function(fcn, scope){
860 return !Ext.isFunction(fcn) ?
867 return (fcn.apply(scope || me || window, args) !== false) ?
868 method.apply(me || window, args) :
874 * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
875 * Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code>
876 * Will create a function that is bound to those 2 args. <b>If a specific scope is required in the
877 * callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always
878 * executes in the window scope.
879 * <p>This method is required when you want to pass arguments to a callback function. If no arguments
880 * are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn).
881 * However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function
882 * would simply execute immediately when the code is parsed. Example usage:
884 var sayHi = function(name){
885 alert('Hi, ' + name);
888 // clicking the button alerts "Hi, Fred"
891 renderTo: Ext.getBody(),
892 handler: sayHi.createCallback('Fred')
895 * @return {Function} The new function
897 createCallback : function(/*args...*/){
898 // make args available, in function below
899 var args = arguments,
902 return method.apply(window, args);
907 * Creates a delegate (callback) that sets the scope to obj.
908 * Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code>
909 * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
910 * callback points to obj. Example usage:
912 var sayHi = function(name){
913 // Note this use of "this.text" here. This function expects to
914 // execute within a scope that contains a text property. In this
915 // example, the "this" variable is pointing to the btn object that
916 // was passed in createDelegate below.
917 alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
920 var btn = new Ext.Button({
922 renderTo: Ext.getBody()
925 // This callback will execute in the scope of the
926 // button instance. Clicking the button alerts
927 // "Hi, Fred. You clicked the "Say Hi" button."
928 btn.on('click', sayHi.createDelegate(btn, ['Fred']));
930 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
931 * <b>If omitted, defaults to the browser window.</b>
932 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
933 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
934 * if a number the args are inserted at the specified position
935 * @return {Function} The new function
937 createDelegate : function(obj, args, appendArgs){
940 var callArgs = args || arguments;
941 if (appendArgs === true){
942 callArgs = Array.prototype.slice.call(arguments, 0);
943 callArgs = callArgs.concat(args);
944 }else if (Ext.isNumber(appendArgs)){
945 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
946 var applyArgs = [appendArgs, 0].concat(args); // create method call params
947 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
949 return method.apply(obj || window, callArgs);
954 * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
956 var sayHi = function(name){
957 alert('Hi, ' + name);
960 // executes immediately:
963 // executes after 2 seconds:
964 sayHi.defer(2000, this, ['Fred']);
966 // this syntax is sometimes useful for deferring
967 // execution of an anonymous function:
972 * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
973 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
974 * <b>If omitted, defaults to the browser window.</b>
975 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
976 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
977 * if a number the args are inserted at the specified position
978 * @return {Number} The timeout id that can be used with clearTimeout
980 defer : function(millis, obj, args, appendArgs){
981 var fn = this.createDelegate(obj, args, appendArgs);
983 return setTimeout(fn, millis);
992 * These functions are available on every String object.
994 Ext.applyIf(String, {
996 * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
997 * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
999 var cls = 'my-class', text = 'Some text';
1000 var s = String.format('<div class="{0}">{1}</div>', cls, text);
1001 // s now contains the string: '<div class="my-class">Some text</div>'
1003 * @param {String} string The tokenized string to be formatted
1004 * @param {String} value1 The value to replace token {0}
1005 * @param {String} value2 Etc...
1006 * @return {String} The formatted string
1009 format : function(format){
1010 var args = Ext.toArray(arguments, 1);
1011 return format.replace(/\{(\d+)\}/g, function(m, i){
1020 Ext.applyIf(Array.prototype, {
1022 * Checks whether or not the specified object exists in the array.
1023 * @param {Object} o The object to check for
1024 * @param {Number} from (Optional) The index at which to begin the search
1025 * @return {Number} The index of o in the array (or -1 if it is not found)
1027 indexOf : function(o, from){
1028 var len = this.length;
1030 from += (from < 0) ? len : 0;
1031 for (; from < len; ++from){
1032 if(this[from] === o){
1040 * Removes the specified object from the array. If the object is not found nothing happens.
1041 * @param {Object} o The object to remove
1042 * @return {Array} this array
1044 remove : function(o){
1045 var index = this.indexOf(o);
1047 this.splice(index, 1);