3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">
\r
10 window.undefined = window.undefined;
\r
12 <div id="cls-Ext"></div>/**
\r
14 * Ext core utilities and functions.
\r
19 <div id="prop-Ext-version"></div>/**
\r
20 * The version of the framework
\r
26 <div id="method-Ext-apply"></div>/**
\r
27 * Copies all the properties of config to obj.
\r
28 * @param {Object} obj The receiver of the properties
\r
29 * @param {Object} config The source of the properties
\r
30 * @param {Object} defaults A different object that will also be applied for default values
\r
31 * @return {Object} returns obj
\r
34 Ext.apply = function(o, c, defaults){
\r
35 // no "this" reference for friendly out of scope calls
\r
37 Ext.apply(o, defaults);
\r
39 if(o && c && typeof c == 'object'){
\r
49 toString = Object.prototype.toString,
\r
50 //assume it's not null and not an array
\r
51 isIterable = function(v){
\r
52 //check for array or arguments
\r
53 if(Ext.isArray(v) || v.callee){
\r
56 //check for node list type
\r
57 if(/NodeList|HTMLCollection/.test(toString.call(v))){
\r
60 //NodeList has an item and length property
\r
61 //IXMLDOMNodeList has nextNode method, needs to be checked first.
\r
62 return ((v.nextNode || v.item) && Ext.isNumber(v.length));
\r
64 ua = navigator.userAgent.toLowerCase(),
\r
65 check = function(r){
\r
69 isStrict = DOC.compatMode == "CSS1Compat",
\r
70 isOpera = check(/opera/),
\r
71 isChrome = check(/chrome/),
\r
72 isWebKit = check(/webkit/),
\r
73 isSafari = !isChrome && check(/safari/),
\r
74 isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
\r
75 isSafari3 = isSafari && check(/version\/3/),
\r
76 isSafari4 = isSafari && check(/version\/4/),
\r
77 isIE = !isOpera && check(/msie/),
\r
78 isIE7 = isIE && check(/msie 7/),
\r
79 isIE8 = isIE && check(/msie 8/),
\r
80 isIE6 = isIE && !isIE7 && !isIE8,
\r
81 isGecko = !isWebKit && check(/gecko/),
\r
82 isGecko2 = isGecko && check(/rv:1\.8/),
\r
83 isGecko3 = isGecko && check(/rv:1\.9/),
\r
84 isBorderBox = isIE && !isStrict,
\r
85 isWindows = check(/windows|win32/),
\r
86 isMac = check(/macintosh|mac os x/),
\r
87 isAir = check(/adobeair/),
\r
88 isLinux = check(/linux/),
\r
89 isSecure = /^https/i.test(window.location.protocol);
\r
91 // remove css image flicker
\r
94 DOC.execCommand("BackgroundImageCache", false, true);
\r
99 <div id="prop-Ext-SSL_SECURE_URL"></div>/**
\r
100 * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent
\r
101 * the IE insecure content warning (defaults to javascript:false).
\r
104 SSL_SECURE_URL : 'javascript:false',
\r
105 <div id="prop-Ext-isStrict"></div>/**
\r
106 * True if the browser is in strict (standards-compliant) mode, as opposed to quirks mode
\r
109 isStrict : isStrict,
\r
110 <div id="prop-Ext-isSecure"></div>/**
\r
111 * True if the page is running over SSL
\r
114 isSecure : isSecure,
\r
115 <div id="prop-Ext-isReady"></div>/**
\r
116 * True when the document is fully initialized and ready for action
\r
121 <div id="prop-Ext-enableFx"></div>/**
\r
122 * True if the {@link Ext.Fx} Class is available
\r
124 * @property enableFx
\r
127 <div id="prop-Ext-enableGarbageCollector"></div>/**
\r
128 * True to automatically uncache orphaned Ext.Elements periodically (defaults to true)
\r
131 enableGarbageCollector : true,
\r
133 <div id="prop-Ext-enableListenerCollection"></div>/**
\r
134 * True to automatically purge event listeners after uncaching an element (defaults to false).
\r
135 * Note: this only happens if {@link #enableGarbageCollector} is true.
\r
138 enableListenerCollection : false,
\r
140 <div id="prop-Ext-USE_NATIVE_JSON"></div>/**
\r
141 * Indicates whether to use native browser parsing for JSON methods.
\r
142 * This option is ignored if the browser does not support native JSON methods.
\r
143 * <b>Note: Native JSON methods will not work with objects that have functions.
\r
144 * Also, property names must be quoted, otherwise the data will not parse.</b> (Defaults to false)
\r
147 USE_NATIVE_JSON : false,
\r
149 <div id="method-Ext-applyIf"></div>/**
\r
150 * Copies all the properties of config to obj if they don't already exist.
\r
151 * @param {Object} obj The receiver of the properties
\r
152 * @param {Object} config The source of the properties
\r
153 * @return {Object} returns obj
\r
155 applyIf : function(o, c){
\r
158 if(Ext.isEmpty(o[p])){
\r
166 <div id="method-Ext-id"></div>/**
\r
167 * Generates unique ids. If the element already has an id, it is unchanged
\r
168 * @param {Mixed} el (optional) The element to generate an id for
\r
169 * @param {String} prefix (optional) Id prefix (defaults "ext-gen")
\r
170 * @return {String} The generated Id.
\r
172 id : function(el, prefix){
\r
173 return (el = Ext.getDom(el) || {}).id = el.id || (prefix || "ext-gen") + (++idSeed);
\r
176 <div id="method-Ext-extend"></div>/**
\r
177 * Extends one class with another class and optionally overrides members with the passed literal. This class
\r
178 * also adds the function "override()" to the class that can be used to override
\r
179 * members on an instance.
\r
181 * This function also supports a 2-argument call in which the subclass's constructor is
\r
182 * not passed as an argument. In this form, the parameters are as follows:</p><p>
\r
183 * <div class="mdetail-params"><ul>
\r
184 * <li><code>superclass</code>
\r
185 * <div class="sub-desc">The class being extended</div></li>
\r
186 * <li><code>overrides</code>
\r
187 * <div class="sub-desc">A literal with members which are copied into the subclass's
\r
188 * prototype, and are therefore shared among all instances of the new class.<p>
\r
189 * This may contain a special member named <tt><b>constructor</b></tt>. This is used
\r
190 * to define the constructor of the new class, and is returned. If this property is
\r
191 * <i>not</i> specified, a constructor is generated and returned which just calls the
\r
192 * superclass's constructor passing on its parameters.</p></div></li>
\r
193 * </ul></div></p><p>
\r
194 * For example, to create a subclass of the Ext GridPanel:
\r
196 MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
\r
197 constructor: function(config) {
\r
198 // Your preprocessing here
\r
199 MyGridPanel.superclass.constructor.apply(this, arguments);
\r
200 // Your postprocessing here
\r
203 yourMethod: function() {
\r
209 * @param {Function} subclass The class inheriting the functionality
\r
210 * @param {Function} superclass The class being extended
\r
211 * @param {Object} overrides (optional) A literal with members which are copied into the subclass's
\r
212 * prototype, and are therefore shared between all instances of the new class.
\r
213 * @return {Function} The subclass constructor.
\r
216 extend : function(){
\r
217 // inline overrides
\r
218 var io = function(o){
\r
223 var oc = Object.prototype.constructor;
\r
225 return function(sb, sp, overrides){
\r
226 if(Ext.isObject(sp)){
\r
229 sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
\r
231 var F = function(){},
\r
233 spp = sp.prototype;
\r
236 sbp = sb.prototype = new F();
\r
237 sbp.constructor=sb;
\r
239 if(spp.constructor == oc){
\r
240 spp.constructor=sp;
\r
242 sb.override = function(o){
\r
243 Ext.override(sb, o);
\r
245 sbp.superclass = sbp.supr = (function(){
\r
249 Ext.override(sb, overrides);
\r
250 sb.extend = function(o){Ext.extend(sb, o);};
\r
255 <div id="method-Ext-override"></div>/**
\r
256 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
\r
257 * Usage:<pre><code>
\r
258 Ext.override(MyClass, {
\r
259 newMethod1: function(){
\r
262 newMethod2: function(foo){
\r
267 * @param {Object} origclass The class to override
\r
268 * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
\r
269 * containing one or more methods.
\r
272 override : function(origclass, overrides){
\r
274 var p = origclass.prototype;
\r
275 Ext.apply(p, overrides);
\r
276 if(Ext.isIE && overrides.toString != origclass.toString){
\r
277 p.toString = overrides.toString;
\r
283 * Creates namespaces to be used for scoping variables and classes so that they are not global.
\r
284 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
\r
286 Ext.namespace('Company', 'Company.data');
\r
287 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
\r
288 Company.Widget = function() { ... }
\r
289 Company.data.CustomStore = function(config) { ... }
\r
291 * @param {String} namespace1
\r
292 * @param {String} namespace2
\r
293 * @param {String} etc
\r
294 * @method namespace
\r
296 namespace : function(){
\r
298 Ext.each(arguments, function(v) {
\r
300 o = window[d[0]] = window[d[0]] || {};
\r
301 Ext.each(d.slice(1), function(v2){
\r
302 o = o[v2] = o[v2] || {};
\r
308 <div id="method-Ext-urlEncode"></div>/**
\r
309 * 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.
\r
310 * @param {Object} o
\r
311 * @param {String} pre (optional) A prefix to add to the url encoded string
\r
314 urlEncode: function(o, pre){
\r
315 var undef, buf = [], key, e = encodeURIComponent;
\r
318 undef = !Ext.isDefined(o[key]);
\r
319 Ext.each(undef ? key : o[key], function(val, i){
\r
320 buf.push("&", e(key), "=", (val != key || !undef) ? e(val) : "");
\r
327 return pre + buf.join('');
\r
330 <div id="method-Ext-urlDecode"></div>/**
\r
331 * Takes an encoded URL and and converts it to an object. Example: <pre><code>
\r
332 Ext.urlDecode("foo=1&bar=2"); // returns {foo: "1", bar: "2"}
\r
333 Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2", "3", "4"]}
\r
335 * @param {String} string
\r
336 * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
\r
337 * @return {Object} A literal with members
\r
339 urlDecode : function(string, overwrite){
\r
341 pairs = string.split('&'),
\r
342 d = decodeURIComponent,
\r
345 Ext.each(pairs, function(pair) {
\r
346 pair = pair.split('=');
\r
348 value = d(pair[1]);
\r
349 obj[name] = overwrite || !obj[name] ? value :
\r
350 [].concat(obj[name]).concat(value);
\r
355 <div id="method-Ext-urlAppend"></div>/**
\r
356 * Appends content to the query string of a URL, which handles logic for whether to place
\r
357 * a question mark or ampersand.
\r
358 * @param {String} url The url to append to.
\r
359 * @@param {String} s The content to append to the url.
\r
360 * @return (String) The appended string
\r
362 urlAppend : function(url, s){
\r
363 if(!Ext.isEmpty(s)){
\r
364 return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
\r
369 <div id="method-Ext-toArray"></div>/**
\r
370 * Converts any iterable (numeric indices and a length property) into a true array
\r
371 * Don't use this on strings. IE doesn't support "abc"[0] which this implementation depends on.
\r
372 * For strings, use this instead: "abc".match(/./g) => [a,b,c];
\r
373 * @param {Iterable} the iterable object to be turned into a true Array.
\r
374 * @return (Array) array
\r
376 toArray : function(){
\r
378 function(a, i, j, res){
\r
380 Ext.each(a, function(v) {
\r
383 return res.slice(i || 0, j || res.length);
\r
386 return Array.prototype.slice.call(a, i || 0, j || a.length);
\r
390 <div id="method-Ext-each"></div>/**
\r
391 * Iterates an array calling the passed function with each item, stopping if your function returns false. If the
\r
392 * passed array is not really an array, your function is called once with it.
\r
393 * The supplied function is called with (Object item, Number index, Array allItems).
\r
394 * @param {Array/NodeList/Mixed} array
\r
395 * @param {Function} fn
\r
396 * @param {Object} scope
\r
398 each: function(array, fn, scope){
\r
399 if(Ext.isEmpty(array, true)){
\r
402 if(!isIterable(array) || Ext.isPrimitive(array)){
\r
405 for(var i = 0, len = array.length; i < len; i++){
\r
406 if(fn.call(scope || array[i], array[i], i, array) === false){
\r
412 <div id="method-Ext-iterate"></div>/**
\r
413 * Iterates either the elements in an array, or each of the properties in an object.
\r
414 * <b>Note</b>: If you are only iterating arrays, it is better to call {@link #each}.
\r
415 * @param {Object/Array} object The object or array to be iterated
\r
416 * @param {Function} fn The function to be called for each iteration.
\r
417 * The iteration will stop if the supplied function returns false, or
\r
418 * all array elements / object properties have been covered. The signature
\r
419 * varies depending on the type of object being interated:
\r
420 * <div class="mdetail-params"><ul>
\r
421 * <li>Arrays : <tt>(Object item, Number index, Array allItems)</tt>
\r
422 * <div class="sub-desc">
\r
423 * When iterating an array, the supplied function is called with each item.</div></li>
\r
424 * <li>Objects : <tt>(String key, Object value)</tt>
\r
425 * <div class="sub-desc">
\r
426 * When iterating an object, the supplied function is called with each key-value pair in
\r
427 * the object.</div></li>
\r
429 * @param {Object} scope The scope to call the supplied function with, defaults to
\r
430 * the specified <tt>object</tt>
\r
432 iterate : function(obj, fn, scope){
\r
433 if(isIterable(obj)){
\r
434 Ext.each(obj, fn, scope);
\r
436 }else if(Ext.isObject(obj)){
\r
437 for(var prop in obj){
\r
438 if(obj.hasOwnProperty(prop)){
\r
439 if(fn.call(scope || obj, prop, obj[prop]) === false){
\r
447 <div id="method-Ext-getDom"></div>/**
\r
448 * Return the dom node for the passed String (id), dom node, or Ext.Element.
\r
449 * Here are some examples:
\r
451 // gets dom node based on id
\r
452 var elDom = Ext.getDom('elId');
\r
453 // gets dom node based on the dom node
\r
454 var elDom1 = Ext.getDom(elDom);
\r
456 // If we don't know if we are working with an
\r
457 // Ext.Element or a dom node use Ext.getDom
\r
459 var dom = Ext.getDom(el);
\r
460 // do something with the dom node
\r
463 * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc)
\r
464 * when this method is called to be successful.
\r
465 * @param {Mixed} el
\r
466 * @return HTMLElement
\r
468 getDom : function(el){
\r
472 return el.dom ? el.dom : (Ext.isString(el) ? DOC.getElementById(el) : el);
\r
475 <div id="method-Ext-getBody"></div>/**
\r
476 * Returns the current document body as an {@link Ext.Element}.
\r
477 * @return Ext.Element The document body
\r
479 getBody : function(){
\r
480 return Ext.get(DOC.body || DOC.documentElement);
\r
483 <div id="method-Ext-removeNode"></div>/**
\r
484 * Removes a DOM node from the document. The body node will be ignored if passed in.
\r
485 * @param {HTMLElement} node The node to remove
\r
487 removeNode : isIE ? function(){
\r
489 return function(n){
\r
490 if(n && n.tagName != 'BODY'){
\r
491 d = d || DOC.createElement('div');
\r
497 if(n && n.parentNode && n.tagName != 'BODY'){
\r
498 n.parentNode.removeChild(n);
\r
502 <div id="method-Ext-isEmpty"></div>/**
\r
503 * <p>Returns true if the passed value is empty.</p>
\r
504 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
\r
506 * <li>undefined</li>
\r
507 * <li>an empty array</li>
\r
508 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
\r
510 * @param {Mixed} value The value to test
\r
511 * @param {Boolean} allowBlank (optional) true to allow empty strings (defaults to false)
\r
512 * @return {Boolean}
\r
514 isEmpty : function(v, allowBlank){
\r
515 return v === null || v === undefined || ((Ext.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false);
\r
518 <div id="method-Ext-isArray"></div>/**
\r
519 * Returns true if the passed object is a JavaScript array, otherwise false.
\r
520 * @param {Object} object The object to test
\r
521 * @return {Boolean}
\r
523 isArray : function(v){
\r
524 return toString.apply(v) === '[object Array]';
\r
527 <div id="method-Ext-isObject"></div>/**
\r
528 * Returns true if the passed object is a JavaScript Object, otherwise false.
\r
529 * @param {Object} object The object to test
\r
530 * @return {Boolean}
\r
532 isObject : function(v){
\r
533 return v && typeof v == "object";
\r
536 <div id="method-Ext-isPrimitive"></div>/**
\r
537 * Returns true if the passed object is a JavaScript 'primitive', a string, number or boolean.
\r
538 * @param {Mixed} value The value to test
\r
539 * @return {Boolean}
\r
541 isPrimitive : function(v){
\r
542 return Ext.isString(v) || Ext.isNumber(v) || Ext.isBoolean(v);
\r
545 <div id="method-Ext-isFunction"></div>/**
\r
546 * Returns true if the passed object is a JavaScript Function, otherwise false.
\r
547 * @param {Object} object The object to test
\r
548 * @return {Boolean}
\r
550 isFunction : function(v){
\r
551 return toString.apply(v) === '[object Function]';
\r
554 <div id="method-Ext-isNumber"></div>/**
\r
555 * Returns true if the passed object is a number. Returns false for non-finite numbers.
\r
556 * @param {Object} v The object to test
\r
557 * @return {Boolean}
\r
559 isNumber: function(v){
\r
560 return typeof v === 'number' && isFinite(v);
\r
563 <div id="method-Ext-isString"></div>/**
\r
564 * Returns true if the passed object is a string.
\r
565 * @param {Object} v The object to test
\r
566 * @return {Boolean}
\r
568 isString: function(v){
\r
569 return typeof v === 'string';
\r
572 <div id="method-Ext-isBoolean"></div>/**
\r
573 * Returns true if the passed object is a boolean.
\r
574 * @param {Object} v The object to test
\r
575 * @return {Boolean}
\r
577 isBoolean: function(v){
\r
578 return typeof v === 'boolean';
\r
581 <div id="method-Ext-isDefined"></div>/**
\r
582 * Returns true if the passed object is not undefined.
\r
583 * @param {Object} v The object to test
\r
584 * @return {Boolean}
\r
586 isDefined: function(v){
\r
587 return typeof v !== 'undefined';
\r
590 <div id="prop-Ext-isOpera"></div>/**
\r
591 * True if the detected browser is Opera.
\r
595 <div id="prop-Ext-isWebKit"></div>/**
\r
596 * True if the detected browser uses WebKit.
\r
599 isWebKit: isWebKit,
\r
600 <div id="prop-Ext-isChrome"></div>/**
\r
601 * True if the detected browser is Chrome.
\r
604 isChrome : isChrome,
\r
605 <div id="prop-Ext-isSafari"></div>/**
\r
606 * True if the detected browser is Safari.
\r
609 isSafari : isSafari,
\r
610 <div id="prop-Ext-isSafari3"></div>/**
\r
611 * True if the detected browser is Safari 3.x.
\r
614 isSafari3 : isSafari3,
\r
615 <div id="prop-Ext-isSafari4"></div>/**
\r
616 * True if the detected browser is Safari 4.x.
\r
619 isSafari4 : isSafari4,
\r
620 <div id="prop-Ext-isSafari2"></div>/**
\r
621 * True if the detected browser is Safari 2.x.
\r
624 isSafari2 : isSafari2,
\r
625 <div id="prop-Ext-isIE"></div>/**
\r
626 * True if the detected browser is Internet Explorer.
\r
630 <div id="prop-Ext-isIE6"></div>/**
\r
631 * True if the detected browser is Internet Explorer 6.x.
\r
635 <div id="prop-Ext-isIE7"></div>/**
\r
636 * True if the detected browser is Internet Explorer 7.x.
\r
640 <div id="prop-Ext-isIE8"></div>/**
\r
641 * True if the detected browser is Internet Explorer 8.x.
\r
645 <div id="prop-Ext-isGecko"></div>/**
\r
646 * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
\r
650 <div id="prop-Ext-isGecko2"></div>/**
\r
651 * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x).
\r
654 isGecko2 : isGecko2,
\r
655 <div id="prop-Ext-isGecko3"></div>/**
\r
656 * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
\r
659 isGecko3 : isGecko3,
\r
660 <div id="prop-Ext-isBorderBox"></div>/**
\r
661 * True if the detected browser is Internet Explorer running in non-strict mode.
\r
664 isBorderBox : isBorderBox,
\r
665 <div id="prop-Ext-isLinux"></div>/**
\r
666 * True if the detected platform is Linux.
\r
670 <div id="prop-Ext-isWindows"></div>/**
\r
671 * True if the detected platform is Windows.
\r
674 isWindows : isWindows,
\r
675 <div id="prop-Ext-isMac"></div>/**
\r
676 * True if the detected platform is Mac OS.
\r
680 <div id="prop-Ext-isAir"></div>/**
\r
681 * True if the detected platform is Adobe Air.
\r
687 <div id="method-Ext-namespace"></div>/**
\r
688 * Creates namespaces to be used for scoping variables and classes so that they are not global.
\r
689 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
\r
691 Ext.namespace('Company', 'Company.data');
\r
692 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
\r
693 Company.Widget = function() { ... }
\r
694 Company.data.CustomStore = function(config) { ... }
\r
696 * @param {String} namespace1
\r
697 * @param {String} namespace2
\r
698 * @param {String} etc
\r
699 * @method namespace
\r
701 Ext.ns = Ext.namespace;
\r
704 Ext.ns("Ext", "Ext.util", "Ext.lib", "Ext.data");
\r
707 <div id="cls-Function"></div>/**
\r
709 * These functions are available on every Function object (any JavaScript function).
\r
711 Ext.apply(Function.prototype, {
\r
712 <div id="method-Function-createInterceptor"></div>/**
\r
713 * Creates an interceptor function. The passed fcn is called before the original one. If it returns false,
\r
714 * the original one is not called. The resulting function returns the results of the original function.
\r
715 * The passed fcn is called with the parameters of the original function. Example usage:
\r
717 var sayHi = function(name){
\r
718 alert('Hi, ' + name);
\r
721 sayHi('Fred'); // alerts "Hi, Fred"
\r
723 // create a new function that validates input without
\r
724 // directly modifying the original function:
\r
725 var sayHiToFriend = sayHi.createInterceptor(function(name){
\r
726 return name == 'Brian';
\r
729 sayHiToFriend('Fred'); // no alert
\r
730 sayHiToFriend('Brian'); // alerts "Hi, Brian"
\r
732 * @param {Function} fcn The function to call before the original
\r
733 * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
\r
734 * @return {Function} The new function
\r
736 createInterceptor : function(fcn, scope){
\r
738 return !Ext.isFunction(fcn) ?
\r
744 fcn.method = method;
\r
745 return (fcn.apply(scope || me || window, args) !== false) ?
\r
746 method.apply(me || window, args) :
\r
751 <div id="method-Function-createCallback"></div>/**
\r
752 * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
\r
753 * Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code>
\r
754 * Will create a function that is bound to those 2 args. <b>If a specific scope is required in the
\r
755 * callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always
\r
756 * executes in the window scope.
\r
757 * <p>This method is required when you want to pass arguments to a callback function. If no arguments
\r
758 * are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn).
\r
759 * However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function
\r
760 * would simply execute immediately when the code is parsed. Example usage:
\r
762 var sayHi = function(name){
\r
763 alert('Hi, ' + name);
\r
766 // clicking the button alerts "Hi, Fred"
\r
769 renderTo: Ext.getBody(),
\r
770 handler: sayHi.createCallback('Fred')
\r
773 * @return {Function} The new function
\r
775 createCallback : function(/*args...*/){
\r
776 // make args available, in function below
\r
777 var args = arguments,
\r
779 return function() {
\r
780 return method.apply(window, args);
\r
784 <div id="method-Function-createDelegate"></div>/**
\r
785 * Creates a delegate (callback) that sets the scope to obj.
\r
786 * Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code>
\r
787 * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
\r
788 * callback points to obj. Example usage:
\r
790 var sayHi = function(name){
\r
791 // Note this use of "this.text" here. This function expects to
\r
792 // execute within a scope that contains a text property. In this
\r
793 // example, the "this" variable is pointing to the btn object that
\r
794 // was passed in createDelegate below.
\r
795 alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
\r
798 var btn = new Ext.Button({
\r
800 renderTo: Ext.getBody()
\r
803 // This callback will execute in the scope of the
\r
804 // button instance. Clicking the button alerts
\r
805 // "Hi, Fred. You clicked the "Say Hi" button."
\r
806 btn.on('click', sayHi.createDelegate(btn, ['Fred']));
\r
808 * @param {Object} obj (optional) The object for which the scope is set
\r
809 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
\r
810 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
\r
811 * if a number the args are inserted at the specified position
\r
812 * @return {Function} The new function
\r
814 createDelegate : function(obj, args, appendArgs){
\r
816 return function() {
\r
817 var callArgs = args || arguments;
\r
818 if (appendArgs === true){
\r
819 callArgs = Array.prototype.slice.call(arguments, 0);
\r
820 callArgs = callArgs.concat(args);
\r
821 }else if (Ext.isNumber(appendArgs)){
\r
822 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
\r
823 var applyArgs = [appendArgs, 0].concat(args); // create method call params
\r
824 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
\r
826 return method.apply(obj || window, callArgs);
\r
830 <div id="method-Function-defer"></div>/**
\r
831 * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
\r
833 var sayHi = function(name){
\r
834 alert('Hi, ' + name);
\r
837 // executes immediately:
\r
840 // executes after 2 seconds:
\r
841 sayHi.defer(2000, this, ['Fred']);
\r
843 // this syntax is sometimes useful for deferring
\r
844 // execution of an anonymous function:
\r
846 alert('Anonymous');
\r
849 * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
\r
850 * @param {Object} obj (optional) The object for which the scope is set
\r
851 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
\r
852 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
\r
853 * if a number the args are inserted at the specified position
\r
854 * @return {Number} The timeout id that can be used with clearTimeout
\r
856 defer : function(millis, obj, args, appendArgs){
\r
857 var fn = this.createDelegate(obj, args, appendArgs);
\r
859 return setTimeout(fn, millis);
\r
866 <div id="cls-String"></div>/**
\r
868 * These functions are available on every String object.
\r
870 Ext.applyIf(String, {
\r
871 <div id="method-String-format"></div>/**
\r
872 * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
\r
873 * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
\r
875 var cls = 'my-class', text = 'Some text';
\r
876 var s = String.format('<div class="{0}">{1}</div>', cls, text);
\r
877 // s now contains the string: '<div class="my-class">Some text</div>'
\r
879 * @param {String} string The tokenized string to be formatted
\r
880 * @param {String} value1 The value to replace token {0}
\r
881 * @param {String} value2 Etc...
\r
882 * @return {String} The formatted string
\r
885 format : function(format){
\r
886 var args = Ext.toArray(arguments, 1);
\r
887 return format.replace(/\{(\d+)\}/g, function(m, i){
\r
893 <div id="cls-Array"></div>/**
\r
896 Ext.applyIf(Array.prototype, {
\r
897 <div id="method-Array-indexOf"></div>/**
\r
898 * Checks whether or not the specified object exists in the array.
\r
899 * @param {Object} o The object to check for
\r
900 * @return {Number} The index of o in the array (or -1 if it is not found)
\r
902 indexOf : function(o){
\r
903 for (var i = 0, len = this.length; i < len; i++){
\r
911 <div id="method-Array-remove"></div>/**
\r
912 * Removes the specified object from the array. If the object is not found nothing happens.
\r
913 * @param {Object} o The object to remove
\r
914 * @return {Array} this array
\r
916 remove : function(o){
\r
917 var index = this.indexOf(o);
\r
919 this.splice(index, 1);
\r