3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
8 window.undefined = window.undefined;
12 * Ext core utilities and functions.
18 * The version of the framework
30 * Copies all the properties of config to obj.
31 * @param {Object} obj The receiver of the properties
32 * @param {Object} config The source of the properties
33 * @param {Object} defaults A different object that will also be applied for default values
34 * @return {Object} returns obj
37 Ext.apply = function(o, c, defaults){
38 // no "this" reference for friendly out of scope calls
40 Ext.apply(o, defaults);
42 if(o && c && typeof c == 'object'){
52 toString = Object.prototype.toString,
53 ua = navigator.userAgent.toLowerCase(),
58 isStrict = DOC.compatMode == "CSS1Compat",
59 isOpera = check(/opera/),
60 isChrome = check(/\bchrome\b/),
61 isWebKit = check(/webkit/),
62 isSafari = !isChrome && check(/safari/),
63 isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
64 isSafari3 = isSafari && check(/version\/3/),
65 isSafari4 = isSafari && check(/version\/4/),
66 isIE = !isOpera && check(/msie/),
67 isIE7 = isIE && check(/msie 7/),
68 isIE8 = isIE && check(/msie 8/),
69 isIE6 = isIE && !isIE7 && !isIE8,
70 isGecko = !isWebKit && check(/gecko/),
71 isGecko2 = isGecko && check(/rv:1\.8/),
72 isGecko3 = isGecko && check(/rv:1\.9/),
73 isBorderBox = isIE && !isStrict,
74 isWindows = check(/windows|win32/),
75 isMac = check(/macintosh|mac os x/),
76 isAir = check(/adobeair/),
77 isLinux = check(/linux/),
78 isSecure = /^https/i.test(window.location.protocol);
80 // remove css image flicker
83 DOC.execCommand("BackgroundImageCache", false, true);
89 * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent
90 * the IE insecure content warning (<tt>'about:blank'</tt>, except for IE in secure mode, which is <tt>'javascript:""'</tt>).
93 SSL_SECURE_URL : isSecure && isIE ? 'javascript:""' : 'about:blank',
95 * True if the browser is in strict (standards-compliant) mode, as opposed to quirks mode
100 * True if the page is running over SSL
105 * True when the document is fully initialized and ready for action
111 * True if the {@link Ext.Fx} Class is available
117 * True to automatically uncache orphaned Ext.Elements periodically (defaults to true)
120 enableGarbageCollector : true,
123 * True to automatically purge event listeners during garbageCollection (defaults to false).
126 enableListenerCollection : false,
129 * EXPERIMENTAL - True to cascade listener removal to child elements when an element is removed.
130 * Currently not optimized for performance.
133 enableNestedListenerRemoval : false,
136 * Indicates whether to use native browser parsing for JSON methods.
137 * This option is ignored if the browser does not support native JSON methods.
138 * <b>Note: Native JSON methods will not work with objects that have functions.
139 * Also, property names must be quoted, otherwise the data will not parse.</b> (Defaults to false)
142 USE_NATIVE_JSON : false,
145 * Copies all the properties of config to obj if they don't already exist.
146 * @param {Object} obj The receiver of the properties
147 * @param {Object} config The source of the properties
148 * @return {Object} returns obj
150 applyIf : function(o, c){
153 if(!Ext.isDefined(o[p])){
162 * Generates unique ids. If the element already has an id, it is unchanged
163 * @param {Mixed} el (optional) The element to generate an id for
164 * @param {String} prefix (optional) Id prefix (defaults "ext-gen")
165 * @return {String} The generated Id.
167 id : function(el, prefix){
168 el = Ext.getDom(el, true) || {};
170 el.id = (prefix || "ext-gen") + (++idSeed);
176 * <p>Extends one class to create a subclass and optionally overrides members with the passed literal. This method
177 * also adds the function "override()" to the subclass that can be used to override members of the class.</p>
178 * For example, to create a subclass of Ext GridPanel:
180 MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
181 constructor: function(config) {
183 // Create configuration for this Grid.
184 var store = new Ext.data.Store({...});
185 var colModel = new Ext.grid.ColumnModel({...});
187 // Create a new config object containing our computed properties
188 // *plus* whatever was in the config parameter.
194 MyGridPanel.superclass.constructor.call(this, config);
196 // Your postprocessing here
199 yourMethod: function() {
205 * <p>This function also supports a 3-argument call in which the subclass's constructor is
206 * passed as an argument. In this form, the parameters are as follows:</p>
207 * <div class="mdetail-params"><ul>
208 * <li><code>subclass</code> : Function <div class="sub-desc">The subclass constructor.</div></li>
209 * <li><code>superclass</code> : Function <div class="sub-desc">The constructor of class being extended</div></li>
210 * <li><code>overrides</code> : Object <div class="sub-desc">A literal with members which are copied into the subclass's
211 * prototype, and are therefore shared among all instances of the new class.</div></li>
214 * @param {Function} superclass The constructor of class being extended.
215 * @param {Object} overrides <p>A literal with members which are copied into the subclass's
216 * prototype, and are therefore shared between all instances of the new class.</p>
217 * <p>This may contain a special member named <tt><b>constructor</b></tt>. This is used
218 * to define the constructor of the new class, and is returned. If this property is
219 * <i>not</i> specified, a constructor is generated and returned which just calls the
220 * superclass's constructor passing on its parameters.</p>
221 * <p><b>It is essential that you call the superclass constructor in any provided constructor. See example code.</b></p>
222 * @return {Function} The subclass constructor from the <code>overrides</code> parameter, or a generated one if not provided.
226 var io = function(o){
231 var oc = Object.prototype.constructor;
233 return function(sb, sp, overrides){
234 if(typeof sp == 'object'){
237 sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
239 var F = function(){},
244 sbp = sb.prototype = new F();
247 if(spp.constructor == oc){
250 sb.override = function(o){
253 sbp.superclass = sbp.supr = (function(){
257 Ext.override(sb, overrides);
258 sb.extend = function(o){return Ext.extend(sb, o);};
264 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
266 Ext.override(MyClass, {
267 newMethod1: function(){
270 newMethod2: function(foo){
275 * @param {Object} origclass The class to override
276 * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
277 * containing one or more methods.
280 override : function(origclass, overrides){
282 var p = origclass.prototype;
283 Ext.apply(p, overrides);
284 if(Ext.isIE && overrides.hasOwnProperty('toString')){
285 p.toString = overrides.toString;
291 * Creates namespaces to be used for scoping variables and classes so that they are not global.
292 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
294 Ext.namespace('Company', 'Company.data');
295 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
296 Company.Widget = function() { ... }
297 Company.data.CustomStore = function(config) { ... }
299 * @param {String} namespace1
300 * @param {String} namespace2
301 * @param {String} etc
302 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
305 namespace : function(){
307 Ext.each(arguments, function(v) {
309 o = window[d[0]] = window[d[0]] || {};
310 Ext.each(d.slice(1), function(v2){
311 o = o[v2] = o[v2] || {};
318 * 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.
320 * @param {String} pre (optional) A prefix to add to the url encoded string
323 urlEncode : function(o, pre){
326 e = encodeURIComponent;
328 Ext.iterate(o, function(key, item){
329 empty = Ext.isEmpty(item);
330 Ext.each(empty ? key : item, function(val){
331 buf.push('&', e(key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : '');
338 return pre + buf.join('');
342 * Takes an encoded URL and and converts it to an object. Example: <pre><code>
343 Ext.urlDecode("foo=1&bar=2"); // returns {foo: "1", bar: "2"}
344 Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2", "3", "4"]}
346 * @param {String} string
347 * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
348 * @return {Object} A literal with members
350 urlDecode : function(string, overwrite){
351 if(Ext.isEmpty(string)){
355 pairs = string.split('&'),
356 d = decodeURIComponent,
359 Ext.each(pairs, function(pair) {
360 pair = pair.split('=');
363 obj[name] = overwrite || !obj[name] ? value :
364 [].concat(obj[name]).concat(value);
370 * Appends content to the query string of a URL, handling logic for whether to place
371 * a question mark or ampersand.
372 * @param {String} url The URL to append to.
373 * @param {String} s The content to append to the URL.
374 * @return (String) The resulting URL
376 urlAppend : function(url, s){
378 return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
384 * Converts any iterable (numeric indices and a length property) into a true array
385 * Don't use this on strings. IE doesn't support "abc"[0] which this implementation depends on.
386 * For strings, use this instead: "abc".match(/./g) => [a,b,c];
387 * @param {Iterable} the iterable object to be turned into a true Array.
388 * @return (Array) array
390 toArray : function(){
392 function(a, i, j, res){
394 for(var x = 0, len = a.length; x < len; x++) {
397 return res.slice(i || 0, j || res.length);
400 return Array.prototype.slice.call(a, i || 0, j || a.length);
404 isIterable : function(v){
405 //check for array or arguments
406 if(Ext.isArray(v) || v.callee){
409 //check for node list type
410 if(/NodeList|HTMLCollection/.test(toString.call(v))){
413 //NodeList has an item and length property
414 //IXMLDOMNodeList has nextNode method, needs to be checked first.
415 return ((typeof v.nextNode != 'undefined' || v.item) && Ext.isNumber(v.length));
419 * Iterates an array calling the supplied function.
420 * @param {Array/NodeList/Mixed} array The array to be iterated. If this
421 * argument is not really an array, the supplied function is called once.
422 * @param {Function} fn The function to be called with each item. If the
423 * supplied function returns false, iteration stops and this method returns
424 * the current <code>index</code>. This function is called with
425 * the following arguments:
426 * <div class="mdetail-params"><ul>
427 * <li><code>item</code> : <i>Mixed</i>
428 * <div class="sub-desc">The item at the current <code>index</code>
429 * in the passed <code>array</code></div></li>
430 * <li><code>index</code> : <i>Number</i>
431 * <div class="sub-desc">The current index within the array</div></li>
432 * <li><code>allItems</code> : <i>Array</i>
433 * <div class="sub-desc">The <code>array</code> passed as the first
434 * argument to <code>Ext.each</code>.</div></li>
436 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed.
437 * Defaults to the <code>item</code> at the current <code>index</code>
438 * within the passed <code>array</code>.
439 * @return See description for the fn parameter.
441 each : function(array, fn, scope){
442 if(Ext.isEmpty(array, true)){
445 if(!Ext.isIterable(array) || Ext.isPrimitive(array)){
448 for(var i = 0, len = array.length; i < len; i++){
449 if(fn.call(scope || array[i], array[i], i, array) === false){
456 * Iterates either the elements in an array, or each of the properties in an object.
457 * <b>Note</b>: If you are only iterating arrays, it is better to call {@link #each}.
458 * @param {Object/Array} object The object or array to be iterated
459 * @param {Function} fn The function to be called for each iteration.
460 * The iteration will stop if the supplied function returns false, or
461 * all array elements / object properties have been covered. The signature
462 * varies depending on the type of object being interated:
463 * <div class="mdetail-params"><ul>
464 * <li>Arrays : <tt>(Object item, Number index, Array allItems)</tt>
465 * <div class="sub-desc">
466 * When iterating an array, the supplied function is called with each item.</div></li>
467 * <li>Objects : <tt>(String key, Object value, Object)</tt>
468 * <div class="sub-desc">
469 * When iterating an object, the supplied function is called with each key-value pair in
470 * the object, and the iterated object</div></li>
472 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed. Defaults to
473 * the <code>object</code> being iterated.
475 iterate : function(obj, fn, scope){
476 if(Ext.isEmpty(obj)){
479 if(Ext.isIterable(obj)){
480 Ext.each(obj, fn, scope);
482 }else if(typeof obj == 'object'){
483 for(var prop in obj){
484 if(obj.hasOwnProperty(prop)){
485 if(fn.call(scope || obj, prop, obj[prop], obj) === false){
494 * Return the dom node for the passed String (id), dom node, or Ext.Element.
495 * Optional 'strict' flag is needed for IE since it can return 'name' and
496 * 'id' elements by using getElementById.
497 * Here are some examples:
499 // gets dom node based on id
500 var elDom = Ext.getDom('elId');
501 // gets dom node based on the dom node
502 var elDom1 = Ext.getDom(elDom);
504 // If we don't know if we are working with an
505 // Ext.Element or a dom node use Ext.getDom
507 var dom = Ext.getDom(el);
508 // do something with the dom node
511 * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc)
512 * when this method is called to be successful.
514 * @return HTMLElement
516 getDom : function(el, strict){
523 if (typeof el == 'string') {
524 var e = DOC.getElementById(el);
525 // IE returns elements with the 'name' and 'id' attribute.
526 // we do a strict check to return the element with only the id attribute
527 if (e && isIE && strict) {
528 if (el == e.getAttribute('id')) {
542 * Returns the current document body as an {@link Ext.Element}.
543 * @return Ext.Element The document body
545 getBody : function(){
546 return Ext.get(DOC.body || DOC.documentElement);
550 * Removes a DOM node from the document.
553 * <p>Removes this element from the document, removes all DOM event listeners, and deletes the cache reference.
554 * All DOM event listeners are removed from this element. If {@link Ext#enableNestedListenerRemoval} is
555 * <code>true</code>, then DOM event listeners are also removed from all child nodes. The body node
556 * will be ignored if passed in.</p>
557 * @param {HTMLElement} node The node to remove
559 removeNode : isIE && !isIE8 ? function(){
562 if(n && n.tagName != 'BODY'){
563 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
564 d = d || DOC.createElement('div');
567 delete Ext.elCache[n.id];
571 if(n && n.parentNode && n.tagName != 'BODY'){
572 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
573 n.parentNode.removeChild(n);
574 delete Ext.elCache[n.id];
579 * <p>Returns true if the passed value is empty.</p>
580 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
583 * <li>an empty array</li>
584 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
586 * @param {Mixed} value The value to test
587 * @param {Boolean} allowBlank (optional) true to allow empty strings (defaults to false)
590 isEmpty : function(v, allowBlank){
591 return v === null || v === undefined || ((Ext.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false);
595 * Returns true if the passed value is a JavaScript array, otherwise false.
596 * @param {Mixed} value The value to test
599 isArray : function(v){
600 return toString.apply(v) === '[object Array]';
604 * Returns true if the passed object is a JavaScript date object, otherwise false.
605 * @param {Object} object The object to test
608 isDate : function(v){
609 return toString.apply(v) === '[object Date]';
613 * Returns true if the passed value is a JavaScript Object, otherwise false.
614 * @param {Mixed} value The value to test
617 isObject : function(v){
618 return !!v && Object.prototype.toString.call(v) === '[object Object]';
622 * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean.
623 * @param {Mixed} value The value to test
626 isPrimitive : function(v){
627 return Ext.isString(v) || Ext.isNumber(v) || Ext.isBoolean(v);
631 * Returns true if the passed value is a JavaScript Function, otherwise false.
632 * @param {Mixed} value The value to test
635 isFunction : function(v){
636 return toString.apply(v) === '[object Function]';
640 * Returns true if the passed value is a number. Returns false for non-finite numbers.
641 * @param {Mixed} value The value to test
644 isNumber : function(v){
645 return typeof v === 'number' && isFinite(v);
649 * Returns true if the passed value is a string.
650 * @param {Mixed} value The value to test
653 isString : function(v){
654 return typeof v === 'string';
658 * Returns true if the passed value is a boolean.
659 * @param {Mixed} value The value to test
662 isBoolean : function(v){
663 return typeof v === 'boolean';
667 * Returns true if the passed value is an HTMLElement
668 * @param {Mixed} value The value to test
671 isElement : function(v) {
672 return v ? !!v.tagName : false;
676 * Returns true if the passed value is not undefined.
677 * @param {Mixed} value The value to test
680 isDefined : function(v){
681 return typeof v !== 'undefined';
685 * True if the detected browser is Opera.
690 * True if the detected browser uses WebKit.
695 * True if the detected browser is Chrome.
700 * True if the detected browser is Safari.
705 * True if the detected browser is Safari 3.x.
708 isSafari3 : isSafari3,
710 * True if the detected browser is Safari 4.x.
713 isSafari4 : isSafari4,
715 * True if the detected browser is Safari 2.x.
718 isSafari2 : isSafari2,
720 * True if the detected browser is Internet Explorer.
725 * True if the detected browser is Internet Explorer 6.x.
730 * True if the detected browser is Internet Explorer 7.x.
735 * True if the detected browser is Internet Explorer 8.x.
740 * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
745 * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x).
750 * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
755 * True if the detected browser is Internet Explorer running in non-strict mode.
758 isBorderBox : isBorderBox,
760 * True if the detected platform is Linux.
765 * True if the detected platform is Windows.
768 isWindows : isWindows,
770 * True if the detected platform is Mac OS.
775 * True if the detected platform is Adobe Air.
782 * Creates namespaces to be used for scoping variables and classes so that they are not global.
783 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
785 Ext.namespace('Company', 'Company.data');
786 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
787 Company.Widget = function() { ... }
788 Company.data.CustomStore = function(config) { ... }
790 * @param {String} namespace1
791 * @param {String} namespace2
792 * @param {String} etc
793 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
796 Ext.ns = Ext.namespace;
799 Ext.ns("Ext.util", "Ext.lib", "Ext.data");
805 * These functions are available on every Function object (any JavaScript function).
807 Ext.apply(Function.prototype, {
809 * Creates an interceptor function. The passed function is called before the original one. If it returns false,
810 * the original one is not called. The resulting function returns the results of the original function.
811 * The passed function is called with the parameters of the original function. Example usage:
813 var sayHi = function(name){
814 alert('Hi, ' + name);
817 sayHi('Fred'); // alerts "Hi, Fred"
819 // create a new function that validates input without
820 // directly modifying the original function:
821 var sayHiToFriend = sayHi.createInterceptor(function(name){
822 return name == 'Brian';
825 sayHiToFriend('Fred'); // no alert
826 sayHiToFriend('Brian'); // alerts "Hi, Brian"
828 * @param {Function} fcn The function to call before the original
829 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
830 * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
831 * @return {Function} The new function
833 createInterceptor : function(fcn, scope){
835 return !Ext.isFunction(fcn) ?
842 return (fcn.apply(scope || me || window, args) !== false) ?
843 method.apply(me || window, args) :
849 * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
850 * Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code>
851 * Will create a function that is bound to those 2 args. <b>If a specific scope is required in the
852 * callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always
853 * executes in the window scope.
854 * <p>This method is required when you want to pass arguments to a callback function. If no arguments
855 * are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn).
856 * However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function
857 * would simply execute immediately when the code is parsed. Example usage:
859 var sayHi = function(name){
860 alert('Hi, ' + name);
863 // clicking the button alerts "Hi, Fred"
866 renderTo: Ext.getBody(),
867 handler: sayHi.createCallback('Fred')
870 * @return {Function} The new function
872 createCallback : function(/*args...*/){
873 // make args available, in function below
874 var args = arguments,
877 return method.apply(window, args);
882 * Creates a delegate (callback) that sets the scope to obj.
883 * Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code>
884 * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
885 * callback points to obj. Example usage:
887 var sayHi = function(name){
888 // Note this use of "this.text" here. This function expects to
889 // execute within a scope that contains a text property. In this
890 // example, the "this" variable is pointing to the btn object that
891 // was passed in createDelegate below.
892 alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
895 var btn = new Ext.Button({
897 renderTo: Ext.getBody()
900 // This callback will execute in the scope of the
901 // button instance. Clicking the button alerts
902 // "Hi, Fred. You clicked the "Say Hi" button."
903 btn.on('click', sayHi.createDelegate(btn, ['Fred']));
905 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
906 * <b>If omitted, defaults to the browser window.</b>
907 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
908 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
909 * if a number the args are inserted at the specified position
910 * @return {Function} The new function
912 createDelegate : function(obj, args, appendArgs){
915 var callArgs = args || arguments;
916 if (appendArgs === true){
917 callArgs = Array.prototype.slice.call(arguments, 0);
918 callArgs = callArgs.concat(args);
919 }else if (Ext.isNumber(appendArgs)){
920 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
921 var applyArgs = [appendArgs, 0].concat(args); // create method call params
922 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
924 return method.apply(obj || window, callArgs);
929 * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
931 var sayHi = function(name){
932 alert('Hi, ' + name);
935 // executes immediately:
938 // executes after 2 seconds:
939 sayHi.defer(2000, this, ['Fred']);
941 // this syntax is sometimes useful for deferring
942 // execution of an anonymous function:
947 * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
948 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
949 * <b>If omitted, defaults to the browser window.</b>
950 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
951 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
952 * if a number the args are inserted at the specified position
953 * @return {Number} The timeout id that can be used with clearTimeout
955 defer : function(millis, obj, args, appendArgs){
956 var fn = this.createDelegate(obj, args, appendArgs);
958 return setTimeout(fn, millis);
967 * These functions are available on every String object.
969 Ext.applyIf(String, {
971 * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
972 * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
974 var cls = 'my-class', text = 'Some text';
975 var s = String.format('<div class="{0}">{1}</div>', cls, text);
976 // s now contains the string: '<div class="my-class">Some text</div>'
978 * @param {String} string The tokenized string to be formatted
979 * @param {String} value1 The value to replace token {0}
980 * @param {String} value2 Etc...
981 * @return {String} The formatted string
984 format : function(format){
985 var args = Ext.toArray(arguments, 1);
986 return format.replace(/\{(\d+)\}/g, function(m, i){
995 Ext.applyIf(Array.prototype, {
997 * Checks whether or not the specified object exists in the array.
998 * @param {Object} o The object to check for
999 * @param {Number} from (Optional) The index at which to begin the search
1000 * @return {Number} The index of o in the array (or -1 if it is not found)
1002 indexOf : function(o, from){
1003 var len = this.length;
1005 from += (from < 0) ? len : 0;
1006 for (; from < len; ++from){
1007 if(this[from] === o){
1015 * Removes the specified object from the array. If the object is not found nothing happens.
1016 * @param {Object} o The object to remove
1017 * @return {Array} this array
1019 remove : function(o){
1020 var index = this.indexOf(o);
1022 this.splice(index, 1);
1031 Ext.ns("Ext.grid", "Ext.list", "Ext.dd", "Ext.tree", "Ext.form", "Ext.menu",
1032 "Ext.state", "Ext.layout", "Ext.app", "Ext.ux", "Ext.chart", "Ext.direct");
1034 * Namespace alloted for extensions to the framework.
1039 Ext.apply(Ext, function(){
1046 * A reusable empty function
1050 emptyFn : function(){},
1053 * URL to a 1x1 transparent gif image used by Ext to create inline icons with CSS background images.
1054 * In older versions of IE, this defaults to "http://extjs.com/s.gif" and you should change this to a URL on your server.
1055 * For other browsers it uses an inline data URL.
1058 BLANK_IMAGE_URL : Ext.isIE6 || Ext.isIE7 || Ext.isAir ?
1059 'http:/' + '/www.extjs.com/s.gif' :
1060 'data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==',
1062 extendX : function(supr, fn){
1063 return Ext.extend(supr, fn(supr.prototype));
1067 * Returns the current HTML document object as an {@link Ext.Element}.
1068 * @return Ext.Element The document
1070 getDoc : function(){
1071 return Ext.get(document);
1075 * Utility method for validating that a value is numeric, returning the specified default value if it is not.
1076 * @param {Mixed} value Should be a number, but any type will be handled appropriately
1077 * @param {Number} defaultValue The value to return if the original value is non-numeric
1078 * @return {Number} Value, if numeric, else defaultValue
1080 num : function(v, defaultValue){
1081 v = Number(Ext.isEmpty(v) || Ext.isArray(v) || typeof v == 'boolean' || (typeof v == 'string' && v.trim().length == 0) ? NaN : v);
1082 return isNaN(v) ? defaultValue : v;
1086 * <p>Utility method for returning a default value if the passed value is empty.</p>
1087 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
1089 * <li>undefined</li>
1090 * <li>an empty array</li>
1091 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
1093 * @param {Mixed} value The value to test
1094 * @param {Mixed} defaultValue The value to return if the original value is empty
1095 * @param {Boolean} allowBlank (optional) true to allow zero length strings to qualify as non-empty (defaults to false)
1096 * @return {Mixed} value, if non-empty, else defaultValue
1098 value : function(v, defaultValue, allowBlank){
1099 return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
1103 * Escapes the passed string for use in a regular expression
1104 * @param {String} str
1107 escapeRe : function(s) {
1108 return s.replace(/([-.*+?^${}()|[\]\/\\])/g, "\\$1");
1111 sequence : function(o, name, fn, scope){
1112 o[name] = o[name].createSequence(fn, scope);
1116 * Applies event listeners to elements by selectors when the document is ready.
1117 * The event name is specified with an <tt>@</tt> suffix.
1120 // add a listener for click on all anchors in element with id foo
1121 '#foo a@click' : function(e, t){
1125 // add the same listener to multiple selectors (separated by comma BEFORE the @)
1126 '#foo a, #bar span.some-class@mouseover' : function(){
1131 * @param {Object} obj The list of behaviors to apply
1133 addBehaviors : function(o){
1135 Ext.onReady(function(){
1136 Ext.addBehaviors(o);
1139 var cache = {}, // simple cache for applying multiple behaviors to same selector does query multiple times
1144 if ((parts = b.split('@'))[1]) { // for Object prototype breakers
1147 cache[s] = Ext.select(s);
1149 cache[s].on(parts[1], o[b]);
1157 * Utility method for getting the width of the browser scrollbar. This can differ depending on
1158 * operating system settings, such as the theme or font size.
1159 * @param {Boolean} force (optional) true to force a recalculation of the value.
1160 * @return {Number} The width of the scrollbar.
1162 getScrollBarWidth: function(force){
1167 if(force === true || scrollWidth === null){
1168 // Append our div, do our calculation and then remove it
1169 var div = Ext.getBody().createChild('<div class="x-hide-offsets" style="width:100px;height:50px;overflow:hidden;"><div style="height:200px;"></div></div>'),
1170 child = div.child('div', true);
1171 var w1 = child.offsetWidth;
1172 div.setStyle('overflow', (Ext.isWebKit || Ext.isGecko) ? 'auto' : 'scroll');
1173 var w2 = child.offsetWidth;
1175 // Need to add 2 to ensure we leave enough space
1176 scrollWidth = w1 - w2 + 2;
1183 combine : function(){
1184 var as = arguments, l = as.length, r = [];
1185 for(var i = 0; i < l; i++){
1189 }else if(a.length !== undefined && !a.substr){
1190 r = r.concat(Array.prototype.slice.call(a, 0));
1199 * Copies a set of named properties fom the source object to the destination object.
1200 * <p>example:<pre><code>
1201 ImageComponent = Ext.extend(Ext.BoxComponent, {
1202 initComponent: function() {
1203 this.autoEl = { tag: 'img' };
1204 MyComponent.superclass.initComponent.apply(this, arguments);
1205 this.initialBox = Ext.copyTo({}, this.initialConfig, 'x,y,width,height');
1209 * @param {Object} dest The destination object.
1210 * @param {Object} source The source object.
1211 * @param {Array/String} names Either an Array of property names, or a comma-delimited list
1212 * of property names to copy.
1213 * @return {Object} The modified object.
1215 copyTo : function(dest, source, names){
1216 if(typeof names == 'string'){
1217 names = names.split(/[,;\s]/);
1219 Ext.each(names, function(name){
1220 if(source.hasOwnProperty(name)){
1221 dest[name] = source[name];
1228 * Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
1229 * DOM (if applicable) and calling their destroy functions (if available). This method is primarily
1230 * intended for arguments of type {@link Ext.Element} and {@link Ext.Component}, but any subclass of
1231 * {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
1232 * passed into this function in a single call as separate arguments.
1233 * @param {Mixed} arg1 An {@link Ext.Element}, {@link Ext.Component}, or an Array of either of these to destroy
1234 * @param {Mixed} arg2 (optional)
1235 * @param {Mixed} etc... (optional)
1237 destroy : function(){
1238 Ext.each(arguments, function(arg){
1240 if(Ext.isArray(arg)){
1241 this.destroy.apply(this, arg);
1242 }else if(typeof arg.destroy == 'function'){
1252 * Attempts to destroy and then remove a set of named properties of the passed object.
1253 * @param {Object} o The object (most likely a Component) who's properties you wish to destroy.
1254 * @param {Mixed} arg1 The name of the property to destroy and remove from the object.
1255 * @param {Mixed} etc... More property names to destroy and remove.
1257 destroyMembers : function(o, arg1, arg2, etc){
1258 for(var i = 1, a = arguments, len = a.length; i < len; i++) {
1259 Ext.destroy(o[a[i]]);
1265 * Creates a copy of the passed Array with falsy values removed.
1266 * @param {Array/NodeList} arr The Array from which to remove falsy values.
1267 * @return {Array} The new, compressed Array.
1269 clean : function(arr){
1271 Ext.each(arr, function(v){
1280 * Creates a copy of the passed Array, filtered to contain only unique values.
1281 * @param {Array} arr The Array to filter
1282 * @return {Array} The new Array containing unique values.
1284 unique : function(arr){
1288 Ext.each(arr, function(v) {
1298 * Recursively flattens into 1-d Array. Injects Arrays inline.
1299 * @param {Array} arr The array to flatten
1300 * @return {Array} The new, flattened array.
1302 flatten : function(arr){
1304 function rFlatten(a) {
1305 Ext.each(a, function(v) {
1314 return rFlatten(arr);
1318 * Returns the minimum value in the Array.
1319 * @param {Array|NodeList} arr The Array from which to select the minimum value.
1320 * @param {Function} comp (optional) a function to perform the comparision which determines minimization.
1321 * If omitted the "<" operator will be used. Note: gt = 1; eq = 0; lt = -1
1322 * @return {Object} The minimum value in the Array.
1324 min : function(arr, comp){
1326 comp = comp || function(a,b){ return a < b ? -1 : 1; };
1327 Ext.each(arr, function(v) {
1328 ret = comp(ret, v) == -1 ? ret : v;
1334 * Returns the maximum value in the Array
1335 * @param {Array|NodeList} arr The Array from which to select the maximum value.
1336 * @param {Function} comp (optional) a function to perform the comparision which determines maximization.
1337 * If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1
1338 * @return {Object} The maximum value in the Array.
1340 max : function(arr, comp){
1342 comp = comp || function(a,b){ return a > b ? 1 : -1; };
1343 Ext.each(arr, function(v) {
1344 ret = comp(ret, v) == 1 ? ret : v;
1350 * Calculates the mean of the Array
1351 * @param {Array} arr The Array to calculate the mean value of.
1352 * @return {Number} The mean.
1354 mean : function(arr){
1355 return arr.length > 0 ? Ext.sum(arr) / arr.length : undefined;
1359 * Calculates the sum of the Array
1360 * @param {Array} arr The Array to calculate the sum value of.
1361 * @return {Number} The sum.
1363 sum : function(arr){
1365 Ext.each(arr, function(v) {
1372 * Partitions the set into two sets: a true set and a false set.
1377 Ext.partition([true, false, true, true, false]); // [[true, true, true], [false, false]]
1383 return val.className == "class1"
1386 // true are those paragraph elements with a className of "class1",
1387 // false set are those that do not have that className.
1389 * @param {Array|NodeList} arr The array to partition
1390 * @param {Function} truth (optional) a function to determine truth. If this is omitted the element
1391 * itself must be able to be evaluated for its truthfulness.
1392 * @return {Array} [true<Array>,false<Array>]
1394 partition : function(arr, truth){
1396 Ext.each(arr, function(v, i, a) {
1397 ret[ (truth && truth(v, i, a)) || (!truth && v) ? 0 : 1].push(v);
1403 * Invokes a method on each item in an Array.
1406 Ext.invoke(Ext.query("p"), "getAttribute", "id");
1407 // [el1.getAttribute("id"), el2.getAttribute("id"), ..., elN.getAttribute("id")]
1409 * @param {Array|NodeList} arr The Array of items to invoke the method on.
1410 * @param {String} methodName The method name to invoke.
1411 * @param {...*} args Arguments to send into the method invocation.
1412 * @return {Array} The results of invoking the method on each item in the array.
1414 invoke : function(arr, methodName){
1416 args = Array.prototype.slice.call(arguments, 2);
1417 Ext.each(arr, function(v,i) {
1418 if (v && typeof v[methodName] == 'function') {
1419 ret.push(v[methodName].apply(v, args));
1421 ret.push(undefined);
1428 * Plucks the value of a property from each item in the Array
1431 Ext.pluck(Ext.query("p"), "className"); // [el1.className, el2.className, ..., elN.className]
1433 * @param {Array|NodeList} arr The Array of items to pluck the value from.
1434 * @param {String} prop The property name to pluck from each element.
1435 * @return {Array} The value from each item in the Array.
1437 pluck : function(arr, prop){
1439 Ext.each(arr, function(v) {
1440 ret.push( v[prop] );
1446 * <p>Zips N sets together.</p>
1449 Ext.zip([1,2,3],[4,5,6]); // [[1,4],[2,5],[3,6]]
1456 return "$" + a + "" + b + "." + c
1458 ); // ["$+12.43", "$-10.15", "$+22.96"]
1460 * @param {Arrays|NodeLists} arr This argument may be repeated. Array(s) to contribute values.
1461 * @param {Function} zipper (optional) The last item in the argument list. This will drive how the items are zipped together.
1462 * @return {Array} The zipped set.
1465 var parts = Ext.partition(arguments, function( val ){ return typeof val != 'function'; }),
1468 len = Ext.max(Ext.pluck(arrs, "length")),
1471 for (var i = 0; i < len; i++) {
1474 ret[i] = fn.apply(fn, Ext.pluck(arrs, i));
1476 for (var j = 0, aLen = arrs.length; j < aLen; j++){
1477 ret[i].push( arrs[j][i] );
1485 * This is shorthand reference to {@link Ext.ComponentMgr#get}.
1486 * Looks up an existing {@link Ext.Component Component} by {@link Ext.Component#id id}
1487 * @param {String} id The component {@link Ext.Component#id id}
1488 * @return Ext.Component The Component, <tt>undefined</tt> if not found, or <tt>null</tt> if a
1491 getCmp : function(id){
1492 return Ext.ComponentMgr.get(id);
1496 * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
1497 * you may want to set this to true.
1500 useShims: E.isIE6 || (E.isMac && E.isGecko2),
1502 // inpired by a similar function in mootools library
1504 * Returns the type of object that is passed in. If the object passed in is null or undefined it
1505 * return false otherwise it returns one of the following values:<div class="mdetail-params"><ul>
1506 * <li><b>string</b>: If the object passed is a string</li>
1507 * <li><b>number</b>: If the object passed is a number</li>
1508 * <li><b>boolean</b>: If the object passed is a boolean value</li>
1509 * <li><b>date</b>: If the object passed is a Date object</li>
1510 * <li><b>function</b>: If the object passed is a function reference</li>
1511 * <li><b>object</b>: If the object passed is an object</li>
1512 * <li><b>array</b>: If the object passed is an array</li>
1513 * <li><b>regexp</b>: If the object passed is a regular expression</li>
1514 * <li><b>element</b>: If the object passed is a DOM Element</li>
1515 * <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
1516 * <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
1517 * <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
1519 * @param {Mixed} object
1523 if(o === undefined || o === null){
1530 if(t == 'object' && o.nodeName) {
1531 switch(o.nodeType) {
1532 case 1: return 'element';
1533 case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
1536 if(t == 'object' || t == 'function') {
1537 switch(o.constructor) {
1538 case Array: return 'array';
1539 case RegExp: return 'regexp';
1540 case Date: return 'date';
1542 if(typeof o.length == 'number' && typeof o.item == 'function') {
1549 intercept : function(o, name, fn, scope){
1550 o[name] = o[name].createInterceptor(fn, scope);
1554 callback : function(cb, scope, args, delay){
1555 if(typeof cb == 'function'){
1557 cb.defer(delay, scope, args || []);
1559 cb.apply(scope, args || []);
1568 * These functions are available on every Function object (any JavaScript function).
1570 Ext.apply(Function.prototype, {
1572 * Create a combined function call sequence of the original function + the passed function.
1573 * The resulting function returns the results of the original function.
1574 * The passed fcn is called with the parameters of the original function. Example usage:
1576 var sayHi = function(name){
1577 alert('Hi, ' + name);
1580 sayHi('Fred'); // alerts "Hi, Fred"
1582 var sayGoodbye = sayHi.createSequence(function(name){
1583 alert('Bye, ' + name);
1586 sayGoodbye('Fred'); // both alerts show
1588 * @param {Function} fcn The function to sequence
1589 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
1590 * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
1591 * @return {Function} The new function
1593 createSequence : function(fcn, scope){
1595 return (typeof fcn != 'function') ?
1598 var retval = method.apply(this || window, arguments);
1599 fcn.apply(scope || this || window, arguments);
1608 * These functions are available as static methods on the JavaScript String object.
1610 Ext.applyIf(String, {
1613 * Escapes the passed string for ' and \
1614 * @param {String} string The string to escape
1615 * @return {String} The escaped string
1618 escape : function(string) {
1619 return string.replace(/('|\\)/g, "\\$1");
1623 * Pads the left side of a string with a specified character. This is especially useful
1624 * for normalizing number and date strings. Example usage:
1626 var s = String.leftPad('123', 5, '0');
1627 // s now contains the string: '00123'
1629 * @param {String} string The original string
1630 * @param {Number} size The total length of the output string
1631 * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
1632 * @return {String} The padded string
1635 leftPad : function (val, size, ch) {
1636 var result = String(val);
1640 while (result.length < size) {
1641 result = ch + result;
1648 * Utility function that allows you to easily switch a string between two alternating values. The passed value
1649 * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
1650 * they are already different, the first value passed in is returned. Note that this method returns the new value
1651 * but does not change the current string.
1653 // alternate sort directions
1654 sort = sort.toggle('ASC', 'DESC');
1656 // instead of conditional logic:
1657 sort = (sort == 'ASC' ? 'DESC' : 'ASC');
1659 * @param {String} value The value to compare to the current string
1660 * @param {String} other The new value to use if the string already equals the first value passed in
1661 * @return {String} The new value
1663 String.prototype.toggle = function(value, other){
1664 return this == value ? other : value;
1668 * Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
1670 var s = ' foo bar ';
1671 alert('-' + s + '-'); //alerts "- foo bar -"
1672 alert('-' + s.trim() + '-'); //alerts "-foo bar-"
1674 * @return {String} The trimmed string
1676 String.prototype.trim = function(){
1677 var re = /^\s+|\s+$/g;
1678 return function(){ return this.replace(re, ""); };
1681 // here to prevent dependency on Date.js
1683 Returns the number of milliseconds between this date and date
1684 @param {Date} date (optional) Defaults to now
1685 @return {Number} The diff in milliseconds
1686 @member Date getElapsed
1688 Date.prototype.getElapsed = function(date) {
1689 return Math.abs((date || new Date()).getTime()-this.getTime());
1696 Ext.applyIf(Number.prototype, {
1698 * Checks whether or not the current number is within a desired range. If the number is already within the
1699 * range it is returned, otherwise the min or max value is returned depending on which side of the range is
1700 * exceeded. Note that this method returns the constrained value but does not change the current number.
1701 * @param {Number} min The minimum number in the range
1702 * @param {Number} max The maximum number in the range
1703 * @return {Number} The constrained value if outside the range, otherwise the current value
1705 constrain : function(min, max){
1706 return Math.min(Math.max(this, min), max);
1710 * @class Ext.util.TaskRunner
1711 * Provides the ability to execute one or more arbitrary tasks in a multithreaded
1712 * manner. Generally, you can use the singleton {@link Ext.TaskMgr} instead, but
1713 * if needed, you can create separate instances of TaskRunner. Any number of
1714 * separate tasks can be started at any time and will run independently of each
1715 * other. Example usage:
1717 // Start a simple clock task that updates a div once per second
1718 var updateClock = function(){
1719 Ext.fly('clock').update(new Date().format('g:i:s A'));
1723 interval: 1000 //1 second
1725 var runner = new Ext.util.TaskRunner();
1728 // equivalent using TaskMgr
1735 * <p>See the {@link #start} method for details about how to configure a task object.</p>
1736 * Also see {@link Ext.util.DelayedTask}.
1739 * @param {Number} interval (optional) The minimum precision in milliseconds supported by this TaskRunner instance
1742 Ext.util.TaskRunner = function(interval){
1743 interval = interval || 10;
1750 stopThread = function(){
1757 startThread = function(){
1760 id = setInterval(runTasks, interval);
1765 removeTask = function(t){
1766 removeQueue.push(t);
1768 t.onStop.apply(t.scope || t);
1773 runTasks = function(){
1774 var rqLen = removeQueue.length,
1775 now = new Date().getTime();
1778 for(var i = 0; i < rqLen; i++){
1779 tasks.remove(removeQueue[i]);
1782 if(tasks.length < 1){
1787 for(var i = 0, t, itime, rt, len = tasks.length; i < len; ++i){
1789 itime = now - t.taskRunTime;
1790 if(t.interval <= itime){
1791 rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
1792 t.taskRunTime = now;
1793 if(rt === false || t.taskRunCount === t.repeat){
1798 if(t.duration && t.duration <= (now - t.taskStartTime)){
1805 * Starts a new task.
1807 * @param {Object} task <p>A config object that supports the following properties:<ul>
1808 * <li><code>run</code> : Function<div class="sub-desc"><p>The function to execute each time the task is invoked. The
1809 * function will be called at each interval and passed the <code>args</code> argument if specified, and the
1810 * current invocation count if not.</p>
1811 * <p>If a particular scope (<code>this</code> reference) is required, be sure to specify it using the <code>scope</code> argument.</p>
1812 * <p>Return <code>false</code> from this function to terminate the task.</p></div></li>
1813 * <li><code>interval</code> : Number<div class="sub-desc">The frequency in milliseconds with which the task
1814 * should be invoked.</div></li>
1815 * <li><code>args</code> : Array<div class="sub-desc">(optional) An array of arguments to be passed to the function
1816 * specified by <code>run</code>. If not specified, the current invocation count is passed.</div></li>
1817 * <li><code>scope</code> : Object<div class="sub-desc">(optional) The scope (<tt>this</tt> reference) in which to execute the
1818 * <code>run</code> function. Defaults to the task config object.</div></li>
1819 * <li><code>duration</code> : Number<div class="sub-desc">(optional) The length of time in milliseconds to invoke
1820 * the task before stopping automatically (defaults to indefinite).</div></li>
1821 * <li><code>repeat</code> : Number<div class="sub-desc">(optional) The number of times to invoke the task before
1822 * stopping automatically (defaults to indefinite).</div></li>
1824 * <p>Before each invocation, Ext injects the property <code>taskRunCount</code> into the task object so
1825 * that calculations based on the repeat count can be performed.</p>
1826 * @return {Object} The task
1828 this.start = function(task){
1830 task.taskStartTime = new Date().getTime();
1831 task.taskRunTime = 0;
1832 task.taskRunCount = 0;
1838 * Stops an existing running task.
1840 * @param {Object} task The task to stop
1841 * @return {Object} The task
1843 this.stop = function(task){
1849 * Stops all tasks that are currently running.
1852 this.stopAll = function(){
1854 for(var i = 0, len = tasks.length; i < len; i++){
1855 if(tasks[i].onStop){
1865 * @class Ext.TaskMgr
1866 * @extends Ext.util.TaskRunner
1867 * A static {@link Ext.util.TaskRunner} instance that can be used to start and stop arbitrary tasks. See
1868 * {@link Ext.util.TaskRunner} for supported methods and task config properties.
1870 // Start a simple clock task that updates a div once per second
1873 Ext.fly('clock').update(new Date().format('g:i:s A'));
1875 interval: 1000 //1 second
1877 Ext.TaskMgr.start(task);
1879 * <p>See the {@link #start} method for details about how to configure a task object.</p>
1882 Ext.TaskMgr = new Ext.util.TaskRunner();(function(){
1886 if (!libFlyweight) {
1887 libFlyweight = new Ext.Element.Flyweight();
1889 libFlyweight.dom = el;
1890 return libFlyweight;
1895 isCSS1 = doc.compatMode == "CSS1Compat",
1898 PARSEINT = parseInt;
1901 isAncestor : function(p, c) {
1908 return p.contains(c);
1909 } else if (p.compareDocumentPosition) {
1910 return !!(p.compareDocumentPosition(c) & 16);
1912 while (c = c.parentNode) {
1913 ret = c == p || ret;
1920 getViewWidth : function(full) {
1921 return full ? this.getDocumentWidth() : this.getViewportWidth();
1924 getViewHeight : function(full) {
1925 return full ? this.getDocumentHeight() : this.getViewportHeight();
1928 getDocumentHeight: function() {
1929 return MAX(!isCSS1 ? doc.body.scrollHeight : doc.documentElement.scrollHeight, this.getViewportHeight());
1932 getDocumentWidth: function() {
1933 return MAX(!isCSS1 ? doc.body.scrollWidth : doc.documentElement.scrollWidth, this.getViewportWidth());
1936 getViewportHeight: function(){
1938 (Ext.isStrict ? doc.documentElement.clientHeight : doc.body.clientHeight) :
1942 getViewportWidth : function() {
1943 return !Ext.isStrict && !Ext.isOpera ? doc.body.clientWidth :
1944 Ext.isIE ? doc.documentElement.clientWidth : self.innerWidth;
1947 getY : function(el) {
1948 return this.getXY(el)[1];
1951 getX : function(el) {
1952 return this.getXY(el)[0];
1955 getXY : function(el) {
1966 bd = (doc.body || doc.documentElement),
1969 el = Ext.getDom(el);
1972 if (el.getBoundingClientRect) {
1973 b = el.getBoundingClientRect();
1974 scroll = fly(document).getScroll();
1975 ret = [ROUND(b.left + scroll.left), ROUND(b.top + scroll.top)];
1978 hasAbsolute = fly(el).isStyle("position", "absolute");
1985 hasAbsolute = hasAbsolute || pe.isStyle("position", "absolute");
1988 y += bt = PARSEINT(pe.getStyle("borderTopWidth"), 10) || 0;
1989 x += bl = PARSEINT(pe.getStyle("borderLeftWidth"), 10) || 0;
1991 if (p != el && !pe.isStyle('overflow','visible')) {
1999 if (Ext.isSafari && hasAbsolute) {
2004 if (Ext.isGecko && !hasAbsolute) {
2006 x += PARSEINT(dbd.getStyle("borderLeftWidth"), 10) || 0;
2007 y += PARSEINT(dbd.getStyle("borderTopWidth"), 10) || 0;
2011 while (p && p != bd) {
2012 if (!Ext.isOpera || (p.tagName != 'TR' && !fly(p).isStyle("display", "inline"))) {
2024 setXY : function(el, xy) {
2025 (el = Ext.fly(el, '_setXY')).position();
2027 var pts = el.translatePoints(xy),
2028 style = el.dom.style,
2032 if(!isNaN(pts[pos])) style[pos] = pts[pos] + "px"
2036 setX : function(el, x) {
2037 this.setXY(el, [x, false]);
2040 setY : function(el, y) {
2041 this.setXY(el, [false, y]);
2044 })();Ext.lib.Dom.getRegion = function(el) {
2045 return Ext.lib.Region.getRegion(el);
2046 };Ext.lib.Event = function() {
2047 var loadComplete = false,
2048 unloadListeners = {},
2065 SCROLLLEFT = 'scrollLeft',
2066 SCROLLTOP = 'scrollTop',
2068 MOUSEOVER = 'mouseover',
2069 MOUSEOUT = 'mouseout',
2071 doAdd = function() {
2073 if (win.addEventListener) {
2074 ret = function(el, eventName, fn, capture) {
2075 if (eventName == 'mouseenter') {
2076 fn = fn.createInterceptor(checkRelatedTarget);
2077 el.addEventListener(MOUSEOVER, fn, (capture));
2078 } else if (eventName == 'mouseleave') {
2079 fn = fn.createInterceptor(checkRelatedTarget);
2080 el.addEventListener(MOUSEOUT, fn, (capture));
2082 el.addEventListener(eventName, fn, (capture));
2086 } else if (win.attachEvent) {
2087 ret = function(el, eventName, fn, capture) {
2088 el.attachEvent("on" + eventName, fn);
2097 doRemove = function(){
2099 if (win.removeEventListener) {
2100 ret = function (el, eventName, fn, capture) {
2101 if (eventName == 'mouseenter') {
2102 eventName = MOUSEOVER;
2103 } else if (eventName == 'mouseleave') {
2104 eventName = MOUSEOUT;
2106 el.removeEventListener(eventName, fn, (capture));
2108 } else if (win.detachEvent) {
2109 ret = function (el, eventName, fn) {
2110 el.detachEvent("on" + eventName, fn);
2118 function checkRelatedTarget(e) {
2119 return !elContains(e.currentTarget, pub.getRelatedTarget(e));
2122 function elContains(parent, child) {
2123 if(parent && parent.firstChild){
2125 if(child === parent) {
2128 child = child.parentNode;
2129 if(child && (child.nodeType != 1)) {
2138 function _tryPreloadAttach() {
2141 element, i, v, override,
2142 tryAgain = !loadComplete || (retryCount > 0);
2147 for(i = 0; i < onAvailStack.length; ++i){
2148 v = onAvailStack[i];
2149 if(v && (element = doc.getElementById(v.id))){
2150 if(!v.checkReady || loadComplete || element.nextSibling || (doc && doc.body)) {
2151 override = v.override;
2152 element = override ? (override === true ? v.obj : override) : element;
2153 v.fn.call(element, v.obj);
2154 onAvailStack.remove(v);
2162 retryCount = (notAvail.length === 0) ? 0 : retryCount - 1;
2167 clearInterval(_interval);
2170 ret = !(locked = false);
2176 function startInterval() {
2178 var callback = function() {
2179 _tryPreloadAttach();
2181 _interval = setInterval(callback, POLL_INTERVAL);
2186 function getScroll() {
2187 var dd = doc.documentElement,
2189 if(dd && (dd[SCROLLTOP] || dd[SCROLLLEFT])){
2190 return [dd[SCROLLLEFT], dd[SCROLLTOP]];
2192 return [db[SCROLLLEFT], db[SCROLLTOP]];
2199 function getPageCoord (ev, xy) {
2200 ev = ev.browserEvent || ev;
2201 var coord = ev['page' + xy];
2202 if (!coord && coord !== 0) {
2203 coord = ev['client' + xy] || 0;
2206 coord += getScroll()[xy == "X" ? 0 : 1];
2215 onAvailable : function(p_id, p_fn, p_obj, p_override) {
2220 override: p_override,
2221 checkReady: false });
2223 retryCount = POLL_RETRYS;
2227 // This function should ALWAYS be called from Ext.EventManager
2228 addListener: function(el, eventName, fn) {
2229 el = Ext.getDom(el);
2231 if (eventName == UNLOAD) {
2232 if (unloadListeners[el.id] === undefined) {
2233 unloadListeners[el.id] = [];
2235 unloadListeners[el.id].push([eventName, fn]);
2238 return doAdd(el, eventName, fn, false);
2243 // This function should ALWAYS be called from Ext.EventManager
2244 removeListener: function(el, eventName, fn) {
2245 el = Ext.getDom(el);
2246 var i, len, li, lis;
2248 if(eventName == UNLOAD){
2249 if((lis = unloadListeners[el.id]) !== undefined){
2250 for(i = 0, len = lis.length; i < len; i++){
2251 if((li = lis[i]) && li[TYPE] == eventName && li[FN] == fn){
2252 unloadListeners[el.id].splice(i, 1);
2258 doRemove(el, eventName, fn, false);
2262 getTarget : function(ev) {
2263 ev = ev.browserEvent || ev;
2264 return this.resolveTextNode(ev.target || ev.srcElement);
2267 resolveTextNode : Ext.isGecko ? function(node){
2271 // work around firefox bug, https://bugzilla.mozilla.org/show_bug.cgi?id=101197
2272 var s = HTMLElement.prototype.toString.call(node);
2273 if(s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]'){
2276 return node.nodeType == 3 ? node.parentNode : node;
2278 return node && node.nodeType == 3 ? node.parentNode : node;
2281 getRelatedTarget : function(ev) {
2282 ev = ev.browserEvent || ev;
2283 return this.resolveTextNode(ev.relatedTarget ||
2284 (ev.type == MOUSEOUT ? ev.toElement :
2285 ev.type == MOUSEOVER ? ev.fromElement : null));
2288 getPageX : function(ev) {
2289 return getPageCoord(ev, "X");
2292 getPageY : function(ev) {
2293 return getPageCoord(ev, "Y");
2297 getXY : function(ev) {
2298 return [this.getPageX(ev), this.getPageY(ev)];
2301 stopEvent : function(ev) {
2302 this.stopPropagation(ev);
2303 this.preventDefault(ev);
2306 stopPropagation : function(ev) {
2307 ev = ev.browserEvent || ev;
2308 if (ev.stopPropagation) {
2309 ev.stopPropagation();
2311 ev.cancelBubble = true;
2315 preventDefault : function(ev) {
2316 ev = ev.browserEvent || ev;
2317 if (ev.preventDefault) {
2318 ev.preventDefault();
2320 ev.returnValue = false;
2324 getEvent : function(e) {
2327 var c = this.getEvent.caller;
2330 if (e && Event == e.constructor) {
2339 getCharCode : function(ev) {
2340 ev = ev.browserEvent || ev;
2341 return ev.charCode || ev.keyCode || 0;
2344 //clearCache: function() {},
2345 // deprecated, call from EventManager
2346 getListeners : function(el, eventName) {
2347 Ext.EventManager.getListeners(el, eventName);
2350 // deprecated, call from EventManager
2351 purgeElement : function(el, recurse, eventName) {
2352 Ext.EventManager.purgeElement(el, recurse, eventName);
2355 _load : function(e) {
2356 loadComplete = true;
2357 var EU = Ext.lib.Event;
2358 if (Ext.isIE && e !== true) {
2359 // IE8 complains that _load is null or not an object
2360 // so lets remove self via arguments.callee
2361 doRemove(win, "load", arguments.callee);
2365 _unload : function(e) {
2366 var EU = Ext.lib.Event,
2367 i, j, l, v, ul, id, len, index, scope;
2370 for (id in unloadListeners) {
2371 ul = unloadListeners[id];
2372 for (i = 0, len = ul.length; i < len; i++) {
2376 scope = v[ADJ_SCOPE] ? (v[ADJ_SCOPE] === true ? v[OBJ] : v[ADJ_SCOPE]) : win;
2377 v[FN].call(scope, EU.getEvent(e), v[OBJ]);
2383 Ext.EventManager._unload();
2385 doRemove(win, UNLOAD, EU._unload);
2389 // Initialize stuff.
2390 pub.on = pub.addListener;
2391 pub.un = pub.removeListener;
2392 if (doc && doc.body) {
2395 doAdd(win, "load", pub._load);
2397 doAdd(win, UNLOAD, pub._unload);
2398 _tryPreloadAttach();
2403 * Portions of this file are based on pieces of Yahoo User Interface Library
2404 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
2405 * YUI licensed under the BSD License:
2406 * http://developer.yahoo.net/yui/license.txt
2408 Ext.lib.Ajax = function() {
2409 var activeX = ['MSXML2.XMLHTTP.3.0',
2411 'Microsoft.XMLHTTP'],
2412 CONTENTTYPE = 'Content-Type';
2415 function setHeader(o) {
2419 function setTheHeaders(conn, headers){
2420 for (prop in headers) {
2421 if (headers.hasOwnProperty(prop)) {
2422 conn.setRequestHeader(prop, headers[prop]);
2427 if (pub.defaultHeaders) {
2428 setTheHeaders(conn, pub.defaultHeaders);
2432 setTheHeaders(conn, pub.headers);
2438 function createExceptionObject(tId, callbackArg, isAbort, isTimeout) {
2441 status : isAbort ? -1 : 0,
2442 statusText : isAbort ? 'transaction aborted' : 'communication failure',
2444 isTimeout: isTimeout,
2445 argument : callbackArg
2450 function initHeader(label, value) {
2451 (pub.headers = pub.headers || {})[label] = value;
2455 function createResponseObject(o, callbackArg) {
2461 // see: https://prototype.lighthouseapp.com/projects/8886/tickets/129-ie-mangles-http-response-status-code-204-to-1223
2462 isBrokenStatus = conn.status == 1223;
2465 headerStr = o.conn.getAllResponseHeaders();
2466 Ext.each(headerStr.replace(/\r\n/g, '\n').split('\n'), function(v){
2469 s = v.substr(0, t).toLowerCase();
2470 if(v.charAt(t + 1) == ' '){
2473 headerObj[s] = v.substr(t + 1);
2480 // Normalize the status and statusText when IE returns 1223, see the above link.
2481 status : isBrokenStatus ? 204 : conn.status,
2482 statusText : isBrokenStatus ? 'No Content' : conn.statusText,
2483 getResponseHeader : function(header){return headerObj[header.toLowerCase()];},
2484 getAllResponseHeaders : function(){return headerStr},
2485 responseText : conn.responseText,
2486 responseXML : conn.responseXML,
2487 argument : callbackArg
2492 function releaseObject(o) {
2494 pub.conn[o.tId] = null;
2501 function handleTransactionResponse(o, callback, isAbort, isTimeout) {
2507 var httpStatus, responseObject;
2510 if (o.conn.status !== undefined && o.conn.status != 0) {
2511 httpStatus = o.conn.status;
2521 if ((httpStatus >= 200 && httpStatus < 300) || (Ext.isIE && httpStatus == 1223)) {
2522 responseObject = createResponseObject(o, callback.argument);
2523 if (callback.success) {
2524 if (!callback.scope) {
2525 callback.success(responseObject);
2528 callback.success.apply(callback.scope, [responseObject]);
2533 switch (httpStatus) {
2540 responseObject = createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false), isTimeout);
2541 if (callback.failure) {
2542 if (!callback.scope) {
2543 callback.failure(responseObject);
2546 callback.failure.apply(callback.scope, [responseObject]);
2551 responseObject = createResponseObject(o, callback.argument);
2552 if (callback.failure) {
2553 if (!callback.scope) {
2554 callback.failure(responseObject);
2557 callback.failure.apply(callback.scope, [responseObject]);
2564 responseObject = null;
2568 function handleReadyState(o, callback){
2569 callback = callback || {};
2573 cbTimeout = callback.timeout || null;
2576 pub.conn[tId] = conn;
2577 pub.timeout[tId] = setTimeout(function() {
2578 pub.abort(o, callback, true);
2582 poll[tId] = setInterval(
2584 if (conn && conn.readyState == 4) {
2585 clearInterval(poll[tId]);
2589 clearTimeout(pub.timeout[tId]);
2590 pub.timeout[tId] = null;
2593 handleTransactionResponse(o, callback);
2600 function asyncRequest(method, uri, callback, postData) {
2601 var o = getConnectionObject() || null;
2604 o.conn.open(method, uri, true);
2606 if (pub.useDefaultXhrHeader) {
2607 initHeader('X-Requested-With', pub.defaultXhrHeader);
2610 if(postData && pub.useDefaultHeader && (!pub.headers || !pub.headers[CONTENTTYPE])){
2611 initHeader(CONTENTTYPE, pub.defaultPostHeader);
2614 if (pub.defaultHeaders || pub.headers) {
2618 handleReadyState(o, callback);
2619 o.conn.send(postData || null);
2625 function getConnectionObject() {
2629 if (o = createXhrObject(pub.transactionId)) {
2630 pub.transactionId++;
2639 function createXhrObject(transactionId) {
2643 http = new XMLHttpRequest();
2645 for (var i = 0; i < activeX.length; ++i) {
2647 http = new ActiveXObject(activeX[i]);
2652 return {conn : http, tId : transactionId};
2657 request : function(method, uri, cb, data, options) {
2660 xmlData = options.xmlData,
2661 jsonData = options.jsonData,
2664 Ext.applyIf(me, options);
2666 if(xmlData || jsonData){
2668 if(!hs || !hs[CONTENTTYPE]){
2669 initHeader(CONTENTTYPE, xmlData ? 'text/xml' : 'application/json');
2671 data = xmlData || (!Ext.isPrimitive(jsonData) ? Ext.encode(jsonData) : jsonData);
2674 return asyncRequest(method || options.method || "POST", uri, cb, data);
2677 serializeForm : function(form) {
2678 var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements,
2680 encoder = encodeURIComponent,
2688 Ext.each(fElements, function(element) {
2689 name = element.name;
2690 type = element.type;
2692 if (!element.disabled && name){
2693 if(/select-(one|multiple)/i.test(type)) {
2694 Ext.each(element.options, function(opt) {
2696 data += String.format("{0}={1}&", encoder(name), encoder((opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttribute('value') !== null) ? opt.value : opt.text));
2699 } else if(!/file|undefined|reset|button/i.test(type)) {
2700 if(!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit)){
2702 data += encoder(name) + '=' + encoder(element.value) + '&';
2703 hasSubmit = /submit/i.test(type);
2708 return data.substr(0, data.length - 1);
2711 useDefaultHeader : true,
2712 defaultPostHeader : 'application/x-www-form-urlencoded; charset=UTF-8',
2713 useDefaultXhrHeader : true,
2714 defaultXhrHeader : 'XMLHttpRequest',
2721 // This is never called - Is it worth exposing this?
2722 // setProgId : function(id) {
2723 // activeX.unshift(id);
2726 // This is never called - Is it worth exposing this?
2727 // setDefaultPostHeader : function(b) {
2728 // this.useDefaultHeader = b;
2731 // This is never called - Is it worth exposing this?
2732 // setDefaultXhrHeader : function(b) {
2733 // this.useDefaultXhrHeader = b;
2736 // This is never called - Is it worth exposing this?
2737 // setPollingInterval : function(i) {
2738 // if (typeof i == 'number' && isFinite(i)) {
2739 // this.pollInterval = i;
2743 // This is never called - Is it worth exposing this?
2744 // resetDefaultHeaders : function() {
2745 // this.defaultHeaders = null;
2748 abort : function(o, callback, isTimeout) {
2753 if (me.isCallInProgress(o)) {
2755 clearInterval(me.poll[tId]);
2756 me.poll[tId] = null;
2757 clearTimeout(pub.timeout[tId]);
2758 me.timeout[tId] = null;
2760 handleTransactionResponse(o, callback, (isAbort = true), isTimeout);
2765 isCallInProgress : function(o) {
2766 // if there is a connection and readyState is not 0 or 4
2767 return o.conn && !{0:true,4:true}[o.conn.readyState];
2771 }(); Ext.lib.Region = function(t, r, b, l) {
2781 Ext.lib.Region.prototype = {
2782 contains : function(region) {
2784 return ( region.left >= me.left &&
2785 region.right <= me.right &&
2786 region.top >= me.top &&
2787 region.bottom <= me.bottom );
2791 getArea : function() {
2793 return ( (me.bottom - me.top) * (me.right - me.left) );
2796 intersect : function(region) {
2798 t = Math.max(me.top, region.top),
2799 r = Math.min(me.right, region.right),
2800 b = Math.min(me.bottom, region.bottom),
2801 l = Math.max(me.left, region.left);
2803 if (b >= t && r >= l) {
2804 return new Ext.lib.Region(t, r, b, l);
2808 union : function(region) {
2810 t = Math.min(me.top, region.top),
2811 r = Math.max(me.right, region.right),
2812 b = Math.max(me.bottom, region.bottom),
2813 l = Math.min(me.left, region.left);
2815 return new Ext.lib.Region(t, r, b, l);
2818 constrainTo : function(r) {
2820 me.top = me.top.constrain(r.top, r.bottom);
2821 me.bottom = me.bottom.constrain(r.top, r.bottom);
2822 me.left = me.left.constrain(r.left, r.right);
2823 me.right = me.right.constrain(r.left, r.right);
2827 adjust : function(t, l, b, r) {
2837 Ext.lib.Region.getRegion = function(el) {
2838 var p = Ext.lib.Dom.getXY(el),
2840 r = p[0] + el.offsetWidth,
2841 b = p[1] + el.offsetHeight,
2844 return new Ext.lib.Region(t, r, b, l);
2845 }; Ext.lib.Point = function(x, y) {
2846 if (Ext.isArray(x)) {
2851 me.x = me.right = me.left = me[0] = x;
2852 me.y = me.top = me.bottom = me[1] = y;
2855 Ext.lib.Point.prototype = new Ext.lib.Region();
2857 var EXTLIB = Ext.lib,
2858 noNegatives = /width|height|opacity|padding/i,
2859 offsetAttribute = /^((width|height)|(top|left))$/,
2860 defaultUnit = /width|height|top$|bottom$|left$|right$/i,
2861 offsetUnit = /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i,
2862 isset = function(v){
2863 return typeof v !== 'undefined';
2870 motion : function(el, args, duration, easing, cb, scope) {
2871 return this.run(el, args, duration, easing, cb, scope, Ext.lib.Motion);
2874 run : function(el, args, duration, easing, cb, scope, type) {
2875 type = type || Ext.lib.AnimBase;
2876 if (typeof easing == "string") {
2877 easing = Ext.lib.Easing[easing];
2879 var anim = new type(el, args, duration, easing);
2880 anim.animateX(function() {
2881 if(Ext.isFunction(cb)){
2889 EXTLIB.AnimBase = function(el, attributes, duration, method) {
2891 this.init(el, attributes, duration, method);
2895 EXTLIB.AnimBase.prototype = {
2896 doMethod: function(attr, start, end) {
2898 return me.method(me.curFrame, start, end - start, me.totalFrames);
2902 setAttr: function(attr, val, unit) {
2903 if (noNegatives.test(attr) && val < 0) {
2906 Ext.fly(this.el, '_anim').setStyle(attr, val + unit);
2910 getAttr: function(attr) {
2911 var el = Ext.fly(this.el),
2912 val = el.getStyle(attr),
2913 a = offsetAttribute.exec(attr) || [];
2915 if (val !== 'auto' && !offsetUnit.test(val)) {
2916 return parseFloat(val);
2919 return (!!(a[2]) || (el.getStyle('position') == 'absolute' && !!(a[3]))) ? el.dom['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)] : 0;
2923 getDefaultUnit: function(attr) {
2924 return defaultUnit.test(attr) ? 'px' : '';
2927 animateX : function(callback, scope) {
2930 me.onComplete.removeListener(f);
2931 if (Ext.isFunction(callback)) {
2932 callback.call(scope || me, me);
2935 me.onComplete.addListener(f, me);
2940 setRunAttr: function(attr) {
2942 a = this.attributes[attr],
2947 ra = (this.runAttrs[attr] = {}),
2950 if (!isset(to) && !isset(by)){
2954 var start = isset(from) ? from : me.getAttr(attr);
2957 }else if(isset(by)) {
2958 if (Ext.isArray(start)){
2960 for(var i=0,len=start.length; i<len; i++) {
2961 end[i] = start[i] + by[i];
2971 unit: isset(unit) ? unit : me.getDefaultUnit(attr)
2976 init: function(el, attributes, duration, method) {
2979 mgr = EXTLIB.AnimMgr;
2985 attributes: attributes || {},
2986 duration: duration || 1,
2987 method: method || EXTLIB.Easing.easeNone,
2990 totalFrames: mgr.fps,
2992 animate: function(){
3001 me.totalFrames = me.useSec ? Math.ceil(mgr.fps * d) : d;
3002 mgr.registerElement(me);
3005 stop: function(finish){
3009 me.curFrame = me.totalFrames;
3016 var onStart = function(){
3022 for(attr in this.attributes){
3023 this.setRunAttr(attr);
3026 me.isAnimated = true;
3027 me.startTime = now();
3032 var onTween = function(){
3036 duration: now() - me.startTime,
3037 curFrame: me.curFrame
3040 var ra = me.runAttrs;
3041 for (var attr in ra) {
3042 this.setAttr(attr, me.doMethod(attr, ra[attr].start, ra[attr].end), ra[attr].unit);
3048 var onComplete = function() {
3050 actual = (now() - me.startTime) / 1000,
3053 frames: actualFrames,
3054 fps: actualFrames / actual
3057 me.isAnimated = false;
3059 me.onComplete.fire(data);
3062 me.onStart = new Ext.util.Event(me);
3063 me.onTween = new Ext.util.Event(me);
3064 me.onComplete = new Ext.util.Event(me);
3065 (me._onStart = new Ext.util.Event(me)).addListener(onStart);
3066 (me._onTween = new Ext.util.Event(me)).addListener(onTween);
3067 (me._onComplete = new Ext.util.Event(me)).addListener(onComplete);
3072 Ext.lib.AnimMgr = new function() {
3082 registerElement: function(tween){
3085 tween._onStart.fire();
3089 unRegister: function(tween, index){
3090 tween._onComplete.fire();
3091 index = index || getIndex(tween);
3093 queue.splice(index, 1);
3096 if (--tweenCount <= 0) {
3102 if(thread === null){
3103 thread = setInterval(me.run, me.delay);
3107 stop: function(tween){
3109 clearInterval(thread);
3110 for(var i = 0, len = queue.length; i < len; ++i){
3111 if(queue[0].isAnimated){
3112 me.unRegister(queue[0], 0);
3120 me.unRegister(tween);
3125 var tf, i, len, tween;
3126 for(i = 0, len = queue.length; i<len; i++) {
3128 if(tween && tween.isAnimated){
3129 tf = tween.totalFrames;
3130 if(tween.curFrame < tf || tf === null){
3133 correctFrame(tween);
3135 tween._onTween.fire();
3144 var getIndex = function(anim) {
3146 for(i = 0, len = queue.length; i<len; i++) {
3147 if(queue[i] === anim) {
3154 var correctFrame = function(tween) {
3155 var frames = tween.totalFrames,
3156 frame = tween.curFrame,
3157 duration = tween.duration,
3158 expected = (frame * duration * 1000 / frames),
3159 elapsed = (now() - tween.startTime),
3162 if(elapsed < duration * 1000){
3163 tweak = Math.round((elapsed / expected - 1) * frame);
3165 tweak = frames - (frame + 1);
3167 if(tweak > 0 && isFinite(tweak)){
3168 if(tween.curFrame + tweak >= frames){
3169 tweak = frames - (frame + 1);
3171 tween.curFrame += tweak;
3176 EXTLIB.Bezier = new function() {
3178 this.getPosition = function(points, t) {
3179 var n = points.length,
3185 for (i = 0; i < n; ++i) {
3186 tmp[i] = [points[i][0], points[i][1]];
3189 for (j = 1; j < n; ++j) {
3190 for (i = 0; i < n - j; ++i) {
3191 tmp[i][0] = c * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
3192 tmp[i][1] = c * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
3196 return [ tmp[0][0], tmp[0][1] ];
3203 easeNone: function (t, b, c, d) {
3204 return c * t / d + b;
3208 easeIn: function (t, b, c, d) {
3209 return c * (t /= d) * t + b;
3213 easeOut: function (t, b, c, d) {
3214 return -c * (t /= d) * (t - 2) + b;
3219 EXTLIB.Motion = function(el, attributes, duration, method) {
3221 EXTLIB.Motion.superclass.constructor.call(this, el, attributes, duration, method);
3225 Ext.extend(EXTLIB.Motion, Ext.lib.AnimBase);
3227 var superclass = EXTLIB.Motion.superclass,
3228 proto = EXTLIB.Motion.prototype,
3229 pointsRe = /^points$/i;
3231 Ext.apply(EXTLIB.Motion.prototype, {
3232 setAttr: function(attr, val, unit){
3234 setAttr = superclass.setAttr;
3236 if (pointsRe.test(attr)) {
3237 unit = unit || 'px';
3238 setAttr.call(me, 'left', val[0], unit);
3239 setAttr.call(me, 'top', val[1], unit);
3241 setAttr.call(me, attr, val, unit);
3245 getAttr: function(attr){
3247 getAttr = superclass.getAttr;
3249 return pointsRe.test(attr) ? [getAttr.call(me, 'left'), getAttr.call(me, 'top')] : getAttr.call(me, attr);
3252 doMethod: function(attr, start, end){
3255 return pointsRe.test(attr)
3256 ? EXTLIB.Bezier.getPosition(me.runAttrs[attr], me.method(me.curFrame, 0, 100, me.totalFrames) / 100)
3257 : superclass.doMethod.call(me, attr, start, end);
3260 setRunAttr: function(attr){
3261 if(pointsRe.test(attr)){
3265 points = this.attributes.points,
3266 control = points.control || [],
3278 if(control.length > 0 && !Ext.isArray(control[0])){
3279 control = [control];
3283 for (i = 0,len = control.length; i < len; ++i) {
3284 tmp[i] = control[i];
3290 Ext.fly(el, '_anim').position();
3291 DOM.setXY(el, isset(from) ? from : DOM.getXY(el));
3292 start = me.getAttr('points');
3296 end = translateValues.call(me, to, start);
3297 for (i = 0,len = control.length; i < len; ++i) {
3298 control[i] = translateValues.call(me, control[i], start);
3300 } else if (isset(by)) {
3301 end = [start[0] + by[0], start[1] + by[1]];
3303 for (i = 0,len = control.length; i < len; ++i) {
3304 control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
3308 ra = this.runAttrs[attr] = [start];
3309 if (control.length > 0) {
3310 ra = ra.concat(control);
3313 ra[ra.length] = end;
3315 superclass.setRunAttr.call(this, attr);
3320 var translateValues = function(val, start) {
3321 var pageXY = EXTLIB.Dom.getXY(this.el);
3322 return [val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1]];
3325 })();// Easing functions
3327 // shortcuts to aid compression
3335 Ext.apply(EXTLIB.Easing, {
3337 easeBoth: function (t, b, c, d) {
3338 return ((t /= d / 2) < 1) ? c / 2 * t * t + b : -c / 2 * ((--t) * (t - 2) - 1) + b;
3341 easeInStrong: function (t, b, c, d) {
3342 return c * (t /= d) * t * t * t + b;
3345 easeOutStrong: function (t, b, c, d) {
3346 return -c * ((t = t / d - 1) * t * t * t - 1) + b;
3349 easeBothStrong: function (t, b, c, d) {
3350 return ((t /= d / 2) < 1) ? c / 2 * t * t * t * t + b : -c / 2 * ((t -= 2) * t * t * t - 2) + b;
3353 elasticIn: function (t, b, c, d, a, p) {
3354 if (t == 0 || (t /= d) == 1) {
3355 return t == 0 ? b : b + c;
3361 s = p / (2 * pi) * asin(c / a);
3367 return -(a * pow(2, 10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p)) + b;
3371 elasticOut: function (t, b, c, d, a, p) {
3372 if (t == 0 || (t /= d) == 1) {
3373 return t == 0 ? b : b + c;
3379 s = p / (2 * pi) * asin(c / a);
3385 return a * pow(2, -10 * t) * sin((t * d - s) * (2 * pi) / p) + c + b;
3388 elasticBoth: function (t, b, c, d, a, p) {
3389 if (t == 0 || (t /= d / 2) == 2) {
3390 return t == 0 ? b : b + c;
3393 p = p || (d * (.3 * 1.5));
3397 s = p / (2 * pi) * asin(c / a);
3404 -.5 * (a * pow(2, 10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p)) + b :
3405 a * pow(2, -10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p) * .5 + c + b;
3408 backIn: function (t, b, c, d, s) {
3410 return c * (t /= d) * t * ((s + 1) * t - s) + b;
3414 backOut: function (t, b, c, d, s) {
3418 return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
3422 backBoth: function (t, b, c, d, s) {
3425 return ((t /= d / 2 ) < 1) ?
3426 c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b :
3427 c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
3431 bounceIn: function (t, b, c, d) {
3432 return c - EXTLIB.Easing.bounceOut(d - t, 0, c, d) + b;
3436 bounceOut: function (t, b, c, d) {
3437 if ((t /= d) < (1 / 2.75)) {
3438 return c * (7.5625 * t * t) + b;
3439 } else if (t < (2 / 2.75)) {
3440 return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
3441 } else if (t < (2.5 / 2.75)) {
3442 return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
3444 return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
3448 bounceBoth: function (t, b, c, d) {
3449 return (t < d / 2) ?
3450 EXTLIB.Easing.bounceIn(t * 2, 0, c, d) * .5 + b :
3451 EXTLIB.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
3457 var EXTLIB = Ext.lib;
3459 EXTLIB.Anim.color = function(el, args, duration, easing, cb, scope) {
3460 return EXTLIB.Anim.run(el, args, duration, easing, cb, scope, EXTLIB.ColorAnim);
3463 EXTLIB.ColorAnim = function(el, attributes, duration, method) {
3464 EXTLIB.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
3467 Ext.extend(EXTLIB.ColorAnim, EXTLIB.AnimBase);
3469 var superclass = EXTLIB.ColorAnim.superclass,
3470 colorRE = /color$/i,
3471 transparentRE = /^transparent|rgba\(0, 0, 0, 0\)$/,
3472 rgbRE = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i,
3473 hexRE= /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i,
3474 hex3RE = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i,
3475 isset = function(v){
3476 return typeof v !== 'undefined';
3480 function parseColor(s) {
3486 if (s.length == 3) {
3490 Ext.each([hexRE, rgbRE, hex3RE], function(re, idx){
3491 base = (idx % 2 == 0) ? 16 : 10;
3493 if(c && c.length == 4){
3494 out = [pi(c[1], base), pi(c[2], base), pi(c[3], base)];
3501 Ext.apply(EXTLIB.ColorAnim.prototype, {
3502 getAttr : function(attr) {
3506 if(colorRE.test(attr)){
3507 while(el && transparentRE.test(val = Ext.fly(el).getStyle(attr))){
3512 val = superclass.getAttr.call(me, attr);
3517 doMethod : function(attr, start, end) {
3525 if(colorRE.test(attr)){
3529 for(i = 0, len = start.length; i < len; i++) {
3531 val[i] = superclass.doMethod.call(me, attr, v, end[i]);
3533 val = 'rgb(' + floor(val[0]) + ',' + floor(val[1]) + ',' + floor(val[2]) + ')';
3535 val = superclass.doMethod.call(me, attr, start, end);
3540 setRunAttr : function(attr) {
3542 a = me.attributes[attr],
3547 superclass.setRunAttr.call(me, attr);
3548 ra = me.runAttrs[attr];
3549 if(colorRE.test(attr)){
3550 var start = parseColor(ra.start),
3551 end = parseColor(ra.end);
3553 if(!isset(to) && isset(by)){
3554 end = parseColor(by);
3555 for(var i=0,len=start.length; i<len; i++) {
3556 end[i] = start[i] + end[i];
3569 var EXTLIB = Ext.lib;
3570 EXTLIB.Anim.scroll = function(el, args, duration, easing, cb, scope) {
3571 return EXTLIB.Anim.run(el, args, duration, easing, cb, scope, EXTLIB.Scroll);
3574 EXTLIB.Scroll = function(el, attributes, duration, method) {
3576 EXTLIB.Scroll.superclass.constructor.call(this, el, attributes, duration, method);
3580 Ext.extend(EXTLIB.Scroll, EXTLIB.ColorAnim);
3582 var superclass = EXTLIB.Scroll.superclass,
3585 Ext.apply(EXTLIB.Scroll.prototype, {
3587 doMethod : function(attr, start, end) {
3590 curFrame = me.curFrame,
3591 totalFrames = me.totalFrames;
3594 val = [me.method(curFrame, start[0], end[0] - start[0], totalFrames),
3595 me.method(curFrame, start[1], end[1] - start[1], totalFrames)];
3597 val = superclass.doMethod.call(me, attr, start, end);
3602 getAttr : function(attr) {
3605 if (attr == SCROLL) {
3606 return [me.el.scrollLeft, me.el.scrollTop];
3608 return superclass.getAttr.call(me, attr);
3612 setAttr : function(attr, val, unit) {
3616 me.el.scrollLeft = val[0];
3617 me.el.scrollTop = val[1];
3619 superclass.setAttr.call(me, attr, val, unit);
3625 function fnCleanUp() {
3626 var p = Function.prototype;
3627 delete p.createSequence;
3629 delete p.createDelegate;
3630 delete p.createCallback;
3631 delete p.createInterceptor;
3633 window.detachEvent("onunload", fnCleanUp);
3635 window.attachEvent("onunload", fnCleanUp);