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;
13 <div id="cls-Ext"></div>/**
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(/chrome/),
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 return (el = Ext.getDom(el) || {}).id = el.id || (prefix || "ext-gen") + (++idSeed);
169 <div id="method-Ext-extend"></div>/**
170 * <p>Extends one class to create a subclass and optionally overrides members with the passed literal. This method
171 * also adds the function "override()" to the subclass that can be used to override members of the class.</p>
172 * For example, to create a subclass of Ext GridPanel:
174 MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
175 constructor: function(config) {
177 // Create configuration for this Grid.
178 var store = new Ext.data.Store({...});
179 var colModel = new Ext.grid.ColumnModel({...});
181 // Create a new config object containing our computed properties
182 // *plus* whatever was in the config parameter.
188 MyGridPanel.superclass.constructor.call(this, config);
190 // Your postprocessing here
193 yourMethod: function() {
199 * <p>This function also supports a 3-argument call in which the subclass's constructor is
200 * passed as an argument. In this form, the parameters are as follows:</p>
201 * <div class="mdetail-params"><ul>
202 * <li><code>subclass</code> : Function <div class="sub-desc">The subclass constructor.</div></li>
203 * <li><code>superclass</code> : Function <div class="sub-desc">The constructor of class being extended</div></li>
204 * <li><code>overrides</code> : Object <div class="sub-desc">A literal with members which are copied into the subclass's
205 * prototype, and are therefore shared among all instances of the new class.</div></li>
208 * @param {Function} superclass The constructor of class being extended.
209 * @param {Object} overrides <p>A literal with members which are copied into the subclass's
210 * prototype, and are therefore shared between all instances of the new class.</p>
211 * <p>This may contain a special member named <tt><b>constructor</b></tt>. This is used
212 * to define the constructor of the new class, and is returned. If this property is
213 * <i>not</i> specified, a constructor is generated and returned which just calls the
214 * superclass's constructor passing on its parameters.</p>
215 * <p><b>It is essential that you call the superclass constructor in any provided constructor. See example code.</b></p>
216 * @return {Function} The subclass constructor from the <code>overrides</code> parameter, or a generated one if not provided.
220 var io = function(o){
225 var oc = Object.prototype.constructor;
227 return function(sb, sp, overrides){
228 if(Ext.isObject(sp)){
231 sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
233 var F = function(){},
238 sbp = sb.prototype = new F();
241 if(spp.constructor == oc){
244 sb.override = function(o){
247 sbp.superclass = sbp.supr = (function(){
251 Ext.override(sb, overrides);
252 sb.extend = function(o){return Ext.extend(sb, o);};
257 <div id="method-Ext-override"></div>/**
258 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
260 Ext.override(MyClass, {
261 newMethod1: function(){
264 newMethod2: function(foo){
269 * @param {Object} origclass The class to override
270 * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
271 * containing one or more methods.
274 override : function(origclass, overrides){
276 var p = origclass.prototype;
277 Ext.apply(p, overrides);
278 if(Ext.isIE && overrides.hasOwnProperty('toString')){
279 p.toString = overrides.toString;
284 <div id="method-Ext-namespace"></div>/**
285 * Creates namespaces to be used for scoping variables and classes so that they are not global.
286 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
288 Ext.namespace('Company', 'Company.data');
289 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
290 Company.Widget = function() { ... }
291 Company.data.CustomStore = function(config) { ... }
293 * @param {String} namespace1
294 * @param {String} namespace2
295 * @param {String} etc
296 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
299 namespace : function(){
301 Ext.each(arguments, function(v) {
303 o = window[d[0]] = window[d[0]] || {};
304 Ext.each(d.slice(1), function(v2){
305 o = o[v2] = o[v2] || {};
311 <div id="method-Ext-urlEncode"></div>/**
312 * 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.
314 * @param {String} pre (optional) A prefix to add to the url encoded string
317 urlEncode : function(o, pre){
320 e = encodeURIComponent;
322 Ext.iterate(o, function(key, item){
323 empty = Ext.isEmpty(item);
324 Ext.each(empty ? key : item, function(val){
325 buf.push('&', e(key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : '');
332 return pre + buf.join('');
335 <div id="method-Ext-urlDecode"></div>/**
336 * Takes an encoded URL and and converts it to an object. Example: <pre><code>
337 Ext.urlDecode("foo=1&bar=2"); // returns {foo: "1", bar: "2"}
338 Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2", "3", "4"]}
340 * @param {String} string
341 * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
342 * @return {Object} A literal with members
344 urlDecode : function(string, overwrite){
345 if(Ext.isEmpty(string)){
349 pairs = string.split('&'),
350 d = decodeURIComponent,
353 Ext.each(pairs, function(pair) {
354 pair = pair.split('=');
357 obj[name] = overwrite || !obj[name] ? value :
358 [].concat(obj[name]).concat(value);
363 <div id="method-Ext-urlAppend"></div>/**
364 * Appends content to the query string of a URL, handling logic for whether to place
365 * a question mark or ampersand.
366 * @param {String} url The URL to append to.
367 * @param {String} s The content to append to the URL.
368 * @return (String) The resulting URL
370 urlAppend : function(url, s){
372 return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
377 <div id="method-Ext-toArray"></div>/**
378 * Converts any iterable (numeric indices and a length property) into a true array
379 * Don't use this on strings. IE doesn't support "abc"[0] which this implementation depends on.
380 * For strings, use this instead: "abc".match(/./g) => [a,b,c];
381 * @param {Iterable} the iterable object to be turned into a true Array.
382 * @return (Array) array
384 toArray : function(){
386 function(a, i, j, res){
388 for(var x = 0, len = a.length; x < len; x++) {
391 return res.slice(i || 0, j || res.length);
394 return Array.prototype.slice.call(a, i || 0, j || a.length);
398 isIterable : function(v){
399 //check for array or arguments
400 if(Ext.isArray(v) || v.callee){
403 //check for node list type
404 if(/NodeList|HTMLCollection/.test(toString.call(v))){
407 //NodeList has an item and length property
408 //IXMLDOMNodeList has nextNode method, needs to be checked first.
409 return ((v.nextNode || v.item) && Ext.isNumber(v.length));
412 <div id="method-Ext-each"></div>/**
413 * Iterates an array calling the supplied function.
414 * @param {Array/NodeList/Mixed} array The array to be iterated. If this
415 * argument is not really an array, the supplied function is called once.
416 * @param {Function} fn The function to be called with each item. If the
417 * supplied function returns false, iteration stops and this method returns
418 * the current <code>index</code>. This function is called with
419 * the following arguments:
420 * <div class="mdetail-params"><ul>
421 * <li><code>item</code> : <i>Mixed</i>
422 * <div class="sub-desc">The item at the current <code>index</code>
423 * in the passed <code>array</code></div></li>
424 * <li><code>index</code> : <i>Number</i>
425 * <div class="sub-desc">The current index within the array</div></li>
426 * <li><code>allItems</code> : <i>Array</i>
427 * <div class="sub-desc">The <code>array</code> passed as the first
428 * argument to <code>Ext.each</code>.</div></li>
430 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed.
431 * Defaults to the <code>item</code> at the current <code>index</code>
432 * within the passed <code>array</code>.
433 * @return See description for the fn parameter.
435 each : function(array, fn, scope){
436 if(Ext.isEmpty(array, true)){
439 if(!Ext.isIterable(array) || Ext.isPrimitive(array)){
442 for(var i = 0, len = array.length; i < len; i++){
443 if(fn.call(scope || array[i], array[i], i, array) === false){
449 <div id="method-Ext-iterate"></div>/**
450 * Iterates either the elements in an array, or each of the properties in an object.
451 * <b>Note</b>: If you are only iterating arrays, it is better to call {@link #each}.
452 * @param {Object/Array} object The object or array to be iterated
453 * @param {Function} fn The function to be called for each iteration.
454 * The iteration will stop if the supplied function returns false, or
455 * all array elements / object properties have been covered. The signature
456 * varies depending on the type of object being interated:
457 * <div class="mdetail-params"><ul>
458 * <li>Arrays : <tt>(Object item, Number index, Array allItems)</tt>
459 * <div class="sub-desc">
460 * When iterating an array, the supplied function is called with each item.</div></li>
461 * <li>Objects : <tt>(String key, Object value, Object)</tt>
462 * <div class="sub-desc">
463 * When iterating an object, the supplied function is called with each key-value pair in
464 * the object, and the iterated object</div></li>
466 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed. Defaults to
467 * the <code>object</code> being iterated.
469 iterate : function(obj, fn, scope){
470 if(Ext.isEmpty(obj)){
473 if(Ext.isIterable(obj)){
474 Ext.each(obj, fn, scope);
476 }else if(Ext.isObject(obj)){
477 for(var prop in obj){
478 if(obj.hasOwnProperty(prop)){
479 if(fn.call(scope || obj, prop, obj[prop], obj) === false){
487 <div id="method-Ext-getDom"></div>/**
488 * Return the dom node for the passed String (id), dom node, or Ext.Element.
489 * Here are some examples:
491 // gets dom node based on id
492 var elDom = Ext.getDom('elId');
493 // gets dom node based on the dom node
494 var elDom1 = Ext.getDom(elDom);
496 // If we don't know if we are working with an
497 // Ext.Element or a dom node use Ext.getDom
499 var dom = Ext.getDom(el);
500 // do something with the dom node
503 * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc)
504 * when this method is called to be successful.
506 * @return HTMLElement
508 getDom : function(el){
512 return el.dom ? el.dom : (Ext.isString(el) ? DOC.getElementById(el) : el);
515 <div id="method-Ext-getBody"></div>/**
516 * Returns the current document body as an {@link Ext.Element}.
517 * @return Ext.Element The document body
519 getBody : function(){
520 return Ext.get(DOC.body || DOC.documentElement);
523 <div id="prop-Ext-"></div>/**
524 * Removes a DOM node from the document.
526 <div id="method-Ext-removeNode"></div>/**
527 * <p>Removes this element from the document, removes all DOM event listeners, and deletes the cache reference.
528 * All DOM event listeners are removed from this element. If {@link Ext#enableNestedListenerRemoval} is
529 * <code>true</code>, then DOM event listeners are also removed from all child nodes. The body node
530 * will be ignored if passed in.</p>
531 * @param {HTMLElement} node The node to remove
533 removeNode : isIE && !isIE8 ? function(){
536 if(n && n.tagName != 'BODY'){
537 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
538 d = d || DOC.createElement('div');
541 delete Ext.elCache[n.id];
545 if(n && n.parentNode && n.tagName != 'BODY'){
546 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
547 n.parentNode.removeChild(n);
548 delete Ext.elCache[n.id];
552 <div id="method-Ext-isEmpty"></div>/**
553 * <p>Returns true if the passed value is empty.</p>
554 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
557 * <li>an empty array</li>
558 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
560 * @param {Mixed} value The value to test
561 * @param {Boolean} allowBlank (optional) true to allow empty strings (defaults to false)
564 isEmpty : function(v, allowBlank){
565 return v === null || v === undefined || ((Ext.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false);
568 <div id="method-Ext-isArray"></div>/**
569 * Returns true if the passed value is a JavaScript array, otherwise false.
570 * @param {Mixed} value The value to test
573 isArray : function(v){
574 return toString.apply(v) === '[object Array]';
577 <div id="method-Ext-isDate"></div>/**
578 * Returns true if the passed object is a JavaScript date object, otherwise false.
579 * @param {Object} object The object to test
582 isDate : function(v){
583 return toString.apply(v) === '[object Date]';
586 <div id="method-Ext-isObject"></div>/**
587 * Returns true if the passed value is a JavaScript Object, otherwise false.
588 * @param {Mixed} value The value to test
591 isObject : function(v){
592 return !!v && Object.prototype.toString.call(v) === '[object Object]';
595 <div id="method-Ext-isPrimitive"></div>/**
596 * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean.
597 * @param {Mixed} value The value to test
600 isPrimitive : function(v){
601 return Ext.isString(v) || Ext.isNumber(v) || Ext.isBoolean(v);
604 <div id="method-Ext-isFunction"></div>/**
605 * Returns true if the passed value is a JavaScript Function, otherwise false.
606 * @param {Mixed} value The value to test
609 isFunction : function(v){
610 return toString.apply(v) === '[object Function]';
613 <div id="method-Ext-isNumber"></div>/**
614 * Returns true if the passed value is a number. Returns false for non-finite numbers.
615 * @param {Mixed} value The value to test
618 isNumber : function(v){
619 return typeof v === 'number' && isFinite(v);
622 <div id="method-Ext-isString"></div>/**
623 * Returns true if the passed value is a string.
624 * @param {Mixed} value The value to test
627 isString : function(v){
628 return typeof v === 'string';
631 <div id="method-Ext-isBoolean"></div>/**
632 * Returns true if the passed value is a boolean.
633 * @param {Mixed} value The value to test
636 isBoolean : function(v){
637 return typeof v === 'boolean';
640 <div id="method-Ext-isElement"></div>/**
641 * Returns true if the passed value is an HTMLElement
642 * @param {Mixed} value The value to test
645 isElement : function(v) {
646 return !!v && v.tagName;
649 <div id="method-Ext-isDefined"></div>/**
650 * Returns true if the passed value is not undefined.
651 * @param {Mixed} value The value to test
654 isDefined : function(v){
655 return typeof v !== 'undefined';
658 <div id="prop-Ext-isOpera"></div>/**
659 * True if the detected browser is Opera.
663 <div id="prop-Ext-isWebKit"></div>/**
664 * True if the detected browser uses WebKit.
668 <div id="prop-Ext-isChrome"></div>/**
669 * True if the detected browser is Chrome.
673 <div id="prop-Ext-isSafari"></div>/**
674 * True if the detected browser is Safari.
678 <div id="prop-Ext-isSafari3"></div>/**
679 * True if the detected browser is Safari 3.x.
682 isSafari3 : isSafari3,
683 <div id="prop-Ext-isSafari4"></div>/**
684 * True if the detected browser is Safari 4.x.
687 isSafari4 : isSafari4,
688 <div id="prop-Ext-isSafari2"></div>/**
689 * True if the detected browser is Safari 2.x.
692 isSafari2 : isSafari2,
693 <div id="prop-Ext-isIE"></div>/**
694 * True if the detected browser is Internet Explorer.
698 <div id="prop-Ext-isIE6"></div>/**
699 * True if the detected browser is Internet Explorer 6.x.
703 <div id="prop-Ext-isIE7"></div>/**
704 * True if the detected browser is Internet Explorer 7.x.
708 <div id="prop-Ext-isIE8"></div>/**
709 * True if the detected browser is Internet Explorer 8.x.
713 <div id="prop-Ext-isGecko"></div>/**
714 * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
718 <div id="prop-Ext-isGecko2"></div>/**
719 * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x).
723 <div id="prop-Ext-isGecko3"></div>/**
724 * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
728 <div id="prop-Ext-isBorderBox"></div>/**
729 * True if the detected browser is Internet Explorer running in non-strict mode.
732 isBorderBox : isBorderBox,
733 <div id="prop-Ext-isLinux"></div>/**
734 * True if the detected platform is Linux.
738 <div id="prop-Ext-isWindows"></div>/**
739 * True if the detected platform is Windows.
742 isWindows : isWindows,
743 <div id="prop-Ext-isMac"></div>/**
744 * True if the detected platform is Mac OS.
748 <div id="prop-Ext-isAir"></div>/**
749 * True if the detected platform is Adobe Air.
755 <div id="method-Ext-ns"></div>/**
756 * Creates namespaces to be used for scoping variables and classes so that they are not global.
757 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
759 Ext.namespace('Company', 'Company.data');
760 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
761 Company.Widget = function() { ... }
762 Company.data.CustomStore = function(config) { ... }
764 * @param {String} namespace1
765 * @param {String} namespace2
766 * @param {String} etc
767 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
770 Ext.ns = Ext.namespace;
773 Ext.ns("Ext.util", "Ext.lib", "Ext.data");
777 <div id="cls-Function"></div>/**
779 * These functions are available on every Function object (any JavaScript function).
781 Ext.apply(Function.prototype, {
782 <div id="method-Function-createInterceptor"></div>/**
783 * Creates an interceptor function. The passed function is called before the original one. If it returns false,
784 * the original one is not called. The resulting function returns the results of the original function.
785 * The passed function is called with the parameters of the original function. Example usage:
787 var sayHi = function(name){
788 alert('Hi, ' + name);
791 sayHi('Fred'); // alerts "Hi, Fred"
793 // create a new function that validates input without
794 // directly modifying the original function:
795 var sayHiToFriend = sayHi.createInterceptor(function(name){
796 return name == 'Brian';
799 sayHiToFriend('Fred'); // no alert
800 sayHiToFriend('Brian'); // alerts "Hi, Brian"
802 * @param {Function} fcn The function to call before the original
803 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
804 * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
805 * @return {Function} The new function
807 createInterceptor : function(fcn, scope){
809 return !Ext.isFunction(fcn) ?
816 return (fcn.apply(scope || me || window, args) !== false) ?
817 method.apply(me || window, args) :
822 <div id="method-Function-createCallback"></div>/**
823 * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
824 * Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code>
825 * Will create a function that is bound to those 2 args. <b>If a specific scope is required in the
826 * callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always
827 * executes in the window scope.
828 * <p>This method is required when you want to pass arguments to a callback function. If no arguments
829 * are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn).
830 * However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function
831 * would simply execute immediately when the code is parsed. Example usage:
833 var sayHi = function(name){
834 alert('Hi, ' + name);
837 // clicking the button alerts "Hi, Fred"
840 renderTo: Ext.getBody(),
841 handler: sayHi.createCallback('Fred')
844 * @return {Function} The new function
846 createCallback : function(/*args...*/){
847 // make args available, in function below
848 var args = arguments,
851 return method.apply(window, args);
855 <div id="method-Function-createDelegate"></div>/**
856 * Creates a delegate (callback) that sets the scope to obj.
857 * Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code>
858 * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
859 * callback points to obj. Example usage:
861 var sayHi = function(name){
862 // Note this use of "this.text" here. This function expects to
863 // execute within a scope that contains a text property. In this
864 // example, the "this" variable is pointing to the btn object that
865 // was passed in createDelegate below.
866 alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
869 var btn = new Ext.Button({
871 renderTo: Ext.getBody()
874 // This callback will execute in the scope of the
875 // button instance. Clicking the button alerts
876 // "Hi, Fred. You clicked the "Say Hi" button."
877 btn.on('click', sayHi.createDelegate(btn, ['Fred']));
879 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
880 * <b>If omitted, defaults to the browser window.</b>
881 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
882 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
883 * if a number the args are inserted at the specified position
884 * @return {Function} The new function
886 createDelegate : function(obj, args, appendArgs){
889 var callArgs = args || arguments;
890 if (appendArgs === true){
891 callArgs = Array.prototype.slice.call(arguments, 0);
892 callArgs = callArgs.concat(args);
893 }else if (Ext.isNumber(appendArgs)){
894 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
895 var applyArgs = [appendArgs, 0].concat(args); // create method call params
896 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
898 return method.apply(obj || window, callArgs);
902 <div id="method-Function-defer"></div>/**
903 * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
905 var sayHi = function(name){
906 alert('Hi, ' + name);
909 // executes immediately:
912 // executes after 2 seconds:
913 sayHi.defer(2000, this, ['Fred']);
915 // this syntax is sometimes useful for deferring
916 // execution of an anonymous function:
921 * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
922 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
923 * <b>If omitted, defaults to the browser window.</b>
924 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
925 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
926 * if a number the args are inserted at the specified position
927 * @return {Number} The timeout id that can be used with clearTimeout
929 defer : function(millis, obj, args, appendArgs){
930 var fn = this.createDelegate(obj, args, appendArgs);
932 return setTimeout(fn, millis);
939 <div id="cls-String"></div>/**
941 * These functions are available on every String object.
943 Ext.applyIf(String, {
944 <div id="method-String-format"></div>/**
945 * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
946 * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
948 var cls = 'my-class', text = 'Some text';
949 var s = String.format('<div class="{0}">{1}</div>', cls, text);
950 // s now contains the string: '<div class="my-class">Some text</div>'
952 * @param {String} string The tokenized string to be formatted
953 * @param {String} value1 The value to replace token {0}
954 * @param {String} value2 Etc...
955 * @return {String} The formatted string
958 format : function(format){
959 var args = Ext.toArray(arguments, 1);
960 return format.replace(/\{(\d+)\}/g, function(m, i){
966 <div id="cls-Array"></div>/**
969 Ext.applyIf(Array.prototype, {
970 <div id="method-Array-indexOf"></div>/**
971 * Checks whether or not the specified object exists in the array.
972 * @param {Object} o The object to check for
973 * @param {Number} from (Optional) The index at which to begin the search
974 * @return {Number} The index of o in the array (or -1 if it is not found)
976 indexOf : function(o, from){
977 var len = this.length;
979 from += (from < 0) ? len : 0;
980 for (; from < len; ++from){
981 if(this[from] === o){
988 <div id="method-Array-remove"></div>/**
989 * Removes the specified object from the array. If the object is not found nothing happens.
990 * @param {Object} o The object to remove
991 * @return {Array} this array
993 remove : function(o){
994 var index = this.indexOf(o);
996 this.splice(index, 1);