3 * Copyright(c) 2006-2010 Ext JS, LLC
5 * http://www.extjs.com/license
9 window.undefined = window.undefined;
13 * Ext core utilities and functions.
19 * The version of the framework
26 * Copies all the properties of config to obj.
27 * @param {Object} obj The receiver of the properties
28 * @param {Object} config The source of the properties
29 * @param {Object} defaults A different object that will also be applied for default values
30 * @return {Object} returns obj
33 Ext.apply = function(o, c, defaults){
34 // no "this" reference for friendly out of scope calls
36 Ext.apply(o, defaults);
38 if(o && c && typeof c == 'object'){
48 toString = Object.prototype.toString,
49 ua = navigator.userAgent.toLowerCase(),
54 isStrict = DOC.compatMode == "CSS1Compat",
55 isOpera = check(/opera/),
56 isChrome = check(/\bchrome\b/),
57 isWebKit = check(/webkit/),
58 isSafari = !isChrome && check(/safari/),
59 isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
60 isSafari3 = isSafari && check(/version\/3/),
61 isSafari4 = isSafari && check(/version\/4/),
62 isIE = !isOpera && check(/msie/),
63 isIE7 = isIE && check(/msie 7/),
64 isIE8 = isIE && check(/msie 8/),
65 isIE6 = isIE && !isIE7 && !isIE8,
66 isGecko = !isWebKit && check(/gecko/),
67 isGecko2 = isGecko && check(/rv:1\.8/),
68 isGecko3 = isGecko && check(/rv:1\.9/),
69 isBorderBox = isIE && !isStrict,
70 isWindows = check(/windows|win32/),
71 isMac = check(/macintosh|mac os x/),
72 isAir = check(/adobeair/),
73 isLinux = check(/linux/),
74 isSecure = /^https/i.test(window.location.protocol);
76 // remove css image flicker
79 DOC.execCommand("BackgroundImageCache", false, true);
85 * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent
86 * the IE insecure content warning (<tt>'about:blank'</tt>, except for IE in secure mode, which is <tt>'javascript:""'</tt>).
89 SSL_SECURE_URL : isSecure && isIE ? 'javascript:""' : 'about:blank',
91 * True if the browser is in strict (standards-compliant) mode, as opposed to quirks mode
96 * True if the page is running over SSL
101 * True when the document is fully initialized and ready for action
107 * True if the {@link Ext.Fx} Class is available
113 * True to automatically uncache orphaned Ext.Elements periodically (defaults to true)
116 enableGarbageCollector : true,
119 * True to automatically purge event listeners during garbageCollection (defaults to false).
122 enableListenerCollection : false,
125 * EXPERIMENTAL - True to cascade listener removal to child elements when an element is removed.
126 * Currently not optimized for performance.
129 enableNestedListenerRemoval : false,
132 * Indicates whether to use native browser parsing for JSON methods.
133 * This option is ignored if the browser does not support native JSON methods.
134 * <b>Note: Native JSON methods will not work with objects that have functions.
135 * Also, property names must be quoted, otherwise the data will not parse.</b> (Defaults to false)
138 USE_NATIVE_JSON : false,
141 * Copies all the properties of config to obj if they don't already exist.
142 * @param {Object} obj The receiver of the properties
143 * @param {Object} config The source of the properties
144 * @return {Object} returns obj
146 applyIf : function(o, c){
149 if(!Ext.isDefined(o[p])){
158 * Generates unique ids. If the element already has an id, it is unchanged
159 * @param {Mixed} el (optional) The element to generate an id for
160 * @param {String} prefix (optional) Id prefix (defaults "ext-gen")
161 * @return {String} The generated Id.
163 id : function(el, prefix){
164 el = Ext.getDom(el, true) || {};
166 el.id = (prefix || "ext-gen") + (++idSeed);
172 * <p>Extends one class to create a subclass and optionally overrides members with the passed literal. This method
173 * also adds the function "override()" to the subclass that can be used to override members of the class.</p>
174 * For example, to create a subclass of Ext GridPanel:
176 MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
177 constructor: function(config) {
179 // Create configuration for this Grid.
180 var store = new Ext.data.Store({...});
181 var colModel = new Ext.grid.ColumnModel({...});
183 // Create a new config object containing our computed properties
184 // *plus* whatever was in the config parameter.
190 MyGridPanel.superclass.constructor.call(this, config);
192 // Your postprocessing here
195 yourMethod: function() {
201 * <p>This function also supports a 3-argument call in which the subclass's constructor is
202 * passed as an argument. In this form, the parameters are as follows:</p>
203 * <div class="mdetail-params"><ul>
204 * <li><code>subclass</code> : Function <div class="sub-desc">The subclass constructor.</div></li>
205 * <li><code>superclass</code> : Function <div class="sub-desc">The constructor of class being extended</div></li>
206 * <li><code>overrides</code> : Object <div class="sub-desc">A literal with members which are copied into the subclass's
207 * prototype, and are therefore shared among all instances of the new class.</div></li>
210 * @param {Function} superclass The constructor of class being extended.
211 * @param {Object} overrides <p>A literal with members which are copied into the subclass's
212 * prototype, and are therefore shared between all instances of the new class.</p>
213 * <p>This may contain a special member named <tt><b>constructor</b></tt>. This is used
214 * to define the constructor of the new class, and is returned. If this property is
215 * <i>not</i> specified, a constructor is generated and returned which just calls the
216 * superclass's constructor passing on its parameters.</p>
217 * <p><b>It is essential that you call the superclass constructor in any provided constructor. See example code.</b></p>
218 * @return {Function} The subclass constructor from the <code>overrides</code> parameter, or a generated one if not provided.
222 var io = function(o){
227 var oc = Object.prototype.constructor;
229 return function(sb, sp, overrides){
230 if(Ext.isObject(sp)){
233 sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
235 var F = function(){},
240 sbp = sb.prototype = new F();
243 if(spp.constructor == oc){
246 sb.override = function(o){
249 sbp.superclass = sbp.supr = (function(){
253 Ext.override(sb, overrides);
254 sb.extend = function(o){return Ext.extend(sb, o);};
260 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
262 Ext.override(MyClass, {
263 newMethod1: function(){
266 newMethod2: function(foo){
271 * @param {Object} origclass The class to override
272 * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
273 * containing one or more methods.
276 override : function(origclass, overrides){
278 var p = origclass.prototype;
279 Ext.apply(p, overrides);
280 if(Ext.isIE && overrides.hasOwnProperty('toString')){
281 p.toString = overrides.toString;
287 * Creates namespaces to be used for scoping variables and classes so that they are not global.
288 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
290 Ext.namespace('Company', 'Company.data');
291 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
292 Company.Widget = function() { ... }
293 Company.data.CustomStore = function(config) { ... }
295 * @param {String} namespace1
296 * @param {String} namespace2
297 * @param {String} etc
298 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
301 namespace : function(){
303 Ext.each(arguments, function(v) {
305 o = window[d[0]] = window[d[0]] || {};
306 Ext.each(d.slice(1), function(v2){
307 o = o[v2] = o[v2] || {};
314 * 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.
316 * @param {String} pre (optional) A prefix to add to the url encoded string
319 urlEncode : function(o, pre){
322 e = encodeURIComponent;
324 Ext.iterate(o, function(key, item){
325 empty = Ext.isEmpty(item);
326 Ext.each(empty ? key : item, function(val){
327 buf.push('&', e(key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : '');
334 return pre + buf.join('');
338 * Takes an encoded URL and and converts it to an object. Example: <pre><code>
339 Ext.urlDecode("foo=1&bar=2"); // returns {foo: "1", bar: "2"}
340 Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2", "3", "4"]}
342 * @param {String} string
343 * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
344 * @return {Object} A literal with members
346 urlDecode : function(string, overwrite){
347 if(Ext.isEmpty(string)){
351 pairs = string.split('&'),
352 d = decodeURIComponent,
355 Ext.each(pairs, function(pair) {
356 pair = pair.split('=');
359 obj[name] = overwrite || !obj[name] ? value :
360 [].concat(obj[name]).concat(value);
366 * Appends content to the query string of a URL, handling logic for whether to place
367 * a question mark or ampersand.
368 * @param {String} url The URL to append to.
369 * @param {String} s The content to append to the URL.
370 * @return (String) The resulting URL
372 urlAppend : function(url, s){
374 return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
380 * Converts any iterable (numeric indices and a length property) into a true array
381 * Don't use this on strings. IE doesn't support "abc"[0] which this implementation depends on.
382 * For strings, use this instead: "abc".match(/./g) => [a,b,c];
383 * @param {Iterable} the iterable object to be turned into a true Array.
384 * @return (Array) array
386 toArray : function(){
388 function(a, i, j, res){
390 for(var x = 0, len = a.length; x < len; x++) {
393 return res.slice(i || 0, j || res.length);
396 return Array.prototype.slice.call(a, i || 0, j || a.length);
400 isIterable : function(v){
401 //check for array or arguments
402 if(Ext.isArray(v) || v.callee){
405 //check for node list type
406 if(/NodeList|HTMLCollection/.test(toString.call(v))){
409 //NodeList has an item and length property
410 //IXMLDOMNodeList has nextNode method, needs to be checked first.
411 return ((typeof v.nextNode != 'undefined' || v.item) && Ext.isNumber(v.length));
415 * Iterates an array calling the supplied function.
416 * @param {Array/NodeList/Mixed} array The array to be iterated. If this
417 * argument is not really an array, the supplied function is called once.
418 * @param {Function} fn The function to be called with each item. If the
419 * supplied function returns false, iteration stops and this method returns
420 * the current <code>index</code>. This function is called with
421 * the following arguments:
422 * <div class="mdetail-params"><ul>
423 * <li><code>item</code> : <i>Mixed</i>
424 * <div class="sub-desc">The item at the current <code>index</code>
425 * in the passed <code>array</code></div></li>
426 * <li><code>index</code> : <i>Number</i>
427 * <div class="sub-desc">The current index within the array</div></li>
428 * <li><code>allItems</code> : <i>Array</i>
429 * <div class="sub-desc">The <code>array</code> passed as the first
430 * argument to <code>Ext.each</code>.</div></li>
432 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed.
433 * Defaults to the <code>item</code> at the current <code>index</code>
434 * within the passed <code>array</code>.
435 * @return See description for the fn parameter.
437 each : function(array, fn, scope){
438 if(Ext.isEmpty(array, true)){
441 if(!Ext.isIterable(array) || Ext.isPrimitive(array)){
444 for(var i = 0, len = array.length; i < len; i++){
445 if(fn.call(scope || array[i], array[i], i, array) === false){
452 * Iterates either the elements in an array, or each of the properties in an object.
453 * <b>Note</b>: If you are only iterating arrays, it is better to call {@link #each}.
454 * @param {Object/Array} object The object or array to be iterated
455 * @param {Function} fn The function to be called for each iteration.
456 * The iteration will stop if the supplied function returns false, or
457 * all array elements / object properties have been covered. The signature
458 * varies depending on the type of object being interated:
459 * <div class="mdetail-params"><ul>
460 * <li>Arrays : <tt>(Object item, Number index, Array allItems)</tt>
461 * <div class="sub-desc">
462 * When iterating an array, the supplied function is called with each item.</div></li>
463 * <li>Objects : <tt>(String key, Object value, Object)</tt>
464 * <div class="sub-desc">
465 * When iterating an object, the supplied function is called with each key-value pair in
466 * the object, and the iterated object</div></li>
468 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed. Defaults to
469 * the <code>object</code> being iterated.
471 iterate : function(obj, fn, scope){
472 if(Ext.isEmpty(obj)){
475 if(Ext.isIterable(obj)){
476 Ext.each(obj, fn, scope);
478 }else if(Ext.isObject(obj)){
479 for(var prop in obj){
480 if(obj.hasOwnProperty(prop)){
481 if(fn.call(scope || obj, prop, obj[prop], obj) === false){
490 * Return the dom node for the passed String (id), dom node, or Ext.Element.
491 * Optional 'strict' flag is needed for IE since it can return 'name' and
492 * 'id' elements by using getElementById.
493 * Here are some examples:
495 // gets dom node based on id
496 var elDom = Ext.getDom('elId');
497 // gets dom node based on the dom node
498 var elDom1 = Ext.getDom(elDom);
500 // If we don't know if we are working with an
501 // Ext.Element or a dom node use Ext.getDom
503 var dom = Ext.getDom(el);
504 // do something with the dom node
507 * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc)
508 * when this method is called to be successful.
510 * @return HTMLElement
512 getDom : function(el, strict){
519 if (Ext.isString(el)) {
520 var e = DOC.getElementById(el);
521 // IE returns elements with the 'name' and 'id' attribute.
522 // we do a strict check to return the element with only the id attribute
523 if (e && isIE && strict) {
524 if (el == e.getAttribute('id')) {
538 * Returns the current document body as an {@link Ext.Element}.
539 * @return Ext.Element The document body
541 getBody : function(){
542 return Ext.get(DOC.body || DOC.documentElement);
546 * Removes a DOM node from the document.
549 * <p>Removes this element from the document, removes all DOM event listeners, and deletes the cache reference.
550 * All DOM event listeners are removed from this element. If {@link Ext#enableNestedListenerRemoval} is
551 * <code>true</code>, then DOM event listeners are also removed from all child nodes. The body node
552 * will be ignored if passed in.</p>
553 * @param {HTMLElement} node The node to remove
555 removeNode : isIE && !isIE8 ? function(){
558 if(n && n.tagName != 'BODY'){
559 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
560 d = d || DOC.createElement('div');
563 delete Ext.elCache[n.id];
567 if(n && n.parentNode && n.tagName != 'BODY'){
568 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
569 n.parentNode.removeChild(n);
570 delete Ext.elCache[n.id];
575 * <p>Returns true if the passed value is empty.</p>
576 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
579 * <li>an empty array</li>
580 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
582 * @param {Mixed} value The value to test
583 * @param {Boolean} allowBlank (optional) true to allow empty strings (defaults to false)
586 isEmpty : function(v, allowBlank){
587 return v === null || v === undefined || ((Ext.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false);
591 * Returns true if the passed value is a JavaScript array, otherwise false.
592 * @param {Mixed} value The value to test
595 isArray : function(v){
596 return toString.apply(v) === '[object Array]';
600 * Returns true if the passed object is a JavaScript date object, otherwise false.
601 * @param {Object} object The object to test
604 isDate : function(v){
605 return toString.apply(v) === '[object Date]';
609 * Returns true if the passed value is a JavaScript Object, otherwise false.
610 * @param {Mixed} value The value to test
613 isObject : function(v){
614 return !!v && Object.prototype.toString.call(v) === '[object Object]';
618 * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean.
619 * @param {Mixed} value The value to test
622 isPrimitive : function(v){
623 return Ext.isString(v) || Ext.isNumber(v) || Ext.isBoolean(v);
627 * Returns true if the passed value is a JavaScript Function, otherwise false.
628 * @param {Mixed} value The value to test
631 isFunction : function(v){
632 return toString.apply(v) === '[object Function]';
636 * Returns true if the passed value is a number. Returns false for non-finite numbers.
637 * @param {Mixed} value The value to test
640 isNumber : function(v){
641 return typeof v === 'number' && isFinite(v);
645 * Returns true if the passed value is a string.
646 * @param {Mixed} value The value to test
649 isString : function(v){
650 return typeof v === 'string';
654 * Returns true if the passed value is a boolean.
655 * @param {Mixed} value The value to test
658 isBoolean : function(v){
659 return typeof v === 'boolean';
663 * Returns true if the passed value is an HTMLElement
664 * @param {Mixed} value The value to test
667 isElement : function(v) {
668 return !!v && v.tagName;
672 * Returns true if the passed value is not undefined.
673 * @param {Mixed} value The value to test
676 isDefined : function(v){
677 return typeof v !== 'undefined';
681 * True if the detected browser is Opera.
686 * True if the detected browser uses WebKit.
691 * True if the detected browser is Chrome.
696 * True if the detected browser is Safari.
701 * True if the detected browser is Safari 3.x.
704 isSafari3 : isSafari3,
706 * True if the detected browser is Safari 4.x.
709 isSafari4 : isSafari4,
711 * True if the detected browser is Safari 2.x.
714 isSafari2 : isSafari2,
716 * True if the detected browser is Internet Explorer.
721 * True if the detected browser is Internet Explorer 6.x.
726 * True if the detected browser is Internet Explorer 7.x.
731 * True if the detected browser is Internet Explorer 8.x.
736 * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
741 * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x).
746 * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
751 * True if the detected browser is Internet Explorer running in non-strict mode.
754 isBorderBox : isBorderBox,
756 * True if the detected platform is Linux.
761 * True if the detected platform is Windows.
764 isWindows : isWindows,
766 * True if the detected platform is Mac OS.
771 * True if the detected platform is Adobe Air.
778 * Creates namespaces to be used for scoping variables and classes so that they are not global.
779 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
781 Ext.namespace('Company', 'Company.data');
782 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
783 Company.Widget = function() { ... }
784 Company.data.CustomStore = function(config) { ... }
786 * @param {String} namespace1
787 * @param {String} namespace2
788 * @param {String} etc
789 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
792 Ext.ns = Ext.namespace;
795 Ext.ns("Ext.util", "Ext.lib", "Ext.data");
801 * These functions are available on every Function object (any JavaScript function).
803 Ext.apply(Function.prototype, {
805 * Creates an interceptor function. The passed function is called before the original one. If it returns false,
806 * the original one is not called. The resulting function returns the results of the original function.
807 * The passed function is called with the parameters of the original function. Example usage:
809 var sayHi = function(name){
810 alert('Hi, ' + name);
813 sayHi('Fred'); // alerts "Hi, Fred"
815 // create a new function that validates input without
816 // directly modifying the original function:
817 var sayHiToFriend = sayHi.createInterceptor(function(name){
818 return name == 'Brian';
821 sayHiToFriend('Fred'); // no alert
822 sayHiToFriend('Brian'); // alerts "Hi, Brian"
824 * @param {Function} fcn The function to call before the original
825 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
826 * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
827 * @return {Function} The new function
829 createInterceptor : function(fcn, scope){
831 return !Ext.isFunction(fcn) ?
838 return (fcn.apply(scope || me || window, args) !== false) ?
839 method.apply(me || window, args) :
845 * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
846 * Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code>
847 * Will create a function that is bound to those 2 args. <b>If a specific scope is required in the
848 * callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always
849 * executes in the window scope.
850 * <p>This method is required when you want to pass arguments to a callback function. If no arguments
851 * are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn).
852 * However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function
853 * would simply execute immediately when the code is parsed. Example usage:
855 var sayHi = function(name){
856 alert('Hi, ' + name);
859 // clicking the button alerts "Hi, Fred"
862 renderTo: Ext.getBody(),
863 handler: sayHi.createCallback('Fred')
866 * @return {Function} The new function
868 createCallback : function(/*args...*/){
869 // make args available, in function below
870 var args = arguments,
873 return method.apply(window, args);
878 * Creates a delegate (callback) that sets the scope to obj.
879 * Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code>
880 * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
881 * callback points to obj. Example usage:
883 var sayHi = function(name){
884 // Note this use of "this.text" here. This function expects to
885 // execute within a scope that contains a text property. In this
886 // example, the "this" variable is pointing to the btn object that
887 // was passed in createDelegate below.
888 alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
891 var btn = new Ext.Button({
893 renderTo: Ext.getBody()
896 // This callback will execute in the scope of the
897 // button instance. Clicking the button alerts
898 // "Hi, Fred. You clicked the "Say Hi" button."
899 btn.on('click', sayHi.createDelegate(btn, ['Fred']));
901 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
902 * <b>If omitted, defaults to the browser window.</b>
903 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
904 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
905 * if a number the args are inserted at the specified position
906 * @return {Function} The new function
908 createDelegate : function(obj, args, appendArgs){
911 var callArgs = args || arguments;
912 if (appendArgs === true){
913 callArgs = Array.prototype.slice.call(arguments, 0);
914 callArgs = callArgs.concat(args);
915 }else if (Ext.isNumber(appendArgs)){
916 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
917 var applyArgs = [appendArgs, 0].concat(args); // create method call params
918 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
920 return method.apply(obj || window, callArgs);
925 * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
927 var sayHi = function(name){
928 alert('Hi, ' + name);
931 // executes immediately:
934 // executes after 2 seconds:
935 sayHi.defer(2000, this, ['Fred']);
937 // this syntax is sometimes useful for deferring
938 // execution of an anonymous function:
943 * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
944 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
945 * <b>If omitted, defaults to the browser window.</b>
946 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
947 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
948 * if a number the args are inserted at the specified position
949 * @return {Number} The timeout id that can be used with clearTimeout
951 defer : function(millis, obj, args, appendArgs){
952 var fn = this.createDelegate(obj, args, appendArgs);
954 return setTimeout(fn, millis);
963 * These functions are available on every String object.
965 Ext.applyIf(String, {
967 * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
968 * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
970 var cls = 'my-class', text = 'Some text';
971 var s = String.format('<div class="{0}">{1}</div>', cls, text);
972 // s now contains the string: '<div class="my-class">Some text</div>'
974 * @param {String} string The tokenized string to be formatted
975 * @param {String} value1 The value to replace token {0}
976 * @param {String} value2 Etc...
977 * @return {String} The formatted string
980 format : function(format){
981 var args = Ext.toArray(arguments, 1);
982 return format.replace(/\{(\d+)\}/g, function(m, i){
991 Ext.applyIf(Array.prototype, {
993 * Checks whether or not the specified object exists in the array.
994 * @param {Object} o The object to check for
995 * @param {Number} from (Optional) The index at which to begin the search
996 * @return {Number} The index of o in the array (or -1 if it is not found)
998 indexOf : function(o, from){
999 var len = this.length;
1001 from += (from < 0) ? len : 0;
1002 for (; from < len; ++from){
1003 if(this[from] === o){
1011 * Removes the specified object from the array. If the object is not found nothing happens.
1012 * @param {Object} o The object to remove
1013 * @return {Array} this array
1015 remove : function(o){
1016 var index = this.indexOf(o);
1018 this.splice(index, 1);
1027 Ext.ns("Ext.grid", "Ext.list", "Ext.dd", "Ext.tree", "Ext.form", "Ext.menu",
1028 "Ext.state", "Ext.layout", "Ext.app", "Ext.ux", "Ext.chart", "Ext.direct");
1030 * Namespace alloted for extensions to the framework.
1035 Ext.apply(Ext, function(){
1042 * A reusable empty function
1046 emptyFn : function(){},
1049 * URL to a 1x1 transparent gif image used by Ext to create inline icons with CSS background images.
1050 * In older versions of IE, this defaults to "http://extjs.com/s.gif" and you should change this to a URL on your server.
1051 * For other browsers it uses an inline data URL.
1054 BLANK_IMAGE_URL : Ext.isIE6 || Ext.isIE7 || Ext.isAir ?
1055 'http:/' + '/extjs.com/s.gif' :
1056 'data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==',
1058 extendX : function(supr, fn){
1059 return Ext.extend(supr, fn(supr.prototype));
1063 * Returns the current HTML document object as an {@link Ext.Element}.
1064 * @return Ext.Element The document
1066 getDoc : function(){
1067 return Ext.get(document);
1071 * Utility method for validating that a value is numeric, returning the specified default value if it is not.
1072 * @param {Mixed} value Should be a number, but any type will be handled appropriately
1073 * @param {Number} defaultValue The value to return if the original value is non-numeric
1074 * @return {Number} Value, if numeric, else defaultValue
1076 num : function(v, defaultValue){
1077 v = Number(Ext.isEmpty(v) || Ext.isArray(v) || Ext.isBoolean(v) || (Ext.isString(v) && v.trim().length == 0) ? NaN : v);
1078 return isNaN(v) ? defaultValue : v;
1082 * <p>Utility method for returning a default value if the passed value is empty.</p>
1083 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
1085 * <li>undefined</li>
1086 * <li>an empty array</li>
1087 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
1089 * @param {Mixed} value The value to test
1090 * @param {Mixed} defaultValue The value to return if the original value is empty
1091 * @param {Boolean} allowBlank (optional) true to allow zero length strings to qualify as non-empty (defaults to false)
1092 * @return {Mixed} value, if non-empty, else defaultValue
1094 value : function(v, defaultValue, allowBlank){
1095 return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
1099 * Escapes the passed string for use in a regular expression
1100 * @param {String} str
1103 escapeRe : function(s) {
1104 return s.replace(/([-.*+?^${}()|[\]\/\\])/g, "\\$1");
1107 sequence : function(o, name, fn, scope){
1108 o[name] = o[name].createSequence(fn, scope);
1112 * Applies event listeners to elements by selectors when the document is ready.
1113 * The event name is specified with an <tt>@</tt> suffix.
1116 // add a listener for click on all anchors in element with id foo
1117 '#foo a@click' : function(e, t){
1121 // add the same listener to multiple selectors (separated by comma BEFORE the @)
1122 '#foo a, #bar span.some-class@mouseover' : function(){
1127 * @param {Object} obj The list of behaviors to apply
1129 addBehaviors : function(o){
1131 Ext.onReady(function(){
1132 Ext.addBehaviors(o);
1135 var cache = {}, // simple cache for applying multiple behaviors to same selector does query multiple times
1140 if ((parts = b.split('@'))[1]) { // for Object prototype breakers
1143 cache[s] = Ext.select(s);
1145 cache[s].on(parts[1], o[b]);
1153 * Utility method for getting the width of the browser scrollbar. This can differ depending on
1154 * operating system settings, such as the theme or font size.
1155 * @param {Boolean} force (optional) true to force a recalculation of the value.
1156 * @return {Number} The width of the scrollbar.
1158 getScrollBarWidth: function(force){
1163 if(force === true || scrollWidth === null){
1164 // Append our div, do our calculation and then remove it
1165 var div = Ext.getBody().createChild('<div class="x-hide-offsets" style="width:100px;height:50px;overflow:hidden;"><div style="height:200px;"></div></div>'),
1166 child = div.child('div', true);
1167 var w1 = child.offsetWidth;
1168 div.setStyle('overflow', (Ext.isWebKit || Ext.isGecko) ? 'auto' : 'scroll');
1169 var w2 = child.offsetWidth;
1171 // Need to add 2 to ensure we leave enough space
1172 scrollWidth = w1 - w2 + 2;
1179 combine : function(){
1180 var as = arguments, l = as.length, r = [];
1181 for(var i = 0; i < l; i++){
1185 }else if(a.length !== undefined && !a.substr){
1186 r = r.concat(Array.prototype.slice.call(a, 0));
1195 * Copies a set of named properties fom the source object to the destination object.
1196 * <p>example:<pre><code>
1197 ImageComponent = Ext.extend(Ext.BoxComponent, {
1198 initComponent: function() {
1199 this.autoEl = { tag: 'img' };
1200 MyComponent.superclass.initComponent.apply(this, arguments);
1201 this.initialBox = Ext.copyTo({}, this.initialConfig, 'x,y,width,height');
1205 * @param {Object} The destination object.
1206 * @param {Object} The source object.
1207 * @param {Array/String} Either an Array of property names, or a comma-delimited list
1208 * of property names to copy.
1209 * @return {Object} The modified object.
1211 copyTo : function(dest, source, names){
1212 if(Ext.isString(names)){
1213 names = names.split(/[,;\s]/);
1215 Ext.each(names, function(name){
1216 if(source.hasOwnProperty(name)){
1217 dest[name] = source[name];
1224 * Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
1225 * DOM (if applicable) and calling their destroy functions (if available). This method is primarily
1226 * intended for arguments of type {@link Ext.Element} and {@link Ext.Component}, but any subclass of
1227 * {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
1228 * passed into this function in a single call as separate arguments.
1229 * @param {Mixed} arg1 An {@link Ext.Element}, {@link Ext.Component}, or an Array of either of these to destroy
1230 * @param {Mixed} arg2 (optional)
1231 * @param {Mixed} etc... (optional)
1233 destroy : function(){
1234 Ext.each(arguments, function(arg){
1236 if(Ext.isArray(arg)){
1237 this.destroy.apply(this, arg);
1238 }else if(Ext.isFunction(arg.destroy)){
1248 * Attempts to destroy and then remove a set of named properties of the passed object.
1249 * @param {Object} o The object (most likely a Component) who's properties you wish to destroy.
1250 * @param {Mixed} arg1 The name of the property to destroy and remove from the object.
1251 * @param {Mixed} etc... More property names to destroy and remove.
1253 destroyMembers : function(o, arg1, arg2, etc){
1254 for(var i = 1, a = arguments, len = a.length; i < len; i++) {
1255 Ext.destroy(o[a[i]]);
1261 * Creates a copy of the passed Array with falsy values removed.
1262 * @param {Array/NodeList} arr The Array from which to remove falsy values.
1263 * @return {Array} The new, compressed Array.
1265 clean : function(arr){
1267 Ext.each(arr, function(v){
1276 * Creates a copy of the passed Array, filtered to contain only unique values.
1277 * @param {Array} arr The Array to filter
1278 * @return {Array} The new Array containing unique values.
1280 unique : function(arr){
1284 Ext.each(arr, function(v) {
1294 * Recursively flattens into 1-d Array. Injects Arrays inline.
1295 * @param {Array} arr The array to flatten
1296 * @return {Array} The new, flattened array.
1298 flatten : function(arr){
1300 function rFlatten(a) {
1301 Ext.each(a, function(v) {
1310 return rFlatten(arr);
1314 * Returns the minimum value in the Array.
1315 * @param {Array|NodeList} arr The Array from which to select the minimum value.
1316 * @param {Function} comp (optional) a function to perform the comparision which determines minimization.
1317 * If omitted the "<" operator will be used. Note: gt = 1; eq = 0; lt = -1
1318 * @return {Object} The minimum value in the Array.
1320 min : function(arr, comp){
1322 comp = comp || function(a,b){ return a < b ? -1 : 1; };
1323 Ext.each(arr, function(v) {
1324 ret = comp(ret, v) == -1 ? ret : v;
1330 * Returns the maximum value in the Array
1331 * @param {Array|NodeList} arr The Array from which to select the maximum value.
1332 * @param {Function} comp (optional) a function to perform the comparision which determines maximization.
1333 * If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1
1334 * @return {Object} The maximum value in the Array.
1336 max : function(arr, comp){
1338 comp = comp || function(a,b){ return a > b ? 1 : -1; };
1339 Ext.each(arr, function(v) {
1340 ret = comp(ret, v) == 1 ? ret : v;
1346 * Calculates the mean of the Array
1347 * @param {Array} arr The Array to calculate the mean value of.
1348 * @return {Number} The mean.
1350 mean : function(arr){
1351 return arr.length > 0 ? Ext.sum(arr) / arr.length : undefined;
1355 * Calculates the sum of the Array
1356 * @param {Array} arr The Array to calculate the sum value of.
1357 * @return {Number} The sum.
1359 sum : function(arr){
1361 Ext.each(arr, function(v) {
1368 * Partitions the set into two sets: a true set and a false set.
1373 Ext.partition([true, false, true, true, false]); // [[true, true, true], [false, false]]
1379 return val.className == "class1"
1382 // true are those paragraph elements with a className of "class1",
1383 // false set are those that do not have that className.
1385 * @param {Array|NodeList} arr The array to partition
1386 * @param {Function} truth (optional) a function to determine truth. If this is omitted the element
1387 * itself must be able to be evaluated for its truthfulness.
1388 * @return {Array} [true<Array>,false<Array>]
1390 partition : function(arr, truth){
1392 Ext.each(arr, function(v, i, a) {
1393 ret[ (truth && truth(v, i, a)) || (!truth && v) ? 0 : 1].push(v);
1399 * Invokes a method on each item in an Array.
1402 Ext.invoke(Ext.query("p"), "getAttribute", "id");
1403 // [el1.getAttribute("id"), el2.getAttribute("id"), ..., elN.getAttribute("id")]
1405 * @param {Array|NodeList} arr The Array of items to invoke the method on.
1406 * @param {String} methodName The method name to invoke.
1407 * @param {Anything} ... Arguments to send into the method invocation.
1408 * @return {Array} The results of invoking the method on each item in the array.
1410 invoke : function(arr, methodName){
1412 args = Array.prototype.slice.call(arguments, 2);
1413 Ext.each(arr, function(v,i) {
1414 if (v && Ext.isFunction(v[methodName])) {
1415 ret.push(v[methodName].apply(v, args));
1417 ret.push(undefined);
1424 * Plucks the value of a property from each item in the Array
1427 Ext.pluck(Ext.query("p"), "className"); // [el1.className, el2.className, ..., elN.className]
1429 * @param {Array|NodeList} arr The Array of items to pluck the value from.
1430 * @param {String} prop The property name to pluck from each element.
1431 * @return {Array} The value from each item in the Array.
1433 pluck : function(arr, prop){
1435 Ext.each(arr, function(v) {
1436 ret.push( v[prop] );
1442 * <p>Zips N sets together.</p>
1445 Ext.zip([1,2,3],[4,5,6]); // [[1,4],[2,5],[3,6]]
1452 return "$" + a + "" + b + "." + c
1454 ); // ["$+12.43", "$-10.15", "$+22.96"]
1456 * @param {Arrays|NodeLists} arr This argument may be repeated. Array(s) to contribute values.
1457 * @param {Function} zipper (optional) The last item in the argument list. This will drive how the items are zipped together.
1458 * @return {Array} The zipped set.
1461 var parts = Ext.partition(arguments, function( val ){ return !Ext.isFunction(val); }),
1464 len = Ext.max(Ext.pluck(arrs, "length")),
1467 for (var i = 0; i < len; i++) {
1470 ret[i] = fn.apply(fn, Ext.pluck(arrs, i));
1472 for (var j = 0, aLen = arrs.length; j < aLen; j++){
1473 ret[i].push( arrs[j][i] );
1481 * This is shorthand reference to {@link Ext.ComponentMgr#get}.
1482 * Looks up an existing {@link Ext.Component Component} by {@link Ext.Component#id id}
1483 * @param {String} id The component {@link Ext.Component#id id}
1484 * @return Ext.Component The Component, <tt>undefined</tt> if not found, or <tt>null</tt> if a
1487 getCmp : function(id){
1488 return Ext.ComponentMgr.get(id);
1492 * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
1493 * you may want to set this to true.
1496 useShims: E.isIE6 || (E.isMac && E.isGecko2),
1498 // inpired by a similar function in mootools library
1500 * Returns the type of object that is passed in. If the object passed in is null or undefined it
1501 * return false otherwise it returns one of the following values:<div class="mdetail-params"><ul>
1502 * <li><b>string</b>: If the object passed is a string</li>
1503 * <li><b>number</b>: If the object passed is a number</li>
1504 * <li><b>boolean</b>: If the object passed is a boolean value</li>
1505 * <li><b>date</b>: If the object passed is a Date object</li>
1506 * <li><b>function</b>: If the object passed is a function reference</li>
1507 * <li><b>object</b>: If the object passed is an object</li>
1508 * <li><b>array</b>: If the object passed is an array</li>
1509 * <li><b>regexp</b>: If the object passed is a regular expression</li>
1510 * <li><b>element</b>: If the object passed is a DOM Element</li>
1511 * <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
1512 * <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
1513 * <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
1515 * @param {Mixed} object
1519 if(o === undefined || o === null){
1526 if(t == 'object' && o.nodeName) {
1527 switch(o.nodeType) {
1528 case 1: return 'element';
1529 case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
1532 if(t == 'object' || t == 'function') {
1533 switch(o.constructor) {
1534 case Array: return 'array';
1535 case RegExp: return 'regexp';
1536 case Date: return 'date';
1538 if(Ext.isNumber(o.length) && Ext.isFunction(o.item)) {
1545 intercept : function(o, name, fn, scope){
1546 o[name] = o[name].createInterceptor(fn, scope);
1550 callback : function(cb, scope, args, delay){
1551 if(Ext.isFunction(cb)){
1553 cb.defer(delay, scope, args || []);
1555 cb.apply(scope, args || []);
1564 * These functions are available on every Function object (any JavaScript function).
1566 Ext.apply(Function.prototype, {
1568 * Create a combined function call sequence of the original function + the passed function.
1569 * The resulting function returns the results of the original function.
1570 * The passed fcn is called with the parameters of the original function. Example usage:
1572 var sayHi = function(name){
1573 alert('Hi, ' + name);
1576 sayHi('Fred'); // alerts "Hi, Fred"
1578 var sayGoodbye = sayHi.createSequence(function(name){
1579 alert('Bye, ' + name);
1582 sayGoodbye('Fred'); // both alerts show
1584 * @param {Function} fcn The function to sequence
1585 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
1586 * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
1587 * @return {Function} The new function
1589 createSequence : function(fcn, scope){
1591 return !Ext.isFunction(fcn) ?
1594 var retval = method.apply(this || window, arguments);
1595 fcn.apply(scope || this || window, arguments);
1604 * These functions are available as static methods on the JavaScript String object.
1606 Ext.applyIf(String, {
1609 * Escapes the passed string for ' and \
1610 * @param {String} string The string to escape
1611 * @return {String} The escaped string
1614 escape : function(string) {
1615 return string.replace(/('|\\)/g, "\\$1");
1619 * Pads the left side of a string with a specified character. This is especially useful
1620 * for normalizing number and date strings. Example usage:
1622 var s = String.leftPad('123', 5, '0');
1623 // s now contains the string: '00123'
1625 * @param {String} string The original string
1626 * @param {Number} size The total length of the output string
1627 * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
1628 * @return {String} The padded string
1631 leftPad : function (val, size, ch) {
1632 var result = String(val);
1636 while (result.length < size) {
1637 result = ch + result;
1644 * Utility function that allows you to easily switch a string between two alternating values. The passed value
1645 * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
1646 * they are already different, the first value passed in is returned. Note that this method returns the new value
1647 * but does not change the current string.
1649 // alternate sort directions
1650 sort = sort.toggle('ASC', 'DESC');
1652 // instead of conditional logic:
1653 sort = (sort == 'ASC' ? 'DESC' : 'ASC');
1655 * @param {String} value The value to compare to the current string
1656 * @param {String} other The new value to use if the string already equals the first value passed in
1657 * @return {String} The new value
1659 String.prototype.toggle = function(value, other){
1660 return this == value ? other : value;
1664 * Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
1666 var s = ' foo bar ';
1667 alert('-' + s + '-'); //alerts "- foo bar -"
1668 alert('-' + s.trim() + '-'); //alerts "-foo bar-"
1670 * @return {String} The trimmed string
1672 String.prototype.trim = function(){
1673 var re = /^\s+|\s+$/g;
1674 return function(){ return this.replace(re, ""); };
1677 // here to prevent dependency on Date.js
1679 Returns the number of milliseconds between this date and date
1680 @param {Date} date (optional) Defaults to now
1681 @return {Number} The diff in milliseconds
1682 @member Date getElapsed
1684 Date.prototype.getElapsed = function(date) {
1685 return Math.abs((date || new Date()).getTime()-this.getTime());
1692 Ext.applyIf(Number.prototype, {
1694 * Checks whether or not the current number is within a desired range. If the number is already within the
1695 * range it is returned, otherwise the min or max value is returned depending on which side of the range is
1696 * exceeded. Note that this method returns the constrained value but does not change the current number.
1697 * @param {Number} min The minimum number in the range
1698 * @param {Number} max The maximum number in the range
1699 * @return {Number} The constrained value if outside the range, otherwise the current value
1701 constrain : function(min, max){
1702 return Math.min(Math.max(this, min), max);
1706 * @class Ext.util.TaskRunner
1707 * Provides the ability to execute one or more arbitrary tasks in a multithreaded
1708 * manner. Generally, you can use the singleton {@link Ext.TaskMgr} instead, but
1709 * if needed, you can create separate instances of TaskRunner. Any number of
1710 * separate tasks can be started at any time and will run independently of each
1711 * other. Example usage:
1713 // Start a simple clock task that updates a div once per second
1714 var updateClock = function(){
1715 Ext.fly('clock').update(new Date().format('g:i:s A'));
1719 interval: 1000 //1 second
1721 var runner = new Ext.util.TaskRunner();
1724 // equivalent using TaskMgr
1731 * Also see {@link Ext.util.DelayedTask}.
1734 * @param {Number} interval (optional) The minimum precision in milliseconds supported by this TaskRunner instance
1737 Ext.util.TaskRunner = function(interval){
1738 interval = interval || 10;
1745 stopThread = function(){
1752 startThread = function(){
1755 id = setInterval(runTasks, interval);
1760 removeTask = function(t){
1761 removeQueue.push(t);
1763 t.onStop.apply(t.scope || t);
1768 runTasks = function(){
1769 var rqLen = removeQueue.length,
1770 now = new Date().getTime();
1773 for(var i = 0; i < rqLen; i++){
1774 tasks.remove(removeQueue[i]);
1777 if(tasks.length < 1){
1782 for(var i = 0, t, itime, rt, len = tasks.length; i < len; ++i){
1784 itime = now - t.taskRunTime;
1785 if(t.interval <= itime){
1786 rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
1787 t.taskRunTime = now;
1788 if(rt === false || t.taskRunCount === t.repeat){
1793 if(t.duration && t.duration <= (now - t.taskStartTime)){
1800 * Starts a new task.
1802 * @param {Object} task A config object that supports the following properties:<ul>
1803 * <li><code>run</code> : Function<div class="sub-desc">The function to execute each time the task is run. The
1804 * function will be called at each interval and passed the <code>args</code> argument if specified. If a
1805 * particular scope is required, be sure to specify it using the <code>scope</code> argument.</div></li>
1806 * <li><code>interval</code> : Number<div class="sub-desc">The frequency in milliseconds with which the task
1807 * should be executed.</div></li>
1808 * <li><code>args</code> : Array<div class="sub-desc">(optional) An array of arguments to be passed to the function
1809 * specified by <code>run</code>.</div></li>
1810 * <li><code>scope</code> : Object<div class="sub-desc">(optional) The scope (<tt>this</tt> reference) in which to execute the
1811 * <code>run</code> function. Defaults to the task config object.</div></li>
1812 * <li><code>duration</code> : Number<div class="sub-desc">(optional) The length of time in milliseconds to execute
1813 * the task before stopping automatically (defaults to indefinite).</div></li>
1814 * <li><code>repeat</code> : Number<div class="sub-desc">(optional) The number of times to execute the task before
1815 * stopping automatically (defaults to indefinite).</div></li>
1817 * @return {Object} The task
1819 this.start = function(task){
1821 task.taskStartTime = new Date().getTime();
1822 task.taskRunTime = 0;
1823 task.taskRunCount = 0;
1829 * Stops an existing running task.
1831 * @param {Object} task The task to stop
1832 * @return {Object} The task
1834 this.stop = function(task){
1840 * Stops all tasks that are currently running.
1843 this.stopAll = function(){
1845 for(var i = 0, len = tasks.length; i < len; i++){
1846 if(tasks[i].onStop){
1856 * @class Ext.TaskMgr
1857 * @extends Ext.util.TaskRunner
1858 * A static {@link Ext.util.TaskRunner} instance that can be used to start and stop arbitrary tasks. See
1859 * {@link Ext.util.TaskRunner} for supported methods and task config properties.
1861 // Start a simple clock task that updates a div once per second
1864 Ext.fly('clock').update(new Date().format('g:i:s A'));
1866 interval: 1000 //1 second
1868 Ext.TaskMgr.start(task);
1872 Ext.TaskMgr = new Ext.util.TaskRunner();(function(){
\r
1875 function fly(el) {
\r
1876 if (!libFlyweight) {
\r
1877 libFlyweight = new Ext.Element.Flyweight();
\r
1879 libFlyweight.dom = el;
\r
1880 return libFlyweight;
\r
1884 var doc = document,
\r
1885 isCSS1 = doc.compatMode == "CSS1Compat",
\r
1887 ROUND = Math.round,
\r
1888 PARSEINT = parseInt;
\r
1891 isAncestor : function(p, c) {
\r
1894 p = Ext.getDom(p);
\r
1895 c = Ext.getDom(c);
\r
1898 return p.contains(c);
\r
1899 } else if (p.compareDocumentPosition) {
\r
1900 return !!(p.compareDocumentPosition(c) & 16);
\r
1902 while (c = c.parentNode) {
\r
1903 ret = c == p || ret;
\r
1910 getViewWidth : function(full) {
\r
1911 return full ? this.getDocumentWidth() : this.getViewportWidth();
\r
1914 getViewHeight : function(full) {
\r
1915 return full ? this.getDocumentHeight() : this.getViewportHeight();
\r
1918 getDocumentHeight: function() {
\r
1919 return MAX(!isCSS1 ? doc.body.scrollHeight : doc.documentElement.scrollHeight, this.getViewportHeight());
\r
1922 getDocumentWidth: function() {
\r
1923 return MAX(!isCSS1 ? doc.body.scrollWidth : doc.documentElement.scrollWidth, this.getViewportWidth());
\r
1926 getViewportHeight: function(){
\r
1927 return Ext.isIE ?
\r
1928 (Ext.isStrict ? doc.documentElement.clientHeight : doc.body.clientHeight) :
\r
1932 getViewportWidth : function() {
\r
1933 return !Ext.isStrict && !Ext.isOpera ? doc.body.clientWidth :
\r
1934 Ext.isIE ? doc.documentElement.clientWidth : self.innerWidth;
\r
1937 getY : function(el) {
\r
1938 return this.getXY(el)[1];
\r
1941 getX : function(el) {
\r
1942 return this.getXY(el)[0];
\r
1945 getXY : function(el) {
\r
1956 bd = (doc.body || doc.documentElement),
\r
1959 el = Ext.getDom(el);
\r
1962 if (el.getBoundingClientRect) {
\r
1963 b = el.getBoundingClientRect();
\r
1964 scroll = fly(document).getScroll();
\r
1965 ret = [ROUND(b.left + scroll.left), ROUND(b.top + scroll.top)];
\r
1968 hasAbsolute = fly(el).isStyle("position", "absolute");
\r
1972 x += p.offsetLeft;
\r
1975 hasAbsolute = hasAbsolute || pe.isStyle("position", "absolute");
\r
1977 if (Ext.isGecko) {
\r
1978 y += bt = PARSEINT(pe.getStyle("borderTopWidth"), 10) || 0;
\r
1979 x += bl = PARSEINT(pe.getStyle("borderLeftWidth"), 10) || 0;
\r
1981 if (p != el && !pe.isStyle('overflow','visible')) {
\r
1986 p = p.offsetParent;
\r
1989 if (Ext.isSafari && hasAbsolute) {
\r
1990 x -= bd.offsetLeft;
\r
1991 y -= bd.offsetTop;
\r
1994 if (Ext.isGecko && !hasAbsolute) {
\r
1996 x += PARSEINT(dbd.getStyle("borderLeftWidth"), 10) || 0;
\r
1997 y += PARSEINT(dbd.getStyle("borderTopWidth"), 10) || 0;
\r
2000 p = el.parentNode;
\r
2001 while (p && p != bd) {
\r
2002 if (!Ext.isOpera || (p.tagName != 'TR' && !fly(p).isStyle("display", "inline"))) {
\r
2003 x -= p.scrollLeft;
\r
2014 setXY : function(el, xy) {
\r
2015 (el = Ext.fly(el, '_setXY')).position();
\r
2017 var pts = el.translatePoints(xy),
\r
2018 style = el.dom.style,
\r
2021 for (pos in pts) {
\r
2022 if(!isNaN(pts[pos])) style[pos] = pts[pos] + "px"
\r
2026 setX : function(el, x) {
\r
2027 this.setXY(el, [x, false]);
\r
2030 setY : function(el, y) {
\r
2031 this.setXY(el, [false, y]);
\r
2034 })();Ext.lib.Dom.getRegion = function(el) {
\r
2035 return Ext.lib.Region.getRegion(el);
\r
2036 };Ext.lib.Event = function() {
2037 var loadComplete = false,
2038 unloadListeners = {},
2055 SCROLLLEFT = 'scrollLeft',
2056 SCROLLTOP = 'scrollTop',
2058 MOUSEOVER = 'mouseover',
2059 MOUSEOUT = 'mouseout',
2061 doAdd = function() {
2063 if (win.addEventListener) {
2064 ret = function(el, eventName, fn, capture) {
2065 if (eventName == 'mouseenter') {
2066 fn = fn.createInterceptor(checkRelatedTarget);
2067 el.addEventListener(MOUSEOVER, fn, (capture));
2068 } else if (eventName == 'mouseleave') {
2069 fn = fn.createInterceptor(checkRelatedTarget);
2070 el.addEventListener(MOUSEOUT, fn, (capture));
2072 el.addEventListener(eventName, fn, (capture));
2076 } else if (win.attachEvent) {
2077 ret = function(el, eventName, fn, capture) {
2078 el.attachEvent("on" + eventName, fn);
2087 doRemove = function(){
2089 if (win.removeEventListener) {
2090 ret = function (el, eventName, fn, capture) {
2091 if (eventName == 'mouseenter') {
2092 eventName = MOUSEOVER;
2093 } else if (eventName == 'mouseleave') {
2094 eventName = MOUSEOUT;
2096 el.removeEventListener(eventName, fn, (capture));
2098 } else if (win.detachEvent) {
2099 ret = function (el, eventName, fn) {
2100 el.detachEvent("on" + eventName, fn);
2108 function checkRelatedTarget(e) {
2109 return !elContains(e.currentTarget, pub.getRelatedTarget(e));
2112 function elContains(parent, child) {
2113 if(parent && parent.firstChild){
2115 if(child === parent) {
2118 child = child.parentNode;
2119 if(child && (child.nodeType != 1)) {
2128 function _tryPreloadAttach() {
2132 tryAgain = !loadComplete || (retryCount > 0);
2137 for (i = 0, len = onAvailStack.length; i < len; i++) {
2138 v = onAvailStack[i];
2139 if(v && (element = doc.getElementById(v.id))){
2140 if(!v.checkReady || loadComplete || element.nextSibling || (doc && doc.body)) {
2141 element = v.override ? (v.override === true ? v.obj : v.override) : element;
2142 v.fn.call(element, v.obj);
2143 onAvailStack.remove(v);
2150 retryCount = (notAvail.length === 0) ? 0 : retryCount - 1;
2155 clearInterval(_interval);
2159 ret = !(locked = false);
2165 function startInterval() {
2167 var callback = function() {
2168 _tryPreloadAttach();
2170 _interval = setInterval(callback, POLL_INTERVAL);
2175 function getScroll() {
2176 var dd = doc.documentElement,
2178 if(dd && (dd[SCROLLTOP] || dd[SCROLLLEFT])){
2179 return [dd[SCROLLLEFT], dd[SCROLLTOP]];
2181 return [db[SCROLLLEFT], db[SCROLLTOP]];
2188 function getPageCoord (ev, xy) {
2189 ev = ev.browserEvent || ev;
2190 var coord = ev['page' + xy];
2191 if (!coord && coord !== 0) {
2192 coord = ev['client' + xy] || 0;
2195 coord += getScroll()[xy == "X" ? 0 : 1];
2204 onAvailable : function(p_id, p_fn, p_obj, p_override) {
2209 override: p_override,
2210 checkReady: false });
2212 retryCount = POLL_RETRYS;
2216 // This function should ALWAYS be called from Ext.EventManager
2217 addListener: function(el, eventName, fn) {
2218 el = Ext.getDom(el);
2220 if (eventName == UNLOAD) {
2221 if (unloadListeners[el.id] === undefined) {
2222 unloadListeners[el.id] = [];
2224 unloadListeners[el.id].push([eventName, fn]);
2227 return doAdd(el, eventName, fn, false);
2232 // This function should ALWAYS be called from Ext.EventManager
2233 removeListener: function(el, eventName, fn) {
2234 el = Ext.getDom(el);
2235 var i, len, li, lis;
2237 if(eventName == UNLOAD){
2238 if((lis = unloadListeners[el.id]) !== undefined){
2239 for(i = 0, len = lis.length; i < len; i++){
2240 if((li = lis[i]) && li[TYPE] == eventName && li[FN] == fn){
2241 unloadListeners[el.id].splice(i, 1);
2247 doRemove(el, eventName, fn, false);
2251 getTarget : function(ev) {
2252 ev = ev.browserEvent || ev;
2253 return this.resolveTextNode(ev.target || ev.srcElement);
2256 resolveTextNode : Ext.isGecko ? function(node){
2260 // work around firefox bug, https://bugzilla.mozilla.org/show_bug.cgi?id=101197
2261 var s = HTMLElement.prototype.toString.call(node);
2262 if(s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]'){
2265 return node.nodeType == 3 ? node.parentNode : node;
2267 return node && node.nodeType == 3 ? node.parentNode : node;
2270 getRelatedTarget : function(ev) {
2271 ev = ev.browserEvent || ev;
2272 return this.resolveTextNode(ev.relatedTarget ||
2273 (ev.type == MOUSEOUT ? ev.toElement :
2274 ev.type == MOUSEOVER ? ev.fromElement : null));
2277 getPageX : function(ev) {
2278 return getPageCoord(ev, "X");
2281 getPageY : function(ev) {
2282 return getPageCoord(ev, "Y");
2286 getXY : function(ev) {
2287 return [this.getPageX(ev), this.getPageY(ev)];
2290 stopEvent : function(ev) {
2291 this.stopPropagation(ev);
2292 this.preventDefault(ev);
2295 stopPropagation : function(ev) {
2296 ev = ev.browserEvent || ev;
2297 if (ev.stopPropagation) {
2298 ev.stopPropagation();
2300 ev.cancelBubble = true;
2304 preventDefault : function(ev) {
2305 ev = ev.browserEvent || ev;
2306 if (ev.preventDefault) {
2307 ev.preventDefault();
2309 ev.returnValue = false;
2313 getEvent : function(e) {
2316 var c = this.getEvent.caller;
2319 if (e && Event == e.constructor) {
2328 getCharCode : function(ev) {
2329 ev = ev.browserEvent || ev;
2330 return ev.charCode || ev.keyCode || 0;
2333 //clearCache: function() {},
2334 // deprecated, call from EventManager
2335 getListeners : function(el, eventName) {
2336 Ext.EventManager.getListeners(el, eventName);
2339 // deprecated, call from EventManager
2340 purgeElement : function(el, recurse, eventName) {
2341 Ext.EventManager.purgeElement(el, recurse, eventName);
2344 _load : function(e) {
2345 loadComplete = true;
2346 var EU = Ext.lib.Event;
2347 if (Ext.isIE && e !== true) {
2348 // IE8 complains that _load is null or not an object
2349 // so lets remove self via arguments.callee
2350 doRemove(win, "load", arguments.callee);
2354 _unload : function(e) {
2355 var EU = Ext.lib.Event,
2356 i, j, l, v, ul, id, len, index, scope;
2359 for (id in unloadListeners) {
2360 ul = unloadListeners[id];
2361 for (i = 0, len = ul.length; i < len; i++) {
2365 scope = v[ADJ_SCOPE] ? (v[ADJ_SCOPE] === true ? v[OBJ] : v[ADJ_SCOPE]) : win;
2366 v[FN].call(scope, EU.getEvent(e), v[OBJ]);
2372 unloadListeners = null;
2373 Ext.EventManager._unload();
2375 doRemove(win, UNLOAD, EU._unload);
2379 // Initialize stuff.
2380 pub.on = pub.addListener;
2381 pub.un = pub.removeListener;
2382 if (doc && doc.body) {
2385 doAdd(win, "load", pub._load);
2387 doAdd(win, UNLOAD, pub._unload);
2388 _tryPreloadAttach();
2393 * Portions of this file are based on pieces of Yahoo User Interface Library
\r
2394 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
\r
2395 * YUI licensed under the BSD License:
\r
2396 * http://developer.yahoo.net/yui/license.txt
\r
2398 Ext.lib.Ajax = function() {
\r
2399 var activeX = ['MSXML2.XMLHTTP.3.0',
\r
2401 'Microsoft.XMLHTTP'],
\r
2402 CONTENTTYPE = 'Content-Type';
\r
2405 function setHeader(o) {
\r
2406 var conn = o.conn,
\r
2409 function setTheHeaders(conn, headers){
\r
2410 for (prop in headers) {
\r
2411 if (headers.hasOwnProperty(prop)) {
\r
2412 conn.setRequestHeader(prop, headers[prop]);
\r
2417 if (pub.defaultHeaders) {
\r
2418 setTheHeaders(conn, pub.defaultHeaders);
\r
2421 if (pub.headers) {
\r
2422 setTheHeaders(conn, pub.headers);
\r
2423 delete pub.headers;
\r
2428 function createExceptionObject(tId, callbackArg, isAbort, isTimeout) {
\r
2431 status : isAbort ? -1 : 0,
\r
2432 statusText : isAbort ? 'transaction aborted' : 'communication failure',
\r
2434 isTimeout: isTimeout,
\r
2435 argument : callbackArg
\r
2440 function initHeader(label, value) {
\r
2441 (pub.headers = pub.headers || {})[label] = value;
\r
2445 function createResponseObject(o, callbackArg) {
\r
2446 var headerObj = {},
\r
2453 headerStr = o.conn.getAllResponseHeaders();
\r
2454 Ext.each(headerStr.replace(/\r\n/g, '\n').split('\n'), function(v){
\r
2455 t = v.indexOf(':');
\r
2457 s = v.substr(0, t).toLowerCase();
\r
2458 if(v.charAt(t + 1) == ' '){
\r
2461 headerObj[s] = v.substr(t + 1);
\r
2468 status : conn.status,
\r
2469 statusText : conn.statusText,
\r
2470 getResponseHeader : function(header){return headerObj[header.toLowerCase()];},
\r
2471 getAllResponseHeaders : function(){return headerStr},
\r
2472 responseText : conn.responseText,
\r
2473 responseXML : conn.responseXML,
\r
2474 argument : callbackArg
\r
2479 function releaseObject(o) {
\r
2485 function handleTransactionResponse(o, callback, isAbort, isTimeout) {
\r
2491 var httpStatus, responseObject;
\r
2494 if (o.conn.status !== undefined && o.conn.status != 0) {
\r
2495 httpStatus = o.conn.status;
\r
2498 httpStatus = 13030;
\r
2502 httpStatus = 13030;
\r
2505 if ((httpStatus >= 200 && httpStatus < 300) || (Ext.isIE && httpStatus == 1223)) {
\r
2506 responseObject = createResponseObject(o, callback.argument);
\r
2507 if (callback.success) {
\r
2508 if (!callback.scope) {
\r
2509 callback.success(responseObject);
\r
2512 callback.success.apply(callback.scope, [responseObject]);
\r
2517 switch (httpStatus) {
\r
2524 responseObject = createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false), isTimeout);
\r
2525 if (callback.failure) {
\r
2526 if (!callback.scope) {
\r
2527 callback.failure(responseObject);
\r
2530 callback.failure.apply(callback.scope, [responseObject]);
\r
2535 responseObject = createResponseObject(o, callback.argument);
\r
2536 if (callback.failure) {
\r
2537 if (!callback.scope) {
\r
2538 callback.failure(responseObject);
\r
2541 callback.failure.apply(callback.scope, [responseObject]);
\r
2548 responseObject = null;
\r
2552 function handleReadyState(o, callback){
\r
2553 callback = callback || {};
\r
2554 var conn = o.conn,
\r
2557 cbTimeout = callback.timeout || null;
\r
2560 pub.timeout[tId] = setTimeout(function() {
\r
2561 pub.abort(o, callback, true);
\r
2565 poll[tId] = setInterval(
\r
2567 if (conn && conn.readyState == 4) {
\r
2568 clearInterval(poll[tId]);
\r
2572 clearTimeout(pub.timeout[tId]);
\r
2573 pub.timeout[tId] = null;
\r
2576 handleTransactionResponse(o, callback);
\r
2579 pub.pollInterval);
\r
2583 function asyncRequest(method, uri, callback, postData) {
\r
2584 var o = getConnectionObject() || null;
\r
2587 o.conn.open(method, uri, true);
\r
2589 if (pub.useDefaultXhrHeader) {
\r
2590 initHeader('X-Requested-With', pub.defaultXhrHeader);
\r
2593 if(postData && pub.useDefaultHeader && (!pub.headers || !pub.headers[CONTENTTYPE])){
\r
2594 initHeader(CONTENTTYPE, pub.defaultPostHeader);
\r
2597 if (pub.defaultHeaders || pub.headers) {
\r
2601 handleReadyState(o, callback);
\r
2602 o.conn.send(postData || null);
\r
2608 function getConnectionObject() {
\r
2612 if (o = createXhrObject(pub.transactionId)) {
\r
2613 pub.transactionId++;
\r
2622 function createXhrObject(transactionId) {
\r
2626 http = new XMLHttpRequest();
\r
2628 for (var i = 0; i < activeX.length; ++i) {
\r
2630 http = new ActiveXObject(activeX[i]);
\r
2635 return {conn : http, tId : transactionId};
\r
2640 request : function(method, uri, cb, data, options) {
\r
2643 xmlData = options.xmlData,
\r
2644 jsonData = options.jsonData,
\r
2647 Ext.applyIf(me, options);
\r
2649 if(xmlData || jsonData){
\r
2651 if(!hs || !hs[CONTENTTYPE]){
\r
2652 initHeader(CONTENTTYPE, xmlData ? 'text/xml' : 'application/json');
\r
2654 data = xmlData || (!Ext.isPrimitive(jsonData) ? Ext.encode(jsonData) : jsonData);
\r
2657 return asyncRequest(method || options.method || "POST", uri, cb, data);
\r
2660 serializeForm : function(form) {
\r
2661 var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements,
\r
2662 hasSubmit = false,
\r
2663 encoder = encodeURIComponent,
\r
2671 Ext.each(fElements, function(element) {
\r
2672 name = element.name;
\r
2673 type = element.type;
\r
2675 if (!element.disabled && name){
\r
2676 if(/select-(one|multiple)/i.test(type)) {
\r
2677 Ext.each(element.options, function(opt) {
\r
2678 if (opt.selected) {
\r
2679 data += String.format("{0}={1}&", encoder(name), encoder((opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttribute('value') !== null) ? opt.value : opt.text));
\r
2682 } else if(!/file|undefined|reset|button/i.test(type)) {
\r
2683 if(!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit)){
\r
2685 data += encoder(name) + '=' + encoder(element.value) + '&';
\r
2686 hasSubmit = /submit/i.test(type);
\r
2691 return data.substr(0, data.length - 1);
\r
2694 useDefaultHeader : true,
\r
2695 defaultPostHeader : 'application/x-www-form-urlencoded; charset=UTF-8',
\r
2696 useDefaultXhrHeader : true,
\r
2697 defaultXhrHeader : 'XMLHttpRequest',
\r
2700 pollInterval : 50,
\r
2701 transactionId : 0,
\r
2703 // This is never called - Is it worth exposing this?
\r
2704 // setProgId : function(id) {
\r
2705 // activeX.unshift(id);
\r
2708 // This is never called - Is it worth exposing this?
\r
2709 // setDefaultPostHeader : function(b) {
\r
2710 // this.useDefaultHeader = b;
\r
2713 // This is never called - Is it worth exposing this?
\r
2714 // setDefaultXhrHeader : function(b) {
\r
2715 // this.useDefaultXhrHeader = b;
\r
2718 // This is never called - Is it worth exposing this?
\r
2719 // setPollingInterval : function(i) {
\r
2720 // if (typeof i == 'number' && isFinite(i)) {
\r
2721 // this.pollInterval = i;
\r
2725 // This is never called - Is it worth exposing this?
\r
2726 // resetDefaultHeaders : function() {
\r
2727 // this.defaultHeaders = null;
\r
2730 abort : function(o, callback, isTimeout) {
\r
2735 if (me.isCallInProgress(o)) {
\r
2737 clearInterval(me.poll[tId]);
\r
2738 me.poll[tId] = null;
\r
2739 clearTimeout(pub.timeout[tId]);
\r
2740 me.timeout[tId] = null;
\r
2742 handleTransactionResponse(o, callback, (isAbort = true), isTimeout);
\r
2747 isCallInProgress : function(o) {
\r
2748 // if there is a connection and readyState is not 0 or 4
\r
2749 return o.conn && !{0:true,4:true}[o.conn.readyState];
\r
2753 }(); Ext.lib.Region = function(t, r, b, l) {
\r
2763 Ext.lib.Region.prototype = {
\r
2764 contains : function(region) {
\r
2766 return ( region.left >= me.left &&
\r
2767 region.right <= me.right &&
\r
2768 region.top >= me.top &&
\r
2769 region.bottom <= me.bottom );
\r
2773 getArea : function() {
\r
2775 return ( (me.bottom - me.top) * (me.right - me.left) );
\r
2778 intersect : function(region) {
\r
2780 t = Math.max(me.top, region.top),
\r
2781 r = Math.min(me.right, region.right),
\r
2782 b = Math.min(me.bottom, region.bottom),
\r
2783 l = Math.max(me.left, region.left);
\r
2785 if (b >= t && r >= l) {
\r
2786 return new Ext.lib.Region(t, r, b, l);
\r
2790 union : function(region) {
\r
2792 t = Math.min(me.top, region.top),
\r
2793 r = Math.max(me.right, region.right),
\r
2794 b = Math.max(me.bottom, region.bottom),
\r
2795 l = Math.min(me.left, region.left);
\r
2797 return new Ext.lib.Region(t, r, b, l);
\r
2800 constrainTo : function(r) {
\r
2802 me.top = me.top.constrain(r.top, r.bottom);
\r
2803 me.bottom = me.bottom.constrain(r.top, r.bottom);
\r
2804 me.left = me.left.constrain(r.left, r.right);
\r
2805 me.right = me.right.constrain(r.left, r.right);
\r
2809 adjust : function(t, l, b, r) {
\r
2819 Ext.lib.Region.getRegion = function(el) {
\r
2820 var p = Ext.lib.Dom.getXY(el),
\r
2822 r = p[0] + el.offsetWidth,
\r
2823 b = p[1] + el.offsetHeight,
\r
2826 return new Ext.lib.Region(t, r, b, l);
\r
2827 }; Ext.lib.Point = function(x, y) {
\r
2828 if (Ext.isArray(x)) {
\r
2833 me.x = me.right = me.left = me[0] = x;
\r
2834 me.y = me.top = me.bottom = me[1] = y;
\r
2837 Ext.lib.Point.prototype = new Ext.lib.Region();
\r
2839 var EXTLIB = Ext.lib,
\r
2840 noNegatives = /width|height|opacity|padding/i,
\r
2841 offsetAttribute = /^((width|height)|(top|left))$/,
\r
2842 defaultUnit = /width|height|top$|bottom$|left$|right$/i,
\r
2843 offsetUnit = /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i,
\r
2844 isset = function(v){
\r
2845 return typeof v !== 'undefined';
\r
2848 return new Date();
\r
2852 motion : function(el, args, duration, easing, cb, scope) {
\r
2853 return this.run(el, args, duration, easing, cb, scope, Ext.lib.Motion);
\r
2856 run : function(el, args, duration, easing, cb, scope, type) {
\r
2857 type = type || Ext.lib.AnimBase;
\r
2858 if (typeof easing == "string") {
\r
2859 easing = Ext.lib.Easing[easing];
\r
2861 var anim = new type(el, args, duration, easing);
\r
2862 anim.animateX(function() {
\r
2863 if(Ext.isFunction(cb)){
\r
2871 EXTLIB.AnimBase = function(el, attributes, duration, method) {
\r
2873 this.init(el, attributes, duration, method);
\r
2877 EXTLIB.AnimBase.prototype = {
\r
2878 doMethod: function(attr, start, end) {
\r
2880 return me.method(me.curFrame, start, end - start, me.totalFrames);
\r
2884 setAttr: function(attr, val, unit) {
\r
2885 if (noNegatives.test(attr) && val < 0) {
\r
2888 Ext.fly(this.el, '_anim').setStyle(attr, val + unit);
\r
2892 getAttr: function(attr) {
\r
2893 var el = Ext.fly(this.el),
\r
2894 val = el.getStyle(attr),
\r
2895 a = offsetAttribute.exec(attr) || []
\r
2897 if (val !== 'auto' && !offsetUnit.test(val)) {
\r
2898 return parseFloat(val);
\r
2901 return (!!(a[2]) || (el.getStyle('position') == 'absolute' && !!(a[3]))) ? el.dom['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)] : 0;
\r
2905 getDefaultUnit: function(attr) {
\r
2906 return defaultUnit.test(attr) ? 'px' : '';
\r
2909 animateX : function(callback, scope) {
\r
2912 me.onComplete.removeListener(f);
\r
2913 if (Ext.isFunction(callback)) {
\r
2914 callback.call(scope || me, me);
\r
2917 me.onComplete.addListener(f, me);
\r
2922 setRunAttr: function(attr) {
\r
2924 a = this.attributes[attr],
\r
2929 ra = (this.runAttrs[attr] = {}),
\r
2932 if (!isset(to) && !isset(by)){
\r
2936 var start = isset(from) ? from : me.getAttr(attr);
\r
2939 }else if(isset(by)) {
\r
2940 if (Ext.isArray(start)){
\r
2942 for(var i=0,len=start.length; i<len; i++) {
\r
2943 end[i] = start[i] + by[i];
\r
2953 unit: isset(unit) ? unit : me.getDefaultUnit(attr)
\r
2958 init: function(el, attributes, duration, method) {
\r
2961 mgr = EXTLIB.AnimMgr;
\r
2964 isAnimated: false,
\r
2966 el: Ext.getDom(el),
\r
2967 attributes: attributes || {},
\r
2968 duration: duration || 1,
\r
2969 method: method || EXTLIB.Easing.easeNone,
\r
2972 totalFrames: mgr.fps,
\r
2974 animate: function(){
\r
2978 if(me.isAnimated){
\r
2983 me.totalFrames = me.useSec ? Math.ceil(mgr.fps * d) : d;
\r
2984 mgr.registerElement(me);
\r
2987 stop: function(finish){
\r
2991 me.curFrame = me.totalFrames;
\r
2992 me._onTween.fire();
\r
2998 var onStart = function(){
\r
3002 me.onStart.fire();
\r
3004 for(attr in this.attributes){
\r
3005 this.setRunAttr(attr);
\r
3008 me.isAnimated = true;
\r
3009 me.startTime = now();
\r
3014 var onTween = function(){
\r
3018 duration: now() - me.startTime,
\r
3019 curFrame: me.curFrame
\r
3022 var ra = me.runAttrs;
\r
3023 for (var attr in ra) {
\r
3024 this.setAttr(attr, me.doMethod(attr, ra[attr].start, ra[attr].end), ra[attr].unit);
\r
3030 var onComplete = function() {
\r
3032 actual = (now() - me.startTime) / 1000,
\r
3035 frames: actualFrames,
\r
3036 fps: actualFrames / actual
\r
3039 me.isAnimated = false;
\r
3041 me.onComplete.fire(data);
\r
3044 me.onStart = new Ext.util.Event(me);
\r
3045 me.onTween = new Ext.util.Event(me);
\r
3046 me.onComplete = new Ext.util.Event(me);
\r
3047 (me._onStart = new Ext.util.Event(me)).addListener(onStart);
\r
3048 (me._onTween = new Ext.util.Event(me)).addListener(onTween);
\r
3049 (me._onComplete = new Ext.util.Event(me)).addListener(onComplete);
\r
3054 Ext.lib.AnimMgr = new function() {
\r
3064 registerElement: function(tween){
\r
3065 queue.push(tween);
\r
3067 tween._onStart.fire();
\r
3071 unRegister: function(tween, index){
\r
3072 tween._onComplete.fire();
\r
3073 index = index || getIndex(tween);
\r
3074 if (index != -1) {
\r
3075 queue.splice(index, 1);
\r
3078 if (--tweenCount <= 0) {
\r
3083 start: function(){
\r
3084 if(thread === null){
\r
3085 thread = setInterval(me.run, me.delay);
\r
3089 stop: function(tween){
\r
3091 clearInterval(thread);
\r
3092 for(var i = 0, len = queue.length; i < len; ++i){
\r
3093 if(queue[0].isAnimated){
\r
3094 me.unRegister(queue[0], 0);
\r
3102 me.unRegister(tween);
\r
3107 var tf, i, len, tween;
\r
3108 for(i = 0, len = queue.length; i<len; i++) {
\r
3110 if(tween && tween.isAnimated){
\r
3111 tf = tween.totalFrames;
\r
3112 if(tween.curFrame < tf || tf === null){
\r
3115 correctFrame(tween);
\r
3117 tween._onTween.fire();
\r
3126 var getIndex = function(anim) {
\r
3128 for(i = 0, len = queue.length; i<len; i++) {
\r
3129 if(queue[i] === anim) {
\r
3136 var correctFrame = function(tween) {
\r
3137 var frames = tween.totalFrames,
\r
3138 frame = tween.curFrame,
\r
3139 duration = tween.duration,
\r
3140 expected = (frame * duration * 1000 / frames),
\r
3141 elapsed = (now() - tween.startTime),
\r
3144 if(elapsed < duration * 1000){
\r
3145 tweak = Math.round((elapsed / expected - 1) * frame);
\r
3147 tweak = frames - (frame + 1);
\r
3149 if(tweak > 0 && isFinite(tweak)){
\r
3150 if(tween.curFrame + tweak >= frames){
\r
3151 tweak = frames - (frame + 1);
\r
3153 tween.curFrame += tweak;
\r
3158 EXTLIB.Bezier = new function() {
\r
3160 this.getPosition = function(points, t) {
\r
3161 var n = points.length,
\r
3167 for (i = 0; i < n; ++i) {
\r
3168 tmp[i] = [points[i][0], points[i][1]];
\r
3171 for (j = 1; j < n; ++j) {
\r
3172 for (i = 0; i < n - j; ++i) {
\r
3173 tmp[i][0] = c * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
\r
3174 tmp[i][1] = c * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
\r
3178 return [ tmp[0][0], tmp[0][1] ];
\r
3185 easeNone: function (t, b, c, d) {
\r
3186 return c * t / d + b;
\r
3190 easeIn: function (t, b, c, d) {
\r
3191 return c * (t /= d) * t + b;
\r
3195 easeOut: function (t, b, c, d) {
\r
3196 return -c * (t /= d) * (t - 2) + b;
\r
3201 EXTLIB.Motion = function(el, attributes, duration, method) {
\r
3203 EXTLIB.Motion.superclass.constructor.call(this, el, attributes, duration, method);
\r
3207 Ext.extend(EXTLIB.Motion, Ext.lib.AnimBase);
\r
3209 var superclass = EXTLIB.Motion.superclass,
\r
3210 proto = EXTLIB.Motion.prototype,
\r
3211 pointsRe = /^points$/i;
\r
3213 Ext.apply(EXTLIB.Motion.prototype, {
\r
3214 setAttr: function(attr, val, unit){
\r
3216 setAttr = superclass.setAttr;
\r
3218 if (pointsRe.test(attr)) {
\r
3219 unit = unit || 'px';
\r
3220 setAttr.call(me, 'left', val[0], unit);
\r
3221 setAttr.call(me, 'top', val[1], unit);
\r
3223 setAttr.call(me, attr, val, unit);
\r
3227 getAttr: function(attr){
\r
3229 getAttr = superclass.getAttr;
\r
3231 return pointsRe.test(attr) ? [getAttr.call(me, 'left'), getAttr.call(me, 'top')] : getAttr.call(me, attr);
\r
3234 doMethod: function(attr, start, end){
\r
3237 return pointsRe.test(attr)
\r
3238 ? EXTLIB.Bezier.getPosition(me.runAttrs[attr], me.method(me.curFrame, 0, 100, me.totalFrames) / 100)
\r
3239 : superclass.doMethod.call(me, attr, start, end);
\r
3242 setRunAttr: function(attr){
\r
3243 if(pointsRe.test(attr)){
\r
3247 points = this.attributes.points,
\r
3248 control = points.control || [],
\r
3249 from = points.from,
\r
3260 if(control.length > 0 && !Ext.isArray(control[0])){
\r
3261 control = [control];
\r
3265 for (i = 0,len = control.length; i < len; ++i) {
\r
3266 tmp[i] = control[i];
\r
3272 Ext.fly(el, '_anim').position();
\r
3273 DOM.setXY(el, isset(from) ? from : DOM.getXY(el));
\r
3274 start = me.getAttr('points');
\r
3278 end = translateValues.call(me, to, start);
\r
3279 for (i = 0,len = control.length; i < len; ++i) {
\r
3280 control[i] = translateValues.call(me, control[i], start);
\r
3282 } else if (isset(by)) {
\r
3283 end = [start[0] + by[0], start[1] + by[1]];
\r
3285 for (i = 0,len = control.length; i < len; ++i) {
\r
3286 control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
\r
3290 ra = this.runAttrs[attr] = [start];
\r
3291 if (control.length > 0) {
\r
3292 ra = ra.concat(control);
\r
3295 ra[ra.length] = end;
\r
3297 superclass.setRunAttr.call(this, attr);
\r
3302 var translateValues = function(val, start) {
\r
3303 var pageXY = EXTLIB.Dom.getXY(this.el);
\r
3304 return [val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1]];
\r
3307 })();// Easing functions
\r
3309 // shortcuts to aid compression
\r
3310 var abs = Math.abs,
\r
3317 Ext.apply(EXTLIB.Easing, {
\r
3319 easeBoth: function (t, b, c, d) {
\r
3320 return ((t /= d / 2) < 1) ? c / 2 * t * t + b : -c / 2 * ((--t) * (t - 2) - 1) + b;
\r
3323 easeInStrong: function (t, b, c, d) {
\r
3324 return c * (t /= d) * t * t * t + b;
\r
3327 easeOutStrong: function (t, b, c, d) {
\r
3328 return -c * ((t = t / d - 1) * t * t * t - 1) + b;
\r
3331 easeBothStrong: function (t, b, c, d) {
\r
3332 return ((t /= d / 2) < 1) ? c / 2 * t * t * t * t + b : -c / 2 * ((t -= 2) * t * t * t - 2) + b;
\r
3335 elasticIn: function (t, b, c, d, a, p) {
\r
3336 if (t == 0 || (t /= d) == 1) {
\r
3337 return t == 0 ? b : b + c;
\r
3339 p = p || (d * .3);
\r
3342 if (a >= abs(c)) {
\r
3343 s = p / (2 * pi) * asin(c / a);
\r
3349 return -(a * pow(2, 10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p)) + b;
\r
3353 elasticOut: function (t, b, c, d, a, p) {
\r
3354 if (t == 0 || (t /= d) == 1) {
\r
3355 return t == 0 ? b : b + c;
\r
3357 p = p || (d * .3);
\r
3360 if (a >= abs(c)) {
\r
3361 s = p / (2 * pi) * asin(c / a);
\r
3367 return a * pow(2, -10 * t) * sin((t * d - s) * (2 * pi) / p) + c + b;
\r
3370 elasticBoth: function (t, b, c, d, a, p) {
\r
3371 if (t == 0 || (t /= d / 2) == 2) {
\r
3372 return t == 0 ? b : b + c;
\r
3375 p = p || (d * (.3 * 1.5));
\r
3378 if (a >= abs(c)) {
\r
3379 s = p / (2 * pi) * asin(c / a);
\r
3386 -.5 * (a * pow(2, 10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p)) + b :
\r
3387 a * pow(2, -10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p) * .5 + c + b;
\r
3390 backIn: function (t, b, c, d, s) {
\r
3391 s = s || 1.70158;
\r
3392 return c * (t /= d) * t * ((s + 1) * t - s) + b;
\r
3396 backOut: function (t, b, c, d, s) {
\r
3400 return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
\r
3404 backBoth: function (t, b, c, d, s) {
\r
3405 s = s || 1.70158;
\r
3407 return ((t /= d / 2 ) < 1) ?
\r
3408 c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b :
\r
3409 c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
\r
3413 bounceIn: function (t, b, c, d) {
\r
3414 return c - EXTLIB.Easing.bounceOut(d - t, 0, c, d) + b;
\r
3418 bounceOut: function (t, b, c, d) {
\r
3419 if ((t /= d) < (1 / 2.75)) {
\r
3420 return c * (7.5625 * t * t) + b;
\r
3421 } else if (t < (2 / 2.75)) {
\r
3422 return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
\r
3423 } else if (t < (2.5 / 2.75)) {
\r
3424 return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
\r
3426 return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
\r
3430 bounceBoth: function (t, b, c, d) {
\r
3431 return (t < d / 2) ?
\r
3432 EXTLIB.Easing.bounceIn(t * 2, 0, c, d) * .5 + b :
\r
3433 EXTLIB.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
\r
3439 var EXTLIB = Ext.lib;
\r
3440 // Color Animation
\r
3441 EXTLIB.Anim.color = function(el, args, duration, easing, cb, scope) {
\r
3442 return EXTLIB.Anim.run(el, args, duration, easing, cb, scope, EXTLIB.ColorAnim);
\r
3445 EXTLIB.ColorAnim = function(el, attributes, duration, method) {
\r
3446 EXTLIB.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
\r
3449 Ext.extend(EXTLIB.ColorAnim, EXTLIB.AnimBase);
\r
3451 var superclass = EXTLIB.ColorAnim.superclass,
\r
3452 colorRE = /color$/i,
\r
3453 transparentRE = /^transparent|rgba\(0, 0, 0, 0\)$/,
\r
3454 rgbRE = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i,
\r
3455 hexRE= /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i,
\r
3456 hex3RE = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i,
\r
3457 isset = function(v){
\r
3458 return typeof v !== 'undefined';
\r
3462 function parseColor(s) {
\r
3463 var pi = parseInt,
\r
3468 if (s.length == 3) {
\r
3472 Ext.each([hexRE, rgbRE, hex3RE], function(re, idx){
\r
3473 base = (idx % 2 == 0) ? 16 : 10;
\r
3475 if(c && c.length == 4){
\r
3476 out = [pi(c[1], base), pi(c[2], base), pi(c[3], base)];
\r
3483 Ext.apply(EXTLIB.ColorAnim.prototype, {
\r
3484 getAttr : function(attr) {
\r
3488 if(colorRE.test(attr)){
\r
3489 while(el && transparentRE.test(val = Ext.fly(el).getStyle(attr))){
\r
3490 el = el.parentNode;
\r
3494 val = superclass.getAttr.call(me, attr);
\r
3499 doMethod : function(attr, start, end) {
\r
3502 floor = Math.floor,
\r
3507 if(colorRE.test(attr)){
\r
3510 for(i = 0, len = start.length; i < len; i++) {
\r
3512 val[i] = superclass.doMethod.call(me, attr, v, end[i]);
\r
3514 val = 'rgb(' + floor(val[0]) + ',' + floor(val[1]) + ',' + floor(val[2]) + ')';
\r
3516 val = superclass.doMethod.call(me, attr, start, end);
\r
3521 setRunAttr : function(attr) {
\r
3523 a = me.attributes[attr],
\r
3528 superclass.setRunAttr.call(me, attr);
\r
3529 ra = me.runAttrs[attr];
\r
3530 if(colorRE.test(attr)){
\r
3531 var start = parseColor(ra.start),
\r
3532 end = parseColor(ra.end);
\r
3534 if(!isset(to) && isset(by)){
\r
3535 end = parseColor(by);
\r
3536 for(var i=0,len=start.length; i<len; i++) {
\r
3537 end[i] = start[i] + end[i];
\r
3549 // Scroll Animation
\r
3550 var EXTLIB = Ext.lib;
\r
3551 EXTLIB.Anim.scroll = function(el, args, duration, easing, cb, scope) {
\r
3552 return EXTLIB.Anim.run(el, args, duration, easing, cb, scope, EXTLIB.Scroll);
\r
3555 EXTLIB.Scroll = function(el, attributes, duration, method) {
\r
3557 EXTLIB.Scroll.superclass.constructor.call(this, el, attributes, duration, method);
\r
3561 Ext.extend(EXTLIB.Scroll, EXTLIB.ColorAnim);
\r
3563 var superclass = EXTLIB.Scroll.superclass,
\r
3564 SCROLL = 'scroll';
\r
3566 Ext.apply(EXTLIB.Scroll.prototype, {
\r
3568 doMethod : function(attr, start, end) {
\r
3571 curFrame = me.curFrame,
\r
3572 totalFrames = me.totalFrames;
\r
3574 if(attr == SCROLL){
\r
3575 val = [me.method(curFrame, start[0], end[0] - start[0], totalFrames),
\r
3576 me.method(curFrame, start[1], end[1] - start[1], totalFrames)];
\r
3578 val = superclass.doMethod.call(me, attr, start, end);
\r
3583 getAttr : function(attr) {
\r
3586 if (attr == SCROLL) {
\r
3587 return [me.el.scrollLeft, me.el.scrollTop];
\r
3589 return superclass.getAttr.call(me, attr);
\r
3593 setAttr : function(attr, val, unit) {
\r
3596 if(attr == SCROLL){
\r
3597 me.el.scrollLeft = val[0];
\r
3598 me.el.scrollTop = val[1];
\r
3600 superclass.setAttr.call(me, attr, val, unit);
\r
3606 function fnCleanUp() {
\r
3607 var p = Function.prototype;
\r
3608 delete p.createSequence;
\r
3610 delete p.createDelegate;
\r
3611 delete p.createCallback;
\r
3612 delete p.createInterceptor;
\r
3614 window.detachEvent("onunload", fnCleanUp);
\r
3616 window.attachEvent("onunload", fnCleanUp);
\r