3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
9 window.undefined = window.undefined;
\r
13 * Ext core utilities and functions.
\r
19 * The version of the framework
\r
26 * Copies all the properties of config to obj.
\r
27 * @param {Object} obj The receiver of the properties
\r
28 * @param {Object} config The source of the properties
\r
29 * @param {Object} defaults A different object that will also be applied for default values
\r
30 * @return {Object} returns obj
\r
33 Ext.apply = function(o, c, defaults){
\r
34 // no "this" reference for friendly out of scope calls
\r
36 Ext.apply(o, defaults);
\r
38 if(o && c && typeof c == 'object'){
\r
48 toString = Object.prototype.toString,
\r
49 //assume it's not null and not an array
\r
50 isIterable = function(v){
\r
51 //check for array or arguments
\r
52 if(Ext.isArray(v) || v.callee){
\r
55 //check for node list type
\r
56 if(/NodeList|HTMLCollection/.test(toString.call(v))){
\r
59 //NodeList has an item and length property
\r
60 //IXMLDOMNodeList has nextNode method, needs to be checked first.
\r
61 return ((v.nextNode || v.item) && Ext.isNumber(v.length));
\r
63 ua = navigator.userAgent.toLowerCase(),
\r
64 check = function(r){
\r
68 isStrict = DOC.compatMode == "CSS1Compat",
\r
69 isOpera = check(/opera/),
\r
70 isChrome = check(/chrome/),
\r
71 isWebKit = check(/webkit/),
\r
72 isSafari = !isChrome && check(/safari/),
\r
73 isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
\r
74 isSafari3 = isSafari && check(/version\/3/),
\r
75 isSafari4 = isSafari && check(/version\/4/),
\r
76 isIE = !isOpera && check(/msie/),
\r
77 isIE7 = isIE && check(/msie 7/),
\r
78 isIE8 = isIE && check(/msie 8/),
\r
79 isIE6 = isIE && !isIE7 && !isIE8,
\r
80 isGecko = !isWebKit && check(/gecko/),
\r
81 isGecko2 = isGecko && check(/rv:1\.8/),
\r
82 isGecko3 = isGecko && check(/rv:1\.9/),
\r
83 isBorderBox = isIE && !isStrict,
\r
84 isWindows = check(/windows|win32/),
\r
85 isMac = check(/macintosh|mac os x/),
\r
86 isAir = check(/adobeair/),
\r
87 isLinux = check(/linux/),
\r
88 isSecure = /^https/i.test(window.location.protocol);
\r
90 // remove css image flicker
\r
93 DOC.execCommand("BackgroundImageCache", false, true);
\r
99 * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent
\r
100 * the IE insecure content warning (defaults to javascript:false).
\r
103 SSL_SECURE_URL : 'javascript:false',
\r
105 * True if the browser is in strict (standards-compliant) mode, as opposed to quirks mode
\r
108 isStrict : isStrict,
\r
110 * True if the page is running over SSL
\r
113 isSecure : isSecure,
\r
115 * True when the document is fully initialized and ready for action
\r
121 * True if the {@link Ext.Fx} Class is available
\r
123 * @property enableFx
\r
127 * True to automatically uncache orphaned Ext.Elements periodically (defaults to true)
\r
130 enableGarbageCollector : true,
\r
133 * True to automatically purge event listeners after uncaching an element (defaults to false).
\r
134 * Note: this only happens if {@link #enableGarbageCollector} is true.
\r
137 enableListenerCollection : false,
\r
140 * Indicates whether to use native browser parsing for JSON methods.
\r
141 * This option is ignored if the browser does not support native JSON methods.
\r
142 * <b>Note: Native JSON methods will not work with objects that have functions.
\r
143 * Also, property names must be quoted, otherwise the data will not parse.</b> (Defaults to false)
\r
146 USE_NATIVE_JSON : false,
\r
149 * Copies all the properties of config to obj if they don't already exist.
\r
150 * @param {Object} obj The receiver of the properties
\r
151 * @param {Object} config The source of the properties
\r
152 * @return {Object} returns obj
\r
154 applyIf : function(o, c){
\r
157 if(Ext.isEmpty(o[p])){
\r
166 * Generates unique ids. If the element already has an id, it is unchanged
\r
167 * @param {Mixed} el (optional) The element to generate an id for
\r
168 * @param {String} prefix (optional) Id prefix (defaults "ext-gen")
\r
169 * @return {String} The generated Id.
\r
171 id : function(el, prefix){
\r
172 return (el = Ext.getDom(el) || {}).id = el.id || (prefix || "ext-gen") + (++idSeed);
\r
176 * Extends one class with another class and optionally overrides members with the passed literal. This class
\r
177 * also adds the function "override()" to the class that can be used to override
\r
178 * members on an instance.
\r
180 * This function also supports a 2-argument call in which the subclass's constructor is
\r
181 * not passed as an argument. In this form, the parameters are as follows:</p><p>
\r
182 * <div class="mdetail-params"><ul>
\r
183 * <li><code>superclass</code>
\r
184 * <div class="sub-desc">The class being extended</div></li>
\r
185 * <li><code>overrides</code>
\r
186 * <div class="sub-desc">A literal with members which are copied into the subclass's
\r
187 * prototype, and are therefore shared among all instances of the new class.<p>
\r
188 * This may contain a special member named <tt><b>constructor</b></tt>. This is used
\r
189 * to define the constructor of the new class, and is returned. If this property is
\r
190 * <i>not</i> specified, a constructor is generated and returned which just calls the
\r
191 * superclass's constructor passing on its parameters.</p></div></li>
\r
192 * </ul></div></p><p>
\r
193 * For example, to create a subclass of the Ext GridPanel:
\r
195 MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
\r
196 constructor: function(config) {
\r
197 // Your preprocessing here
\r
198 MyGridPanel.superclass.constructor.apply(this, arguments);
\r
199 // Your postprocessing here
\r
202 yourMethod: function() {
\r
208 * @param {Function} subclass The class inheriting the functionality
\r
209 * @param {Function} superclass The class being extended
\r
210 * @param {Object} overrides (optional) A literal with members which are copied into the subclass's
\r
211 * prototype, and are therefore shared between all instances of the new class.
\r
212 * @return {Function} The subclass constructor.
\r
215 extend : function(){
\r
216 // inline overrides
\r
217 var io = function(o){
\r
222 var oc = Object.prototype.constructor;
\r
224 return function(sb, sp, overrides){
\r
225 if(Ext.isObject(sp)){
\r
228 sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
\r
230 var F = function(){},
\r
232 spp = sp.prototype;
\r
235 sbp = sb.prototype = new F();
\r
236 sbp.constructor=sb;
\r
238 if(spp.constructor == oc){
\r
239 spp.constructor=sp;
\r
241 sb.override = function(o){
\r
242 Ext.override(sb, o);
\r
244 sbp.superclass = sbp.supr = (function(){
\r
248 Ext.override(sb, overrides);
\r
249 sb.extend = function(o){Ext.extend(sb, o);};
\r
255 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
\r
256 * Usage:<pre><code>
\r
257 Ext.override(MyClass, {
\r
258 newMethod1: function(){
\r
261 newMethod2: function(foo){
\r
266 * @param {Object} origclass The class to override
\r
267 * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
\r
268 * containing one or more methods.
\r
271 override : function(origclass, overrides){
\r
273 var p = origclass.prototype;
\r
274 Ext.apply(p, overrides);
\r
275 if(Ext.isIE && overrides.toString != origclass.toString){
\r
276 p.toString = overrides.toString;
\r
282 * Creates namespaces to be used for scoping variables and classes so that they are not global.
\r
283 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
\r
285 Ext.namespace('Company', 'Company.data');
\r
286 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
\r
287 Company.Widget = function() { ... }
\r
288 Company.data.CustomStore = function(config) { ... }
\r
290 * @param {String} namespace1
\r
291 * @param {String} namespace2
\r
292 * @param {String} etc
\r
293 * @method namespace
\r
295 namespace : function(){
\r
297 Ext.each(arguments, function(v) {
\r
299 o = window[d[0]] = window[d[0]] || {};
\r
300 Ext.each(d.slice(1), function(v2){
\r
301 o = o[v2] = o[v2] || {};
\r
308 * Takes an object and converts it to an encoded URL. e.g. Ext.urlEncode({foo: 1, bar: 2}); would return "foo=1&bar=2". Optionally, property values can be arrays, instead of keys and the resulting string that's returned will contain a name/value pair for each array value.
\r
309 * @param {Object} o
\r
310 * @param {String} pre (optional) A prefix to add to the url encoded string
\r
313 urlEncode: function(o, pre){
\r
314 var undef, buf = [], key, e = encodeURIComponent;
\r
317 undef = !Ext.isDefined(o[key]);
\r
318 Ext.each(undef ? key : o[key], function(val, i){
\r
319 buf.push("&", e(key), "=", (val != key || !undef) ? e(val) : "");
\r
326 return pre + buf.join('');
\r
330 * Takes an encoded URL and and converts it to an object. Example: <pre><code>
\r
331 Ext.urlDecode("foo=1&bar=2"); // returns {foo: "1", bar: "2"}
\r
332 Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2", "3", "4"]}
\r
334 * @param {String} string
\r
335 * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
\r
336 * @return {Object} A literal with members
\r
338 urlDecode : function(string, overwrite){
\r
340 pairs = string.split('&'),
\r
341 d = decodeURIComponent,
\r
344 Ext.each(pairs, function(pair) {
\r
345 pair = pair.split('=');
\r
347 value = d(pair[1]);
\r
348 obj[name] = overwrite || !obj[name] ? value :
\r
349 [].concat(obj[name]).concat(value);
\r
355 * Appends content to the query string of a URL, which handles logic for whether to place
\r
356 * a question mark or ampersand.
\r
357 * @param {String} url The url to append to.
\r
358 * @@param {String} s The content to append to the url.
\r
359 * @return (String) The appended string
\r
361 urlAppend : function(url, s){
\r
362 if(!Ext.isEmpty(s)){
\r
363 return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
\r
369 * Converts any iterable (numeric indices and a length property) into a true array
\r
370 * Don't use this on strings. IE doesn't support "abc"[0] which this implementation depends on.
\r
371 * For strings, use this instead: "abc".match(/./g) => [a,b,c];
\r
372 * @param {Iterable} the iterable object to be turned into a true Array.
\r
373 * @return (Array) array
\r
375 toArray : function(){
\r
377 function(a, i, j, res){
\r
379 Ext.each(a, function(v) {
\r
382 return res.slice(i || 0, j || res.length);
\r
385 return Array.prototype.slice.call(a, i || 0, j || a.length);
\r
390 * Iterates an array calling the passed function with each item, stopping if your function returns false. If the
\r
391 * passed array is not really an array, your function is called once with it.
\r
392 * The supplied function is called with (Object item, Number index, Array allItems).
\r
393 * @param {Array/NodeList/Mixed} array
\r
394 * @param {Function} fn
\r
395 * @param {Object} scope
\r
397 each: function(array, fn, scope){
\r
398 if(Ext.isEmpty(array, true)){
\r
401 if(!isIterable(array) || Ext.isPrimitive(array)){
\r
404 for(var i = 0, len = array.length; i < len; i++){
\r
405 if(fn.call(scope || array[i], array[i], i, array) === false){
\r
412 * Iterates either the elements in an array, or each of the properties in an object.
\r
413 * <b>Note</b>: If you are only iterating arrays, it is better to call {@link #each}.
\r
414 * @param {Object/Array} object The object or array to be iterated
\r
415 * @param {Function} fn The function to be called for each iteration.
\r
416 * The iteration will stop if the supplied function returns false, or
\r
417 * all array elements / object properties have been covered. The signature
\r
418 * varies depending on the type of object being interated:
\r
419 * <div class="mdetail-params"><ul>
\r
420 * <li>Arrays : <tt>(Object item, Number index, Array allItems)</tt>
\r
421 * <div class="sub-desc">
\r
422 * When iterating an array, the supplied function is called with each item.</div></li>
\r
423 * <li>Objects : <tt>(String key, Object value)</tt>
\r
424 * <div class="sub-desc">
\r
425 * When iterating an object, the supplied function is called with each key-value pair in
\r
426 * the object.</div></li>
\r
428 * @param {Object} scope The scope to call the supplied function with, defaults to
\r
429 * the specified <tt>object</tt>
\r
431 iterate : function(obj, fn, scope){
\r
432 if(isIterable(obj)){
\r
433 Ext.each(obj, fn, scope);
\r
435 }else if(Ext.isObject(obj)){
\r
436 for(var prop in obj){
\r
437 if(obj.hasOwnProperty(prop)){
\r
438 if(fn.call(scope || obj, prop, obj[prop]) === false){
\r
447 * Return the dom node for the passed String (id), dom node, or Ext.Element.
\r
448 * Here are some examples:
\r
450 // gets dom node based on id
\r
451 var elDom = Ext.getDom('elId');
\r
452 // gets dom node based on the dom node
\r
453 var elDom1 = Ext.getDom(elDom);
\r
455 // If we don't know if we are working with an
\r
456 // Ext.Element or a dom node use Ext.getDom
\r
458 var dom = Ext.getDom(el);
\r
459 // do something with the dom node
\r
462 * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc)
\r
463 * when this method is called to be successful.
\r
464 * @param {Mixed} el
\r
465 * @return HTMLElement
\r
467 getDom : function(el){
\r
471 return el.dom ? el.dom : (Ext.isString(el) ? DOC.getElementById(el) : el);
\r
475 * Returns the current document body as an {@link Ext.Element}.
\r
476 * @return Ext.Element The document body
\r
478 getBody : function(){
\r
479 return Ext.get(DOC.body || DOC.documentElement);
\r
483 * Removes a DOM node from the document. The body node will be ignored if passed in.
\r
484 * @param {HTMLElement} node The node to remove
\r
486 removeNode : isIE ? function(){
\r
488 return function(n){
\r
489 if(n && n.tagName != 'BODY'){
\r
490 d = d || DOC.createElement('div');
\r
496 if(n && n.parentNode && n.tagName != 'BODY'){
\r
497 n.parentNode.removeChild(n);
\r
502 * <p>Returns true if the passed value is empty.</p>
\r
503 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
\r
505 * <li>undefined</li>
\r
506 * <li>an empty array</li>
\r
507 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
\r
509 * @param {Mixed} value The value to test
\r
510 * @param {Boolean} allowBlank (optional) true to allow empty strings (defaults to false)
\r
511 * @return {Boolean}
\r
513 isEmpty : function(v, allowBlank){
\r
514 return v === null || v === undefined || ((Ext.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false);
\r
518 * Returns true if the passed object is a JavaScript array, otherwise false.
\r
519 * @param {Object} object The object to test
\r
520 * @return {Boolean}
\r
522 isArray : function(v){
\r
523 return toString.apply(v) === '[object Array]';
\r
527 * Returns true if the passed object is a JavaScript Object, otherwise false.
\r
528 * @param {Object} object The object to test
\r
529 * @return {Boolean}
\r
531 isObject : function(v){
\r
532 return v && typeof v == "object";
\r
536 * Returns true if the passed object is a JavaScript 'primitive', a string, number or boolean.
\r
537 * @param {Mixed} value The value to test
\r
538 * @return {Boolean}
\r
540 isPrimitive : function(v){
\r
541 return Ext.isString(v) || Ext.isNumber(v) || Ext.isBoolean(v);
\r
545 * Returns true if the passed object is a JavaScript Function, otherwise false.
\r
546 * @param {Object} object The object to test
\r
547 * @return {Boolean}
\r
549 isFunction : function(v){
\r
550 return toString.apply(v) === '[object Function]';
\r
554 * Returns true if the passed object is a number. Returns false for non-finite numbers.
\r
555 * @param {Object} v The object to test
\r
556 * @return {Boolean}
\r
558 isNumber: function(v){
\r
559 return typeof v === 'number' && isFinite(v);
\r
563 * Returns true if the passed object is a string.
\r
564 * @param {Object} v The object to test
\r
565 * @return {Boolean}
\r
567 isString: function(v){
\r
568 return typeof v === 'string';
\r
572 * Returns true if the passed object is a boolean.
\r
573 * @param {Object} v The object to test
\r
574 * @return {Boolean}
\r
576 isBoolean: function(v){
\r
577 return typeof v === 'boolean';
\r
581 * Returns true if the passed object is not undefined.
\r
582 * @param {Object} v The object to test
\r
583 * @return {Boolean}
\r
585 isDefined: function(v){
\r
586 return typeof v !== 'undefined';
\r
590 * True if the detected browser is Opera.
\r
595 * True if the detected browser uses WebKit.
\r
598 isWebKit: isWebKit,
\r
600 * True if the detected browser is Chrome.
\r
603 isChrome : isChrome,
\r
605 * True if the detected browser is Safari.
\r
608 isSafari : isSafari,
\r
610 * True if the detected browser is Safari 3.x.
\r
613 isSafari3 : isSafari3,
\r
615 * True if the detected browser is Safari 4.x.
\r
618 isSafari4 : isSafari4,
\r
620 * True if the detected browser is Safari 2.x.
\r
623 isSafari2 : isSafari2,
\r
625 * True if the detected browser is Internet Explorer.
\r
630 * True if the detected browser is Internet Explorer 6.x.
\r
635 * True if the detected browser is Internet Explorer 7.x.
\r
640 * True if the detected browser is Internet Explorer 8.x.
\r
645 * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
\r
650 * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x).
\r
653 isGecko2 : isGecko2,
\r
655 * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
\r
658 isGecko3 : isGecko3,
\r
660 * True if the detected browser is Internet Explorer running in non-strict mode.
\r
663 isBorderBox : isBorderBox,
\r
665 * True if the detected platform is Linux.
\r
670 * True if the detected platform is Windows.
\r
673 isWindows : isWindows,
\r
675 * True if the detected platform is Mac OS.
\r
680 * True if the detected platform is Adobe Air.
\r
687 * Creates namespaces to be used for scoping variables and classes so that they are not global.
\r
688 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
\r
690 Ext.namespace('Company', 'Company.data');
\r
691 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
\r
692 Company.Widget = function() { ... }
\r
693 Company.data.CustomStore = function(config) { ... }
\r
695 * @param {String} namespace1
\r
696 * @param {String} namespace2
\r
697 * @param {String} etc
\r
698 * @method namespace
\r
700 Ext.ns = Ext.namespace;
\r
703 Ext.ns("Ext", "Ext.util", "Ext.lib", "Ext.data");
\r
708 * These functions are available on every Function object (any JavaScript function).
\r
710 Ext.apply(Function.prototype, {
\r
712 * Creates an interceptor function. The passed fcn is called before the original one. If it returns false,
\r
713 * the original one is not called. The resulting function returns the results of the original function.
\r
714 * The passed fcn is called with the parameters of the original function. Example usage:
\r
716 var sayHi = function(name){
\r
717 alert('Hi, ' + name);
\r
720 sayHi('Fred'); // alerts "Hi, Fred"
\r
722 // create a new function that validates input without
\r
723 // directly modifying the original function:
\r
724 var sayHiToFriend = sayHi.createInterceptor(function(name){
\r
725 return name == 'Brian';
\r
728 sayHiToFriend('Fred'); // no alert
\r
729 sayHiToFriend('Brian'); // alerts "Hi, Brian"
\r
731 * @param {Function} fcn The function to call before the original
\r
732 * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
\r
733 * @return {Function} The new function
\r
735 createInterceptor : function(fcn, scope){
\r
737 return !Ext.isFunction(fcn) ?
\r
743 fcn.method = method;
\r
744 return (fcn.apply(scope || me || window, args) !== false) ?
\r
745 method.apply(me || window, args) :
\r
751 * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
\r
752 * Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code>
\r
753 * Will create a function that is bound to those 2 args. <b>If a specific scope is required in the
\r
754 * callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always
\r
755 * executes in the window scope.
\r
756 * <p>This method is required when you want to pass arguments to a callback function. If no arguments
\r
757 * are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn).
\r
758 * However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function
\r
759 * would simply execute immediately when the code is parsed. Example usage:
\r
761 var sayHi = function(name){
\r
762 alert('Hi, ' + name);
\r
765 // clicking the button alerts "Hi, Fred"
\r
768 renderTo: Ext.getBody(),
\r
769 handler: sayHi.createCallback('Fred')
\r
772 * @return {Function} The new function
\r
774 createCallback : function(/*args...*/){
\r
775 // make args available, in function below
\r
776 var args = arguments,
\r
778 return function() {
\r
779 return method.apply(window, args);
\r
784 * Creates a delegate (callback) that sets the scope to obj.
\r
785 * Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code>
\r
786 * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
\r
787 * callback points to obj. Example usage:
\r
789 var sayHi = function(name){
\r
790 // Note this use of "this.text" here. This function expects to
\r
791 // execute within a scope that contains a text property. In this
\r
792 // example, the "this" variable is pointing to the btn object that
\r
793 // was passed in createDelegate below.
\r
794 alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
\r
797 var btn = new Ext.Button({
\r
799 renderTo: Ext.getBody()
\r
802 // This callback will execute in the scope of the
\r
803 // button instance. Clicking the button alerts
\r
804 // "Hi, Fred. You clicked the "Say Hi" button."
\r
805 btn.on('click', sayHi.createDelegate(btn, ['Fred']));
\r
807 * @param {Object} obj (optional) The object for which the scope is set
\r
808 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
\r
809 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
\r
810 * if a number the args are inserted at the specified position
\r
811 * @return {Function} The new function
\r
813 createDelegate : function(obj, args, appendArgs){
\r
815 return function() {
\r
816 var callArgs = args || arguments;
\r
817 if (appendArgs === true){
\r
818 callArgs = Array.prototype.slice.call(arguments, 0);
\r
819 callArgs = callArgs.concat(args);
\r
820 }else if (Ext.isNumber(appendArgs)){
\r
821 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
\r
822 var applyArgs = [appendArgs, 0].concat(args); // create method call params
\r
823 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
\r
825 return method.apply(obj || window, callArgs);
\r
830 * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
\r
832 var sayHi = function(name){
\r
833 alert('Hi, ' + name);
\r
836 // executes immediately:
\r
839 // executes after 2 seconds:
\r
840 sayHi.defer(2000, this, ['Fred']);
\r
842 // this syntax is sometimes useful for deferring
\r
843 // execution of an anonymous function:
\r
845 alert('Anonymous');
\r
848 * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
\r
849 * @param {Object} obj (optional) The object for which the scope is set
\r
850 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
\r
851 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
\r
852 * if a number the args are inserted at the specified position
\r
853 * @return {Number} The timeout id that can be used with clearTimeout
\r
855 defer : function(millis, obj, args, appendArgs){
\r
856 var fn = this.createDelegate(obj, args, appendArgs);
\r
858 return setTimeout(fn, millis);
\r
867 * These functions are available on every String object.
\r
869 Ext.applyIf(String, {
\r
871 * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
\r
872 * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
\r
874 var cls = 'my-class', text = 'Some text';
\r
875 var s = String.format('<div class="{0}">{1}</div>', cls, text);
\r
876 // s now contains the string: '<div class="my-class">Some text</div>'
\r
878 * @param {String} string The tokenized string to be formatted
\r
879 * @param {String} value1 The value to replace token {0}
\r
880 * @param {String} value2 Etc...
\r
881 * @return {String} The formatted string
\r
884 format : function(format){
\r
885 var args = Ext.toArray(arguments, 1);
\r
886 return format.replace(/\{(\d+)\}/g, function(m, i){
\r
895 Ext.applyIf(Array.prototype, {
\r
897 * Checks whether or not the specified object exists in the array.
\r
898 * @param {Object} o The object to check for
\r
899 * @return {Number} The index of o in the array (or -1 if it is not found)
\r
901 indexOf : function(o){
\r
902 for (var i = 0, len = this.length; i < len; i++){
\r
911 * Removes the specified object from the array. If the object is not found nothing happens.
\r
912 * @param {Object} o The object to remove
\r
913 * @return {Array} this array
\r
915 remove : function(o){
\r
916 var index = this.indexOf(o);
\r
918 this.splice(index, 1);
\r
927 Ext.ns("Ext.grid", "Ext.dd", "Ext.tree", "Ext.form", "Ext.menu",
928 "Ext.state", "Ext.layout", "Ext.app", "Ext.ux", "Ext.chart", "Ext.direct");
930 * Namespace alloted for extensions to the framework.
935 Ext.apply(Ext, function(){
936 var E = Ext, idSeed = 0;
940 * A reusable empty function
944 emptyFn : function(){},
947 * URL to a 1x1 transparent gif image used by Ext to create inline icons with CSS background images.
948 * In older versions of IE, this defaults to "http://extjs.com/s.gif" and you should change this to a URL on your server.
949 * For other browsers it uses an inline data URL.
952 BLANK_IMAGE_URL : Ext.isIE6 || Ext.isIE7 ?
953 'http:/' + '/extjs.com/s.gif' :
954 'data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==',
956 extendX : function(supr, fn){
957 return Ext.extend(supr, fn(supr.prototype));
961 * Returns the current HTML document object as an {@link Ext.Element}.
962 * @return Ext.Element The document
965 return Ext.get(document);
969 * Returns true if the passed object is a JavaScript date object, otherwise false.
970 * @param {Object} object The object to test
973 isDate : function(v){
974 return Object.prototype.toString.apply(v) === '[object Date]';
978 * Utility method for validating that a value is numeric, returning the specified default value if it is not.
979 * @param {Mixed} value Should be a number, but any type will be handled appropriately
980 * @param {Number} defaultValue The value to return if the original value is non-numeric
981 * @return {Number} Value, if numeric, else defaultValue
983 num : function(v, defaultValue){
984 v = Number(v === null || typeof v == 'boolean'? NaN : v);
985 return isNaN(v)? defaultValue : v;
989 * <p>Utility method for returning a default value if the passed value is empty.</p>
990 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
993 * <li>an empty array</li>
994 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
996 * @param {Mixed} value The value to test
997 * @param {Mixed} defaultValue The value to return if the original value is empty
998 * @param {Boolean} allowBlank (optional) true to allow zero length strings to qualify as non-empty (defaults to false)
999 * @return {Mixed} value, if non-empty, else defaultValue
1001 value : function(v, defaultValue, allowBlank){
1002 return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
1006 * Escapes the passed string for use in a regular expression
1007 * @param {String} str
1010 escapeRe : function(s) {
1011 return s.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1");
1014 sequence : function(o, name, fn, scope){
1015 o[name] = o[name].createSequence(fn, scope);
1019 * Applies event listeners to elements by selectors when the document is ready.
1020 * The event name is specified with an <tt>@</tt> suffix.
1023 // add a listener for click on all anchors in element with id foo
1024 '#foo a@click' : function(e, t){
1028 // add the same listener to multiple selectors (separated by comma BEFORE the @)
1029 '#foo a, #bar span.some-class@mouseover' : function(){
1034 * @param {Object} obj The list of behaviors to apply
1036 addBehaviors : function(o){
1038 Ext.onReady(function(){
1039 Ext.addBehaviors(o);
1042 var cache = {}, // simple cache for applying multiple behaviors to same selector does query multiple times
1047 if ((parts = b.split('@'))[1]) { // for Object prototype breakers
1050 cache[s] = Ext.select(s);
1052 cache[s].on(parts[1], o[b]);
1061 combine : function(){
1062 var as = arguments, l = as.length, r = [];
1063 for(var i = 0; i < l; i++){
1067 }else if(a.length !== undefined && !a.substr){
1068 r = r.concat(Array.prototype.slice.call(a, 0));
1077 * Copies a set of named properties fom the source object to the destination object.
1078 * <p>example:<pre><code>
1079 ImageComponent = Ext.extend(Ext.BoxComponent, {
1080 initComponent: function() {
1081 this.autoEl = { tag: 'img' };
1082 MyComponent.superclass.initComponent.apply(this, arguments);
1083 this.initialBox = Ext.copyTo({}, this.initialConfig, 'x,y,width,height');
1087 * @param {Object} The destination object.
1088 * @param {Object} The source object.
1089 * @param {Array/String} Either an Array of property names, or a comma-delimited list
1090 * of property names to copy.
1091 * @return {Object} The modified object.
1093 copyTo : function(dest, source, names){
1094 if(typeof names == 'string'){
1095 names = names.split(/[,;\s]/);
1097 Ext.each(names, function(name){
1098 if(source.hasOwnProperty(name)){
1099 dest[name] = source[name];
1106 * Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
1107 * DOM (if applicable) and calling their destroy functions (if available). This method is primarily
1108 * intended for arguments of type {@link Ext.Element} and {@link Ext.Component}, but any subclass of
1109 * {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
1110 * passed into this function in a single call as separate arguments.
1111 * @param {Mixed} arg1 An {@link Ext.Element}, {@link Ext.Component}, or an Array of either of these to destroy
1112 * @param {Mixed} arg2 (optional)
1113 * @param {Mixed} etc... (optional)
1115 destroy : function(){
1116 Ext.each(arguments, function(arg){
1118 if(Ext.isArray(arg)){
1119 this.destroy.apply(this, arg);
1120 }else if(Ext.isFunction(arg.destroy)){
1130 * Attempts to destroy and then remove a set of named properties of the passed object.
1131 * @param {Object} o The object (most likely a Component) who's properties you wish to destroy.
1132 * @param {Mixed} arg1 The name of the property to destroy and remove from the object.
1133 * @param {Mixed} etc... More property names to destroy and remove.
1135 destroyMembers : function(o, arg1, arg2, etc){
1136 for(var i = 1, a = arguments, len = a.length; i < len; i++) {
1137 Ext.destroy(o[a[i]]);
1143 * Creates a copy of the passed Array with falsy values removed.
1144 * @param {Array/NodeList} arr The Array from which to remove falsy values.
1145 * @return {Array} The new, compressed Array.
1147 clean : function(arr){
1149 Ext.each(arr, function(v){
1158 * Creates a copy of the passed Array, filtered to contain only unique values.
1159 * @param {Array} arr The Array to filter
1160 * @return {Array} The new Array containing unique values.
1162 unique : function(arr){
1166 Ext.each(arr, function(v) {
1176 * Recursively flattens into 1-d Array. Injects Arrays inline.
1177 * @param {Array} arr The array to flatten
1178 * @return {Array} The new, flattened array.
1180 flatten : function(arr){
1182 function rFlatten(a) {
1183 Ext.each(a, function(v) {
1192 return rFlatten(arr);
1196 * Returns the minimum value in the Array.
1197 * @param {Array|NodeList} arr The Array from which to select the minimum value.
1198 * @param {Function} comp (optional) a function to perform the comparision which determines minimization.
1199 * If omitted the "<" operator will be used. Note: gt = 1; eq = 0; lt = -1
1200 * @return {Object} The minimum value in the Array.
1202 min : function(arr, comp){
1204 comp = comp || function(a,b){ return a < b ? -1 : 1; };
1205 Ext.each(arr, function(v) {
1206 ret = comp(ret, v) == -1 ? ret : v;
1212 * Returns the maximum value in the Array
1213 * @param {Array|NodeList} arr The Array from which to select the maximum value.
1214 * @param {Function} comp (optional) a function to perform the comparision which determines maximization.
1215 * If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1
1216 * @return {Object} The maximum value in the Array.
1218 max : function(arr, comp){
1220 comp = comp || function(a,b){ return a > b ? 1 : -1; };
1221 Ext.each(arr, function(v) {
1222 ret = comp(ret, v) == 1 ? ret : v;
1228 * Calculates the mean of the Array
1229 * @param {Array} arr The Array to calculate the mean value of.
1230 * @return {Number} The mean.
1232 mean : function(arr){
1233 return Ext.sum(arr) / arr.length;
1237 * Calculates the sum of the Array
1238 * @param {Array} arr The Array to calculate the sum value of.
1239 * @return {Number} The sum.
1241 sum : function(arr){
1243 Ext.each(arr, function(v) {
1250 * Partitions the set into two sets: a true set and a false set.
1255 Ext.partition([true, false, true, true, false]); // [[true, true, true], [false, false]]
1261 return val.className == "class1"
1264 // true are those paragraph elements with a className of "class1",
1265 // false set are those that do not have that className.
1267 * @param {Array|NodeList} arr The array to partition
1268 * @param {Function} truth (optional) a function to determine truth. If this is omitted the element
1269 * itself must be able to be evaluated for its truthfulness.
1270 * @return {Array} [true<Array>,false<Array>]
1272 partition : function(arr, truth){
1274 Ext.each(arr, function(v, i, a) {
1275 ret[ (truth && truth(v, i, a)) || (!truth && v) ? 0 : 1].push(v);
1281 * Invokes a method on each item in an Array.
1284 Ext.invoke(Ext.query("p"), "getAttribute", "id");
1285 // [el1.getAttribute("id"), el2.getAttribute("id"), ..., elN.getAttribute("id")]
1287 * @param {Array|NodeList} arr The Array of items to invoke the method on.
1288 * @param {String} methodName The method name to invoke.
1289 * @param {Anything} ... Arguments to send into the method invocation.
1290 * @return {Array} The results of invoking the method on each item in the array.
1292 invoke : function(arr, methodName){
1294 args = Array.prototype.slice.call(arguments, 2);
1295 Ext.each(arr, function(v,i) {
1296 if (v && typeof v[methodName] == "function") {
1297 ret.push(v[methodName].apply(v, args));
1299 ret.push(undefined);
1306 * Plucks the value of a property from each item in the Array
1309 Ext.pluck(Ext.query("p"), "className"); // [el1.className, el2.className, ..., elN.className]
1311 * @param {Array|NodeList} arr The Array of items to pluck the value from.
1312 * @param {String} prop The property name to pluck from each element.
1313 * @return {Array} The value from each item in the Array.
1315 pluck : function(arr, prop){
1317 Ext.each(arr, function(v) {
1318 ret.push( v[prop] );
1324 * <p>Zips N sets together.</p>
1327 Ext.zip([1,2,3],[4,5,6]); // [[1,4],[2,5],[3,6]]
1334 return "$" + a + "" + b + "." + c
1336 ); // ["$+12.43", "$-10.15", "$+22.96"]
1338 * @param {Arrays|NodeLists} arr This argument may be repeated. Array(s) to contribute values.
1339 * @param {Function} zipper (optional) The last item in the argument list. This will drive how the items are zipped together.
1340 * @return {Array} The zipped set.
1343 var parts = Ext.partition(arguments, function( val ){ return !Ext.isFunction(val); }),
1346 len = Ext.max(Ext.pluck(arrs, "length")),
1349 for (var i = 0; i < len; i++) {
1352 ret[i] = fn.apply(fn, Ext.pluck(arrs, i));
1354 for (var j = 0, aLen = arrs.length; j < aLen; j++){
1355 ret[i].push( arrs[j][i] );
1363 * This is shorthand reference to {@link Ext.ComponentMgr#get}.
1364 * Looks up an existing {@link Ext.Component Component} by {@link Ext.Component#id id}
1365 * @param {String} id The component {@link Ext.Component#id id}
1366 * @return Ext.Component The Component, <tt>undefined</tt> if not found, or <tt>null</tt> if a
1369 getCmp : function(id){
1370 return Ext.ComponentMgr.get(id);
1374 * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
1375 * you may want to set this to true.
1378 useShims: E.isIE6 || (E.isMac && E.isGecko2),
1380 // inpired by a similar function in mootools library
1382 * Returns the type of object that is passed in. If the object passed in is null or undefined it
1383 * return false otherwise it returns one of the following values:<div class="mdetail-params"><ul>
1384 * <li><b>string</b>: If the object passed is a string</li>
1385 * <li><b>number</b>: If the object passed is a number</li>
1386 * <li><b>boolean</b>: If the object passed is a boolean value</li>
1387 * <li><b>date</b>: If the object passed is a Date object</li>
1388 * <li><b>function</b>: If the object passed is a function reference</li>
1389 * <li><b>object</b>: If the object passed is an object</li>
1390 * <li><b>array</b>: If the object passed is an array</li>
1391 * <li><b>regexp</b>: If the object passed is a regular expression</li>
1392 * <li><b>element</b>: If the object passed is a DOM Element</li>
1393 * <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
1394 * <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
1395 * <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
1397 * @param {Mixed} object
1401 if(o === undefined || o === null){
1408 if(t == 'object' && o.nodeName) {
1409 switch(o.nodeType) {
1410 case 1: return 'element';
1411 case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
1414 if(t == 'object' || t == 'function') {
1415 switch(o.constructor) {
1416 case Array: return 'array';
1417 case RegExp: return 'regexp';
1418 case Date: return 'date';
1420 if(typeof o.length == 'number' && typeof o.item == 'function') {
1427 intercept : function(o, name, fn, scope){
1428 o[name] = o[name].createInterceptor(fn, scope);
1432 callback : function(cb, scope, args, delay){
1433 if(Ext.isFunction(cb)){
1435 cb.defer(delay, scope, args || []);
1437 cb.apply(scope, args || []);
1446 * These functions are available on every Function object (any JavaScript function).
1448 Ext.apply(Function.prototype, {
1450 * Create a combined function call sequence of the original function + the passed function.
1451 * The resulting function returns the results of the original function.
1452 * The passed fcn is called with the parameters of the original function. Example usage:
1454 var sayHi = function(name){
1455 alert('Hi, ' + name);
1458 sayHi('Fred'); // alerts "Hi, Fred"
1460 var sayGoodbye = sayHi.createSequence(function(name){
1461 alert('Bye, ' + name);
1464 sayGoodbye('Fred'); // both alerts show
1466 * @param {Function} fcn The function to sequence
1467 * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
1468 * @return {Function} The new function
1470 createSequence : function(fcn, scope){
1472 return !Ext.isFunction(fcn) ?
1475 var retval = method.apply(this || window, arguments);
1476 fcn.apply(scope || this || window, arguments);
1485 * These functions are available as static methods on the JavaScript String object.
1487 Ext.applyIf(String, {
1490 * Escapes the passed string for ' and \
1491 * @param {String} string The string to escape
1492 * @return {String} The escaped string
1495 escape : function(string) {
1496 return string.replace(/('|\\)/g, "\\$1");
1500 * Pads the left side of a string with a specified character. This is especially useful
1501 * for normalizing number and date strings. Example usage:
1503 var s = String.leftPad('123', 5, '0');
1504 // s now contains the string: '00123'
1506 * @param {String} string The original string
1507 * @param {Number} size The total length of the output string
1508 * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
1509 * @return {String} The padded string
1512 leftPad : function (val, size, ch) {
1513 var result = String(val);
1517 while (result.length < size) {
1518 result = ch + result;
1525 * Utility function that allows you to easily switch a string between two alternating values. The passed value
1526 * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
1527 * they are already different, the first value passed in is returned. Note that this method returns the new value
1528 * but does not change the current string.
1530 // alternate sort directions
1531 sort = sort.toggle('ASC', 'DESC');
1533 // instead of conditional logic:
1534 sort = (sort == 'ASC' ? 'DESC' : 'ASC');
1536 * @param {String} value The value to compare to the current string
1537 * @param {String} other The new value to use if the string already equals the first value passed in
1538 * @return {String} The new value
1540 String.prototype.toggle = function(value, other){
1541 return this == value ? other : value;
1545 * Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
1547 var s = ' foo bar ';
1548 alert('-' + s + '-'); //alerts "- foo bar -"
1549 alert('-' + s.trim() + '-'); //alerts "-foo bar-"
1551 * @return {String} The trimmed string
1553 String.prototype.trim = function(){
1554 var re = /^\s+|\s+$/g;
1555 return function(){ return this.replace(re, ""); };
1558 // here to prevent dependency on Date.js
1560 Returns the number of milliseconds between this date and date
1561 @param {Date} date (optional) Defaults to now
1562 @return {Number} The diff in milliseconds
1563 @member Date getElapsed
1565 Date.prototype.getElapsed = function(date) {
1566 return Math.abs((date || new Date()).getTime()-this.getTime());
1573 Ext.applyIf(Number.prototype, {
1575 * Checks whether or not the current number is within a desired range. If the number is already within the
1576 * range it is returned, otherwise the min or max value is returned depending on which side of the range is
1577 * exceeded. Note that this method returns the constrained value but does not change the current number.
1578 * @param {Number} min The minimum number in the range
1579 * @param {Number} max The maximum number in the range
1580 * @return {Number} The constrained value if outside the range, otherwise the current value
1582 constrain : function(min, max){
1583 return Math.min(Math.max(this, min), max);
1587 * @class Ext.util.TaskRunner
1588 * Provides the ability to execute one or more arbitrary tasks in a multithreaded
1589 * manner. Generally, you can use the singleton {@link Ext.TaskMgr} instead, but
1590 * if needed, you can create separate instances of TaskRunner. Any number of
1591 * separate tasks can be started at any time and will run independently of each
1592 * other. Example usage:
1594 // Start a simple clock task that updates a div once per second
1595 var updateClock = function(){
1596 Ext.fly('clock').update(new Date().format('g:i:s A'));
1600 interval: 1000 //1 second
1602 var runner = new Ext.util.TaskRunner();
1605 // equivalent using TaskMgr
1612 * Also see {@link Ext.util.DelayedTask}.
1615 * @param {Number} interval (optional) The minimum precision in milliseconds supported by this TaskRunner instance
1618 Ext.util.TaskRunner = function(interval){
1619 interval = interval || 10;
1626 stopThread = function(){
1633 startThread = function(){
1636 id = setInterval(runTasks, interval);
1641 removeTask = function(t){
1642 removeQueue.push(t);
1644 t.onStop.apply(t.scope || t);
1649 runTasks = function(){
1650 var rqLen = removeQueue.length,
1651 now = new Date().getTime();
1654 for(var i = 0; i < rqLen; i++){
1655 tasks.remove(removeQueue[i]);
1658 if(tasks.length < 1){
1663 for(var i = 0, t, itime, rt, len = tasks.length; i < len; ++i){
1665 itime = now - t.taskRunTime;
1666 if(t.interval <= itime){
1667 rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
1668 t.taskRunTime = now;
1669 if(rt === false || t.taskRunCount === t.repeat){
1674 if(t.duration && t.duration <= (now - t.taskStartTime)){
1681 * Starts a new task.
1683 * @param {Object} task A config object that supports the following properties:<ul>
1684 * <li><code>run</code> : Function<div class="sub-desc">The function to execute each time the task is run. The
1685 * function will be called at each interval and passed the <code>args</code> argument if specified. If a
1686 * particular scope is required, be sure to specify it using the <code>scope</code> argument.</div></li>
1687 * <li><code>interval</code> : Number<div class="sub-desc">The frequency in milliseconds with which the task
1688 * should be executed.</div></li>
1689 * <li><code>args</code> : Array<div class="sub-desc">(optional) An array of arguments to be passed to the function
1690 * specified by <code>run</code>.</div></li>
1691 * <li><code>scope</code> : Object<div class="sub-desc">(optional) The scope (<tt>this</tt> reference) in which to execute the
1692 * <code>run</code> function. Defaults to the task config object.</div></li>
1693 * <li><code>duration</code> : Number<div class="sub-desc">(optional) The length of time in milliseconds to execute
1694 * the task before stopping automatically (defaults to indefinite).</div></li>
1695 * <li><code>repeat</code> : Number<div class="sub-desc">(optional) The number of times to execute the task before
1696 * stopping automatically (defaults to indefinite).</div></li>
1698 * @return {Object} The task
1700 this.start = function(task){
1702 task.taskStartTime = new Date().getTime();
1703 task.taskRunTime = 0;
1704 task.taskRunCount = 0;
1710 * Stops an existing running task.
1712 * @param {Object} task The task to stop
1713 * @return {Object} The task
1715 this.stop = function(task){
1721 * Stops all tasks that are currently running.
1724 this.stopAll = function(){
1726 for(var i = 0, len = tasks.length; i < len; i++){
1727 if(tasks[i].onStop){
1737 * @class Ext.TaskMgr
1738 * @extends Ext.util.TaskRunner
1739 * A static {@link Ext.util.TaskRunner} instance that can be used to start and stop arbitrary tasks. See
1740 * {@link Ext.util.TaskRunner} for supported methods and task config properties.
1742 // Start a simple clock task that updates a div once per second
1745 Ext.fly('clock').update(new Date().format('g:i:s A'));
1747 interval: 1000 //1 second
1749 Ext.TaskMgr.start(task);
1753 Ext.TaskMgr = new Ext.util.TaskRunner();(function(){
\r
1756 function fly(el) {
\r
1757 if (!libFlyweight) {
\r
1758 libFlyweight = new Ext.Element.Flyweight();
\r
1760 libFlyweight.dom = el;
\r
1761 return libFlyweight;
\r
1765 var doc = document,
\r
1766 isCSS1 = doc.compatMode == "CSS1Compat",
\r
1768 PARSEINT = parseInt;
\r
1771 isAncestor : function(p, c) {
\r
1774 p = Ext.getDom(p);
\r
1775 c = Ext.getDom(c);
\r
1778 return p.contains(c);
\r
1779 } else if (p.compareDocumentPosition) {
\r
1780 return !!(p.compareDocumentPosition(c) & 16);
\r
1782 while (c = c.parentNode) {
\r
1783 ret = c == p || ret;
\r
1790 getViewWidth : function(full) {
\r
1791 return full ? this.getDocumentWidth() : this.getViewportWidth();
\r
1794 getViewHeight : function(full) {
\r
1795 return full ? this.getDocumentHeight() : this.getViewportHeight();
\r
1798 getDocumentHeight: function() {
\r
1799 return MAX(!isCSS1 ? doc.body.scrollHeight : doc.documentElement.scrollHeight, this.getViewportHeight());
\r
1802 getDocumentWidth: function() {
\r
1803 return MAX(!isCSS1 ? doc.body.scrollWidth : doc.documentElement.scrollWidth, this.getViewportWidth());
\r
1806 getViewportHeight: function(){
\r
1807 return Ext.isIE ?
\r
1808 (Ext.isStrict ? doc.documentElement.clientHeight : doc.body.clientHeight) :
\r
1812 getViewportWidth : function() {
\r
1813 return !Ext.isStrict && !Ext.isOpera ? doc.body.clientWidth :
\r
1814 Ext.isIE ? doc.documentElement.clientWidth : self.innerWidth;
\r
1817 getY : function(el) {
\r
1818 return this.getXY(el)[1];
\r
1821 getX : function(el) {
\r
1822 return this.getXY(el)[0];
\r
1825 getXY : function(el) {
\r
1836 bd = (doc.body || doc.documentElement),
\r
1839 el = Ext.getDom(el);
\r
1842 if (el.getBoundingClientRect) {
\r
1843 b = el.getBoundingClientRect();
\r
1844 scroll = fly(document).getScroll();
\r
1845 ret = [b.left + scroll.left, b.top + scroll.top];
\r
1848 hasAbsolute = fly(el).isStyle("position", "absolute");
\r
1852 x += p.offsetLeft;
\r
1855 hasAbsolute = hasAbsolute || pe.isStyle("position", "absolute");
\r
1857 if (Ext.isGecko) {
\r
1858 y += bt = PARSEINT(pe.getStyle("borderTopWidth"), 10) || 0;
\r
1859 x += bl = PARSEINT(pe.getStyle("borderLeftWidth"), 10) || 0;
\r
1861 if (p != el && !pe.isStyle('overflow','visible')) {
\r
1866 p = p.offsetParent;
\r
1869 if (Ext.isSafari && hasAbsolute) {
\r
1870 x -= bd.offsetLeft;
\r
1871 y -= bd.offsetTop;
\r
1874 if (Ext.isGecko && !hasAbsolute) {
\r
1876 x += PARSEINT(dbd.getStyle("borderLeftWidth"), 10) || 0;
\r
1877 y += PARSEINT(dbd.getStyle("borderTopWidth"), 10) || 0;
\r
1880 p = el.parentNode;
\r
1881 while (p && p != bd) {
\r
1882 if (!Ext.isOpera || (p.tagName != 'TR' && !fly(p).isStyle("display", "inline"))) {
\r
1883 x -= p.scrollLeft;
\r
1894 setXY : function(el, xy) {
\r
1895 (el = Ext.fly(el, '_setXY')).position();
\r
1897 var pts = el.translatePoints(xy),
\r
1898 style = el.dom.style,
\r
1901 for (pos in pts) {
\r
1902 if(!isNaN(pts[pos])) style[pos] = pts[pos] + "px"
\r
1906 setX : function(el, x) {
\r
1907 this.setXY(el, [x, false]);
\r
1910 setY : function(el, y) {
\r
1911 this.setXY(el, [false, y]);
\r
1914 })();Ext.lib.Dom.getRegion = function(el) {
\r
1915 return Ext.lib.Region.getRegion(el);
\r
1916 };Ext.lib.Event = function() {
\r
1917 var loadComplete = false,
\r
1919 unloadListeners = [],
\r
1921 onAvailStack = [],
\r
1928 POLL_RETRYS = 200,
\r
1929 POLL_INTERVAL = 20,
\r
1936 SCROLLLEFT = 'scrollLeft',
\r
1937 SCROLLTOP = 'scrollTop',
\r
1938 UNLOAD = 'unload',
\r
1939 MOUSEOVER = 'mouseover',
\r
1940 MOUSEOUT = 'mouseout',
\r
1942 doAdd = function() {
\r
1944 if (win.addEventListener) {
\r
1945 ret = function(el, eventName, fn, capture) {
\r
1946 if (eventName == 'mouseenter') {
\r
1947 fn = fn.createInterceptor(checkRelatedTarget);
\r
1948 el.addEventListener(MOUSEOVER, fn, (capture));
\r
1949 } else if (eventName == 'mouseleave') {
\r
1950 fn = fn.createInterceptor(checkRelatedTarget);
\r
1951 el.addEventListener(MOUSEOUT, fn, (capture));
\r
1953 el.addEventListener(eventName, fn, (capture));
\r
1957 } else if (win.attachEvent) {
\r
1958 ret = function(el, eventName, fn, capture) {
\r
1959 el.attachEvent("on" + eventName, fn);
\r
1963 ret = function(){};
\r
1968 doRemove = function(){
\r
1970 if (win.removeEventListener) {
\r
1971 ret = function (el, eventName, fn, capture) {
\r
1972 if (eventName == 'mouseenter') {
\r
1973 eventName = MOUSEOVER;
\r
1974 } else if (eventName == 'mouseleave') {
\r
1975 eventName = MOUSEOUT;
\r
1977 el.removeEventListener(eventName, fn, (capture));
\r
1979 } else if (win.detachEvent) {
\r
1980 ret = function (el, eventName, fn) {
\r
1981 el.detachEvent("on" + eventName, fn);
\r
1984 ret = function(){};
\r
1989 var isXUL = Ext.isGecko ? function(node){
\r
1990 return Object.prototype.toString.call(node) == '[object XULElement]';
\r
1993 var isTextNode = Ext.isGecko ? function(node){
\r
1995 return node.nodeType == 3;
\r
2000 } : function(node){
\r
2001 return node.nodeType == 3;
\r
2004 function checkRelatedTarget(e) {
\r
2005 var related = pub.getRelatedTarget(e);
\r
2006 return !(isXUL(related) || elContains(e.currentTarget,related));
\r
2009 function elContains(parent, child) {
\r
2010 if(parent && parent.firstChild){
\r
2012 if(child === parent) {
\r
2016 child = child.parentNode;
\r
2018 // In FF if you mouseout an text input element
\r
2019 // thats inside a div sometimes it randomly throws
\r
2020 // Permission denied to get property HTMLDivElement.parentNode
\r
2021 // See https://bugzilla.mozilla.org/show_bug.cgi?id=208427
\r
2025 if(child && (child.nodeType != 1)) {
\r
2035 function _getCacheIndex(el, eventName, fn) {
\r
2037 Ext.each(listeners, function (v,i) {
\r
2038 if(v && v[FN] == fn && v[EL] == el && v[TYPE] == eventName) {
\r
2046 function _tryPreloadAttach() {
\r
2050 tryAgain = !loadComplete || (retryCount > 0);
\r
2055 Ext.each(onAvailStack, function (v,i,a){
\r
2056 if(v && (element = doc.getElementById(v.id))){
\r
2057 if(!v.checkReady || loadComplete || element.nextSibling || (doc && doc.body)) {
\r
2058 element = v.override ? (v.override === true ? v.obj : v.override) : element;
\r
2059 v.fn.call(element, v.obj);
\r
2060 onAvailStack[i] = null;
\r
2067 retryCount = (notAvail.length === 0) ? 0 : retryCount - 1;
\r
2072 clearInterval(_interval);
\r
2076 ret = !(locked = false);
\r
2082 function startInterval() {
\r
2084 var callback = function() {
\r
2085 _tryPreloadAttach();
\r
2087 _interval = setInterval(callback, POLL_INTERVAL);
\r
2092 function getScroll() {
\r
2093 var dd = doc.documentElement,
\r
2095 if(dd && (dd[SCROLLTOP] || dd[SCROLLLEFT])){
\r
2096 return [dd[SCROLLLEFT], dd[SCROLLTOP]];
\r
2098 return [db[SCROLLLEFT], db[SCROLLTOP]];
\r
2105 function getPageCoord (ev, xy) {
\r
2106 ev = ev.browserEvent || ev;
\r
2107 var coord = ev['page' + xy];
\r
2108 if (!coord && coord !== 0) {
\r
2109 coord = ev['client' + xy] || 0;
\r
2112 coord += getScroll()[xy == "X" ? 0 : 1];
\r
2120 onAvailable : function(p_id, p_fn, p_obj, p_override) {
\r
2121 onAvailStack.push({
\r
2125 override: p_override,
\r
2126 checkReady: false });
\r
2128 retryCount = POLL_RETRYS;
\r
2133 addListener: function(el, eventName, fn) {
\r
2135 el = Ext.getDom(el);
\r
2137 if (UNLOAD == eventName) {
\r
2138 ret = !!(unloadListeners[unloadListeners.length] = [el, eventName, fn]);
\r
2140 listeners.push([el, eventName, fn, ret = doAdd(el, eventName, fn, false)]);
\r
2146 removeListener: function(el, eventName, fn) {
\r
2151 el = Ext.getDom(el);
\r
2154 ret = this.purgeElement(el, false, eventName);
\r
2155 } else if (UNLOAD == eventName) {
\r
2156 Ext.each(unloadListeners, function(v, i, a) {
\r
2157 if( v && v[0] == el && v[1] == eventName && v[2] == fn) {
\r
2158 unloadListeners.splice(i, 1);
\r
2163 index = arguments[3] || _getCacheIndex(el, eventName, fn);
\r
2164 cacheItem = listeners[index];
\r
2166 if (el && cacheItem) {
\r
2167 doRemove(el, eventName, cacheItem[WFN], false);
\r
2168 cacheItem[WFN] = cacheItem[FN] = null;
\r
2169 listeners.splice(index, 1);
\r
2176 getTarget : function(ev) {
\r
2177 ev = ev.browserEvent || ev;
\r
2178 return this.resolveTextNode(ev.target || ev.srcElement);
\r
2181 resolveTextNode : function(node) {
\r
2182 return node && !isXUL(node) && isTextNode(node) ? node.parentNode : node;
\r
2185 getRelatedTarget : function(ev) {
\r
2186 ev = ev.browserEvent || ev;
\r
2187 return this.resolveTextNode(ev.relatedTarget ||
\r
2188 (ev.type == MOUSEOUT ? ev.toElement :
\r
2189 ev.type == MOUSEOVER ? ev.fromElement : null));
\r
2192 getPageX : function(ev) {
\r
2193 return getPageCoord(ev, "X");
\r
2196 getPageY : function(ev) {
\r
2197 return getPageCoord(ev, "Y");
\r
2201 getXY : function(ev) {
\r
2202 return [this.getPageX(ev), this.getPageY(ev)];
\r
2205 // Is this useful? Removing to save space unless use case exists.
\r
2206 // getTime: function(ev) {
\r
2207 // ev = ev.browserEvent || ev;
\r
2208 // if (!ev.time) {
\r
2209 // var t = new Date().getTime();
\r
2217 // return ev.time;
\r
2220 stopEvent : function(ev) {
\r
2221 this.stopPropagation(ev);
\r
2222 this.preventDefault(ev);
\r
2225 stopPropagation : function(ev) {
\r
2226 ev = ev.browserEvent || ev;
\r
2227 if (ev.stopPropagation) {
\r
2228 ev.stopPropagation();
\r
2230 ev.cancelBubble = true;
\r
2234 preventDefault : function(ev) {
\r
2235 ev = ev.browserEvent || ev;
\r
2236 if (ev.preventDefault) {
\r
2237 ev.preventDefault();
\r
2239 ev.returnValue = false;
\r
2243 getEvent : function(e) {
\r
2244 e = e || win.event;
\r
2246 var c = this.getEvent.caller;
\r
2248 e = c.arguments[0];
\r
2249 if (e && Event == e.constructor) {
\r
2258 getCharCode : function(ev) {
\r
2259 ev = ev.browserEvent || ev;
\r
2260 return ev.charCode || ev.keyCode || 0;
\r
2263 //clearCache: function() {},
\r
2265 _load : function(e) {
\r
2266 loadComplete = true;
\r
2267 var EU = Ext.lib.Event;
\r
2268 if (Ext.isIE && e !== true) {
\r
2269 // IE8 complains that _load is null or not an object
\r
2270 // so lets remove self via arguments.callee
\r
2271 doRemove(win, "load", arguments.callee);
\r
2275 purgeElement : function(el, recurse, eventName) {
\r
2277 Ext.each( me.getListeners(el, eventName), function(v){
\r
2279 me.removeListener(el, v.type, v.fn);
\r
2283 if (recurse && el && el.childNodes) {
\r
2284 Ext.each(el.childNodes, function(v){
\r
2285 me.purgeElement(v, recurse, eventName);
\r
2290 getListeners : function(el, eventName) {
\r
2296 searchLists = eventName == UNLOAD ? unloadListeners : listeners;
\r
2298 searchLists = listeners.concat(unloadListeners);
\r
2301 Ext.each(searchLists, function(v, i){
\r
2302 if (v && v[EL] == el && (!eventName || eventName == v[TYPE])) {
\r
2307 adjust: v[ADJ_SCOPE],
\r
2313 return results.length ? results : null;
\r
2316 _unload : function(e) {
\r
2317 var EU = Ext.lib.Event,
\r
2326 Ext.each(unloadListeners, function(v) {
\r
2329 scope = v[ADJ_SCOPE] ? (v[ADJ_SCOPE] === true ? v[OBJ] : v[ADJ_SCOPE]) : win;
\r
2330 v[FN].call(scope, EU.getEvent(e), v[OBJ]);
\r
2335 unloadListeners = null;
\r
2337 if(listeners && (j = listeners.length)){
\r
2339 if((l = listeners[index = --j])){
\r
2340 EU.removeListener(l[EL], l[TYPE], l[FN], index);
\r
2343 //EU.clearCache();
\r
2346 doRemove(win, UNLOAD, EU._unload);
\r
2350 // Initialize stuff.
\r
2351 pub.on = pub.addListener;
\r
2352 pub.un = pub.removeListener;
\r
2353 if (doc && doc.body) {
\r
2356 doAdd(win, "load", pub._load);
\r
2358 doAdd(win, UNLOAD, pub._unload);
\r
2359 _tryPreloadAttach();
\r
2363 * Portions of this file are based on pieces of Yahoo User Interface Library
\r
2364 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
\r
2365 * YUI licensed under the BSD License:
\r
2366 * http://developer.yahoo.net/yui/license.txt
\r
2368 Ext.lib.Ajax = function() {
\r
2369 var activeX = ['MSXML2.XMLHTTP.3.0',
\r
2371 'Microsoft.XMLHTTP'],
\r
2372 CONTENTTYPE = 'Content-Type';
\r
2375 function setHeader(o) {
\r
2376 var conn = o.conn,
\r
2379 function setTheHeaders(conn, headers){
\r
2380 for (prop in headers) {
\r
2381 if (headers.hasOwnProperty(prop)) {
\r
2382 conn.setRequestHeader(prop, headers[prop]);
\r
2387 if (pub.defaultHeaders) {
\r
2388 setTheHeaders(conn, pub.defaultHeaders);
\r
2391 if (pub.headers) {
\r
2392 setTheHeaders(conn, pub.headers);
\r
2393 pub.headers = null;
\r
2398 function createExceptionObject(tId, callbackArg, isAbort, isTimeout) {
\r
2401 status : isAbort ? -1 : 0,
\r
2402 statusText : isAbort ? 'transaction aborted' : 'communication failure',
\r
2405 argument : callbackArg
\r
2410 function initHeader(label, value) {
\r
2411 (pub.headers = pub.headers || {})[label] = value;
\r
2415 function createResponseObject(o, callbackArg) {
\r
2416 var headerObj = {},
\r
2423 headerStr = o.conn.getAllResponseHeaders();
\r
2424 Ext.each(headerStr.replace(/\r\n/g, '\n').split('\n'), function(v){
\r
2425 t = v.indexOf(':');
\r
2427 s = v.substr(0, t).toLowerCase();
\r
2428 if(v.charAt(t + 1) == ' '){
\r
2431 headerObj[s] = v.substr(t + 1);
\r
2438 status : conn.status,
\r
2439 statusText : conn.statusText,
\r
2440 getResponseHeader : function(header){return headerObj[header.toLowerCase()];},
\r
2441 getAllResponseHeaders : function(){return headerStr},
\r
2442 responseText : conn.responseText,
\r
2443 responseXML : conn.responseXML,
\r
2444 argument : callbackArg
\r
2449 function releaseObject(o) {
\r
2455 function handleTransactionResponse(o, callback, isAbort, isTimeout) {
\r
2461 var httpStatus, responseObject;
\r
2464 if (o.conn.status !== undefined && o.conn.status != 0) {
\r
2465 httpStatus = o.conn.status;
\r
2468 httpStatus = 13030;
\r
2472 httpStatus = 13030;
\r
2475 if ((httpStatus >= 200 && httpStatus < 300) || (Ext.isIE && httpStatus == 1223)) {
\r
2476 responseObject = createResponseObject(o, callback.argument);
\r
2477 if (callback.success) {
\r
2478 if (!callback.scope) {
\r
2479 callback.success(responseObject);
\r
2482 callback.success.apply(callback.scope, [responseObject]);
\r
2487 switch (httpStatus) {
\r
2494 responseObject = createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false), isTimeout);
\r
2495 if (callback.failure) {
\r
2496 if (!callback.scope) {
\r
2497 callback.failure(responseObject);
\r
2500 callback.failure.apply(callback.scope, [responseObject]);
\r
2505 responseObject = createResponseObject(o, callback.argument);
\r
2506 if (callback.failure) {
\r
2507 if (!callback.scope) {
\r
2508 callback.failure(responseObject);
\r
2511 callback.failure.apply(callback.scope, [responseObject]);
\r
2518 responseObject = null;
\r
2522 function handleReadyState(o, callback){
\r
2523 callback = callback || {};
\r
2524 var conn = o.conn,
\r
2527 cbTimeout = callback.timeout || null;
\r
2530 pub.timeout[tId] = setTimeout(function() {
\r
2531 pub.abort(o, callback, true);
\r
2535 poll[tId] = setInterval(
\r
2537 if (conn && conn.readyState == 4) {
\r
2538 clearInterval(poll[tId]);
\r
2542 clearTimeout(pub.timeout[tId]);
\r
2543 pub.timeout[tId] = null;
\r
2546 handleTransactionResponse(o, callback);
\r
2549 pub.pollInterval);
\r
2553 function asyncRequest(method, uri, callback, postData) {
\r
2554 var o = getConnectionObject() || null;
\r
2557 o.conn.open(method, uri, true);
\r
2559 if (pub.useDefaultXhrHeader) {
\r
2560 initHeader('X-Requested-With', pub.defaultXhrHeader);
\r
2563 if(postData && pub.useDefaultHeader && (!pub.headers || !pub.headers[CONTENTTYPE])){
\r
2564 initHeader(CONTENTTYPE, pub.defaultPostHeader);
\r
2567 if (pub.defaultHeaders || pub.headers) {
\r
2571 handleReadyState(o, callback);
\r
2572 o.conn.send(postData || null);
\r
2578 function getConnectionObject() {
\r
2582 if (o = createXhrObject(pub.transactionId)) {
\r
2583 pub.transactionId++;
\r
2592 function createXhrObject(transactionId) {
\r
2596 http = new XMLHttpRequest();
\r
2598 for (var i = 0; i < activeX.length; ++i) {
\r
2600 http = new ActiveXObject(activeX[i]);
\r
2605 return {conn : http, tId : transactionId};
\r
2610 request : function(method, uri, cb, data, options) {
\r
2613 xmlData = options.xmlData,
\r
2614 jsonData = options.jsonData,
\r
2617 Ext.applyIf(me, options);
\r
2619 if(xmlData || jsonData){
\r
2621 if(!hs || !hs[CONTENTTYPE]){
\r
2622 initHeader(CONTENTTYPE, xmlData ? 'text/xml' : 'application/json');
\r
2624 data = xmlData || (Ext.isObject(jsonData) ? Ext.encode(jsonData) : jsonData);
\r
2627 return asyncRequest(method || options.method || "POST", uri, cb, data);
\r
2630 serializeForm : function(form) {
\r
2631 var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements,
\r
2632 hasSubmit = false,
\r
2633 encoder = encodeURIComponent,
\r
2641 Ext.each(fElements, function(element) {
\r
2642 name = element.name;
\r
2643 type = element.type;
\r
2645 if (!element.disabled && name){
\r
2646 if(/select-(one|multiple)/i.test(type)){
\r
2647 Ext.each(element.options, function(opt) {
\r
2648 if (opt.selected) {
\r
2649 data += String.format("{0}={1}&",
\r
2651 (opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttributeNode('value').specified) ? opt.value : opt.text);
\r
2654 } else if(!/file|undefined|reset|button/i.test(type)) {
\r
2655 if(!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit)){
\r
2657 data += encoder(name) + '=' + encoder(element.value) + '&';
\r
2658 hasSubmit = /submit/i.test(type);
\r
2663 return data.substr(0, data.length - 1);
\r
2666 useDefaultHeader : true,
\r
2667 defaultPostHeader : 'application/x-www-form-urlencoded; charset=UTF-8',
\r
2668 useDefaultXhrHeader : true,
\r
2669 defaultXhrHeader : 'XMLHttpRequest',
\r
2672 pollInterval : 50,
\r
2673 transactionId : 0,
\r
2675 // This is never called - Is it worth exposing this?
\r
2676 // setProgId : function(id) {
\r
2677 // activeX.unshift(id);
\r
2680 // This is never called - Is it worth exposing this?
\r
2681 // setDefaultPostHeader : function(b) {
\r
2682 // this.useDefaultHeader = b;
\r
2685 // This is never called - Is it worth exposing this?
\r
2686 // setDefaultXhrHeader : function(b) {
\r
2687 // this.useDefaultXhrHeader = b;
\r
2690 // This is never called - Is it worth exposing this?
\r
2691 // setPollingInterval : function(i) {
\r
2692 // if (typeof i == 'number' && isFinite(i)) {
\r
2693 // this.pollInterval = i;
\r
2697 // This is never called - Is it worth exposing this?
\r
2698 // resetDefaultHeaders : function() {
\r
2699 // this.defaultHeaders = null;
\r
2702 abort : function(o, callback, isTimeout) {
\r
2707 if (me.isCallInProgress(o)) {
\r
2709 clearInterval(me.poll[tId]);
\r
2710 me.poll[tId] = null;
\r
2712 me.timeout[tId] = null;
\r
2715 handleTransactionResponse(o, callback, (isAbort = true), isTimeout);
\r
2720 isCallInProgress : function(o) {
\r
2721 // if there is a connection and readyState is not 0 or 4
\r
2722 return o.conn && !{0:true,4:true}[o.conn.readyState];
\r
2726 }(); Ext.lib.Region = function(t, r, b, l) {
\r
2736 Ext.lib.Region.prototype = {
\r
2737 contains : function(region) {
\r
2739 return ( region.left >= me.left &&
\r
2740 region.right <= me.right &&
\r
2741 region.top >= me.top &&
\r
2742 region.bottom <= me.bottom );
\r
2746 getArea : function() {
\r
2748 return ( (me.bottom - me.top) * (me.right - me.left) );
\r
2751 intersect : function(region) {
\r
2753 t = Math.max(me.top, region.top),
\r
2754 r = Math.min(me.right, region.right),
\r
2755 b = Math.min(me.bottom, region.bottom),
\r
2756 l = Math.max(me.left, region.left);
\r
2758 if (b >= t && r >= l) {
\r
2759 return new Ext.lib.Region(t, r, b, l);
\r
2763 union : function(region) {
\r
2765 t = Math.min(me.top, region.top),
\r
2766 r = Math.max(me.right, region.right),
\r
2767 b = Math.max(me.bottom, region.bottom),
\r
2768 l = Math.min(me.left, region.left);
\r
2770 return new Ext.lib.Region(t, r, b, l);
\r
2773 constrainTo : function(r) {
\r
2775 me.top = me.top.constrain(r.top, r.bottom);
\r
2776 me.bottom = me.bottom.constrain(r.top, r.bottom);
\r
2777 me.left = me.left.constrain(r.left, r.right);
\r
2778 me.right = me.right.constrain(r.left, r.right);
\r
2782 adjust : function(t, l, b, r) {
\r
2792 Ext.lib.Region.getRegion = function(el) {
\r
2793 var p = Ext.lib.Dom.getXY(el),
\r
2795 r = p[0] + el.offsetWidth,
\r
2796 b = p[1] + el.offsetHeight,
\r
2799 return new Ext.lib.Region(t, r, b, l);
\r
2800 }; Ext.lib.Point = function(x, y) {
\r
2801 if (Ext.isArray(x)) {
\r
2806 me.x = me.right = me.left = me[0] = x;
\r
2807 me.y = me.top = me.bottom = me[1] = y;
\r
2810 Ext.lib.Point.prototype = new Ext.lib.Region();
\r
2812 var EXTLIB = Ext.lib,
\r
2813 noNegatives = /width|height|opacity|padding/i,
\r
2814 offsetAttribute = /^((width|height)|(top|left))$/,
\r
2815 defaultUnit = /width|height|top$|bottom$|left$|right$/i,
\r
2816 offsetUnit = /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i,
\r
2817 isset = function(v){
\r
2818 return typeof v !== 'undefined';
\r
2821 return new Date();
\r
2825 motion : function(el, args, duration, easing, cb, scope) {
\r
2826 return this.run(el, args, duration, easing, cb, scope, Ext.lib.Motion);
\r
2829 run : function(el, args, duration, easing, cb, scope, type) {
\r
2830 type = type || Ext.lib.AnimBase;
\r
2831 if (typeof easing == "string") {
\r
2832 easing = Ext.lib.Easing[easing];
\r
2834 var anim = new type(el, args, duration, easing);
\r
2835 anim.animateX(function() {
\r
2836 if(Ext.isFunction(cb)){
\r
2844 EXTLIB.AnimBase = function(el, attributes, duration, method) {
\r
2846 this.init(el, attributes, duration, method);
\r
2850 EXTLIB.AnimBase.prototype = {
\r
2851 doMethod: function(attr, start, end) {
\r
2853 return me.method(me.curFrame, start, end - start, me.totalFrames);
\r
2857 setAttr: function(attr, val, unit) {
\r
2858 if (noNegatives.test(attr) && val < 0) {
\r
2861 Ext.fly(this.el, '_anim').setStyle(attr, val + unit);
\r
2865 getAttr: function(attr) {
\r
2866 var el = Ext.fly(this.el),
\r
2867 val = el.getStyle(attr),
\r
2868 a = offsetAttribute.exec(attr) || []
\r
2870 if (val !== 'auto' && !offsetUnit.test(val)) {
\r
2871 return parseFloat(val);
\r
2874 return (!!(a[2]) || (el.getStyle('position') == 'absolute' && !!(a[3]))) ? el.dom['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)] : 0;
\r
2878 getDefaultUnit: function(attr) {
\r
2879 return defaultUnit.test(attr) ? 'px' : '';
\r
2882 animateX : function(callback, scope) {
\r
2885 me.onComplete.removeListener(f);
\r
2886 if (Ext.isFunction(callback)) {
\r
2887 callback.call(scope || me, me);
\r
2890 me.onComplete.addListener(f, me);
\r
2895 setRunAttr: function(attr) {
\r
2897 a = this.attributes[attr],
\r
2902 ra = (this.runAttrs[attr] = {}),
\r
2905 if (!isset(to) && !isset(by)){
\r
2909 var start = isset(from) ? from : me.getAttr(attr);
\r
2912 }else if(isset(by)) {
\r
2913 if (Ext.isArray(start)){
\r
2915 Ext.each(start, function(v, i){
\r
2916 end[i] = v + by[i];
\r
2926 unit: isset(unit) ? unit : me.getDefaultUnit(attr)
\r
2931 init: function(el, attributes, duration, method) {
\r
2934 mgr = EXTLIB.AnimMgr;
\r
2937 isAnimated: false,
\r
2939 el: Ext.getDom(el),
\r
2940 attributes: attributes || {},
\r
2941 duration: duration || 1,
\r
2942 method: method || EXTLIB.Easing.easeNone,
\r
2945 totalFrames: mgr.fps,
\r
2947 animate: function(){
\r
2951 if(me.isAnimated){
\r
2956 me.totalFrames = me.useSec ? Math.ceil(mgr.fps * d) : d;
\r
2957 mgr.registerElement(me);
\r
2960 stop: function(finish){
\r
2964 me.curFrame = me.totalFrames;
\r
2965 me._onTween.fire();
\r
2971 var onStart = function(){
\r
2975 me.onStart.fire();
\r
2977 for(attr in this.attributes){
\r
2978 this.setRunAttr(attr);
\r
2981 me.isAnimated = true;
\r
2982 me.startTime = now();
\r
2987 var onTween = function(){
\r
2991 duration: now() - me.startTime,
\r
2992 curFrame: me.curFrame
\r
2995 var ra = me.runAttrs;
\r
2996 for (var attr in ra) {
\r
2997 this.setAttr(attr, me.doMethod(attr, ra[attr].start, ra[attr].end), ra[attr].unit);
\r
3003 var onComplete = function() {
\r
3005 actual = (now() - me.startTime) / 1000,
\r
3008 frames: actualFrames,
\r
3009 fps: actualFrames / actual
\r
3012 me.isAnimated = false;
\r
3014 me.onComplete.fire(data);
\r
3017 me.onStart = new Ext.util.Event(me);
\r
3018 me.onTween = new Ext.util.Event(me);
\r
3019 me.onComplete = new Ext.util.Event(me);
\r
3020 (me._onStart = new Ext.util.Event(me)).addListener(onStart);
\r
3021 (me._onTween = new Ext.util.Event(me)).addListener(onTween);
\r
3022 (me._onComplete = new Ext.util.Event(me)).addListener(onComplete);
\r
3027 Ext.lib.AnimMgr = new function() {
\r
3037 registerElement: function(tween){
\r
3038 queue.push(tween);
\r
3040 tween._onStart.fire();
\r
3044 unRegister: function(tween, index){
\r
3045 tween._onComplete.fire();
\r
3046 index = index || getIndex(tween);
\r
3047 if (index != -1) {
\r
3048 queue.splice(index, 1);
\r
3051 if (--tweenCount <= 0) {
\r
3056 start: function(){
\r
3057 if(thread === null){
\r
3058 thread = setInterval(me.run, me.delay);
\r
3062 stop: function(tween){
\r
3064 clearInterval(thread);
\r
3065 for(var i = 0, len = queue.length; i < len; ++i){
\r
3066 if(queue[0].isAnimated){
\r
3067 me.unRegister(queue[0], 0);
\r
3075 me.unRegister(tween);
\r
3081 Ext.each(queue, function(tween){
\r
3082 if(tween && tween.isAnimated){
\r
3083 tf = tween.totalFrames;
\r
3084 if(tween.curFrame < tf || tf === null){
\r
3087 correctFrame(tween);
\r
3089 tween._onTween.fire();
\r
3098 var getIndex = function(anim) {
\r
3100 Ext.each(queue, function(item, idx){
\r
3110 var correctFrame = function(tween) {
\r
3111 var frames = tween.totalFrames,
\r
3112 frame = tween.curFrame,
\r
3113 duration = tween.duration,
\r
3114 expected = (frame * duration * 1000 / frames),
\r
3115 elapsed = (now() - tween.startTime),
\r
3118 if(elapsed < duration * 1000){
\r
3119 tweak = Math.round((elapsed / expected - 1) * frame);
\r
3121 tweak = frames - (frame + 1);
\r
3123 if(tweak > 0 && isFinite(tweak)){
\r
3124 if(tween.curFrame + tweak >= frames){
\r
3125 tweak = frames - (frame + 1);
\r
3127 tween.curFrame += tweak;
\r
3132 EXTLIB.Bezier = new function() {
\r
3134 this.getPosition = function(points, t) {
\r
3135 var n = points.length,
\r
3141 for (i = 0; i < n; ++i) {
\r
3142 tmp[i] = [points[i][0], points[i][1]];
\r
3145 for (j = 1; j < n; ++j) {
\r
3146 for (i = 0; i < n - j; ++i) {
\r
3147 tmp[i][0] = c * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
\r
3148 tmp[i][1] = c * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
\r
3152 return [ tmp[0][0], tmp[0][1] ];
\r
3159 easeNone: function (t, b, c, d) {
\r
3160 return c * t / d + b;
\r
3164 easeIn: function (t, b, c, d) {
\r
3165 return c * (t /= d) * t + b;
\r
3169 easeOut: function (t, b, c, d) {
\r
3170 return -c * (t /= d) * (t - 2) + b;
\r
3175 EXTLIB.Motion = function(el, attributes, duration, method) {
\r
3177 EXTLIB.Motion.superclass.constructor.call(this, el, attributes, duration, method);
\r
3181 Ext.extend(EXTLIB.Motion, Ext.lib.AnimBase);
\r
3183 var superclass = EXTLIB.Motion.superclass,
\r
3184 proto = EXTLIB.Motion.prototype,
\r
3185 pointsRe = /^points$/i;
\r
3187 Ext.apply(EXTLIB.Motion.prototype, {
\r
3188 setAttr: function(attr, val, unit){
\r
3190 setAttr = superclass.setAttr;
\r
3192 if (pointsRe.test(attr)) {
\r
3193 unit = unit || 'px';
\r
3194 setAttr.call(me, 'left', val[0], unit);
\r
3195 setAttr.call(me, 'top', val[1], unit);
\r
3197 setAttr.call(me, attr, val, unit);
\r
3201 getAttr: function(attr){
\r
3203 getAttr = superclass.getAttr;
\r
3205 return pointsRe.test(attr) ? [getAttr.call(me, 'left'), getAttr.call(me, 'top')] : getAttr.call(me, attr);
\r
3208 doMethod: function(attr, start, end){
\r
3211 return pointsRe.test(attr)
\r
3212 ? EXTLIB.Bezier.getPosition(me.runAttrs[attr], me.method(me.curFrame, 0, 100, me.totalFrames) / 100)
\r
3213 : superclass.doMethod.call(me, attr, start, end);
\r
3216 setRunAttr: function(attr){
\r
3217 if(pointsRe.test(attr)){
\r
3221 points = this.attributes.points,
\r
3222 control = points.control || [],
\r
3223 from = points.from,
\r
3234 if(control.length > 0 && !Ext.isArray(control[0])){
\r
3235 control = [control];
\r
3239 for (i = 0,len = control.length; i < len; ++i) {
\r
3240 tmp[i] = control[i];
\r
3246 Ext.fly(el, '_anim').position();
\r
3247 DOM.setXY(el, isset(from) ? from : DOM.getXY(el));
\r
3248 start = me.getAttr('points');
\r
3252 end = translateValues.call(me, to, start);
\r
3253 for (i = 0,len = control.length; i < len; ++i) {
\r
3254 control[i] = translateValues.call(me, control[i], start);
\r
3256 } else if (isset(by)) {
\r
3257 end = [start[0] + by[0], start[1] + by[1]];
\r
3259 for (i = 0,len = control.length; i < len; ++i) {
\r
3260 control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
\r
3264 ra = this.runAttrs[attr] = [start];
\r
3265 if (control.length > 0) {
\r
3266 ra = ra.concat(control);
\r
3269 ra[ra.length] = end;
\r
3271 superclass.setRunAttr.call(this, attr);
\r
3276 var translateValues = function(val, start) {
\r
3277 var pageXY = EXTLIB.Dom.getXY(this.el);
\r
3278 return [val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1]];
\r
3281 })();// Easing functions
\r
3283 // shortcuts to aid compression
\r
3284 var abs = Math.abs,
\r
3291 Ext.apply(EXTLIB.Easing, {
\r
3293 easeBoth: function (t, b, c, d) {
\r
3294 return ((t /= d / 2) < 1) ? c / 2 * t * t + b : -c / 2 * ((--t) * (t - 2) - 1) + b;
\r
3297 easeInStrong: function (t, b, c, d) {
\r
3298 return c * (t /= d) * t * t * t + b;
\r
3301 easeOutStrong: function (t, b, c, d) {
\r
3302 return -c * ((t = t / d - 1) * t * t * t - 1) + b;
\r
3305 easeBothStrong: function (t, b, c, d) {
\r
3306 return ((t /= d / 2) < 1) ? c / 2 * t * t * t * t + b : -c / 2 * ((t -= 2) * t * t * t - 2) + b;
\r
3309 elasticIn: function (t, b, c, d, a, p) {
\r
3310 if (t == 0 || (t /= d) == 1) {
\r
3311 return t == 0 ? b : b + c;
\r
3313 p = p || (d * .3);
\r
3316 if (a >= abs(c)) {
\r
3317 s = p / (2 * pi) * asin(c / a);
\r
3323 return -(a * pow(2, 10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p)) + b;
\r
3327 elasticOut: function (t, b, c, d, a, p) {
\r
3328 if (t == 0 || (t /= d) == 1) {
\r
3329 return t == 0 ? b : b + c;
\r
3331 p = p || (d * .3);
\r
3334 if (a >= abs(c)) {
\r
3335 s = p / (2 * pi) * asin(c / a);
\r
3341 return a * pow(2, -10 * t) * sin((t * d - s) * (2 * pi) / p) + c + b;
\r
3344 elasticBoth: function (t, b, c, d, a, p) {
\r
3345 if (t == 0 || (t /= d / 2) == 2) {
\r
3346 return t == 0 ? b : b + c;
\r
3349 p = p || (d * (.3 * 1.5));
\r
3352 if (a >= abs(c)) {
\r
3353 s = p / (2 * pi) * asin(c / a);
\r
3360 -.5 * (a * pow(2, 10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p)) + b :
\r
3361 a * pow(2, -10 * (t -= 1)) * sin((t * d - s) * (2 * pi) / p) * .5 + c + b;
\r
3364 backIn: function (t, b, c, d, s) {
\r
3365 s = s || 1.70158;
\r
3366 return c * (t /= d) * t * ((s + 1) * t - s) + b;
\r
3370 backOut: function (t, b, c, d, s) {
\r
3374 return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
\r
3378 backBoth: function (t, b, c, d, s) {
\r
3379 s = s || 1.70158;
\r
3381 return ((t /= d / 2 ) < 1) ?
\r
3382 c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b :
\r
3383 c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
\r
3387 bounceIn: function (t, b, c, d) {
\r
3388 return c - EXTLIB.Easing.bounceOut(d - t, 0, c, d) + b;
\r
3392 bounceOut: function (t, b, c, d) {
\r
3393 if ((t /= d) < (1 / 2.75)) {
\r
3394 return c * (7.5625 * t * t) + b;
\r
3395 } else if (t < (2 / 2.75)) {
\r
3396 return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
\r
3397 } else if (t < (2.5 / 2.75)) {
\r
3398 return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
\r
3400 return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
\r
3404 bounceBoth: function (t, b, c, d) {
\r
3405 return (t < d / 2) ?
\r
3406 EXTLIB.Easing.bounceIn(t * 2, 0, c, d) * .5 + b :
\r
3407 EXTLIB.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
\r
3413 var EXTLIB = Ext.lib;
\r
3414 // Color Animation
\r
3415 EXTLIB.Anim.color = function(el, args, duration, easing, cb, scope) {
\r
3416 return EXTLIB.Anim.run(el, args, duration, easing, cb, scope, EXTLIB.ColorAnim);
\r
3419 EXTLIB.ColorAnim = function(el, attributes, duration, method) {
\r
3420 EXTLIB.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
\r
3423 Ext.extend(EXTLIB.ColorAnim, EXTLIB.AnimBase);
\r
3425 var superclass = EXTLIB.ColorAnim.superclass,
\r
3426 colorRE = /color$/i,
\r
3427 transparentRE = /^transparent|rgba\(0, 0, 0, 0\)$/,
\r
3428 rgbRE = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i,
\r
3429 hexRE= /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i,
\r
3430 hex3RE = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i,
\r
3431 isset = function(v){
\r
3432 return typeof v !== 'undefined';
\r
3436 function parseColor(s) {
\r
3437 var pi = parseInt,
\r
3442 if (s.length == 3) {
\r
3446 Ext.each([hexRE, rgbRE, hex3RE], function(re, idx){
\r
3447 base = (idx % 2 == 0) ? 16 : 10;
\r
3449 if(c && c.length == 4){
\r
3450 out = [pi(c[1], base), pi(c[2], base), pi(c[3], base)];
\r
3457 Ext.apply(EXTLIB.ColorAnim.prototype, {
\r
3458 getAttr : function(attr) {
\r
3462 if(colorRE.test(attr)){
\r
3463 while(el && transparentRE.test(val = Ext.fly(el).getStyle(attr))){
\r
3464 el = el.parentNode;
\r
3468 val = superclass.getAttr.call(me, attr);
\r
3473 doMethod : function(attr, start, end) {
\r
3476 floor = Math.floor;
\r
3478 if(colorRE.test(attr)){
\r
3481 Ext.each(start, function(v, i) {
\r
3482 val[i] = superclass.doMethod.call(me, attr, v, end[i]);
\r
3485 val = 'rgb(' + floor(val[0]) + ',' + floor(val[1]) + ',' + floor(val[2]) + ')';
\r
3487 val = superclass.doMethod.call(me, attr, start, end);
\r
3492 setRunAttr : function(attr) {
\r
3494 a = me.attributes[attr],
\r
3499 superclass.setRunAttr.call(me, attr);
\r
3500 ra = me.runAttrs[attr];
\r
3501 if(colorRE.test(attr)){
\r
3502 var start = parseColor(ra.start),
\r
3503 end = parseColor(ra.end);
\r
3505 if(!isset(to) && isset(by)){
\r
3506 end = parseColor(by);
\r
3507 Ext.each(start, function(item, i){
\r
3508 end[i] = item + end[i];
\r
3520 // Scroll Animation
\r
3521 var EXTLIB = Ext.lib;
\r
3522 EXTLIB.Anim.scroll = function(el, args, duration, easing, cb, scope) {
\r
3523 return EXTLIB.Anim.run(el, args, duration, easing, cb, scope, EXTLIB.Scroll);
\r
3526 EXTLIB.Scroll = function(el, attributes, duration, method) {
\r
3528 EXTLIB.Scroll.superclass.constructor.call(this, el, attributes, duration, method);
\r
3532 Ext.extend(EXTLIB.Scroll, EXTLIB.ColorAnim);
\r
3534 var superclass = EXTLIB.Scroll.superclass,
\r
3535 SCROLL = 'scroll';
\r
3537 Ext.apply(EXTLIB.Scroll.prototype, {
\r
3539 doMethod : function(attr, start, end) {
\r
3542 curFrame = me.curFrame,
\r
3543 totalFrames = me.totalFrames;
\r
3545 if(attr == SCROLL){
\r
3546 val = [me.method(curFrame, start[0], end[0] - start[0], totalFrames),
\r
3547 me.method(curFrame, start[1], end[1] - start[1], totalFrames)];
\r
3549 val = superclass.doMethod.call(me, attr, start, end);
\r
3554 getAttr : function(attr) {
\r
3557 if (attr == SCROLL) {
\r
3558 return [me.el.scrollLeft, me.el.scrollTop];
\r
3560 return superclass.getAttr.call(me, attr);
\r
3564 setAttr : function(attr, val, unit) {
\r
3567 if(attr == SCROLL){
\r
3568 me.el.scrollLeft = val[0];
\r
3569 me.el.scrollTop = val[1];
\r
3571 superclass.setAttr.call(me, attr, val, unit);
\r
3577 function fnCleanUp() {
\r
3578 var p = Function.prototype;
\r
3579 delete p.createSequence;
\r
3581 delete p.createDelegate;
\r
3582 delete p.createCallback;
\r
3583 delete p.createInterceptor;
\r
3585 window.detachEvent("onunload", fnCleanUp);
\r
3587 window.attachEvent("onunload", fnCleanUp);
\r