3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js">
11 window.undefined = window.undefined;
15 * Ext core utilities and functions.
20 <div id="prop-Ext-version"></div>/**
21 * The version of the framework
27 <div id="method-Ext-apply"></div>/**
28 * Copies all the properties of config to obj.
29 * @param {Object} obj The receiver of the properties
30 * @param {Object} config The source of the properties
31 * @param {Object} defaults A different object that will also be applied for default values
32 * @return {Object} returns obj
35 Ext.apply = function(o, c, defaults){
36 // no "this" reference for friendly out of scope calls
38 Ext.apply(o, defaults);
40 if(o && c && typeof c == 'object'){
50 toString = Object.prototype.toString,
51 ua = navigator.userAgent.toLowerCase(),
56 isStrict = DOC.compatMode == "CSS1Compat",
57 isOpera = check(/opera/),
58 isChrome = check(/\bchrome\b/),
59 isWebKit = check(/webkit/),
60 isSafari = !isChrome && check(/safari/),
61 isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
62 isSafari3 = isSafari && check(/version\/3/),
63 isSafari4 = isSafari && check(/version\/4/),
64 isIE = !isOpera && check(/msie/),
65 isIE7 = isIE && check(/msie 7/),
66 isIE8 = isIE && check(/msie 8/),
67 isIE6 = isIE && !isIE7 && !isIE8,
68 isGecko = !isWebKit && check(/gecko/),
69 isGecko2 = isGecko && check(/rv:1\.8/),
70 isGecko3 = isGecko && check(/rv:1\.9/),
71 isBorderBox = isIE && !isStrict,
72 isWindows = check(/windows|win32/),
73 isMac = check(/macintosh|mac os x/),
74 isAir = check(/adobeair/),
75 isLinux = check(/linux/),
76 isSecure = /^https/i.test(window.location.protocol);
78 // remove css image flicker
81 DOC.execCommand("BackgroundImageCache", false, true);
86 <div id="prop-Ext-SSL_SECURE_URL"></div>/**
87 * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent
88 * the IE insecure content warning (<tt>'about:blank'</tt>, except for IE in secure mode, which is <tt>'javascript:""'</tt>).
91 SSL_SECURE_URL : isSecure && isIE ? 'javascript:""' : 'about:blank',
92 <div id="prop-Ext-isStrict"></div>/**
93 * True if the browser is in strict (standards-compliant) mode, as opposed to quirks mode
97 <div id="prop-Ext-isSecure"></div>/**
98 * True if the page is running over SSL
102 <div id="prop-Ext-isReady"></div>/**
103 * True when the document is fully initialized and ready for action
108 <div id="prop-Ext-enableFx"></div>/**
109 * True if the {@link Ext.Fx} Class is available
114 <div id="prop-Ext-enableGarbageCollector"></div>/**
115 * True to automatically uncache orphaned Ext.Elements periodically (defaults to true)
118 enableGarbageCollector : true,
120 <div id="prop-Ext-enableListenerCollection"></div>/**
121 * True to automatically purge event listeners during garbageCollection (defaults to false).
124 enableListenerCollection : false,
126 <div id="prop-Ext-enableNestedListenerRemoval"></div>/**
127 * EXPERIMENTAL - True to cascade listener removal to child elements when an element is removed.
128 * Currently not optimized for performance.
131 enableNestedListenerRemoval : false,
133 <div id="prop-Ext-USE_NATIVE_JSON"></div>/**
134 * Indicates whether to use native browser parsing for JSON methods.
135 * This option is ignored if the browser does not support native JSON methods.
136 * <b>Note: Native JSON methods will not work with objects that have functions.
137 * Also, property names must be quoted, otherwise the data will not parse.</b> (Defaults to false)
140 USE_NATIVE_JSON : false,
142 <div id="method-Ext-applyIf"></div>/**
143 * Copies all the properties of config to obj if they don't already exist.
144 * @param {Object} obj The receiver of the properties
145 * @param {Object} config The source of the properties
146 * @return {Object} returns obj
148 applyIf : function(o, c){
151 if(!Ext.isDefined(o[p])){
159 <div id="method-Ext-id"></div>/**
160 * Generates unique ids. If the element already has an id, it is unchanged
161 * @param {Mixed} el (optional) The element to generate an id for
162 * @param {String} prefix (optional) Id prefix (defaults "ext-gen")
163 * @return {String} The generated Id.
165 id : function(el, prefix){
166 el = Ext.getDom(el, true) || {};
168 el.id = (prefix || "ext-gen") + (++idSeed);
173 <div id="method-Ext-extend"></div>/**
174 * <p>Extends one class to create a subclass and optionally overrides members with the passed literal. This method
175 * also adds the function "override()" to the subclass that can be used to override members of the class.</p>
176 * For example, to create a subclass of Ext GridPanel:
178 MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
179 constructor: function(config) {
181 // Create configuration for this Grid.
182 var store = new Ext.data.Store({...});
183 var colModel = new Ext.grid.ColumnModel({...});
185 // Create a new config object containing our computed properties
186 // *plus* whatever was in the config parameter.
192 MyGridPanel.superclass.constructor.call(this, config);
194 // Your postprocessing here
197 yourMethod: function() {
203 * <p>This function also supports a 3-argument call in which the subclass's constructor is
204 * passed as an argument. In this form, the parameters are as follows:</p>
205 * <div class="mdetail-params"><ul>
206 * <li><code>subclass</code> : Function <div class="sub-desc">The subclass constructor.</div></li>
207 * <li><code>superclass</code> : Function <div class="sub-desc">The constructor of class being extended</div></li>
208 * <li><code>overrides</code> : Object <div class="sub-desc">A literal with members which are copied into the subclass's
209 * prototype, and are therefore shared among all instances of the new class.</div></li>
212 * @param {Function} superclass The constructor of class being extended.
213 * @param {Object} overrides <p>A literal with members which are copied into the subclass's
214 * prototype, and are therefore shared between all instances of the new class.</p>
215 * <p>This may contain a special member named <tt><b>constructor</b></tt>. This is used
216 * to define the constructor of the new class, and is returned. If this property is
217 * <i>not</i> specified, a constructor is generated and returned which just calls the
218 * superclass's constructor passing on its parameters.</p>
219 * <p><b>It is essential that you call the superclass constructor in any provided constructor. See example code.</b></p>
220 * @return {Function} The subclass constructor from the <code>overrides</code> parameter, or a generated one if not provided.
224 var io = function(o){
229 var oc = Object.prototype.constructor;
231 return function(sb, sp, overrides){
232 if(Ext.isObject(sp)){
235 sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
237 var F = function(){},
242 sbp = sb.prototype = new F();
245 if(spp.constructor == oc){
248 sb.override = function(o){
251 sbp.superclass = sbp.supr = (function(){
255 Ext.override(sb, overrides);
256 sb.extend = function(o){return Ext.extend(sb, o);};
261 <div id="method-Ext-override"></div>/**
262 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
264 Ext.override(MyClass, {
265 newMethod1: function(){
268 newMethod2: function(foo){
273 * @param {Object} origclass The class to override
274 * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
275 * containing one or more methods.
278 override : function(origclass, overrides){
280 var p = origclass.prototype;
281 Ext.apply(p, overrides);
282 if(Ext.isIE && overrides.hasOwnProperty('toString')){
283 p.toString = overrides.toString;
288 <div id="method-Ext-namespace"></div>/**
289 * Creates namespaces to be used for scoping variables and classes so that they are not global.
290 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
292 Ext.namespace('Company', 'Company.data');
293 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
294 Company.Widget = function() { ... }
295 Company.data.CustomStore = function(config) { ... }
297 * @param {String} namespace1
298 * @param {String} namespace2
299 * @param {String} etc
300 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
303 namespace : function(){
305 Ext.each(arguments, function(v) {
307 o = window[d[0]] = window[d[0]] || {};
308 Ext.each(d.slice(1), function(v2){
309 o = o[v2] = o[v2] || {};
315 <div id="method-Ext-urlEncode"></div>/**
316 * 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.
318 * @param {String} pre (optional) A prefix to add to the url encoded string
321 urlEncode : function(o, pre){
324 e = encodeURIComponent;
326 Ext.iterate(o, function(key, item){
327 empty = Ext.isEmpty(item);
328 Ext.each(empty ? key : item, function(val){
329 buf.push('&', e(key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : '');
336 return pre + buf.join('');
339 <div id="method-Ext-urlDecode"></div>/**
340 * Takes an encoded URL and and converts it to an object. Example: <pre><code>
341 Ext.urlDecode("foo=1&bar=2"); // returns {foo: "1", bar: "2"}
342 Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2", "3", "4"]}
344 * @param {String} string
345 * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
346 * @return {Object} A literal with members
348 urlDecode : function(string, overwrite){
349 if(Ext.isEmpty(string)){
353 pairs = string.split('&'),
354 d = decodeURIComponent,
357 Ext.each(pairs, function(pair) {
358 pair = pair.split('=');
361 obj[name] = overwrite || !obj[name] ? value :
362 [].concat(obj[name]).concat(value);
367 <div id="method-Ext-urlAppend"></div>/**
368 * Appends content to the query string of a URL, handling logic for whether to place
369 * a question mark or ampersand.
370 * @param {String} url The URL to append to.
371 * @param {String} s The content to append to the URL.
372 * @return (String) The resulting URL
374 urlAppend : function(url, s){
376 return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
381 <div id="method-Ext-toArray"></div>/**
382 * Converts any iterable (numeric indices and a length property) into a true array
383 * Don't use this on strings. IE doesn't support "abc"[0] which this implementation depends on.
384 * For strings, use this instead: "abc".match(/./g) => [a,b,c];
385 * @param {Iterable} the iterable object to be turned into a true Array.
386 * @return (Array) array
388 toArray : function(){
390 function(a, i, j, res){
392 for(var x = 0, len = a.length; x < len; x++) {
395 return res.slice(i || 0, j || res.length);
398 return Array.prototype.slice.call(a, i || 0, j || a.length);
402 isIterable : function(v){
403 //check for array or arguments
404 if(Ext.isArray(v) || v.callee){
407 //check for node list type
408 if(/NodeList|HTMLCollection/.test(toString.call(v))){
411 //NodeList has an item and length property
412 //IXMLDOMNodeList has nextNode method, needs to be checked first.
413 return ((typeof v.nextNode != 'undefined' || v.item) && Ext.isNumber(v.length));
416 <div id="method-Ext-each"></div>/**
417 * Iterates an array calling the supplied function.
418 * @param {Array/NodeList/Mixed} array The array to be iterated. If this
419 * argument is not really an array, the supplied function is called once.
420 * @param {Function} fn The function to be called with each item. If the
421 * supplied function returns false, iteration stops and this method returns
422 * the current <code>index</code>. This function is called with
423 * the following arguments:
424 * <div class="mdetail-params"><ul>
425 * <li><code>item</code> : <i>Mixed</i>
426 * <div class="sub-desc">The item at the current <code>index</code>
427 * in the passed <code>array</code></div></li>
428 * <li><code>index</code> : <i>Number</i>
429 * <div class="sub-desc">The current index within the array</div></li>
430 * <li><code>allItems</code> : <i>Array</i>
431 * <div class="sub-desc">The <code>array</code> passed as the first
432 * argument to <code>Ext.each</code>.</div></li>
434 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed.
435 * Defaults to the <code>item</code> at the current <code>index</code>
436 * within the passed <code>array</code>.
437 * @return See description for the fn parameter.
439 each : function(array, fn, scope){
440 if(Ext.isEmpty(array, true)){
443 if(!Ext.isIterable(array) || Ext.isPrimitive(array)){
446 for(var i = 0, len = array.length; i < len; i++){
447 if(fn.call(scope || array[i], array[i], i, array) === false){
453 <div id="method-Ext-iterate"></div>/**
454 * Iterates either the elements in an array, or each of the properties in an object.
455 * <b>Note</b>: If you are only iterating arrays, it is better to call {@link #each}.
456 * @param {Object/Array} object The object or array to be iterated
457 * @param {Function} fn The function to be called for each iteration.
458 * The iteration will stop if the supplied function returns false, or
459 * all array elements / object properties have been covered. The signature
460 * varies depending on the type of object being interated:
461 * <div class="mdetail-params"><ul>
462 * <li>Arrays : <tt>(Object item, Number index, Array allItems)</tt>
463 * <div class="sub-desc">
464 * When iterating an array, the supplied function is called with each item.</div></li>
465 * <li>Objects : <tt>(String key, Object value, Object)</tt>
466 * <div class="sub-desc">
467 * When iterating an object, the supplied function is called with each key-value pair in
468 * the object, and the iterated object</div></li>
470 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed. Defaults to
471 * the <code>object</code> being iterated.
473 iterate : function(obj, fn, scope){
474 if(Ext.isEmpty(obj)){
477 if(Ext.isIterable(obj)){
478 Ext.each(obj, fn, scope);
480 }else if(Ext.isObject(obj)){
481 for(var prop in obj){
482 if(obj.hasOwnProperty(prop)){
483 if(fn.call(scope || obj, prop, obj[prop], obj) === false){
491 <div id="method-Ext-getDom"></div>/**
492 * Return the dom node for the passed String (id), dom node, or Ext.Element.
493 * Optional 'strict' flag is needed for IE since it can return 'name' and
494 * 'id' elements by using getElementById.
495 * Here are some examples:
497 // gets dom node based on id
498 var elDom = Ext.getDom('elId');
499 // gets dom node based on the dom node
500 var elDom1 = Ext.getDom(elDom);
502 // If we don't know if we are working with an
503 // Ext.Element or a dom node use Ext.getDom
505 var dom = Ext.getDom(el);
506 // do something with the dom node
509 * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc)
510 * when this method is called to be successful.
512 * @return HTMLElement
514 getDom : function(el, strict){
521 if (Ext.isString(el)) {
522 var e = DOC.getElementById(el);
523 // IE returns elements with the 'name' and 'id' attribute.
524 // we do a strict check to return the element with only the id attribute
525 if (e && isIE && strict) {
526 if (el == e.getAttribute('id')) {
539 <div id="method-Ext-getBody"></div>/**
540 * Returns the current document body as an {@link Ext.Element}.
541 * @return Ext.Element The document body
543 getBody : function(){
544 return Ext.get(DOC.body || DOC.documentElement);
547 <div id="prop-Ext-"></div>/**
548 * Removes a DOM node from the document.
550 <div id="method-Ext-removeNode"></div>/**
551 * <p>Removes this element from the document, removes all DOM event listeners, and deletes the cache reference.
552 * All DOM event listeners are removed from this element. If {@link Ext#enableNestedListenerRemoval} is
553 * <code>true</code>, then DOM event listeners are also removed from all child nodes. The body node
554 * will be ignored if passed in.</p>
555 * @param {HTMLElement} node The node to remove
557 removeNode : isIE && !isIE8 ? function(){
560 if(n && n.tagName != 'BODY'){
561 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
562 d = d || DOC.createElement('div');
565 delete Ext.elCache[n.id];
569 if(n && n.parentNode && n.tagName != 'BODY'){
570 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
571 n.parentNode.removeChild(n);
572 delete Ext.elCache[n.id];
576 <div id="method-Ext-isEmpty"></div>/**
577 * <p>Returns true if the passed value is empty.</p>
578 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
581 * <li>an empty array</li>
582 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
584 * @param {Mixed} value The value to test
585 * @param {Boolean} allowBlank (optional) true to allow empty strings (defaults to false)
588 isEmpty : function(v, allowBlank){
589 return v === null || v === undefined || ((Ext.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false);
592 <div id="method-Ext-isArray"></div>/**
593 * Returns true if the passed value is a JavaScript array, otherwise false.
594 * @param {Mixed} value The value to test
597 isArray : function(v){
598 return toString.apply(v) === '[object Array]';
601 <div id="method-Ext-isDate"></div>/**
602 * Returns true if the passed object is a JavaScript date object, otherwise false.
603 * @param {Object} object The object to test
606 isDate : function(v){
607 return toString.apply(v) === '[object Date]';
610 <div id="method-Ext-isObject"></div>/**
611 * Returns true if the passed value is a JavaScript Object, otherwise false.
612 * @param {Mixed} value The value to test
615 isObject : function(v){
616 return !!v && Object.prototype.toString.call(v) === '[object Object]';
619 <div id="method-Ext-isPrimitive"></div>/**
620 * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean.
621 * @param {Mixed} value The value to test
624 isPrimitive : function(v){
625 return Ext.isString(v) || Ext.isNumber(v) || Ext.isBoolean(v);
628 <div id="method-Ext-isFunction"></div>/**
629 * Returns true if the passed value is a JavaScript Function, otherwise false.
630 * @param {Mixed} value The value to test
633 isFunction : function(v){
634 return toString.apply(v) === '[object Function]';
637 <div id="method-Ext-isNumber"></div>/**
638 * Returns true if the passed value is a number. Returns false for non-finite numbers.
639 * @param {Mixed} value The value to test
642 isNumber : function(v){
643 return typeof v === 'number' && isFinite(v);
646 <div id="method-Ext-isString"></div>/**
647 * Returns true if the passed value is a string.
648 * @param {Mixed} value The value to test
651 isString : function(v){
652 return typeof v === 'string';
655 <div id="method-Ext-isBoolean"></div>/**
656 * Returns true if the passed value is a boolean.
657 * @param {Mixed} value The value to test
660 isBoolean : function(v){
661 return typeof v === 'boolean';
664 <div id="method-Ext-isElement"></div>/**
665 * Returns true if the passed value is an HTMLElement
666 * @param {Mixed} value The value to test
669 isElement : function(v) {
670 return !!v && v.tagName;
673 <div id="method-Ext-isDefined"></div>/**
674 * Returns true if the passed value is not undefined.
675 * @param {Mixed} value The value to test
678 isDefined : function(v){
679 return typeof v !== 'undefined';
682 <div id="prop-Ext-isOpera"></div>/**
683 * True if the detected browser is Opera.
687 <div id="prop-Ext-isWebKit"></div>/**
688 * True if the detected browser uses WebKit.
692 <div id="prop-Ext-isChrome"></div>/**
693 * True if the detected browser is Chrome.
697 <div id="prop-Ext-isSafari"></div>/**
698 * True if the detected browser is Safari.
702 <div id="prop-Ext-isSafari3"></div>/**
703 * True if the detected browser is Safari 3.x.
706 isSafari3 : isSafari3,
707 <div id="prop-Ext-isSafari4"></div>/**
708 * True if the detected browser is Safari 4.x.
711 isSafari4 : isSafari4,
712 <div id="prop-Ext-isSafari2"></div>/**
713 * True if the detected browser is Safari 2.x.
716 isSafari2 : isSafari2,
717 <div id="prop-Ext-isIE"></div>/**
718 * True if the detected browser is Internet Explorer.
722 <div id="prop-Ext-isIE6"></div>/**
723 * True if the detected browser is Internet Explorer 6.x.
727 <div id="prop-Ext-isIE7"></div>/**
728 * True if the detected browser is Internet Explorer 7.x.
732 <div id="prop-Ext-isIE8"></div>/**
733 * True if the detected browser is Internet Explorer 8.x.
737 <div id="prop-Ext-isGecko"></div>/**
738 * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
742 <div id="prop-Ext-isGecko2"></div>/**
743 * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x).
747 <div id="prop-Ext-isGecko3"></div>/**
748 * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
752 <div id="prop-Ext-isBorderBox"></div>/**
753 * True if the detected browser is Internet Explorer running in non-strict mode.
756 isBorderBox : isBorderBox,
757 <div id="prop-Ext-isLinux"></div>/**
758 * True if the detected platform is Linux.
762 <div id="prop-Ext-isWindows"></div>/**
763 * True if the detected platform is Windows.
766 isWindows : isWindows,
767 <div id="prop-Ext-isMac"></div>/**
768 * True if the detected platform is Mac OS.
772 <div id="prop-Ext-isAir"></div>/**
773 * True if the detected platform is Adobe Air.
779 <div id="method-Ext-ns"></div>/**
780 * Creates namespaces to be used for scoping variables and classes so that they are not global.
781 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
783 Ext.namespace('Company', 'Company.data');
784 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
785 Company.Widget = function() { ... }
786 Company.data.CustomStore = function(config) { ... }
788 * @param {String} namespace1
789 * @param {String} namespace2
790 * @param {String} etc
791 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
794 Ext.ns = Ext.namespace;
797 Ext.ns("Ext.util", "Ext.lib", "Ext.data");
803 * These functions are available on every Function object (any JavaScript function).
805 Ext.apply(Function.prototype, {
806 <div id="method-Function-createInterceptor"></div>/**
807 * Creates an interceptor function. The passed function is called before the original one. If it returns false,
808 * the original one is not called. The resulting function returns the results of the original function.
809 * The passed function is called with the parameters of the original function. Example usage:
811 var sayHi = function(name){
812 alert('Hi, ' + name);
815 sayHi('Fred'); // alerts "Hi, Fred"
817 // create a new function that validates input without
818 // directly modifying the original function:
819 var sayHiToFriend = sayHi.createInterceptor(function(name){
820 return name == 'Brian';
823 sayHiToFriend('Fred'); // no alert
824 sayHiToFriend('Brian'); // alerts "Hi, Brian"
826 * @param {Function} fcn The function to call before the original
827 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
828 * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
829 * @return {Function} The new function
831 createInterceptor : function(fcn, scope){
833 return !Ext.isFunction(fcn) ?
840 return (fcn.apply(scope || me || window, args) !== false) ?
841 method.apply(me || window, args) :
846 <div id="method-Function-createCallback"></div>/**
847 * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
848 * Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code>
849 * Will create a function that is bound to those 2 args. <b>If a specific scope is required in the
850 * callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always
851 * executes in the window scope.
852 * <p>This method is required when you want to pass arguments to a callback function. If no arguments
853 * are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn).
854 * However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function
855 * would simply execute immediately when the code is parsed. Example usage:
857 var sayHi = function(name){
858 alert('Hi, ' + name);
861 // clicking the button alerts "Hi, Fred"
864 renderTo: Ext.getBody(),
865 handler: sayHi.createCallback('Fred')
868 * @return {Function} The new function
870 createCallback : function(/*args...*/){
871 // make args available, in function below
872 var args = arguments,
875 return method.apply(window, args);
879 <div id="method-Function-createDelegate"></div>/**
880 * Creates a delegate (callback) that sets the scope to obj.
881 * Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code>
882 * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
883 * callback points to obj. Example usage:
885 var sayHi = function(name){
886 // Note this use of "this.text" here. This function expects to
887 // execute within a scope that contains a text property. In this
888 // example, the "this" variable is pointing to the btn object that
889 // was passed in createDelegate below.
890 alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
893 var btn = new Ext.Button({
895 renderTo: Ext.getBody()
898 // This callback will execute in the scope of the
899 // button instance. Clicking the button alerts
900 // "Hi, Fred. You clicked the "Say Hi" button."
901 btn.on('click', sayHi.createDelegate(btn, ['Fred']));
903 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
904 * <b>If omitted, defaults to the browser window.</b>
905 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
906 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
907 * if a number the args are inserted at the specified position
908 * @return {Function} The new function
910 createDelegate : function(obj, args, appendArgs){
913 var callArgs = args || arguments;
914 if (appendArgs === true){
915 callArgs = Array.prototype.slice.call(arguments, 0);
916 callArgs = callArgs.concat(args);
917 }else if (Ext.isNumber(appendArgs)){
918 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
919 var applyArgs = [appendArgs, 0].concat(args); // create method call params
920 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
922 return method.apply(obj || window, callArgs);
926 <div id="method-Function-defer"></div>/**
927 * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
929 var sayHi = function(name){
930 alert('Hi, ' + name);
933 // executes immediately:
936 // executes after 2 seconds:
937 sayHi.defer(2000, this, ['Fred']);
939 // this syntax is sometimes useful for deferring
940 // execution of an anonymous function:
945 * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
946 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
947 * <b>If omitted, defaults to the browser window.</b>
948 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
949 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
950 * if a number the args are inserted at the specified position
951 * @return {Number} The timeout id that can be used with clearTimeout
953 defer : function(millis, obj, args, appendArgs){
954 var fn = this.createDelegate(obj, args, appendArgs);
956 return setTimeout(fn, millis);
965 * These functions are available on every String object.
967 Ext.applyIf(String, {
968 <div id="method-String-format"></div>/**
969 * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
970 * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
972 var cls = 'my-class', text = 'Some text';
973 var s = String.format('<div class="{0}">{1}</div>', cls, text);
974 // s now contains the string: '<div class="my-class">Some text</div>'
976 * @param {String} string The tokenized string to be formatted
977 * @param {String} value1 The value to replace token {0}
978 * @param {String} value2 Etc...
979 * @return {String} The formatted string
982 format : function(format){
983 var args = Ext.toArray(arguments, 1);
984 return format.replace(/\{(\d+)\}/g, function(m, i){
990 <div id="cls-Array"></div>/**
993 Ext.applyIf(Array.prototype, {
994 <div id="method-Array-indexOf"></div>/**
995 * Checks whether or not the specified object exists in the array.
996 * @param {Object} o The object to check for
997 * @param {Number} from (Optional) The index at which to begin the search
998 * @return {Number} The index of o in the array (or -1 if it is not found)
1000 indexOf : function(o, from){
1001 var len = this.length;
1003 from += (from < 0) ? len : 0;
1004 for (; from < len; ++from){
1005 if(this[from] === o){
1012 <div id="method-Array-remove"></div>/**
1013 * Removes the specified object from the array. If the object is not found nothing happens.
1014 * @param {Object} o The object to remove
1015 * @return {Array} this array
1017 remove : function(o){
1018 var index = this.indexOf(o);
1020 this.splice(index, 1);