3 * Copyright(c) 2006-2009 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(/chrome/),
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 return (el = Ext.getDom(el) || {}).id = el.id || (prefix || "ext-gen") + (++idSeed);
168 * <p>Extends one class to create a subclass and optionally overrides members with the passed literal. This method
169 * also adds the function "override()" to the subclass that can be used to override members of the class.</p>
170 * For example, to create a subclass of Ext GridPanel:
172 MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
173 constructor: function(config) {
175 // Create configuration for this Grid.
176 var store = new Ext.data.Store({...});
177 var colModel = new Ext.grid.ColumnModel({...});
179 // Create a new config object containing our computed properties
180 // *plus* whatever was in the config parameter.
186 MyGridPanel.superclass.constructor.call(this, config);
188 // Your postprocessing here
191 yourMethod: function() {
197 * <p>This function also supports a 3-argument call in which the subclass's constructor is
198 * passed as an argument. In this form, the parameters are as follows:</p>
199 * <div class="mdetail-params"><ul>
200 * <li><code>subclass</code> : Function <div class="sub-desc">The subclass constructor.</div></li>
201 * <li><code>superclass</code> : Function <div class="sub-desc">The constructor of class being extended</div></li>
202 * <li><code>overrides</code> : Object <div class="sub-desc">A literal with members which are copied into the subclass's
203 * prototype, and are therefore shared among all instances of the new class.</div></li>
206 * @param {Function} superclass The constructor of class being extended.
207 * @param {Object} overrides <p>A literal with members which are copied into the subclass's
208 * prototype, and are therefore shared between all instances of the new class.</p>
209 * <p>This may contain a special member named <tt><b>constructor</b></tt>. This is used
210 * to define the constructor of the new class, and is returned. If this property is
211 * <i>not</i> specified, a constructor is generated and returned which just calls the
212 * superclass's constructor passing on its parameters.</p>
213 * <p><b>It is essential that you call the superclass constructor in any provided constructor. See example code.</b></p>
214 * @return {Function} The subclass constructor from the <code>overrides</code> parameter, or a generated one if not provided.
218 var io = function(o){
223 var oc = Object.prototype.constructor;
225 return function(sb, sp, overrides){
226 if(Ext.isObject(sp)){
229 sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
231 var F = function(){},
236 sbp = sb.prototype = new F();
239 if(spp.constructor == oc){
242 sb.override = function(o){
245 sbp.superclass = sbp.supr = (function(){
249 Ext.override(sb, overrides);
250 sb.extend = function(o){return Ext.extend(sb, o);};
256 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
258 Ext.override(MyClass, {
259 newMethod1: function(){
262 newMethod2: function(foo){
267 * @param {Object} origclass The class to override
268 * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
269 * containing one or more methods.
272 override : function(origclass, overrides){
274 var p = origclass.prototype;
275 Ext.apply(p, overrides);
276 if(Ext.isIE && overrides.hasOwnProperty('toString')){
277 p.toString = overrides.toString;
283 * Creates namespaces to be used for scoping variables and classes so that they are not global.
284 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
286 Ext.namespace('Company', 'Company.data');
287 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
288 Company.Widget = function() { ... }
289 Company.data.CustomStore = function(config) { ... }
291 * @param {String} namespace1
292 * @param {String} namespace2
293 * @param {String} etc
294 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
297 namespace : function(){
299 Ext.each(arguments, function(v) {
301 o = window[d[0]] = window[d[0]] || {};
302 Ext.each(d.slice(1), function(v2){
303 o = o[v2] = o[v2] || {};
310 * 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.
312 * @param {String} pre (optional) A prefix to add to the url encoded string
315 urlEncode : function(o, pre){
318 e = encodeURIComponent;
320 Ext.iterate(o, function(key, item){
321 empty = Ext.isEmpty(item);
322 Ext.each(empty ? key : item, function(val){
323 buf.push('&', e(key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : '');
330 return pre + buf.join('');
334 * Takes an encoded URL and and converts it to an object. Example: <pre><code>
335 Ext.urlDecode("foo=1&bar=2"); // returns {foo: "1", bar: "2"}
336 Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2", "3", "4"]}
338 * @param {String} string
339 * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
340 * @return {Object} A literal with members
342 urlDecode : function(string, overwrite){
343 if(Ext.isEmpty(string)){
347 pairs = string.split('&'),
348 d = decodeURIComponent,
351 Ext.each(pairs, function(pair) {
352 pair = pair.split('=');
355 obj[name] = overwrite || !obj[name] ? value :
356 [].concat(obj[name]).concat(value);
362 * Appends content to the query string of a URL, handling logic for whether to place
363 * a question mark or ampersand.
364 * @param {String} url The URL to append to.
365 * @param {String} s The content to append to the URL.
366 * @return (String) The resulting URL
368 urlAppend : function(url, s){
370 return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
376 * Converts any iterable (numeric indices and a length property) into a true array
377 * Don't use this on strings. IE doesn't support "abc"[0] which this implementation depends on.
378 * For strings, use this instead: "abc".match(/./g) => [a,b,c];
379 * @param {Iterable} the iterable object to be turned into a true Array.
380 * @return (Array) array
382 toArray : function(){
384 function(a, i, j, res){
386 for(var x = 0, len = a.length; x < len; x++) {
389 return res.slice(i || 0, j || res.length);
392 return Array.prototype.slice.call(a, i || 0, j || a.length);
396 isIterable : function(v){
397 //check for array or arguments
398 if(Ext.isArray(v) || v.callee){
401 //check for node list type
402 if(/NodeList|HTMLCollection/.test(toString.call(v))){
405 //NodeList has an item and length property
406 //IXMLDOMNodeList has nextNode method, needs to be checked first.
407 return ((v.nextNode || v.item) && Ext.isNumber(v.length));
411 * Iterates an array calling the supplied function.
412 * @param {Array/NodeList/Mixed} array The array to be iterated. If this
413 * argument is not really an array, the supplied function is called once.
414 * @param {Function} fn The function to be called with each item. If the
415 * supplied function returns false, iteration stops and this method returns
416 * the current <code>index</code>. This function is called with
417 * the following arguments:
418 * <div class="mdetail-params"><ul>
419 * <li><code>item</code> : <i>Mixed</i>
420 * <div class="sub-desc">The item at the current <code>index</code>
421 * in the passed <code>array</code></div></li>
422 * <li><code>index</code> : <i>Number</i>
423 * <div class="sub-desc">The current index within the array</div></li>
424 * <li><code>allItems</code> : <i>Array</i>
425 * <div class="sub-desc">The <code>array</code> passed as the first
426 * argument to <code>Ext.each</code>.</div></li>
428 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed.
429 * Defaults to the <code>item</code> at the current <code>index</code>
430 * within the passed <code>array</code>.
431 * @return See description for the fn parameter.
433 each : function(array, fn, scope){
434 if(Ext.isEmpty(array, true)){
437 if(!Ext.isIterable(array) || Ext.isPrimitive(array)){
440 for(var i = 0, len = array.length; i < len; i++){
441 if(fn.call(scope || array[i], array[i], i, array) === false){
448 * Iterates either the elements in an array, or each of the properties in an object.
449 * <b>Note</b>: If you are only iterating arrays, it is better to call {@link #each}.
450 * @param {Object/Array} object The object or array to be iterated
451 * @param {Function} fn The function to be called for each iteration.
452 * The iteration will stop if the supplied function returns false, or
453 * all array elements / object properties have been covered. The signature
454 * varies depending on the type of object being interated:
455 * <div class="mdetail-params"><ul>
456 * <li>Arrays : <tt>(Object item, Number index, Array allItems)</tt>
457 * <div class="sub-desc">
458 * When iterating an array, the supplied function is called with each item.</div></li>
459 * <li>Objects : <tt>(String key, Object value, Object)</tt>
460 * <div class="sub-desc">
461 * When iterating an object, the supplied function is called with each key-value pair in
462 * the object, and the iterated object</div></li>
464 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed. Defaults to
465 * the <code>object</code> being iterated.
467 iterate : function(obj, fn, scope){
468 if(Ext.isEmpty(obj)){
471 if(Ext.isIterable(obj)){
472 Ext.each(obj, fn, scope);
474 }else if(Ext.isObject(obj)){
475 for(var prop in obj){
476 if(obj.hasOwnProperty(prop)){
477 if(fn.call(scope || obj, prop, obj[prop], obj) === false){
486 * Return the dom node for the passed String (id), dom node, or Ext.Element.
487 * Here are some examples:
489 // gets dom node based on id
490 var elDom = Ext.getDom('elId');
491 // gets dom node based on the dom node
492 var elDom1 = Ext.getDom(elDom);
494 // If we don't know if we are working with an
495 // Ext.Element or a dom node use Ext.getDom
497 var dom = Ext.getDom(el);
498 // do something with the dom node
501 * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc)
502 * when this method is called to be successful.
504 * @return HTMLElement
506 getDom : function(el){
510 return el.dom ? el.dom : (Ext.isString(el) ? DOC.getElementById(el) : el);
514 * Returns the current document body as an {@link Ext.Element}.
515 * @return Ext.Element The document body
517 getBody : function(){
518 return Ext.get(DOC.body || DOC.documentElement);
522 * Removes a DOM node from the document.
525 * <p>Removes this element from the document, removes all DOM event listeners, and deletes the cache reference.
526 * All DOM event listeners are removed from this element. If {@link Ext#enableNestedListenerRemoval} is
527 * <code>true</code>, then DOM event listeners are also removed from all child nodes. The body node
528 * will be ignored if passed in.</p>
529 * @param {HTMLElement} node The node to remove
531 removeNode : isIE && !isIE8 ? function(){
534 if(n && n.tagName != 'BODY'){
535 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
536 d = d || DOC.createElement('div');
539 delete Ext.elCache[n.id];
543 if(n && n.parentNode && n.tagName != 'BODY'){
544 (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n, true) : Ext.EventManager.removeAll(n);
545 n.parentNode.removeChild(n);
546 delete Ext.elCache[n.id];
551 * <p>Returns true if the passed value is empty.</p>
552 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
555 * <li>an empty array</li>
556 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
558 * @param {Mixed} value The value to test
559 * @param {Boolean} allowBlank (optional) true to allow empty strings (defaults to false)
562 isEmpty : function(v, allowBlank){
563 return v === null || v === undefined || ((Ext.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false);
567 * Returns true if the passed value is a JavaScript array, otherwise false.
568 * @param {Mixed} value The value to test
571 isArray : function(v){
572 return toString.apply(v) === '[object Array]';
576 * Returns true if the passed object is a JavaScript date object, otherwise false.
577 * @param {Object} object The object to test
580 isDate : function(v){
581 return toString.apply(v) === '[object Date]';
585 * Returns true if the passed value is a JavaScript Object, otherwise false.
586 * @param {Mixed} value The value to test
589 isObject : function(v){
590 return !!v && Object.prototype.toString.call(v) === '[object Object]';
594 * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean.
595 * @param {Mixed} value The value to test
598 isPrimitive : function(v){
599 return Ext.isString(v) || Ext.isNumber(v) || Ext.isBoolean(v);
603 * Returns true if the passed value is a JavaScript Function, otherwise false.
604 * @param {Mixed} value The value to test
607 isFunction : function(v){
608 return toString.apply(v) === '[object Function]';
612 * Returns true if the passed value is a number. Returns false for non-finite numbers.
613 * @param {Mixed} value The value to test
616 isNumber : function(v){
617 return typeof v === 'number' && isFinite(v);
621 * Returns true if the passed value is a string.
622 * @param {Mixed} value The value to test
625 isString : function(v){
626 return typeof v === 'string';
630 * Returns true if the passed value is a boolean.
631 * @param {Mixed} value The value to test
634 isBoolean : function(v){
635 return typeof v === 'boolean';
639 * Returns true if the passed value is an HTMLElement
640 * @param {Mixed} value The value to test
643 isElement : function(v) {
644 return !!v && v.tagName;
648 * Returns true if the passed value is not undefined.
649 * @param {Mixed} value The value to test
652 isDefined : function(v){
653 return typeof v !== 'undefined';
657 * True if the detected browser is Opera.
662 * True if the detected browser uses WebKit.
667 * True if the detected browser is Chrome.
672 * True if the detected browser is Safari.
677 * True if the detected browser is Safari 3.x.
680 isSafari3 : isSafari3,
682 * True if the detected browser is Safari 4.x.
685 isSafari4 : isSafari4,
687 * True if the detected browser is Safari 2.x.
690 isSafari2 : isSafari2,
692 * True if the detected browser is Internet Explorer.
697 * True if the detected browser is Internet Explorer 6.x.
702 * True if the detected browser is Internet Explorer 7.x.
707 * True if the detected browser is Internet Explorer 8.x.
712 * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
717 * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x).
722 * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
727 * True if the detected browser is Internet Explorer running in non-strict mode.
730 isBorderBox : isBorderBox,
732 * True if the detected platform is Linux.
737 * True if the detected platform is Windows.
740 isWindows : isWindows,
742 * True if the detected platform is Mac OS.
747 * True if the detected platform is Adobe Air.
754 * Creates namespaces to be used for scoping variables and classes so that they are not global.
755 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
757 Ext.namespace('Company', 'Company.data');
758 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
759 Company.Widget = function() { ... }
760 Company.data.CustomStore = function(config) { ... }
762 * @param {String} namespace1
763 * @param {String} namespace2
764 * @param {String} etc
765 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
768 Ext.ns = Ext.namespace;
771 Ext.ns("Ext.util", "Ext.lib", "Ext.data");
777 * These functions are available on every Function object (any JavaScript function).
779 Ext.apply(Function.prototype, {
781 * Creates an interceptor function. The passed function is called before the original one. If it returns false,
782 * the original one is not called. The resulting function returns the results of the original function.
783 * The passed function is called with the parameters of the original function. Example usage:
785 var sayHi = function(name){
786 alert('Hi, ' + name);
789 sayHi('Fred'); // alerts "Hi, Fred"
791 // create a new function that validates input without
792 // directly modifying the original function:
793 var sayHiToFriend = sayHi.createInterceptor(function(name){
794 return name == 'Brian';
797 sayHiToFriend('Fred'); // no alert
798 sayHiToFriend('Brian'); // alerts "Hi, Brian"
800 * @param {Function} fcn The function to call before the original
801 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
802 * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
803 * @return {Function} The new function
805 createInterceptor : function(fcn, scope){
807 return !Ext.isFunction(fcn) ?
814 return (fcn.apply(scope || me || window, args) !== false) ?
815 method.apply(me || window, args) :
821 * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
822 * Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code>
823 * Will create a function that is bound to those 2 args. <b>If a specific scope is required in the
824 * callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always
825 * executes in the window scope.
826 * <p>This method is required when you want to pass arguments to a callback function. If no arguments
827 * are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn).
828 * However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function
829 * would simply execute immediately when the code is parsed. Example usage:
831 var sayHi = function(name){
832 alert('Hi, ' + name);
835 // clicking the button alerts "Hi, Fred"
838 renderTo: Ext.getBody(),
839 handler: sayHi.createCallback('Fred')
842 * @return {Function} The new function
844 createCallback : function(/*args...*/){
845 // make args available, in function below
846 var args = arguments,
849 return method.apply(window, args);
854 * Creates a delegate (callback) that sets the scope to obj.
855 * Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code>
856 * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
857 * callback points to obj. Example usage:
859 var sayHi = function(name){
860 // Note this use of "this.text" here. This function expects to
861 // execute within a scope that contains a text property. In this
862 // example, the "this" variable is pointing to the btn object that
863 // was passed in createDelegate below.
864 alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
867 var btn = new Ext.Button({
869 renderTo: Ext.getBody()
872 // This callback will execute in the scope of the
873 // button instance. Clicking the button alerts
874 // "Hi, Fred. You clicked the "Say Hi" button."
875 btn.on('click', sayHi.createDelegate(btn, ['Fred']));
877 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
878 * <b>If omitted, defaults to the browser window.</b>
879 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
880 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
881 * if a number the args are inserted at the specified position
882 * @return {Function} The new function
884 createDelegate : function(obj, args, appendArgs){
887 var callArgs = args || arguments;
888 if (appendArgs === true){
889 callArgs = Array.prototype.slice.call(arguments, 0);
890 callArgs = callArgs.concat(args);
891 }else if (Ext.isNumber(appendArgs)){
892 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
893 var applyArgs = [appendArgs, 0].concat(args); // create method call params
894 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
896 return method.apply(obj || window, callArgs);
901 * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
903 var sayHi = function(name){
904 alert('Hi, ' + name);
907 // executes immediately:
910 // executes after 2 seconds:
911 sayHi.defer(2000, this, ['Fred']);
913 // this syntax is sometimes useful for deferring
914 // execution of an anonymous function:
919 * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
920 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
921 * <b>If omitted, defaults to the browser window.</b>
922 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
923 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
924 * if a number the args are inserted at the specified position
925 * @return {Number} The timeout id that can be used with clearTimeout
927 defer : function(millis, obj, args, appendArgs){
928 var fn = this.createDelegate(obj, args, appendArgs);
930 return setTimeout(fn, millis);
939 * These functions are available on every String object.
941 Ext.applyIf(String, {
943 * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
944 * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
946 var cls = 'my-class', text = 'Some text';
947 var s = String.format('<div class="{0}">{1}</div>', cls, text);
948 // s now contains the string: '<div class="my-class">Some text</div>'
950 * @param {String} string The tokenized string to be formatted
951 * @param {String} value1 The value to replace token {0}
952 * @param {String} value2 Etc...
953 * @return {String} The formatted string
956 format : function(format){
957 var args = Ext.toArray(arguments, 1);
958 return format.replace(/\{(\d+)\}/g, function(m, i){
967 Ext.applyIf(Array.prototype, {
969 * Checks whether or not the specified object exists in the array.
970 * @param {Object} o The object to check for
971 * @param {Number} from (Optional) The index at which to begin the search
972 * @return {Number} The index of o in the array (or -1 if it is not found)
974 indexOf : function(o, from){
975 var len = this.length;
977 from += (from < 0) ? len : 0;
978 for (; from < len; ++from){
979 if(this[from] === o){
987 * Removes the specified object from the array. If the object is not found nothing happens.
988 * @param {Object} o The object to remove
989 * @return {Array} this array
991 remove : function(o){
992 var index = this.indexOf(o);
994 this.splice(index, 1);
1003 Ext.ns("Ext.grid", "Ext.list", "Ext.dd", "Ext.tree", "Ext.form", "Ext.menu",
1004 "Ext.state", "Ext.layout", "Ext.app", "Ext.ux", "Ext.chart", "Ext.direct");
1006 * Namespace alloted for extensions to the framework.
1011 Ext.apply(Ext, function(){
1018 * A reusable empty function
1022 emptyFn : function(){},
1025 * URL to a 1x1 transparent gif image used by Ext to create inline icons with CSS background images.
1026 * In older versions of IE, this defaults to "http://extjs.com/s.gif" and you should change this to a URL on your server.
1027 * For other browsers it uses an inline data URL.
1030 BLANK_IMAGE_URL : Ext.isIE6 || Ext.isIE7 || Ext.isAir ?
1031 'http:/' + '/extjs.com/s.gif' :
1032 'data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==',
1034 extendX : function(supr, fn){
1035 return Ext.extend(supr, fn(supr.prototype));
1039 * Returns the current HTML document object as an {@link Ext.Element}.
1040 * @return Ext.Element The document
1042 getDoc : function(){
1043 return Ext.get(document);
1047 * Utility method for validating that a value is numeric, returning the specified default value if it is not.
1048 * @param {Mixed} value Should be a number, but any type will be handled appropriately
1049 * @param {Number} defaultValue The value to return if the original value is non-numeric
1050 * @return {Number} Value, if numeric, else defaultValue
1052 num : function(v, defaultValue){
1053 v = Number(Ext.isEmpty(v) || Ext.isBoolean(v) ? NaN : v);
1054 return isNaN(v) ? defaultValue : v;
1058 * <p>Utility method for returning a default value if the passed value is empty.</p>
1059 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
1061 * <li>undefined</li>
1062 * <li>an empty array</li>
1063 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
1065 * @param {Mixed} value The value to test
1066 * @param {Mixed} defaultValue The value to return if the original value is empty
1067 * @param {Boolean} allowBlank (optional) true to allow zero length strings to qualify as non-empty (defaults to false)
1068 * @return {Mixed} value, if non-empty, else defaultValue
1070 value : function(v, defaultValue, allowBlank){
1071 return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
1075 * Escapes the passed string for use in a regular expression
1076 * @param {String} str
1079 escapeRe : function(s) {
1080 return s.replace(/([-.*+?^${}()|[\]\/\\])/g, "\\$1");
1083 sequence : function(o, name, fn, scope){
1084 o[name] = o[name].createSequence(fn, scope);
1088 * Applies event listeners to elements by selectors when the document is ready.
1089 * The event name is specified with an <tt>@</tt> suffix.
1092 // add a listener for click on all anchors in element with id foo
1093 '#foo a@click' : function(e, t){
1097 // add the same listener to multiple selectors (separated by comma BEFORE the @)
1098 '#foo a, #bar span.some-class@mouseover' : function(){
1103 * @param {Object} obj The list of behaviors to apply
1105 addBehaviors : function(o){
1107 Ext.onReady(function(){
1108 Ext.addBehaviors(o);
1111 var cache = {}, // simple cache for applying multiple behaviors to same selector does query multiple times
1116 if ((parts = b.split('@'))[1]) { // for Object prototype breakers
1119 cache[s] = Ext.select(s);
1121 cache[s].on(parts[1], o[b]);
1129 * Utility method for getting the width of the browser scrollbar. This can differ depending on
1130 * operating system settings, such as the theme or font size.
1131 * @param {Boolean} force (optional) true to force a recalculation of the value.
1132 * @return {Number} The width of the scrollbar.
1134 getScrollBarWidth: function(force){
1139 if(force === true || scrollWidth === null){
1140 // Append our div, do our calculation and then remove it
1141 var div = Ext.getBody().createChild('<div class="x-hide-offsets" style="width:100px;height:50px;overflow:hidden;"><div style="height:200px;"></div></div>'),
1142 child = div.child('div', true);
1143 var w1 = child.offsetWidth;
1144 div.setStyle('overflow', (Ext.isWebKit || Ext.isGecko) ? 'auto' : 'scroll');
1145 var w2 = child.offsetWidth;
1147 // Need to add 2 to ensure we leave enough space
1148 scrollWidth = w1 - w2 + 2;
1155 combine : function(){
1156 var as = arguments, l = as.length, r = [];
1157 for(var i = 0; i < l; i++){
1161 }else if(a.length !== undefined && !a.substr){
1162 r = r.concat(Array.prototype.slice.call(a, 0));
1171 * Copies a set of named properties fom the source object to the destination object.
1172 * <p>example:<pre><code>
1173 ImageComponent = Ext.extend(Ext.BoxComponent, {
1174 initComponent: function() {
1175 this.autoEl = { tag: 'img' };
1176 MyComponent.superclass.initComponent.apply(this, arguments);
1177 this.initialBox = Ext.copyTo({}, this.initialConfig, 'x,y,width,height');
1181 * @param {Object} The destination object.
1182 * @param {Object} The source object.
1183 * @param {Array/String} Either an Array of property names, or a comma-delimited list
1184 * of property names to copy.
1185 * @return {Object} The modified object.
1187 copyTo : function(dest, source, names){
1188 if(Ext.isString(names)){
1189 names = names.split(/[,;\s]/);
1191 Ext.each(names, function(name){
1192 if(source.hasOwnProperty(name)){
1193 dest[name] = source[name];
1200 * Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
1201 * DOM (if applicable) and calling their destroy functions (if available). This method is primarily
1202 * intended for arguments of type {@link Ext.Element} and {@link Ext.Component}, but any subclass of
1203 * {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
1204 * passed into this function in a single call as separate arguments.
1205 * @param {Mixed} arg1 An {@link Ext.Element}, {@link Ext.Component}, or an Array of either of these to destroy
1206 * @param {Mixed} arg2 (optional)
1207 * @param {Mixed} etc... (optional)
1209 destroy : function(){
1210 Ext.each(arguments, function(arg){
1212 if(Ext.isArray(arg)){
1213 this.destroy.apply(this, arg);
1214 }else if(Ext.isFunction(arg.destroy)){
1224 * Attempts to destroy and then remove a set of named properties of the passed object.
1225 * @param {Object} o The object (most likely a Component) who's properties you wish to destroy.
1226 * @param {Mixed} arg1 The name of the property to destroy and remove from the object.
1227 * @param {Mixed} etc... More property names to destroy and remove.
1229 destroyMembers : function(o, arg1, arg2, etc){
1230 for(var i = 1, a = arguments, len = a.length; i < len; i++) {
1231 Ext.destroy(o[a[i]]);
1237 * Creates a copy of the passed Array with falsy values removed.
1238 * @param {Array/NodeList} arr The Array from which to remove falsy values.
1239 * @return {Array} The new, compressed Array.
1241 clean : function(arr){
1243 Ext.each(arr, function(v){
1252 * Creates a copy of the passed Array, filtered to contain only unique values.
1253 * @param {Array} arr The Array to filter
1254 * @return {Array} The new Array containing unique values.
1256 unique : function(arr){
1260 Ext.each(arr, function(v) {
1270 * Recursively flattens into 1-d Array. Injects Arrays inline.
1271 * @param {Array} arr The array to flatten
1272 * @return {Array} The new, flattened array.
1274 flatten : function(arr){
1276 function rFlatten(a) {
1277 Ext.each(a, function(v) {
1286 return rFlatten(arr);
1290 * Returns the minimum value in the Array.
1291 * @param {Array|NodeList} arr The Array from which to select the minimum value.
1292 * @param {Function} comp (optional) a function to perform the comparision which determines minimization.
1293 * If omitted the "<" operator will be used. Note: gt = 1; eq = 0; lt = -1
1294 * @return {Object} The minimum value in the Array.
1296 min : function(arr, comp){
1298 comp = comp || function(a,b){ return a < b ? -1 : 1; };
1299 Ext.each(arr, function(v) {
1300 ret = comp(ret, v) == -1 ? ret : v;
1306 * Returns the maximum value in the Array
1307 * @param {Array|NodeList} arr The Array from which to select the maximum value.
1308 * @param {Function} comp (optional) a function to perform the comparision which determines maximization.
1309 * If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1
1310 * @return {Object} The maximum value in the Array.
1312 max : function(arr, comp){
1314 comp = comp || function(a,b){ return a > b ? 1 : -1; };
1315 Ext.each(arr, function(v) {
1316 ret = comp(ret, v) == 1 ? ret : v;
1322 * Calculates the mean of the Array
1323 * @param {Array} arr The Array to calculate the mean value of.
1324 * @return {Number} The mean.
1326 mean : function(arr){
1327 return Ext.sum(arr) / arr.length;
1331 * Calculates the sum of the Array
1332 * @param {Array} arr The Array to calculate the sum value of.
1333 * @return {Number} The sum.
1335 sum : function(arr){
1337 Ext.each(arr, function(v) {
1344 * Partitions the set into two sets: a true set and a false set.
1349 Ext.partition([true, false, true, true, false]); // [[true, true, true], [false, false]]
1355 return val.className == "class1"
1358 // true are those paragraph elements with a className of "class1",
1359 // false set are those that do not have that className.
1361 * @param {Array|NodeList} arr The array to partition
1362 * @param {Function} truth (optional) a function to determine truth. If this is omitted the element
1363 * itself must be able to be evaluated for its truthfulness.
1364 * @return {Array} [true<Array>,false<Array>]
1366 partition : function(arr, truth){
1368 Ext.each(arr, function(v, i, a) {
1369 ret[ (truth && truth(v, i, a)) || (!truth && v) ? 0 : 1].push(v);
1375 * Invokes a method on each item in an Array.
1378 Ext.invoke(Ext.query("p"), "getAttribute", "id");
1379 // [el1.getAttribute("id"), el2.getAttribute("id"), ..., elN.getAttribute("id")]
1381 * @param {Array|NodeList} arr The Array of items to invoke the method on.
1382 * @param {String} methodName The method name to invoke.
1383 * @param {Anything} ... Arguments to send into the method invocation.
1384 * @return {Array} The results of invoking the method on each item in the array.
1386 invoke : function(arr, methodName){
1388 args = Array.prototype.slice.call(arguments, 2);
1389 Ext.each(arr, function(v,i) {
1390 if (v && Ext.isFunction(v[methodName])) {
1391 ret.push(v[methodName].apply(v, args));
1393 ret.push(undefined);
1400 * Plucks the value of a property from each item in the Array
1403 Ext.pluck(Ext.query("p"), "className"); // [el1.className, el2.className, ..., elN.className]
1405 * @param {Array|NodeList} arr The Array of items to pluck the value from.
1406 * @param {String} prop The property name to pluck from each element.
1407 * @return {Array} The value from each item in the Array.
1409 pluck : function(arr, prop){
1411 Ext.each(arr, function(v) {
1412 ret.push( v[prop] );
1418 * <p>Zips N sets together.</p>
1421 Ext.zip([1,2,3],[4,5,6]); // [[1,4],[2,5],[3,6]]
1428 return "$" + a + "" + b + "." + c
1430 ); // ["$+12.43", "$-10.15", "$+22.96"]
1432 * @param {Arrays|NodeLists} arr This argument may be repeated. Array(s) to contribute values.
1433 * @param {Function} zipper (optional) The last item in the argument list. This will drive how the items are zipped together.
1434 * @return {Array} The zipped set.
1437 var parts = Ext.partition(arguments, function( val ){ return !Ext.isFunction(val); }),
1440 len = Ext.max(Ext.pluck(arrs, "length")),
1443 for (var i = 0; i < len; i++) {
1446 ret[i] = fn.apply(fn, Ext.pluck(arrs, i));
1448 for (var j = 0, aLen = arrs.length; j < aLen; j++){
1449 ret[i].push( arrs[j][i] );
1457 * This is shorthand reference to {@link Ext.ComponentMgr#get}.
1458 * Looks up an existing {@link Ext.Component Component} by {@link Ext.Component#id id}
1459 * @param {String} id The component {@link Ext.Component#id id}
1460 * @return Ext.Component The Component, <tt>undefined</tt> if not found, or <tt>null</tt> if a
1463 getCmp : function(id){
1464 return Ext.ComponentMgr.get(id);
1468 * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
1469 * you may want to set this to true.
1472 useShims: E.isIE6 || (E.isMac && E.isGecko2),
1474 // inpired by a similar function in mootools library
1476 * Returns the type of object that is passed in. If the object passed in is null or undefined it
1477 * return false otherwise it returns one of the following values:<div class="mdetail-params"><ul>
1478 * <li><b>string</b>: If the object passed is a string</li>
1479 * <li><b>number</b>: If the object passed is a number</li>
1480 * <li><b>boolean</b>: If the object passed is a boolean value</li>
1481 * <li><b>date</b>: If the object passed is a Date object</li>
1482 * <li><b>function</b>: If the object passed is a function reference</li>
1483 * <li><b>object</b>: If the object passed is an object</li>
1484 * <li><b>array</b>: If the object passed is an array</li>
1485 * <li><b>regexp</b>: If the object passed is a regular expression</li>
1486 * <li><b>element</b>: If the object passed is a DOM Element</li>
1487 * <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
1488 * <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
1489 * <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
1491 * @param {Mixed} object
1495 if(o === undefined || o === null){
1502 if(t == 'object' && o.nodeName) {
1503 switch(o.nodeType) {
1504 case 1: return 'element';
1505 case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
1508 if(t == 'object' || t == 'function') {
1509 switch(o.constructor) {
1510 case Array: return 'array';
1511 case RegExp: return 'regexp';
1512 case Date: return 'date';
1514 if(Ext.isNumber(o.length) && Ext.isFunction(o.item)) {
1521 intercept : function(o, name, fn, scope){
1522 o[name] = o[name].createInterceptor(fn, scope);
1526 callback : function(cb, scope, args, delay){
1527 if(Ext.isFunction(cb)){
1529 cb.defer(delay, scope, args || []);
1531 cb.apply(scope, args || []);
1540 * These functions are available on every Function object (any JavaScript function).
1542 Ext.apply(Function.prototype, {
1544 * Create a combined function call sequence of the original function + the passed function.
1545 * The resulting function returns the results of the original function.
1546 * The passed fcn is called with the parameters of the original function. Example usage:
1548 var sayHi = function(name){
1549 alert('Hi, ' + name);
1552 sayHi('Fred'); // alerts "Hi, Fred"
1554 var sayGoodbye = sayHi.createSequence(function(name){
1555 alert('Bye, ' + name);
1558 sayGoodbye('Fred'); // both alerts show
1560 * @param {Function} fcn The function to sequence
1561 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
1562 * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
1563 * @return {Function} The new function
1565 createSequence : function(fcn, scope){
1567 return !Ext.isFunction(fcn) ?
1570 var retval = method.apply(this || window, arguments);
1571 fcn.apply(scope || this || window, arguments);
1580 * These functions are available as static methods on the JavaScript String object.
1582 Ext.applyIf(String, {
1585 * Escapes the passed string for ' and \
1586 * @param {String} string The string to escape
1587 * @return {String} The escaped string
1590 escape : function(string) {
1591 return string.replace(/('|\\)/g, "\\$1");
1595 * Pads the left side of a string with a specified character. This is especially useful
1596 * for normalizing number and date strings. Example usage:
1598 var s = String.leftPad('123', 5, '0');
1599 // s now contains the string: '00123'
1601 * @param {String} string The original string
1602 * @param {Number} size The total length of the output string
1603 * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
1604 * @return {String} The padded string
1607 leftPad : function (val, size, ch) {
1608 var result = String(val);
1612 while (result.length < size) {
1613 result = ch + result;
1620 * Utility function that allows you to easily switch a string between two alternating values. The passed value
1621 * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
1622 * they are already different, the first value passed in is returned. Note that this method returns the new value
1623 * but does not change the current string.
1625 // alternate sort directions
1626 sort = sort.toggle('ASC', 'DESC');
1628 // instead of conditional logic:
1629 sort = (sort == 'ASC' ? 'DESC' : 'ASC');
1631 * @param {String} value The value to compare to the current string
1632 * @param {String} other The new value to use if the string already equals the first value passed in
1633 * @return {String} The new value
1635 String.prototype.toggle = function(value, other){
1636 return this == value ? other : value;
1640 * Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
1642 var s = ' foo bar ';
1643 alert('-' + s + '-'); //alerts "- foo bar -"
1644 alert('-' + s.trim() + '-'); //alerts "-foo bar-"
1646 * @return {String} The trimmed string
1648 String.prototype.trim = function(){
1649 var re = /^\s+|\s+$/g;
1650 return function(){ return this.replace(re, ""); };
1653 // here to prevent dependency on Date.js
1655 Returns the number of milliseconds between this date and date
1656 @param {Date} date (optional) Defaults to now
1657 @return {Number} The diff in milliseconds
1658 @member Date getElapsed
1660 Date.prototype.getElapsed = function(date) {
1661 return Math.abs((date || new Date()).getTime()-this.getTime());
1668 Ext.applyIf(Number.prototype, {
1670 * Checks whether or not the current number is within a desired range. If the number is already within the
1671 * range it is returned, otherwise the min or max value is returned depending on which side of the range is
1672 * exceeded. Note that this method returns the constrained value but does not change the current number.
1673 * @param {Number} min The minimum number in the range
1674 * @param {Number} max The maximum number in the range
1675 * @return {Number} The constrained value if outside the range, otherwise the current value
1677 constrain : function(min, max){
1678 return Math.min(Math.max(this, min), max);
1682 * @class Ext.util.TaskRunner
1683 * Provides the ability to execute one or more arbitrary tasks in a multithreaded
1684 * manner. Generally, you can use the singleton {@link Ext.TaskMgr} instead, but
1685 * if needed, you can create separate instances of TaskRunner. Any number of
1686 * separate tasks can be started at any time and will run independently of each
1687 * other. Example usage:
1689 // Start a simple clock task that updates a div once per second
1690 var updateClock = function(){
1691 Ext.fly('clock').update(new Date().format('g:i:s A'));
1695 interval: 1000 //1 second
1697 var runner = new Ext.util.TaskRunner();
1700 // equivalent using TaskMgr
1707 * Also see {@link Ext.util.DelayedTask}.
1710 * @param {Number} interval (optional) The minimum precision in milliseconds supported by this TaskRunner instance
1713 Ext.util.TaskRunner = function(interval){
1714 interval = interval || 10;
1721 stopThread = function(){
1728 startThread = function(){
1731 id = setInterval(runTasks, interval);
1736 removeTask = function(t){
1737 removeQueue.push(t);
1739 t.onStop.apply(t.scope || t);
1744 runTasks = function(){
1745 var rqLen = removeQueue.length,
1746 now = new Date().getTime();
1749 for(var i = 0; i < rqLen; i++){
1750 tasks.remove(removeQueue[i]);
1753 if(tasks.length < 1){
1758 for(var i = 0, t, itime, rt, len = tasks.length; i < len; ++i){
1760 itime = now - t.taskRunTime;
1761 if(t.interval <= itime){
1762 rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
1763 t.taskRunTime = now;
1764 if(rt === false || t.taskRunCount === t.repeat){
1769 if(t.duration && t.duration <= (now - t.taskStartTime)){
1776 * Starts a new task.
1778 * @param {Object} task A config object that supports the following properties:<ul>
1779 * <li><code>run</code> : Function<div class="sub-desc">The function to execute each time the task is run. The
1780 * function will be called at each interval and passed the <code>args</code> argument if specified. If a
1781 * particular scope is required, be sure to specify it using the <code>scope</code> argument.</div></li>
1782 * <li><code>interval</code> : Number<div class="sub-desc">The frequency in milliseconds with which the task
1783 * should be executed.</div></li>
1784 * <li><code>args</code> : Array<div class="sub-desc">(optional) An array of arguments to be passed to the function
1785 * specified by <code>run</code>.</div></li>
1786 * <li><code>scope</code> : Object<div class="sub-desc">(optional) The scope (<tt>this</tt> reference) in which to execute the
1787 * <code>run</code> function. Defaults to the task config object.</div></li>
1788 * <li><code>duration</code> : Number<div class="sub-desc">(optional) The length of time in milliseconds to execute
1789 * the task before stopping automatically (defaults to indefinite).</div></li>
1790 * <li><code>repeat</code> : Number<div class="sub-desc">(optional) The number of times to execute the task before
1791 * stopping automatically (defaults to indefinite).</div></li>
1793 * @return {Object} The task
1795 this.start = function(task){
1797 task.taskStartTime = new Date().getTime();
1798 task.taskRunTime = 0;
1799 task.taskRunCount = 0;
1805 * Stops an existing running task.
1807 * @param {Object} task The task to stop
1808 * @return {Object} The task
1810 this.stop = function(task){
1816 * Stops all tasks that are currently running.
1819 this.stopAll = function(){
1821 for(var i = 0, len = tasks.length; i < len; i++){
1822 if(tasks[i].onStop){
1832 * @class Ext.TaskMgr
1833 * @extends Ext.util.TaskRunner
1834 * A static {@link Ext.util.TaskRunner} instance that can be used to start and stop arbitrary tasks. See
1835 * {@link Ext.util.TaskRunner} for supported methods and task config properties.
1837 // Start a simple clock task that updates a div once per second
1840 Ext.fly('clock').update(new Date().format('g:i:s A'));
1842 interval: 1000 //1 second
1844 Ext.TaskMgr.start(task);
1848 Ext.TaskMgr = new Ext.util.TaskRunner();(function(){
\r
1851 function fly(el) {
\r
1852 if (!libFlyweight) {
\r
1853 libFlyweight = new Ext.Element.Flyweight();
\r
1855 libFlyweight.dom = el;
\r
1856 return libFlyweight;
\r
1860 var doc = document,
\r
1861 isCSS1 = doc.compatMode == "CSS1Compat",
\r
1863 ROUND = Math.round,
\r
1864 PARSEINT = parseInt;
\r
1867 isAncestor : function(p, c) {
\r
1870 p = Ext.getDom(p);
\r
1871 c = Ext.getDom(c);
\r
1874 return p.contains(c);
\r
1875 } else if (p.compareDocumentPosition) {
\r
1876 return !!(p.compareDocumentPosition(c) & 16);
\r
1878 while (c = c.parentNode) {
\r
1879 ret = c == p || ret;
\r
1886 getViewWidth : function(full) {
\r
1887 return full ? this.getDocumentWidth() : this.getViewportWidth();
\r
1890 getViewHeight : function(full) {
\r
1891 return full ? this.getDocumentHeight() : this.getViewportHeight();
\r
1894 getDocumentHeight: function() {
\r
1895 return MAX(!isCSS1 ? doc.body.scrollHeight : doc.documentElement.scrollHeight, this.getViewportHeight());
\r
1898 getDocumentWidth: function() {
\r
1899 return MAX(!isCSS1 ? doc.body.scrollWidth : doc.documentElement.scrollWidth, this.getViewportWidth());
\r
1902 getViewportHeight: function(){
\r
1903 return Ext.isIE ?
\r
1904 (Ext.isStrict ? doc.documentElement.clientHeight : doc.body.clientHeight) :
\r
1908 getViewportWidth : function() {
\r
1909 return !Ext.isStrict && !Ext.isOpera ? doc.body.clientWidth :
\r
1910 Ext.isIE ? doc.documentElement.clientWidth : self.innerWidth;
\r
1913 getY : function(el) {
\r
1914 return this.getXY(el)[1];
\r
1917 getX : function(el) {
\r
1918 return this.getXY(el)[0];
\r
1921 getXY : function(el) {
\r
1932 bd = (doc.body || doc.documentElement),
\r
1935 el = Ext.getDom(el);
\r
1938 if (el.getBoundingClientRect) {
\r
1939 b = el.getBoundingClientRect();
\r
1940 scroll = fly(document).getScroll();
\r
1941 ret = [ROUND(b.left + scroll.left), ROUND(b.top + scroll.top)];
\r
1944 hasAbsolute = fly(el).isStyle("position", "absolute");
\r
1948 x += p.offsetLeft;
\r
1951 hasAbsolute = hasAbsolute || pe.isStyle("position", "absolute");
\r
1953 if (Ext.isGecko) {
\r
1954 y += bt = PARSEINT(pe.getStyle("borderTopWidth"), 10) || 0;
\r
1955 x += bl = PARSEINT(pe.getStyle("borderLeftWidth"), 10) || 0;
\r
1957 if (p != el && !pe.isStyle('overflow','visible')) {
\r
1962 p = p.offsetParent;
\r
1965 if (Ext.isSafari && hasAbsolute) {
\r
1966 x -= bd.offsetLeft;
\r
1967 y -= bd.offsetTop;
\r
1970 if (Ext.isGecko && !hasAbsolute) {
\r
1972 x += PARSEINT(dbd.getStyle("borderLeftWidth"), 10) || 0;
\r
1973 y += PARSEINT(dbd.getStyle("borderTopWidth"), 10) || 0;
\r
1976 p = el.parentNode;
\r
1977 while (p && p != bd) {
\r
1978 if (!Ext.isOpera || (p.tagName != 'TR' && !fly(p).isStyle("display", "inline"))) {
\r
1979 x -= p.scrollLeft;
\r
1990 setXY : function(el, xy) {
\r
1991 (el = Ext.fly(el, '_setXY')).position();
\r
1993 var pts = el.translatePoints(xy),
\r
1994 style = el.dom.style,
\r
1997 for (pos in pts) {
\r
1998 if(!isNaN(pts[pos])) style[pos] = pts[pos] + "px"
\r
2002 setX : function(el, x) {
\r
2003 this.setXY(el, [x, false]);
\r
2006 setY : function(el, y) {
\r
2007 this.setXY(el, [false, y]);
\r
2010 })();Ext.lib.Dom.getRegion = function(el) {
\r
2011 return Ext.lib.Region.getRegion(el);
\r
2012 };Ext.lib.Event = function() {
2013 var loadComplete = false,
2014 unloadListeners = {},
2031 SCROLLLEFT = 'scrollLeft',
2032 SCROLLTOP = 'scrollTop',
2034 MOUSEOVER = 'mouseover',
2035 MOUSEOUT = 'mouseout',
2037 doAdd = function() {
2039 if (win.addEventListener) {
2040 ret = function(el, eventName, fn, capture) {
2041 if (eventName == 'mouseenter') {
2042 fn = fn.createInterceptor(checkRelatedTarget);
2043 el.addEventListener(MOUSEOVER, fn, (capture));
2044 } else if (eventName == 'mouseleave') {
2045 fn = fn.createInterceptor(checkRelatedTarget);
2046 el.addEventListener(MOUSEOUT, fn, (capture));
2048 el.addEventListener(eventName, fn, (capture));
2052 } else if (win.attachEvent) {
2053 ret = function(el, eventName, fn, capture) {
2054 el.attachEvent("on" + eventName, fn);
2063 doRemove = function(){
2065 if (win.removeEventListener) {
2066 ret = function (el, eventName, fn, capture) {
2067 if (eventName == 'mouseenter') {
2068 eventName = MOUSEOVER;
2069 } else if (eventName == 'mouseleave') {
2070 eventName = MOUSEOUT;
2072 el.removeEventListener(eventName, fn, (capture));
2074 } else if (win.detachEvent) {
2075 ret = function (el, eventName, fn) {
2076 el.detachEvent("on" + eventName, fn);
2084 function checkRelatedTarget(e) {
2085 return !elContains(e.currentTarget, pub.getRelatedTarget(e));
2088 function elContains(parent, child) {
2089 if(parent && parent.firstChild){
2091 if(child === parent) {
2094 child = child.parentNode;
2095 if(child && (child.nodeType != 1)) {
2104 function _tryPreloadAttach() {
2108 tryAgain = !loadComplete || (retryCount > 0);
2113 for (i = 0, len = onAvailStack.length; i < len; i++) {
2114 v = onAvailStack[i];
2115 if(v && (element = doc.getElementById(v.id))){
2116 if(!v.checkReady || loadComplete || element.nextSibling || (doc && doc.body)) {
2117 element = v.override ? (v.override === true ? v.obj : v.override) : element;
2118 v.fn.call(element, v.obj);
2126 retryCount = (notAvail.length === 0) ? 0 : retryCount - 1;
2131 clearInterval(_interval);
2135 ret = !(locked = false);
2141 function startInterval() {
2143 var callback = function() {
2144 _tryPreloadAttach();
2146 _interval = setInterval(callback, POLL_INTERVAL);
2151 function getScroll() {
2152 var dd = doc.documentElement,
2154 if(dd && (dd[SCROLLTOP] || dd[SCROLLLEFT])){
2155 return [dd[SCROLLLEFT], dd[SCROLLTOP]];
2157 return [db[SCROLLLEFT], db[SCROLLTOP]];
2164 function getPageCoord (ev, xy) {
2165 ev = ev.browserEvent || ev;
2166 var coord = ev['page' + xy];
2167 if (!coord && coord !== 0) {
2168 coord = ev['client' + xy] || 0;
2171 coord += getScroll()[xy == "X" ? 0 : 1];
2180 onAvailable : function(p_id, p_fn, p_obj, p_override) {
2185 override: p_override,
2186 checkReady: false });
2188 retryCount = POLL_RETRYS;
2192 // This function should ALWAYS be called from Ext.EventManager
2193 addListener: function(el, eventName, fn) {
2194 el = Ext.getDom(el);
2196 if (eventName == UNLOAD) {
2197 if (unloadListeners[el.id] === undefined) {
2198 unloadListeners[el.id] = [];
2200 unloadListeners[el.id].push([eventName, fn]);
2203 return doAdd(el, eventName, fn, false);
2208 // This function should ALWAYS be called from Ext.EventManager
2209 removeListener: function(el, eventName, fn) {
2210 el = Ext.getDom(el);
2213 if (eventName == UNLOAD) {
2214 if (unloadListeners[id] !== undefined) {
2215 for (i = 0, len = unloadListeners[id].length; i < len; i++) {
2216 li = unloadListeners[id][i];
2217 if (li && li[TYPE] == eventName && li[FN] == fn) {
2218 unloadListeners[id].splice(i, 1);
2224 doRemove(el, eventName, fn, false);
2228 getTarget : function(ev) {
2229 ev = ev.browserEvent || ev;
2230 return this.resolveTextNode(ev.target || ev.srcElement);
2233 resolveTextNode : Ext.isGecko ? function(node){
2237 // work around firefox bug, https://bugzilla.mozilla.org/show_bug.cgi?id=101197
2238 var s = HTMLElement.prototype.toString.call(node);
2239 if(s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]'){
2242 return node.nodeType == 3 ? node.parentNode : node;
2244 return node && node.nodeType == 3 ? node.parentNode : node;
2247 getRelatedTarget : function(ev) {
2248 ev = ev.browserEvent || ev;
2249 return this.resolveTextNode(ev.relatedTarget ||
2250 (ev.type == MOUSEOUT ? ev.toElement :
2251 ev.type == MOUSEOVER ? ev.fromElement : null));
2254 getPageX : function(ev) {
2255 return getPageCoord(ev, "X");
2258 getPageY : function(ev) {
2259 return getPageCoord(ev, "Y");
2263 getXY : function(ev) {
2264 return [this.getPageX(ev), this.getPageY(ev)];
2267 stopEvent : function(ev) {
2268 this.stopPropagation(ev);
2269 this.preventDefault(ev);
2272 stopPropagation : function(ev) {
2273 ev = ev.browserEvent || ev;
2274 if (ev.stopPropagation) {
2275 ev.stopPropagation();
2277 ev.cancelBubble = true;
2281 preventDefault : function(ev) {
2282 ev = ev.browserEvent || ev;
2283 if (ev.preventDefault) {
2284 ev.preventDefault();
2286 ev.returnValue = false;
2290 getEvent : function(e) {
2293 var c = this.getEvent.caller;
2296 if (e && Event == e.constructor) {
2305 getCharCode : function(ev) {
2306 ev = ev.browserEvent || ev;
2307 return ev.charCode || ev.keyCode || 0;
2310 //clearCache: function() {},
2311 // deprecated, call from EventManager
2312 getListeners : function(el, eventName) {
2313 Ext.EventManager.getListeners(el, eventName);
2316 // deprecated, call from EventManager
2317 purgeElement : function(el, recurse, eventName) {
2318 Ext.EventManager.purgeElement(el, recurse, eventName);
2321 _load : function(e) {
2322 loadComplete = true;
2323 var EU = Ext.lib.Event;
2324 if (Ext.isIE && e !== true) {
2325 // IE8 complains that _load is null or not an object
2326 // so lets remove self via arguments.callee
2327 doRemove(win, "load", arguments.callee);
2331 _unload : function(e) {
2332 var EU = Ext.lib.Event,
2333 i, j, l, v, ul, id, len, index, scope;
2336 for (id in unloadListeners) {
2337 ul = unloadListeners[id];
2338 for (i = 0, len = ul.length; i < len; i++) {
2342 scope = v[ADJ_SCOPE] ? (v[ADJ_SCOPE] === true ? v[OBJ] : v[ADJ_SCOPE]) : win;
2343 v[FN].call(scope, EU.getEvent(e), v[OBJ]);
2349 unloadListeners = null;
2350 Ext.EventManager._unload();
2352 doRemove(win, UNLOAD, EU._unload);
2356 // Initialize stuff.
2357 pub.on = pub.addListener;
2358 pub.un = pub.removeListener;
2359 if (doc && doc.body) {
2362 doAdd(win, "load", pub._load);
2364 doAdd(win, UNLOAD, pub._unload);
2365 _tryPreloadAttach();
2370 * Portions of this file are based on pieces of Yahoo User Interface Library
\r
2371 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
\r
2372 * YUI licensed under the BSD License:
\r
2373 * http://developer.yahoo.net/yui/license.txt
\r
2375 Ext.lib.Ajax = function() {
\r
2376 var activeX = ['MSXML2.XMLHTTP.3.0',
\r
2378 'Microsoft.XMLHTTP'],
\r
2379 CONTENTTYPE = 'Content-Type';
\r
2382 function setHeader(o) {
\r
2383 var conn = o.conn,
\r
2386 function setTheHeaders(conn, headers){
\r
2387 for (prop in headers) {
\r
2388 if (headers.hasOwnProperty(prop)) {
\r
2389 conn.setRequestHeader(prop, headers[prop]);
\r
2394 if (pub.defaultHeaders) {
\r
2395 setTheHeaders(conn, pub.defaultHeaders);
\r
2398 if (pub.headers) {
\r
2399 setTheHeaders(conn, pub.headers);
\r
2400 delete pub.headers;
\r
2405 function createExceptionObject(tId, callbackArg, isAbort, isTimeout) {
\r
2408 status : isAbort ? -1 : 0,
\r
2409 statusText : isAbort ? 'transaction aborted' : 'communication failure',
\r
2411 isTimeout: isTimeout,
\r
2412 argument : callbackArg
\r
2417 function initHeader(label, value) {
\r
2418 (pub.headers = pub.headers || {})[label] = value;
\r
2422 function createResponseObject(o, callbackArg) {
\r
2423 var headerObj = {},
\r
2430 headerStr = o.conn.getAllResponseHeaders();
\r
2431 Ext.each(headerStr.replace(/\r\n/g, '\n').split('\n'), function(v){
\r
2432 t = v.indexOf(':');
\r
2434 s = v.substr(0, t).toLowerCase();
\r
2435 if(v.charAt(t + 1) == ' '){
\r
2438 headerObj[s] = v.substr(t + 1);
\r
2445 status : conn.status,
\r
2446 statusText : conn.statusText,
\r
2447 getResponseHeader : function(header){return headerObj[header.toLowerCase()];},
\r
2448 getAllResponseHeaders : function(){return headerStr},
\r
2449 responseText : conn.responseText,
\r
2450 responseXML : conn.responseXML,
\r
2451 argument : callbackArg
\r
2456 function releaseObject(o) {
\r
2462 function handleTransactionResponse(o, callback, isAbort, isTimeout) {
\r
2468 var httpStatus, responseObject;
\r
2471 if (o.conn.status !== undefined && o.conn.status != 0) {
\r
2472 httpStatus = o.conn.status;
\r
2475 httpStatus = 13030;
\r
2479 httpStatus = 13030;
\r
2482 if ((httpStatus >= 200 && httpStatus < 300) || (Ext.isIE && httpStatus == 1223)) {
\r
2483 responseObject = createResponseObject(o, callback.argument);
\r
2484 if (callback.success) {
\r
2485 if (!callback.scope) {
\r
2486 callback.success(responseObject);
\r
2489 callback.success.apply(callback.scope, [responseObject]);
\r
2494 switch (httpStatus) {
\r
2501 responseObject = createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false), isTimeout);
\r
2502 if (callback.failure) {
\r
2503 if (!callback.scope) {
\r
2504 callback.failure(responseObject);
\r
2507 callback.failure.apply(callback.scope, [responseObject]);
\r
2512 responseObject = createResponseObject(o, callback.argument);
\r
2513 if (callback.failure) {
\r
2514 if (!callback.scope) {
\r
2515 callback.failure(responseObject);
\r
2518 callback.failure.apply(callback.scope, [responseObject]);
\r
2525 responseObject = null;
\r
2529 function handleReadyState(o, callback){
\r
2530 callback = callback || {};
\r
2531 var conn = o.conn,
\r
2534 cbTimeout = callback.timeout || null;
\r
2537 pub.timeout[tId] = setTimeout(function() {
\r
2538 pub.abort(o, callback, true);
\r
2542 poll[tId] = setInterval(
\r
2544 if (conn && conn.readyState == 4) {
\r
2545 clearInterval(poll[tId]);
\r
2549 clearTimeout(pub.timeout[tId]);
\r
2550 pub.timeout[tId] = null;
\r
2553 handleTransactionResponse(o, callback);
\r
2556 pub.pollInterval);
\r
2560 function asyncRequest(method, uri, callback, postData) {
\r
2561 var o = getConnectionObject() || null;
\r
2564 o.conn.open(method, uri, true);
\r
2566 if (pub.useDefaultXhrHeader) {
\r
2567 initHeader('X-Requested-With', pub.defaultXhrHeader);
\r
2570 if(postData && pub.useDefaultHeader && (!pub.headers || !pub.headers[CONTENTTYPE])){
\r
2571 initHeader(CONTENTTYPE, pub.defaultPostHeader);
\r
2574 if (pub.defaultHeaders || pub.headers) {
\r
2578 handleReadyState(o, callback);
\r
2579 o.conn.send(postData || null);
\r
2585 function getConnectionObject() {
\r
2589 if (o = createXhrObject(pub.transactionId)) {
\r
2590 pub.transactionId++;
\r
2599 function createXhrObject(transactionId) {
\r
2603 http = new XMLHttpRequest();
\r
2605 for (var i = 0; i < activeX.length; ++i) {
\r
2607 http = new ActiveXObject(activeX[i]);
\r
2612 return {conn : http, tId : transactionId};
\r
2617 request : function(method, uri, cb, data, options) {
\r
2620 xmlData = options.xmlData,
\r
2621 jsonData = options.jsonData,
\r
2624 Ext.applyIf(me, options);
\r
2626 if(xmlData || jsonData){
\r
2628 if(!hs || !hs[CONTENTTYPE]){
\r
2629 initHeader(CONTENTTYPE, xmlData ? 'text/xml' : 'application/json');
\r
2631 data = xmlData || (!Ext.isPrimitive(jsonData) ? Ext.encode(jsonData) : jsonData);
\r
2634 return asyncRequest(method || options.method || "POST", uri, cb, data);
\r
2637 serializeForm : function(form) {
\r
2638 var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements,
\r
2639 hasSubmit = false,
\r
2640 encoder = encodeURIComponent,
\r
2648 Ext.each(fElements, function(element) {
\r
2649 name = element.name;
\r
2650 type = element.type;
\r
2652 if (!element.disabled && name){
\r
2653 if(/select-(one|multiple)/i.test(type)) {
\r
2654 Ext.each(element.options, function(opt) {
\r
2655 if (opt.selected) {
\r
2656 data += String.format("{0}={1}&", encoder(name), encoder((opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttribute('value') !== null) ? opt.value : opt.text));
\r
2659 } else if(!/file|undefined|reset|button/i.test(type)) {
\r
2660 if(!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit)){
\r
2662 data += encoder(name) + '=' + encoder(element.value) + '&';
\r
2663 hasSubmit = /submit/i.test(type);
\r
2668 return data.substr(0, data.length - 1);
\r
2671 useDefaultHeader : true,
\r
2672 defaultPostHeader : 'application/x-www-form-urlencoded; charset=UTF-8',
\r
2673 useDefaultXhrHeader : true,
\r
2674 defaultXhrHeader : 'XMLHttpRequest',
\r
2677 pollInterval : 50,
\r
2678 transactionId : 0,
\r
2680 // This is never called - Is it worth exposing this?
\r
2681 // setProgId : function(id) {
\r
2682 // activeX.unshift(id);
\r
2685 // This is never called - Is it worth exposing this?
\r
2686 // setDefaultPostHeader : function(b) {
\r
2687 // this.useDefaultHeader = b;
\r
2690 // This is never called - Is it worth exposing this?
\r
2691 // setDefaultXhrHeader : function(b) {
\r
2692 // this.useDefaultXhrHeader = b;
\r
2695 // This is never called - Is it worth exposing this?
\r
2696 // setPollingInterval : function(i) {
\r
2697 // if (typeof i == 'number' && isFinite(i)) {
\r
2698 // this.pollInterval = i;
\r
2702 // This is never called - Is it worth exposing this?
\r
2703 // resetDefaultHeaders : function() {
\r
2704 // this.defaultHeaders = null;
\r
2707 abort : function(o, callback, isTimeout) {
\r
2712 if (me.isCallInProgress(o)) {
\r
2714 clearInterval(me.poll[tId]);
\r
2715 me.poll[tId] = null;
\r
2716 clearTimeout(pub.timeout[tId]);
\r
2717 me.timeout[tId] = null;
\r
2719 handleTransactionResponse(o, callback, (isAbort = true), isTimeout);
\r
2724 isCallInProgress : function(o) {
\r
2725 // if there is a connection and readyState is not 0 or 4
\r
2726 return o.conn && !{0:true,4:true}[o.conn.readyState];
\r
2730 }(); Ext.lib.Region = function(t, r, b, l) {
\r
2740 Ext.lib.Region.prototype = {
\r
2741 contains : function(region) {
\r
2743 return ( region.left >= me.left &&
\r
2744 region.right <= me.right &&
\r
2745 region.top >= me.top &&
\r
2746 region.bottom <= me.bottom );
\r
2750 getArea : function() {
\r
2752 return ( (me.bottom - me.top) * (me.right - me.left) );
\r
2755 intersect : function(region) {
\r
2757 t = Math.max(me.top, region.top),
\r
2758 r = Math.min(me.right, region.right),
\r
2759 b = Math.min(me.bottom, region.bottom),
\r
2760 l = Math.max(me.left, region.left);
\r
2762 if (b >= t && r >= l) {
\r
2763 return new Ext.lib.Region(t, r, b, l);
\r
2767 union : function(region) {
\r
2769 t = Math.min(me.top, region.top),
\r
2770 r = Math.max(me.right, region.right),
\r
2771 b = Math.max(me.bottom, region.bottom),
\r
2772 l = Math.min(me.left, region.left);
\r
2774 return new Ext.lib.Region(t, r, b, l);
\r
2777 constrainTo : function(r) {
\r
2779 me.top = me.top.constrain(r.top, r.bottom);
\r
2780 me.bottom = me.bottom.constrain(r.top, r.bottom);
\r
2781 me.left = me.left.constrain(r.left, r.right);
\r
2782 me.right = me.right.constrain(r.left, r.right);
\r
2786 adjust : function(t, l, b, r) {
\r
2796 Ext.lib.Region.getRegion = function(el) {
\r
2797 var p = Ext.lib.Dom.getXY(el),
\r
2799 r = p[0] + el.offsetWidth,
\r
2800 b = p[1] + el.offsetHeight,
\r
2803 return new Ext.lib.Region(t, r, b, l);
\r
2804 }; Ext.lib.Point = function(x, y) {
\r
2805 if (Ext.isArray(x)) {
\r
2810 me.x = me.right = me.left = me[0] = x;
\r
2811 me.y = me.top = me.bottom = me[1] = y;
\r
2814 Ext.lib.Point.prototype = new Ext.lib.Region();
\r
2816 var EXTLIB = Ext.lib,
\r
2817 noNegatives = /width|height|opacity|padding/i,
\r
2818 offsetAttribute = /^((width|height)|(top|left))$/,
\r
2819 defaultUnit = /width|height|top$|bottom$|left$|right$/i,
\r
2820 offsetUnit = /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i,
\r
2821 isset = function(v){
\r
2822 return typeof v !== 'undefined';
\r
2825 return new Date();
\r
2829 motion : function(el, args, duration, easing, cb, scope) {
\r
2830 return this.run(el, args, duration, easing, cb, scope, Ext.lib.Motion);
\r
2833 run : function(el, args, duration, easing, cb, scope, type) {
\r
2834 type = type || Ext.lib.AnimBase;
\r
2835 if (typeof easing == "string") {
\r
2836 easing = Ext.lib.Easing[easing];
\r
2838 var anim = new type(el, args, duration, easing);
\r
2839 anim.animateX(function() {
\r
2840 if(Ext.isFunction(cb)){
\r
2848 EXTLIB.AnimBase = function(el, attributes, duration, method) {
\r
2850 this.init(el, attributes, duration, method);
\r
2854 EXTLIB.AnimBase.prototype = {
\r
2855 doMethod: function(attr, start, end) {
\r
2857 return me.method(me.curFrame, start, end - start, me.totalFrames);
\r
2861 setAttr: function(attr, val, unit) {
\r
2862 if (noNegatives.test(attr) && val < 0) {
\r
2865 Ext.fly(this.el, '_anim').setStyle(attr, val + unit);
\r
2869 getAttr: function(attr) {
\r
2870 var el = Ext.fly(this.el),
\r
2871 val = el.getStyle(attr),
\r
2872 a = offsetAttribute.exec(attr) || []
\r
2874 if (val !== 'auto' && !offsetUnit.test(val)) {
\r
2875 return parseFloat(val);
\r
2878 return (!!(a[2]) || (el.getStyle('position') == 'absolute' && !!(a[3]))) ? el.dom['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)] : 0;
\r
2882 getDefaultUnit: function(attr) {
\r
2883 return defaultUnit.test(attr) ? 'px' : '';
\r
2886 animateX : function(callback, scope) {
\r
2889 me.onComplete.removeListener(f);
\r
2890 if (Ext.isFunction(callback)) {
\r
2891 callback.call(scope || me, me);
\r
2894 me.onComplete.addListener(f, me);
\r
2899 setRunAttr: function(attr) {
\r
2901 a = this.attributes[attr],
\r
2906 ra = (this.runAttrs[attr] = {}),
\r
2909 if (!isset(to) && !isset(by)){
\r
2913 var start = isset(from) ? from : me.getAttr(attr);
\r
2916 }else if(isset(by)) {
\r
2917 if (Ext.isArray(start)){
\r
2919 for(var i=0,len=start.length; i<len; i++) {
\r
2920 end[i] = start[i] + by[i];
\r
2930 unit: isset(unit) ? unit : me.getDefaultUnit(attr)
\r
2935 init: function(el, attributes, duration, method) {
\r
2938 mgr = EXTLIB.AnimMgr;
\r
2941 isAnimated: false,
\r
2943 el: Ext.getDom(el),
\r
2944 attributes: attributes || {},
\r
2945 duration: duration || 1,
\r
2946 method: method || EXTLIB.Easing.easeNone,
\r
2949 totalFrames: mgr.fps,
\r
2951 animate: function(){
\r
2955 if(me.isAnimated){
\r
2960 me.totalFrames = me.useSec ? Math.ceil(mgr.fps * d) : d;
\r
2961 mgr.registerElement(me);
\r
2964 stop: function(finish){
\r
2968 me.curFrame = me.totalFrames;
\r
2969 me._onTween.fire();
\r
2975 var onStart = function(){
\r
2979 me.onStart.fire();
\r
2981 for(attr in this.attributes){
\r
2982 this.setRunAttr(attr);
\r
2985 me.isAnimated = true;
\r
2986 me.startTime = now();
\r
2991 var onTween = function(){
\r
2995 duration: now() - me.startTime,
\r
2996 curFrame: me.curFrame
\r
2999 var ra = me.runAttrs;
\r
3000 for (var attr in ra) {
\r
3001 this.setAttr(attr, me.doMethod(attr, ra[attr].start, ra[attr].end), ra[attr].unit);
\r
3007 var onComplete = function() {
\r
3009 actual = (now() - me.startTime) / 1000,
\r
3012 frames: actualFrames,
\r
3013 fps: actualFrames / actual
\r
3016 me.isAnimated = false;
\r
3018 me.onComplete.fire(data);
\r
3021 me.onStart = new Ext.util.Event(me);
\r
3022 me.onTween = new Ext.util.Event(me);
\r
3023 me.onComplete = new Ext.util.Event(me);
\r
3024 (me._onStart = new Ext.util.Event(me)).addListener(onStart);
\r
3025 (me._onTween = new Ext.util.Event(me)).addListener(onTween);
\r
3026 (me._onComplete = new Ext.util.Event(me)).addListener(onComplete);
\r
3031 Ext.lib.AnimMgr = new function() {
\r
3041 registerElement: function(tween){
\r
3042 queue.push(tween);
\r
3044 tween._onStart.fire();
\r
3048 unRegister: function(tween, index){
\r
3049 tween._onComplete.fire();
\r
3050 index = index || getIndex(tween);
\r
3051 if (index != -1) {
\r
3052 queue.splice(index, 1);
\r
3055 if (--tweenCount <= 0) {
\r
3060 start: function(){
\r
3061 if(thread === null){
\r
3062 thread = setInterval(me.run, me.delay);
\r
3066 stop: function(tween){
\r
3068 clearInterval(thread);
\r
3069 for(var i = 0, len = queue.length; i < len; ++i){
\r
3070 if(queue[0].isAnimated){
\r
3071 me.unRegister(queue[0], 0);
\r
3079 me.unRegister(tween);
\r
3084 var tf, i, len, tween;
\r
3085 for(i = 0, len = queue.length; i<len; i++) {
\r
3087 if(tween && tween.isAnimated){
\r
3088 tf = tween.totalFrames;
\r
3089 if(tween.curFrame < tf || tf === null){
\r
3092 correctFrame(tween);
\r
3094 tween._onTween.fire();
\r
3103 var getIndex = function(anim) {
\r
3105 for(i = 0, len = queue.length; i<len; i++) {
\r
3106 if(queue[i] === anim) {
\r
3113 var correctFrame = function(tween) {
\r
3114 var frames = tween.totalFrames,
\r
3115 frame = tween.curFrame,
\r
3116 duration = tween.duration,
\r
3117 expected = (frame * duration * 1000 / frames),
\r
3118 elapsed = (now() - tween.startTime),
\r
3121 if(elapsed < duration * 1000){
\r
3122 tweak = Math.round((elapsed / expected - 1) * frame);
\r
3124 tweak = frames - (frame + 1);
\r
3126 if(tweak > 0 && isFinite(tweak)){
\r
3127 if(tween.curFrame + tweak >= frames){
\r
3128 tweak = frames - (frame + 1);
\r
3130 tween.curFrame += tweak;
\r
3135 EXTLIB.Bezier = new function() {
\r
3137 this.getPosition = function(points, t) {
\r
3138 var n = points.length,
\r
3144 for (i = 0; i < n; ++i) {
\r
3145 tmp[i] = [points[i][0], points[i][1]];
\r
3148 for (j = 1; j < n; ++j) {
\r
3149 for (i = 0; i < n - j; ++i) {
\r
3150 tmp[i][0] = c * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
\r
3151 tmp[i][1] = c * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
\r
3155 return [ tmp[0][0], tmp[0][1] ];
\r
3162 easeNone: function (t, b, c, d) {
\r
3163 return c * t / d + b;
\r
3167 easeIn: function (t, b, c, d) {
\r
3168 return c * (t /= d) * t + b;
\r
3172 easeOut: function (t, b, c, d) {
\r
3173 return -c * (t /= d) * (t - 2) + b;
\r
3178 EXTLIB.Motion = function(el, attributes, duration, method) {
\r
3180 EXTLIB.Motion.superclass.constructor.call(this, el, attributes, duration, method);
\r
3184 Ext.extend(EXTLIB.Motion, Ext.lib.AnimBase);
\r
3186 var superclass = EXTLIB.Motion.superclass,
\r
3187 proto = EXTLIB.Motion.prototype,
\r
3188 pointsRe = /^points$/i;
\r
3190 Ext.apply(EXTLIB.Motion.prototype, {
\r
3191 setAttr: function(attr, val, unit){
\r
3193 setAttr = superclass.setAttr;
\r
3195 if (pointsRe.test(attr)) {
\r
3196 unit = unit || 'px';
\r
3197 setAttr.call(me, 'left', val[0], unit);
\r
3198 setAttr.call(me, 'top', val[1], unit);
\r
3200 setAttr.call(me, attr, val, unit);
\r
3204 getAttr: function(attr){
\r
3206 getAttr = superclass.getAttr;
\r
3208 return pointsRe.test(attr) ? [getAttr.call(me, 'left'), getAttr.call(me, 'top')] : getAttr.call(me, attr);
\r
3211 doMethod: function(attr, start, end){
\r
3214 return pointsRe.test(attr)
\r
3215 ? EXTLIB.Bezier.getPosition(me.runAttrs[attr], me.method(me.curFrame, 0, 100, me.totalFrames) / 100)
\r
3216 : superclass.doMethod.call(me, attr, start, end);
\r
3219 setRunAttr: function(attr){
\r
3220 if(pointsRe.test(attr)){
\r
3224 points = this.attributes.points,
\r
3225 control = points.control || [],
\r
3226 from = points.from,
\r
3237 if(control.length > 0 && !Ext.isArray(control[0])){
\r
3238 control = [control];
\r
3242 for (i = 0,len = control.length; i < len; ++i) {
\r
3243 tmp[i] = control[i];
\r
3249 Ext.fly(el, '_anim').position();
\r
3250 DOM.setXY(el, isset(from) ? from : DOM.getXY(el));
\r
3251 start = me.getAttr('points');
\r
3255 end = translateValues.call(me, to, start);
\r
3256 for (i = 0,len = control.length; i < len; ++i) {
\r
3257 control[i] = translateValues.call(me, control[i], start);
\r
3259 } else if (isset(by)) {
\r
3260 end = [start[0] + by[0], start[1] + by[1]];
\r
3262 for (i = 0,len = control.length; i < len; ++i) {
\r
3263 control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
\r
3267 ra = this.runAttrs[attr] = [start];
\r
3268 if (control.length > 0) {
\r
3269 ra = ra.concat(control);
\r
3272 ra[ra.length] = end;
\r
3274 superclass.setRunAttr.call(this, attr);
\r
3279 var translateValues = function(val, start) {
\r
3280 var pageXY = EXTLIB.Dom.getXY(this.el);
\r
3281 return [val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1]];
\r
3284 })();// Easing functions
\r
3286 // shortcuts to aid compression
\r
3287 var abs = Math.abs,
\r
3294 Ext.apply(EXTLIB.Easing, {
\r
3296 easeBoth: function (t, b, c, d) {
\r
3297 return ((t /= d / 2) < 1) ? c / 2 * t * t + b : -c / 2 * ((--t) * (t - 2) - 1) + b;
\r
3300 easeInStrong: function (t, b, c, d) {
\r
3301 return c * (t /= d) * t * t * t + b;
\r
3304 easeOutStrong: function (t, b, c, d) {
\r
3305 return -c * ((t = t / d - 1) * t * t * t - 1) + b;
\r
3308 easeBothStrong: function (t, b, c, d) {
\r
3309 return ((t /= d / 2) < 1) ? c / 2 * t * t * t * t + b : -c / 2 * ((t -= 2) * t * t * t - 2) + b;
\r
3312 elasticIn: function (t, b, c, d, a, p) {
\r
3313 if (t == 0 || (t /= d) == 1) {
\r
3314 return t == 0 ? b : b + c;
\r
3316 p = p || (d * .3);
\r
3319 if (a >= abs(c)) {
\r
3320 s = p / (2 * pi) * asin(c / a);
\r
3326 return -(a * pow(2, 10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p)) + b;
\r
3330 elasticOut: function (t, b, c, d, a, p) {
\r
3331 if (t == 0 || (t /= d) == 1) {
\r
3332 return t == 0 ? b : b + c;
\r
3334 p = p || (d * .3);
\r
3337 if (a >= abs(c)) {
\r
3338 s = p / (2 * pi) * asin(c / a);
\r
3344 return a * pow(2, -10 * t) * sin((t * d - s) * (2 * pi) / p) + c + b;
\r
3347 elasticBoth: function (t, b, c, d, a, p) {
\r
3348 if (t == 0 || (t /= d / 2) == 2) {
\r
3349 return t == 0 ? b : b + c;
\r
3352 p = p || (d * (.3 * 1.5));
\r
3355 if (a >= abs(c)) {
\r
3356 s = p / (2 * pi) * asin(c / a);
\r
3363 -.5 * (a * pow(2, 10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p)) + b :
\r
3364 a * pow(2, -10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p) * .5 + c + b;
\r
3367 backIn: function (t, b, c, d, s) {
\r
3368 s = s || 1.70158;
\r
3369 return c * (t /= d) * t * ((s + 1) * t - s) + b;
\r
3373 backOut: function (t, b, c, d, s) {
\r
3377 return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
\r
3381 backBoth: function (t, b, c, d, s) {
\r
3382 s = s || 1.70158;
\r
3384 return ((t /= d / 2 ) < 1) ?
\r
3385 c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b :
\r
3386 c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
\r
3390 bounceIn: function (t, b, c, d) {
\r
3391 return c - EXTLIB.Easing.bounceOut(d - t, 0, c, d) + b;
\r
3395 bounceOut: function (t, b, c, d) {
\r
3396 if ((t /= d) < (1 / 2.75)) {
\r
3397 return c * (7.5625 * t * t) + b;
\r
3398 } else if (t < (2 / 2.75)) {
\r
3399 return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
\r
3400 } else if (t < (2.5 / 2.75)) {
\r
3401 return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
\r
3403 return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
\r
3407 bounceBoth: function (t, b, c, d) {
\r
3408 return (t < d / 2) ?
\r
3409 EXTLIB.Easing.bounceIn(t * 2, 0, c, d) * .5 + b :
\r
3410 EXTLIB.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
\r
3416 var EXTLIB = Ext.lib;
\r
3417 // Color Animation
\r
3418 EXTLIB.Anim.color = function(el, args, duration, easing, cb, scope) {
\r
3419 return EXTLIB.Anim.run(el, args, duration, easing, cb, scope, EXTLIB.ColorAnim);
\r
3422 EXTLIB.ColorAnim = function(el, attributes, duration, method) {
\r
3423 EXTLIB.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
\r
3426 Ext.extend(EXTLIB.ColorAnim, EXTLIB.AnimBase);
\r
3428 var superclass = EXTLIB.ColorAnim.superclass,
\r
3429 colorRE = /color$/i,
\r
3430 transparentRE = /^transparent|rgba\(0, 0, 0, 0\)$/,
\r
3431 rgbRE = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i,
\r
3432 hexRE= /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i,
\r
3433 hex3RE = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i,
\r
3434 isset = function(v){
\r
3435 return typeof v !== 'undefined';
\r
3439 function parseColor(s) {
\r
3440 var pi = parseInt,
\r
3445 if (s.length == 3) {
\r
3449 Ext.each([hexRE, rgbRE, hex3RE], function(re, idx){
\r
3450 base = (idx % 2 == 0) ? 16 : 10;
\r
3452 if(c && c.length == 4){
\r
3453 out = [pi(c[1], base), pi(c[2], base), pi(c[3], base)];
\r
3460 Ext.apply(EXTLIB.ColorAnim.prototype, {
\r
3461 getAttr : function(attr) {
\r
3465 if(colorRE.test(attr)){
\r
3466 while(el && transparentRE.test(val = Ext.fly(el).getStyle(attr))){
\r
3467 el = el.parentNode;
\r
3471 val = superclass.getAttr.call(me, attr);
\r
3476 doMethod : function(attr, start, end) {
\r
3479 floor = Math.floor,
\r
3480 i, len = start.length, v;
\r
3482 if(colorRE.test(attr)){
\r
3485 for(i=0; i<len; i++) {
\r
3487 val[i] = superclass.doMethod.call(me, attr, v, end[i]);
\r
3489 val = 'rgb(' + floor(val[0]) + ',' + floor(val[1]) + ',' + floor(val[2]) + ')';
\r
3491 val = superclass.doMethod.call(me, attr, start, end);
\r
3496 setRunAttr : function(attr) {
\r
3498 a = me.attributes[attr],
\r
3503 superclass.setRunAttr.call(me, attr);
\r
3504 ra = me.runAttrs[attr];
\r
3505 if(colorRE.test(attr)){
\r
3506 var start = parseColor(ra.start),
\r
3507 end = parseColor(ra.end);
\r
3509 if(!isset(to) && isset(by)){
\r
3510 end = parseColor(by);
\r
3511 for(var i=0,len=start.length; i<len; i++) {
\r
3512 end[i] = start[i] + end[i];
\r
3524 // Scroll Animation
\r
3525 var EXTLIB = Ext.lib;
\r
3526 EXTLIB.Anim.scroll = function(el, args, duration, easing, cb, scope) {
\r
3527 return EXTLIB.Anim.run(el, args, duration, easing, cb, scope, EXTLIB.Scroll);
\r
3530 EXTLIB.Scroll = function(el, attributes, duration, method) {
\r
3532 EXTLIB.Scroll.superclass.constructor.call(this, el, attributes, duration, method);
\r
3536 Ext.extend(EXTLIB.Scroll, EXTLIB.ColorAnim);
\r
3538 var superclass = EXTLIB.Scroll.superclass,
\r
3539 SCROLL = 'scroll';
\r
3541 Ext.apply(EXTLIB.Scroll.prototype, {
\r
3543 doMethod : function(attr, start, end) {
\r
3546 curFrame = me.curFrame,
\r
3547 totalFrames = me.totalFrames;
\r
3549 if(attr == SCROLL){
\r
3550 val = [me.method(curFrame, start[0], end[0] - start[0], totalFrames),
\r
3551 me.method(curFrame, start[1], end[1] - start[1], totalFrames)];
\r
3553 val = superclass.doMethod.call(me, attr, start, end);
\r
3558 getAttr : function(attr) {
\r
3561 if (attr == SCROLL) {
\r
3562 return [me.el.scrollLeft, me.el.scrollTop];
\r
3564 return superclass.getAttr.call(me, attr);
\r
3568 setAttr : function(attr, val, unit) {
\r
3571 if(attr == SCROLL){
\r
3572 me.el.scrollLeft = val[0];
\r
3573 me.el.scrollTop = val[1];
\r
3575 superclass.setAttr.call(me, attr, val, unit);
\r
3581 function fnCleanUp() {
\r
3582 var p = Function.prototype;
\r
3583 delete p.createSequence;
\r
3585 delete p.createDelegate;
\r
3586 delete p.createCallback;
\r
3587 delete p.createInterceptor;
\r
3589 window.detachEvent("onunload", fnCleanUp);
\r
3591 window.attachEvent("onunload", fnCleanUp);
\r