3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
9 window.undefined = window.undefined;
13 * Ext core utilities and functions.
19 * The version of the framework
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
33 Ext.apply = function(o, c, defaults){
34 // no "this" reference for friendly out of scope calls
36 Ext.apply(o, defaults);
38 if(o && c && typeof c == 'object'){
48 toString = Object.prototype.toString,
49 ua = navigator.userAgent.toLowerCase(),
54 isStrict = DOC.compatMode == "CSS1Compat",
55 isOpera = check(/opera/),
56 isChrome = check(/chrome/),
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);
76 // remove css image flicker
79 DOC.execCommand("BackgroundImageCache", false, true);
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>).
89 SSL_SECURE_URL : isSecure && isIE ? 'javascript:""' : 'about:blank',
91 * True if the browser is in strict (standards-compliant) mode, as opposed to quirks mode
96 * True if the page is running over SSL
101 * True when the document is fully initialized and ready for action
107 * True if the {@link Ext.Fx} Class is available
113 * True to automatically uncache orphaned Ext.Elements periodically (defaults to true)
116 enableGarbageCollector : true,
119 * True to automatically purge event listeners during garbageCollection (defaults to false).
122 enableListenerCollection : false,
125 * EXPERIMENTAL - True to cascade listener removal to child elements when an element is removed.
126 * Currently not optimized for performance.
129 enableNestedListenerRemoval : false,
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)
138 USE_NATIVE_JSON : false,
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
146 applyIf : function(o, c){
149 if(!Ext.isDefined(o[p])){
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.
163 id : function(el, prefix){
164 return (el = Ext.getDom(el) || {}).id = el.id || (prefix || "ext-gen") + (++idSeed);
168 * <p>Extends one class to create a subclass and optionally overrides members with the passed literal. This method
169 * also adds the function "override()" to the subclass that can be used to override members of the class.</p>
170 * For example, to create a subclass of Ext GridPanel:
172 MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
173 constructor: function(config) {
175 // Create configuration for this Grid.
176 var store = new Ext.data.Store({...});
177 var colModel = new Ext.grid.ColumnModel({...});
179 // Create a new config object containing our computed properties
180 // *plus* whatever was in the config parameter.
186 MyGridPanel.superclass.constructor.call(this, config);
188 // Your postprocessing here
191 yourMethod: function() {
197 * <p>This function also supports a 3-argument call in which the subclass's constructor is
198 * passed as an argument. In this form, the parameters are as follows:</p>
199 * <div class="mdetail-params"><ul>
200 * <li><code>subclass</code> : Function <div class="sub-desc">The subclass constructor.</div></li>
201 * <li><code>superclass</code> : Function <div class="sub-desc">The constructor of class being extended</div></li>
202 * <li><code>overrides</code> : Object <div class="sub-desc">A literal with members which are copied into the subclass's
203 * prototype, and are therefore shared among all instances of the new class.</div></li>
206 * @param {Function} superclass The constructor of class being extended.
207 * @param {Object} overrides <p>A literal with members which are copied into the subclass's
208 * prototype, and are therefore shared between all instances of the new class.</p>
209 * <p>This may contain a special member named <tt><b>constructor</b></tt>. This is used
210 * to define the constructor of the new class, and is returned. If this property is
211 * <i>not</i> specified, a constructor is generated and returned which just calls the
212 * superclass's constructor passing on its parameters.</p>
213 * <p><b>It is essential that you call the superclass constructor in any provided constructor. See example code.</b></p>
214 * @return {Function} The subclass constructor from the <code>overrides</code> parameter, or a generated one if not provided.
218 var io = function(o){
223 var oc = Object.prototype.constructor;
225 return function(sb, sp, overrides){
226 if(Ext.isObject(sp)){
229 sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
231 var F = function(){},
236 sbp = sb.prototype = new F();
239 if(spp.constructor == oc){
242 sb.override = function(o){
245 sbp.superclass = sbp.supr = (function(){
249 Ext.override(sb, overrides);
250 sb.extend = function(o){return Ext.extend(sb, o);};
256 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
258 Ext.override(MyClass, {
259 newMethod1: function(){
262 newMethod2: function(foo){
267 * @param {Object} origclass The class to override
268 * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
269 * containing one or more methods.
272 override : function(origclass, overrides){
274 var p = origclass.prototype;
275 Ext.apply(p, overrides);
276 if(Ext.isIE && overrides.hasOwnProperty('toString')){
277 p.toString = overrides.toString;
283 * Creates namespaces to be used for scoping variables and classes so that they are not global.
284 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
286 Ext.namespace('Company', 'Company.data');
287 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
288 Company.Widget = function() { ... }
289 Company.data.CustomStore = function(config) { ... }
291 * @param {String} namespace1
292 * @param {String} namespace2
293 * @param {String} etc
294 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
297 namespace : function(){
299 Ext.each(arguments, function(v) {
301 o = window[d[0]] = window[d[0]] || {};
302 Ext.each(d.slice(1), function(v2){
303 o = o[v2] = o[v2] || {};
310 * 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.
312 * @param {String} pre (optional) A prefix to add to the url encoded string
315 urlEncode : function(o, pre){
318 e = encodeURIComponent;
320 Ext.iterate(o, function(key, item){
321 empty = Ext.isEmpty(item);
322 Ext.each(empty ? key : item, function(val){
323 buf.push('&', e(key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : '');
330 return pre + buf.join('');
334 * Takes an encoded URL and and converts it to an object. Example: <pre><code>
335 Ext.urlDecode("foo=1&bar=2"); // returns {foo: "1", bar: "2"}
336 Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2", "3", "4"]}
338 * @param {String} string
339 * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
340 * @return {Object} A literal with members
342 urlDecode : function(string, overwrite){
343 if(Ext.isEmpty(string)){
347 pairs = string.split('&'),
348 d = decodeURIComponent,
351 Ext.each(pairs, function(pair) {
352 pair = pair.split('=');
355 obj[name] = overwrite || !obj[name] ? value :
356 [].concat(obj[name]).concat(value);
362 * Appends content to the query string of a URL, handling logic for whether to place
363 * a question mark or ampersand.
364 * @param {String} url The URL to append to.
365 * @param {String} s The content to append to the URL.
366 * @return (String) The resulting URL
368 urlAppend : function(url, s){
370 return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
376 * Converts any iterable (numeric indices and a length property) into a true array
377 * Don't use this on strings. IE doesn't support "abc"[0] which this implementation depends on.
378 * For strings, use this instead: "abc".match(/./g) => [a,b,c];
379 * @param {Iterable} the iterable object to be turned into a true Array.
380 * @return (Array) array
382 toArray : function(){
384 function(a, i, j, res){
386 for(var x = 0, len = a.length; x < len; x++) {
389 return res.slice(i || 0, j || res.length);
392 return Array.prototype.slice.call(a, i || 0, j || a.length);
396 isIterable : function(v){
397 //check for array or arguments
398 if(Ext.isArray(v) || v.callee){
401 //check for node list type
402 if(/NodeList|HTMLCollection/.test(toString.call(v))){
405 //NodeList has an item and length property
406 //IXMLDOMNodeList has nextNode method, needs to be checked first.
407 return ((v.nextNode || v.item) && Ext.isNumber(v.length));
411 * Iterates an array calling the supplied function.
412 * @param {Array/NodeList/Mixed} array The array to be iterated. If this
413 * argument is not really an array, the supplied function is called once.
414 * @param {Function} fn The function to be called with each item. If the
415 * supplied function returns false, iteration stops and this method returns
416 * the current <code>index</code>. This function is called with
417 * the following arguments:
418 * <div class="mdetail-params"><ul>
419 * <li><code>item</code> : <i>Mixed</i>
420 * <div class="sub-desc">The item at the current <code>index</code>
421 * in the passed <code>array</code></div></li>
422 * <li><code>index</code> : <i>Number</i>
423 * <div class="sub-desc">The current index within the array</div></li>
424 * <li><code>allItems</code> : <i>Array</i>
425 * <div class="sub-desc">The <code>array</code> passed as the first
426 * argument to <code>Ext.each</code>.</div></li>
428 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed.
429 * Defaults to the <code>item</code> at the current <code>index</code>
430 * within the passed <code>array</code>.
431 * @return See description for the fn parameter.
433 each : function(array, fn, scope){
434 if(Ext.isEmpty(array, true)){
437 if(!Ext.isIterable(array) || Ext.isPrimitive(array)){
440 for(var i = 0, len = array.length; i < len; i++){
441 if(fn.call(scope || array[i], array[i], i, array) === false){
448 * Iterates either the elements in an array, or each of the properties in an object.
449 * <b>Note</b>: If you are only iterating arrays, it is better to call {@link #each}.
450 * @param {Object/Array} object The object or array to be iterated
451 * @param {Function} fn The function to be called for each iteration.
452 * The iteration will stop if the supplied function returns false, or
453 * all array elements / object properties have been covered. The signature
454 * varies depending on the type of object being interated:
455 * <div class="mdetail-params"><ul>
456 * <li>Arrays : <tt>(Object item, Number index, Array allItems)</tt>
457 * <div class="sub-desc">
458 * When iterating an array, the supplied function is called with each item.</div></li>
459 * <li>Objects : <tt>(String key, Object value, Object)</tt>
460 * <div class="sub-desc">
461 * When iterating an object, the supplied function is called with each key-value pair in
462 * the object, and the iterated object</div></li>
464 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed. Defaults to
465 * the <code>object</code> being iterated.
467 iterate : function(obj, fn, scope){
468 if(Ext.isEmpty(obj)){
471 if(Ext.isIterable(obj)){
472 Ext.each(obj, fn, scope);
474 }else if(Ext.isObject(obj)){
475 for(var prop in obj){
476 if(obj.hasOwnProperty(prop)){
477 if(fn.call(scope || obj, prop, obj[prop], obj) === false){
486 * Return the dom node for the passed String (id), dom node, or Ext.Element.
487 * Here are some examples:
489 // gets dom node based on id
490 var elDom = Ext.getDom('elId');
491 // gets dom node based on the dom node
492 var elDom1 = Ext.getDom(elDom);
494 // If we don't know if we are working with an
495 // Ext.Element or a dom node use Ext.getDom
497 var dom = Ext.getDom(el);
498 // do something with the dom node
501 * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc)
502 * when this method is called to be successful.
504 * @return HTMLElement
506 getDom : function(el){
510 return el.dom ? el.dom : (Ext.isString(el) ? DOC.getElementById(el) : el);
514 * Returns the current document body as an {@link Ext.Element}.
515 * @return Ext.Element The document body
517 getBody : function(){
518 return Ext.get(DOC.body || DOC.documentElement);
522 * Removes a DOM node from the document.
525 * <p>Removes this element from the document, removes all DOM event listeners, and deletes the cache reference.
526 * All DOM event listeners are removed from this element. If {@link Ext#enableNestedListenerRemoval} is
527 * <code>true</code>, then DOM event listeners are also removed from all child nodes. The body node
528 * will be ignored if passed in.</p>
529 * @param {HTMLElement} node The node to remove
531 removeNode : isIE && !isIE8 ? function(){
534 if(n && n.tagName != 'BODY'){
535 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
536 d = d || DOC.createElement('div');
539 delete Ext.elCache[n.id];
543 if(n && n.parentNode && n.tagName != 'BODY'){
544 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
545 n.parentNode.removeChild(n);
546 delete Ext.elCache[n.id];
551 * <p>Returns true if the passed value is empty.</p>
552 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
555 * <li>an empty array</li>
556 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
558 * @param {Mixed} value The value to test
559 * @param {Boolean} allowBlank (optional) true to allow empty strings (defaults to false)
562 isEmpty : function(v, allowBlank){
563 return v === null || v === undefined || ((Ext.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false);
567 * Returns true if the passed value is a JavaScript array, otherwise false.
568 * @param {Mixed} value The value to test
571 isArray : function(v){
572 return toString.apply(v) === '[object Array]';
576 * Returns true if the passed object is a JavaScript date object, otherwise false.
577 * @param {Object} object The object to test
580 isDate : function(v){
581 return toString.apply(v) === '[object Date]';
585 * Returns true if the passed value is a JavaScript Object, otherwise false.
586 * @param {Mixed} value The value to test
589 isObject : function(v){
590 return !!v && Object.prototype.toString.call(v) === '[object Object]';
594 * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean.
595 * @param {Mixed} value The value to test
598 isPrimitive : function(v){
599 return Ext.isString(v) || Ext.isNumber(v) || Ext.isBoolean(v);
603 * Returns true if the passed value is a JavaScript Function, otherwise false.
604 * @param {Mixed} value The value to test
607 isFunction : function(v){
608 return toString.apply(v) === '[object Function]';
612 * Returns true if the passed value is a number. Returns false for non-finite numbers.
613 * @param {Mixed} value The value to test
616 isNumber : function(v){
617 return typeof v === 'number' && isFinite(v);
621 * Returns true if the passed value is a string.
622 * @param {Mixed} value The value to test
625 isString : function(v){
626 return typeof v === 'string';
630 * Returns true if the passed value is a boolean.
631 * @param {Mixed} value The value to test
634 isBoolean : function(v){
635 return typeof v === 'boolean';
639 * Returns true if the passed value is an HTMLElement
640 * @param {Mixed} value The value to test
643 isElement : function(v) {
644 return !!v && v.tagName;
648 * Returns true if the passed value is not undefined.
649 * @param {Mixed} value The value to test
652 isDefined : function(v){
653 return typeof v !== 'undefined';
657 * True if the detected browser is Opera.
662 * True if the detected browser uses WebKit.
667 * True if the detected browser is Chrome.
672 * True if the detected browser is Safari.
677 * True if the detected browser is Safari 3.x.
680 isSafari3 : isSafari3,
682 * True if the detected browser is Safari 4.x.
685 isSafari4 : isSafari4,
687 * True if the detected browser is Safari 2.x.
690 isSafari2 : isSafari2,
692 * True if the detected browser is Internet Explorer.
697 * True if the detected browser is Internet Explorer 6.x.
702 * True if the detected browser is Internet Explorer 7.x.
707 * True if the detected browser is Internet Explorer 8.x.
712 * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
717 * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x).
722 * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
727 * True if the detected browser is Internet Explorer running in non-strict mode.
730 isBorderBox : isBorderBox,
732 * True if the detected platform is Linux.
737 * True if the detected platform is Windows.
740 isWindows : isWindows,
742 * True if the detected platform is Mac OS.
747 * True if the detected platform is Adobe Air.
754 * Creates namespaces to be used for scoping variables and classes so that they are not global.
755 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
757 Ext.namespace('Company', 'Company.data');
758 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
759 Company.Widget = function() { ... }
760 Company.data.CustomStore = function(config) { ... }
762 * @param {String} namespace1
763 * @param {String} namespace2
764 * @param {String} etc
765 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
768 Ext.ns = Ext.namespace;
771 Ext.ns("Ext.util", "Ext.lib", "Ext.data");
777 * These functions are available on every Function object (any JavaScript function).
779 Ext.apply(Function.prototype, {
781 * Creates an interceptor function. The passed function is called before the original one. If it returns false,
782 * the original one is not called. The resulting function returns the results of the original function.
783 * The passed function is called with the parameters of the original function. Example usage:
785 var sayHi = function(name){
786 alert('Hi, ' + name);
789 sayHi('Fred'); // alerts "Hi, Fred"
791 // create a new function that validates input without
792 // directly modifying the original function:
793 var sayHiToFriend = sayHi.createInterceptor(function(name){
794 return name == 'Brian';
797 sayHiToFriend('Fred'); // no alert
798 sayHiToFriend('Brian'); // alerts "Hi, Brian"
800 * @param {Function} fcn The function to call before the original
801 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
802 * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
803 * @return {Function} The new function
805 createInterceptor : function(fcn, scope){
807 return !Ext.isFunction(fcn) ?
814 return (fcn.apply(scope || me || window, args) !== false) ?
815 method.apply(me || window, args) :
821 * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
822 * Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code>
823 * Will create a function that is bound to those 2 args. <b>If a specific scope is required in the
824 * callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always
825 * executes in the window scope.
826 * <p>This method is required when you want to pass arguments to a callback function. If no arguments
827 * are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn).
828 * However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function
829 * would simply execute immediately when the code is parsed. Example usage:
831 var sayHi = function(name){
832 alert('Hi, ' + name);
835 // clicking the button alerts "Hi, Fred"
838 renderTo: Ext.getBody(),
839 handler: sayHi.createCallback('Fred')
842 * @return {Function} The new function
844 createCallback : function(/*args...*/){
845 // make args available, in function below
846 var args = arguments,
849 return method.apply(window, args);
854 * Creates a delegate (callback) that sets the scope to obj.
855 * Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code>
856 * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
857 * callback points to obj. Example usage:
859 var sayHi = function(name){
860 // Note this use of "this.text" here. This function expects to
861 // execute within a scope that contains a text property. In this
862 // example, the "this" variable is pointing to the btn object that
863 // was passed in createDelegate below.
864 alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
867 var btn = new Ext.Button({
869 renderTo: Ext.getBody()
872 // This callback will execute in the scope of the
873 // button instance. Clicking the button alerts
874 // "Hi, Fred. You clicked the "Say Hi" button."
875 btn.on('click', sayHi.createDelegate(btn, ['Fred']));
877 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
878 * <b>If omitted, defaults to the browser window.</b>
879 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
880 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
881 * if a number the args are inserted at the specified position
882 * @return {Function} The new function
884 createDelegate : function(obj, args, appendArgs){
887 var callArgs = args || arguments;
888 if (appendArgs === true){
889 callArgs = Array.prototype.slice.call(arguments, 0);
890 callArgs = callArgs.concat(args);
891 }else if (Ext.isNumber(appendArgs)){
892 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
893 var applyArgs = [appendArgs, 0].concat(args); // create method call params
894 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
896 return method.apply(obj || window, callArgs);
901 * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
903 var sayHi = function(name){
904 alert('Hi, ' + name);
907 // executes immediately:
910 // executes after 2 seconds:
911 sayHi.defer(2000, this, ['Fred']);
913 // this syntax is sometimes useful for deferring
914 // execution of an anonymous function:
919 * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
920 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
921 * <b>If omitted, defaults to the browser window.</b>
922 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
923 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
924 * if a number the args are inserted at the specified position
925 * @return {Number} The timeout id that can be used with clearTimeout
927 defer : function(millis, obj, args, appendArgs){
928 var fn = this.createDelegate(obj, args, appendArgs);
930 return setTimeout(fn, millis);
939 * These functions are available on every String object.
941 Ext.applyIf(String, {
943 * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
944 * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
946 var cls = 'my-class', text = 'Some text';
947 var s = String.format('<div class="{0}">{1}</div>', cls, text);
948 // s now contains the string: '<div class="my-class">Some text</div>'
950 * @param {String} string The tokenized string to be formatted
951 * @param {String} value1 The value to replace token {0}
952 * @param {String} value2 Etc...
953 * @return {String} The formatted string
956 format : function(format){
957 var args = Ext.toArray(arguments, 1);
958 return format.replace(/\{(\d+)\}/g, function(m, i){
967 Ext.applyIf(Array.prototype, {
969 * Checks whether or not the specified object exists in the array.
970 * @param {Object} o The object to check for
971 * @param {Number} from (Optional) The index at which to begin the search
972 * @return {Number} The index of o in the array (or -1 if it is not found)
974 indexOf : function(o, from){
975 var len = this.length;
977 from += (from < 0) ? len : 0;
978 for (; from < len; ++from){
979 if(this[from] === o){
987 * Removes the specified object from the array. If the object is not found nothing happens.
988 * @param {Object} o The object to remove
989 * @return {Array} this array
991 remove : function(o){
992 var index = this.indexOf(o);
994 this.splice(index, 1);