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 ua = navigator.userAgent.toLowerCase(),
\r
50 check = function(r){
\r
54 isStrict = DOC.compatMode == "CSS1Compat",
\r
55 isOpera = check(/opera/),
\r
56 isChrome = check(/chrome/),
\r
57 isWebKit = check(/webkit/),
\r
58 isSafari = !isChrome && check(/safari/),
\r
59 isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
\r
60 isSafari3 = isSafari && check(/version\/3/),
\r
61 isSafari4 = isSafari && check(/version\/4/),
\r
62 isIE = !isOpera && check(/msie/),
\r
63 isIE7 = isIE && check(/msie 7/),
\r
64 isIE8 = isIE && check(/msie 8/),
\r
65 isIE6 = isIE && !isIE7 && !isIE8,
\r
66 isGecko = !isWebKit && check(/gecko/),
\r
67 isGecko2 = isGecko && check(/rv:1\.8/),
\r
68 isGecko3 = isGecko && check(/rv:1\.9/),
\r
69 isBorderBox = isIE && !isStrict,
\r
70 isWindows = check(/windows|win32/),
\r
71 isMac = check(/macintosh|mac os x/),
\r
72 isAir = check(/adobeair/),
\r
73 isLinux = check(/linux/),
\r
74 isSecure = /^https/i.test(window.location.protocol);
\r
76 // remove css image flicker
\r
79 DOC.execCommand("BackgroundImageCache", false, true);
\r
85 * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent
\r
86 * the IE insecure content warning (<tt>'about:blank'</tt>, except for IE in secure mode, which is <tt>'javascript:""'</tt>).
\r
89 SSL_SECURE_URL : isSecure && isIE ? 'javascript:""' : 'about:blank',
\r
91 * True if the browser is in strict (standards-compliant) mode, as opposed to quirks mode
\r
94 isStrict : isStrict,
\r
96 * True if the page is running over SSL
\r
99 isSecure : isSecure,
\r
101 * True when the document is fully initialized and ready for action
\r
107 * True if the {@link Ext.Fx} Class is available
\r
109 * @property enableFx
\r
113 * True to automatically uncache orphaned Ext.Elements periodically (defaults to true)
\r
116 enableGarbageCollector : true,
\r
119 * True to automatically purge event listeners after uncaching an element (defaults to false).
\r
120 * Note: this only happens if {@link #enableGarbageCollector} is true.
\r
123 enableListenerCollection : false,
\r
126 * Indicates whether to use native browser parsing for JSON methods.
\r
127 * This option is ignored if the browser does not support native JSON methods.
\r
128 * <b>Note: Native JSON methods will not work with objects that have functions.
\r
129 * Also, property names must be quoted, otherwise the data will not parse.</b> (Defaults to false)
\r
132 USE_NATIVE_JSON : false,
\r
135 * Copies all the properties of config to obj if they don't already exist.
\r
136 * @param {Object} obj The receiver of the properties
\r
137 * @param {Object} config The source of the properties
\r
138 * @return {Object} returns obj
\r
140 applyIf : function(o, c){
\r
143 if(!Ext.isDefined(o[p])){
\r
152 * Generates unique ids. If the element already has an id, it is unchanged
\r
153 * @param {Mixed} el (optional) The element to generate an id for
\r
154 * @param {String} prefix (optional) Id prefix (defaults "ext-gen")
\r
155 * @return {String} The generated Id.
\r
157 id : function(el, prefix){
\r
158 return (el = Ext.getDom(el) || {}).id = el.id || (prefix || "ext-gen") + (++idSeed);
\r
162 * <p>Extends one class to create a subclass and optionally overrides members with the passed literal. This method
\r
163 * also adds the function "override()" to the subclass that can be used to override members of the class.</p>
\r
164 * For example, to create a subclass of Ext GridPanel:
\r
166 MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
\r
167 constructor: function(config) {
\r
169 // Create configuration for this Grid.
\r
170 var store = new Ext.data.Store({...});
\r
171 var colModel = new Ext.grid.ColumnModel({...});
\r
173 // Create a new config object containing our computed properties
\r
174 // *plus* whatever was in the config parameter.
\r
175 config = Ext.apply({
\r
180 MyGridPanel.superclass.constructor.call(this, config);
\r
182 // Your postprocessing here
\r
185 yourMethod: function() {
\r
191 * <p>This function also supports a 3-argument call in which the subclass's constructor is
\r
192 * passed as an argument. In this form, the parameters are as follows:</p>
\r
193 * <div class="mdetail-params"><ul>
\r
194 * <li><code>subclass</code> : Function <div class="sub-desc">The subclass constructor.</div></li>
\r
195 * <li><code>superclass</code> : Function <div class="sub-desc">The constructor of class being extended</div></li>
\r
196 * <li><code>overrides</code> : Object <div class="sub-desc">A literal with members which are copied into the subclass's
\r
197 * prototype, and are therefore shared among all instances of the new class.</div></li>
\r
200 * @param {Function} subclass The constructor of class being extended.
\r
201 * @param {Object} overrides <p>A literal with members which are copied into the subclass's
\r
202 * prototype, and are therefore shared between all instances of the new class.</p>
\r
203 * <p>This may contain a special member named <tt><b>constructor</b></tt>. This is used
\r
204 * to define the constructor of the new class, and is returned. If this property is
\r
205 * <i>not</i> specified, a constructor is generated and returned which just calls the
\r
206 * superclass's constructor passing on its parameters.</p>
\r
207 * <p><b>It is essential that you call the superclass constructor in any provided constructor. See example code.</b></p>
\r
208 * @return {Function} The subclass constructor.
\r
210 extend : function(){
\r
211 // inline overrides
\r
212 var io = function(o){
\r
217 var oc = Object.prototype.constructor;
\r
219 return function(sb, sp, overrides){
\r
220 if(Ext.isObject(sp)){
\r
223 sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
\r
225 var F = function(){},
\r
227 spp = sp.prototype;
\r
230 sbp = sb.prototype = new F();
\r
231 sbp.constructor=sb;
\r
233 if(spp.constructor == oc){
\r
234 spp.constructor=sp;
\r
236 sb.override = function(o){
\r
237 Ext.override(sb, o);
\r
239 sbp.superclass = sbp.supr = (function(){
\r
243 Ext.override(sb, overrides);
\r
244 sb.extend = function(o){return Ext.extend(sb, o);};
\r
250 * Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
\r
251 * Usage:<pre><code>
\r
252 Ext.override(MyClass, {
\r
253 newMethod1: function(){
\r
256 newMethod2: function(foo){
\r
261 * @param {Object} origclass The class to override
\r
262 * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
\r
263 * containing one or more methods.
\r
266 override : function(origclass, overrides){
\r
268 var p = origclass.prototype;
\r
269 Ext.apply(p, overrides);
\r
270 if(Ext.isIE && overrides.toString != origclass.toString){
\r
271 p.toString = overrides.toString;
\r
277 * Creates namespaces to be used for scoping variables and classes so that they are not global.
\r
278 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
\r
280 Ext.namespace('Company', 'Company.data');
\r
281 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
\r
282 Company.Widget = function() { ... }
\r
283 Company.data.CustomStore = function(config) { ... }
\r
285 * @param {String} namespace1
\r
286 * @param {String} namespace2
\r
287 * @param {String} etc
\r
288 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
\r
289 * @method namespace
\r
291 namespace : function(){
\r
293 Ext.each(arguments, function(v) {
\r
295 o = window[d[0]] = window[d[0]] || {};
\r
296 Ext.each(d.slice(1), function(v2){
\r
297 o = o[v2] = o[v2] || {};
\r
304 * 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
305 * @param {Object} o
\r
306 * @param {String} pre (optional) A prefix to add to the url encoded string
\r
309 urlEncode : function(o, pre){
\r
312 e = encodeURIComponent;
\r
314 Ext.iterate(o, function(key, item){
\r
315 empty = Ext.isEmpty(item);
\r
316 Ext.each(empty ? key : item, function(val){
\r
317 buf.push('&', e(key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : '');
\r
324 return pre + buf.join('');
\r
328 * Takes an encoded URL and and converts it to an object. Example: <pre><code>
\r
329 Ext.urlDecode("foo=1&bar=2"); // returns {foo: "1", bar: "2"}
\r
330 Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2", "3", "4"]}
\r
332 * @param {String} string
\r
333 * @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
\r
334 * @return {Object} A literal with members
\r
336 urlDecode : function(string, overwrite){
\r
337 if(Ext.isEmpty(string)){
\r
341 pairs = string.split('&'),
\r
342 d = decodeURIComponent,
\r
345 Ext.each(pairs, function(pair) {
\r
346 pair = pair.split('=');
\r
348 value = d(pair[1]);
\r
349 obj[name] = overwrite || !obj[name] ? value :
\r
350 [].concat(obj[name]).concat(value);
\r
356 * Appends content to the query string of a URL, handling logic for whether to place
\r
357 * a question mark or ampersand.
\r
358 * @param {String} url The URL to append to.
\r
359 * @param {String} s The content to append to the URL.
\r
360 * @return (String) The resulting URL
\r
362 urlAppend : function(url, s){
\r
363 if(!Ext.isEmpty(s)){
\r
364 return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
\r
370 * Converts any iterable (numeric indices and a length property) into a true array
\r
371 * Don't use this on strings. IE doesn't support "abc"[0] which this implementation depends on.
\r
372 * For strings, use this instead: "abc".match(/./g) => [a,b,c];
\r
373 * @param {Iterable} the iterable object to be turned into a true Array.
\r
374 * @return (Array) array
\r
376 toArray : function(){
\r
378 function(a, i, j, res){
\r
380 Ext.each(a, function(v) {
\r
383 return res.slice(i || 0, j || res.length);
\r
386 return Array.prototype.slice.call(a, i || 0, j || a.length);
\r
390 isIterable : function(v){
\r
391 //check for array or arguments
\r
392 if(Ext.isArray(v) || v.callee){
\r
395 //check for node list type
\r
396 if(/NodeList|HTMLCollection/.test(toString.call(v))){
\r
399 //NodeList has an item and length property
\r
400 //IXMLDOMNodeList has nextNode method, needs to be checked first.
\r
401 return ((v.nextNode || v.item) && Ext.isNumber(v.length));
\r
405 * Iterates an array calling the supplied function.
\r
406 * @param {Array/NodeList/Mixed} array The array to be iterated. If this
\r
407 * argument is not really an array, the supplied function is called once.
\r
408 * @param {Function} fn The function to be called with each item. If the
\r
409 * supplied function returns false, iteration stops and this method returns
\r
410 * the current <code>index</code>. This function is called with
\r
411 * the following arguments:
\r
412 * <div class="mdetail-params"><ul>
\r
413 * <li><code>item</code> : <i>Mixed</i>
\r
414 * <div class="sub-desc">The item at the current <code>index</code>
\r
415 * in the passed <code>array</code></div></li>
\r
416 * <li><code>index</code> : <i>Number</i>
\r
417 * <div class="sub-desc">The current index within the array</div></li>
\r
418 * <li><code>allItems</code> : <i>Array</i>
\r
419 * <div class="sub-desc">The <code>array</code> passed as the first
\r
420 * argument to <code>Ext.each</code>.</div></li>
\r
422 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed.
\r
423 * Defaults to the <code>item</code> at the current <code>index</code>
\r
424 * within the passed <code>array</code>.
\r
425 * @return See description for the fn parameter.
\r
427 each : function(array, fn, scope){
\r
428 if(Ext.isEmpty(array, true)){
\r
431 if(!Ext.isIterable(array) || Ext.isPrimitive(array)){
\r
434 for(var i = 0, len = array.length; i < len; i++){
\r
435 if(fn.call(scope || array[i], array[i], i, array) === false){
\r
442 * Iterates either the elements in an array, or each of the properties in an object.
\r
443 * <b>Note</b>: If you are only iterating arrays, it is better to call {@link #each}.
\r
444 * @param {Object/Array} object The object or array to be iterated
\r
445 * @param {Function} fn The function to be called for each iteration.
\r
446 * The iteration will stop if the supplied function returns false, or
\r
447 * all array elements / object properties have been covered. The signature
\r
448 * varies depending on the type of object being interated:
\r
449 * <div class="mdetail-params"><ul>
\r
450 * <li>Arrays : <tt>(Object item, Number index, Array allItems)</tt>
\r
451 * <div class="sub-desc">
\r
452 * When iterating an array, the supplied function is called with each item.</div></li>
\r
453 * <li>Objects : <tt>(String key, Object value)</tt>
\r
454 * <div class="sub-desc">
\r
455 * When iterating an object, the supplied function is called with each key-value pair in
\r
456 * the object.</div></li>
\r
458 * @param {Object} scope The scope (<code>this</code> reference) in which the specified function is executed. Defaults to
\r
459 * the <code>object</code> being iterated.
\r
461 iterate : function(obj, fn, scope){
\r
462 if(Ext.isEmpty(obj)){
\r
465 if(Ext.isIterable(obj)){
\r
466 Ext.each(obj, fn, scope);
\r
468 }else if(Ext.isObject(obj)){
\r
469 for(var prop in obj){
\r
470 if(obj.hasOwnProperty(prop)){
\r
471 if(fn.call(scope || obj, prop, obj[prop]) === false){
\r
480 * Return the dom node for the passed String (id), dom node, or Ext.Element.
\r
481 * Here are some examples:
\r
483 // gets dom node based on id
\r
484 var elDom = Ext.getDom('elId');
\r
485 // gets dom node based on the dom node
\r
486 var elDom1 = Ext.getDom(elDom);
\r
488 // If we don't know if we are working with an
\r
489 // Ext.Element or a dom node use Ext.getDom
\r
491 var dom = Ext.getDom(el);
\r
492 // do something with the dom node
\r
495 * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc)
\r
496 * when this method is called to be successful.
\r
497 * @param {Mixed} el
\r
498 * @return HTMLElement
\r
500 getDom : function(el){
\r
504 return el.dom ? el.dom : (Ext.isString(el) ? DOC.getElementById(el) : el);
\r
508 * Returns the current document body as an {@link Ext.Element}.
\r
509 * @return Ext.Element The document body
\r
511 getBody : function(){
\r
512 return Ext.get(DOC.body || DOC.documentElement);
\r
516 * Removes a DOM node from the document. The body node will be ignored if passed in.
\r
517 * @param {HTMLElement} node The node to remove
\r
519 removeNode : isIE ? function(){
\r
521 return function(n){
\r
522 if(n && n.tagName != 'BODY'){
\r
523 d = d || DOC.createElement('div');
\r
529 if(n && n.parentNode && n.tagName != 'BODY'){
\r
530 n.parentNode.removeChild(n);
\r
535 * <p>Returns true if the passed value is empty.</p>
\r
536 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
\r
538 * <li>undefined</li>
\r
539 * <li>an empty array</li>
\r
540 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
\r
542 * @param {Mixed} value The value to test
\r
543 * @param {Boolean} allowBlank (optional) true to allow empty strings (defaults to false)
\r
544 * @return {Boolean}
\r
546 isEmpty : function(v, allowBlank){
\r
547 return v === null || v === undefined || ((Ext.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false);
\r
551 * Returns true if the passed value is a JavaScript array, otherwise false.
\r
552 * @param {Mixed} value The value to test
\r
553 * @return {Boolean}
\r
555 isArray : function(v){
\r
556 return toString.apply(v) === '[object Array]';
\r
560 * Returns true if the passed object is a JavaScript date object, otherwise false.
\r
561 * @param {Object} object The object to test
\r
562 * @return {Boolean}
\r
564 isDate : function(v){
\r
565 return toString.apply(v) === '[object Date]';
\r
569 * Returns true if the passed value is a JavaScript Object, otherwise false.
\r
570 * @param {Mixed} value The value to test
\r
571 * @return {Boolean}
\r
573 isObject : function(v){
\r
574 return v && typeof v == "object";
\r
578 * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean.
\r
579 * @param {Mixed} value The value to test
\r
580 * @return {Boolean}
\r
582 isPrimitive : function(v){
\r
583 return Ext.isString(v) || Ext.isNumber(v) || Ext.isBoolean(v);
\r
587 * Returns true if the passed value is a JavaScript Function, otherwise false.
\r
588 * @param {Mixed} value The value to test
\r
589 * @return {Boolean}
\r
591 isFunction : function(v){
\r
592 return toString.apply(v) === '[object Function]';
\r
596 * Returns true if the passed value is a number. Returns false for non-finite numbers.
\r
597 * @param {Mixed} value The value to test
\r
598 * @return {Boolean}
\r
600 isNumber : function(v){
\r
601 return typeof v === 'number' && isFinite(v);
\r
605 * Returns true if the passed value is a string.
\r
606 * @param {Mixed} value The value to test
\r
607 * @return {Boolean}
\r
609 isString : function(v){
\r
610 return typeof v === 'string';
\r
614 * Returns true if the passed value is a boolean.
\r
615 * @param {Mixed} value The value to test
\r
616 * @return {Boolean}
\r
618 isBoolean : function(v){
\r
619 return typeof v === 'boolean';
\r
623 * Returns true if the passed value is not undefined.
\r
624 * @param {Mixed} value The value to test
\r
625 * @return {Boolean}
\r
627 isDefined : function(v){
\r
628 return typeof v !== 'undefined';
\r
632 * True if the detected browser is Opera.
\r
637 * True if the detected browser uses WebKit.
\r
640 isWebKit : isWebKit,
\r
642 * True if the detected browser is Chrome.
\r
645 isChrome : isChrome,
\r
647 * True if the detected browser is Safari.
\r
650 isSafari : isSafari,
\r
652 * True if the detected browser is Safari 3.x.
\r
655 isSafari3 : isSafari3,
\r
657 * True if the detected browser is Safari 4.x.
\r
660 isSafari4 : isSafari4,
\r
662 * True if the detected browser is Safari 2.x.
\r
665 isSafari2 : isSafari2,
\r
667 * True if the detected browser is Internet Explorer.
\r
672 * True if the detected browser is Internet Explorer 6.x.
\r
677 * True if the detected browser is Internet Explorer 7.x.
\r
682 * True if the detected browser is Internet Explorer 8.x.
\r
687 * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
\r
692 * True if the detected browser uses a pre-Gecko 1.9 layout engine (e.g. Firefox 2.x).
\r
695 isGecko2 : isGecko2,
\r
697 * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
\r
700 isGecko3 : isGecko3,
\r
702 * True if the detected browser is Internet Explorer running in non-strict mode.
\r
705 isBorderBox : isBorderBox,
\r
707 * True if the detected platform is Linux.
\r
712 * True if the detected platform is Windows.
\r
715 isWindows : isWindows,
\r
717 * True if the detected platform is Mac OS.
\r
722 * True if the detected platform is Adobe Air.
\r
729 * Creates namespaces to be used for scoping variables and classes so that they are not global.
\r
730 * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
\r
732 Ext.namespace('Company', 'Company.data');
\r
733 Ext.namespace('Company.data'); // equivalent and preferable to above syntax
\r
734 Company.Widget = function() { ... }
\r
735 Company.data.CustomStore = function(config) { ... }
\r
737 * @param {String} namespace1
\r
738 * @param {String} namespace2
\r
739 * @param {String} etc
\r
740 * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
\r
743 Ext.ns = Ext.namespace;
\r
746 Ext.ns("Ext", "Ext.util", "Ext.lib", "Ext.data");
\r
751 * These functions are available on every Function object (any JavaScript function).
\r
753 Ext.apply(Function.prototype, {
\r
755 * Creates an interceptor function. The passed function is called before the original one. If it returns false,
\r
756 * the original one is not called. The resulting function returns the results of the original function.
\r
757 * The passed function is called with the parameters of the original function. Example usage:
\r
759 var sayHi = function(name){
\r
760 alert('Hi, ' + name);
\r
763 sayHi('Fred'); // alerts "Hi, Fred"
\r
765 // create a new function that validates input without
\r
766 // directly modifying the original function:
\r
767 var sayHiToFriend = sayHi.createInterceptor(function(name){
\r
768 return name == 'Brian';
\r
771 sayHiToFriend('Fred'); // no alert
\r
772 sayHiToFriend('Brian'); // alerts "Hi, Brian"
\r
774 * @param {Function} fcn The function to call before the original
\r
775 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
\r
776 * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
\r
777 * @return {Function} The new function
\r
779 createInterceptor : function(fcn, scope){
\r
781 return !Ext.isFunction(fcn) ?
\r
787 fcn.method = method;
\r
788 return (fcn.apply(scope || me || window, args) !== false) ?
\r
789 method.apply(me || window, args) :
\r
795 * Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
\r
796 * Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code>
\r
797 * Will create a function that is bound to those 2 args. <b>If a specific scope is required in the
\r
798 * callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always
\r
799 * executes in the window scope.
\r
800 * <p>This method is required when you want to pass arguments to a callback function. If no arguments
\r
801 * are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn).
\r
802 * However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function
\r
803 * would simply execute immediately when the code is parsed. Example usage:
\r
805 var sayHi = function(name){
\r
806 alert('Hi, ' + name);
\r
809 // clicking the button alerts "Hi, Fred"
\r
812 renderTo: Ext.getBody(),
\r
813 handler: sayHi.createCallback('Fred')
\r
816 * @return {Function} The new function
\r
818 createCallback : function(/*args...*/){
\r
819 // make args available, in function below
\r
820 var args = arguments,
\r
822 return function() {
\r
823 return method.apply(window, args);
\r
828 * Creates a delegate (callback) that sets the scope to obj.
\r
829 * Call directly on any function. Example: <code>this.myFunction.createDelegate(this, [arg1, arg2])</code>
\r
830 * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
\r
831 * callback points to obj. Example usage:
\r
833 var sayHi = function(name){
\r
834 // Note this use of "this.text" here. This function expects to
\r
835 // execute within a scope that contains a text property. In this
\r
836 // example, the "this" variable is pointing to the btn object that
\r
837 // was passed in createDelegate below.
\r
838 alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
\r
841 var btn = new Ext.Button({
\r
843 renderTo: Ext.getBody()
\r
846 // This callback will execute in the scope of the
\r
847 // button instance. Clicking the button alerts
\r
848 // "Hi, Fred. You clicked the "Say Hi" button."
\r
849 btn.on('click', sayHi.createDelegate(btn, ['Fred']));
\r
851 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
\r
852 * <b>If omitted, defaults to the browser window.</b>
\r
853 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
\r
854 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
\r
855 * if a number the args are inserted at the specified position
\r
856 * @return {Function} The new function
\r
858 createDelegate : function(obj, args, appendArgs){
\r
860 return function() {
\r
861 var callArgs = args || arguments;
\r
862 if (appendArgs === true){
\r
863 callArgs = Array.prototype.slice.call(arguments, 0);
\r
864 callArgs = callArgs.concat(args);
\r
865 }else if (Ext.isNumber(appendArgs)){
\r
866 callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
\r
867 var applyArgs = [appendArgs, 0].concat(args); // create method call params
\r
868 Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
\r
870 return method.apply(obj || window, callArgs);
\r
875 * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
\r
877 var sayHi = function(name){
\r
878 alert('Hi, ' + name);
\r
881 // executes immediately:
\r
884 // executes after 2 seconds:
\r
885 sayHi.defer(2000, this, ['Fred']);
\r
887 // this syntax is sometimes useful for deferring
\r
888 // execution of an anonymous function:
\r
890 alert('Anonymous');
\r
893 * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
\r
894 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
\r
895 * <b>If omitted, defaults to the browser window.</b>
\r
896 * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
\r
897 * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
\r
898 * if a number the args are inserted at the specified position
\r
899 * @return {Number} The timeout id that can be used with clearTimeout
\r
901 defer : function(millis, obj, args, appendArgs){
\r
902 var fn = this.createDelegate(obj, args, appendArgs);
\r
904 return setTimeout(fn, millis);
\r
913 * These functions are available on every String object.
\r
915 Ext.applyIf(String, {
\r
917 * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
\r
918 * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
\r
920 var cls = 'my-class', text = 'Some text';
\r
921 var s = String.format('<div class="{0}">{1}</div>', cls, text);
\r
922 // s now contains the string: '<div class="my-class">Some text</div>'
\r
924 * @param {String} string The tokenized string to be formatted
\r
925 * @param {String} value1 The value to replace token {0}
\r
926 * @param {String} value2 Etc...
\r
927 * @return {String} The formatted string
\r
930 format : function(format){
\r
931 var args = Ext.toArray(arguments, 1);
\r
932 return format.replace(/\{(\d+)\}/g, function(m, i){
\r
941 Ext.applyIf(Array.prototype, {
\r
943 * Checks whether or not the specified object exists in the array.
\r
944 * @param {Object} o The object to check for
\r
945 * @param {Number} from (Optional) The index at which to begin the search
\r
946 * @return {Number} The index of o in the array (or -1 if it is not found)
\r
948 indexOf : function(o, from){
\r
949 var len = this.length;
\r
951 from += (from < 0) ? len : 0;
\r
952 for (; from < len; ++from){
\r
953 if(this[from] === o){
\r
961 * Removes the specified object from the array. If the object is not found nothing happens.
\r
962 * @param {Object} o The object to remove
\r
963 * @return {Array} this array
\r
965 remove : function(o){
\r
966 var index = this.indexOf(o);
\r
968 this.splice(index, 1);
\r
977 Ext.ns("Ext.grid", "Ext.dd", "Ext.tree", "Ext.form", "Ext.menu",
978 "Ext.state", "Ext.layout", "Ext.app", "Ext.ux", "Ext.chart", "Ext.direct");
980 * Namespace alloted for extensions to the framework.
985 Ext.apply(Ext, function(){
992 * A reusable empty function
996 emptyFn : function(){},
999 * URL to a 1x1 transparent gif image used by Ext to create inline icons with CSS background images.
1000 * In older versions of IE, this defaults to "http://extjs.com/s.gif" and you should change this to a URL on your server.
1001 * For other browsers it uses an inline data URL.
1004 BLANK_IMAGE_URL : Ext.isIE6 || Ext.isIE7 || Ext.isAir ?
1005 'http:/' + '/extjs.com/s.gif' :
1006 'data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==',
1008 extendX : function(supr, fn){
1009 return Ext.extend(supr, fn(supr.prototype));
1013 * Returns the current HTML document object as an {@link Ext.Element}.
1014 * @return Ext.Element The document
1016 getDoc : function(){
1017 return Ext.get(document);
1021 * Utility method for validating that a value is numeric, returning the specified default value if it is not.
1022 * @param {Mixed} value Should be a number, but any type will be handled appropriately
1023 * @param {Number} defaultValue The value to return if the original value is non-numeric
1024 * @return {Number} Value, if numeric, else defaultValue
1026 num : function(v, defaultValue){
1027 v = Number(Ext.isEmpty(v) || Ext.isBoolean(v) ? NaN : v);
1028 return isNaN(v)? defaultValue : v;
1032 * <p>Utility method for returning a default value if the passed value is empty.</p>
1033 * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
1035 * <li>undefined</li>
1036 * <li>an empty array</li>
1037 * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
1039 * @param {Mixed} value The value to test
1040 * @param {Mixed} defaultValue The value to return if the original value is empty
1041 * @param {Boolean} allowBlank (optional) true to allow zero length strings to qualify as non-empty (defaults to false)
1042 * @return {Mixed} value, if non-empty, else defaultValue
1044 value : function(v, defaultValue, allowBlank){
1045 return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
1049 * Escapes the passed string for use in a regular expression
1050 * @param {String} str
1053 escapeRe : function(s) {
1054 return s.replace(/([-.*+?^${}()|[\]\/\\])/g, "\\$1");
1057 sequence : function(o, name, fn, scope){
1058 o[name] = o[name].createSequence(fn, scope);
1062 * Applies event listeners to elements by selectors when the document is ready.
1063 * The event name is specified with an <tt>@</tt> suffix.
1066 // add a listener for click on all anchors in element with id foo
1067 '#foo a@click' : function(e, t){
1071 // add the same listener to multiple selectors (separated by comma BEFORE the @)
1072 '#foo a, #bar span.some-class@mouseover' : function(){
1077 * @param {Object} obj The list of behaviors to apply
1079 addBehaviors : function(o){
1081 Ext.onReady(function(){
1082 Ext.addBehaviors(o);
1085 var cache = {}, // simple cache for applying multiple behaviors to same selector does query multiple times
1090 if ((parts = b.split('@'))[1]) { // for Object prototype breakers
1093 cache[s] = Ext.select(s);
1095 cache[s].on(parts[1], o[b]);
1103 * Utility method for getting the width of the browser scrollbar. This can differ depending on
1104 * operating system settings, such as the theme or font size.
1105 * @param {Boolean} force (optional) true to force a recalculation of the value.
1106 * @return {Number} The width of the scrollbar.
1108 getScrollBarWidth: function(force){
1113 if(force === true || scrollWidth === null){
1114 // Append our div, do our calculation and then remove it
1115 var div = Ext.getBody().createChild('<div class="x-hide-offsets" style="width:100px;height:50px;overflow:hidden;"><div style="height:200px;"></div></div>'),
1116 child = div.child('div', true);
1117 var w1 = child.offsetWidth;
1118 div.setStyle('overflow', (Ext.isWebKit || Ext.isGecko) ? 'auto' : 'scroll');
1119 var w2 = child.offsetWidth;
1121 // Need to add 2 to ensure we leave enough space
1122 scrollWidth = w1 - w2 + 2;
1129 combine : function(){
1130 var as = arguments, l = as.length, r = [];
1131 for(var i = 0; i < l; i++){
1135 }else if(a.length !== undefined && !a.substr){
1136 r = r.concat(Array.prototype.slice.call(a, 0));
1145 * Copies a set of named properties fom the source object to the destination object.
1146 * <p>example:<pre><code>
1147 ImageComponent = Ext.extend(Ext.BoxComponent, {
1148 initComponent: function() {
1149 this.autoEl = { tag: 'img' };
1150 MyComponent.superclass.initComponent.apply(this, arguments);
1151 this.initialBox = Ext.copyTo({}, this.initialConfig, 'x,y,width,height');
1155 * @param {Object} The destination object.
1156 * @param {Object} The source object.
1157 * @param {Array/String} Either an Array of property names, or a comma-delimited list
1158 * of property names to copy.
1159 * @return {Object} The modified object.
1161 copyTo : function(dest, source, names){
1162 if(Ext.isString(names)){
1163 names = names.split(/[,;\s]/);
1165 Ext.each(names, function(name){
1166 if(source.hasOwnProperty(name)){
1167 dest[name] = source[name];
1174 * Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
1175 * DOM (if applicable) and calling their destroy functions (if available). This method is primarily
1176 * intended for arguments of type {@link Ext.Element} and {@link Ext.Component}, but any subclass of
1177 * {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
1178 * passed into this function in a single call as separate arguments.
1179 * @param {Mixed} arg1 An {@link Ext.Element}, {@link Ext.Component}, or an Array of either of these to destroy
1180 * @param {Mixed} arg2 (optional)
1181 * @param {Mixed} etc... (optional)
1183 destroy : function(){
1184 Ext.each(arguments, function(arg){
1186 if(Ext.isArray(arg)){
1187 this.destroy.apply(this, arg);
1188 }else if(Ext.isFunction(arg.destroy)){
1198 * Attempts to destroy and then remove a set of named properties of the passed object.
1199 * @param {Object} o The object (most likely a Component) who's properties you wish to destroy.
1200 * @param {Mixed} arg1 The name of the property to destroy and remove from the object.
1201 * @param {Mixed} etc... More property names to destroy and remove.
1203 destroyMembers : function(o, arg1, arg2, etc){
1204 for(var i = 1, a = arguments, len = a.length; i < len; i++) {
1205 Ext.destroy(o[a[i]]);
1211 * Creates a copy of the passed Array with falsy values removed.
1212 * @param {Array/NodeList} arr The Array from which to remove falsy values.
1213 * @return {Array} The new, compressed Array.
1215 clean : function(arr){
1217 Ext.each(arr, function(v){
1226 * Creates a copy of the passed Array, filtered to contain only unique values.
1227 * @param {Array} arr The Array to filter
1228 * @return {Array} The new Array containing unique values.
1230 unique : function(arr){
1234 Ext.each(arr, function(v) {
1244 * Recursively flattens into 1-d Array. Injects Arrays inline.
1245 * @param {Array} arr The array to flatten
1246 * @return {Array} The new, flattened array.
1248 flatten : function(arr){
1250 function rFlatten(a) {
1251 Ext.each(a, function(v) {
1260 return rFlatten(arr);
1264 * Returns the minimum value in the Array.
1265 * @param {Array|NodeList} arr The Array from which to select the minimum value.
1266 * @param {Function} comp (optional) a function to perform the comparision which determines minimization.
1267 * If omitted the "<" operator will be used. Note: gt = 1; eq = 0; lt = -1
1268 * @return {Object} The minimum value in the Array.
1270 min : function(arr, comp){
1272 comp = comp || function(a,b){ return a < b ? -1 : 1; };
1273 Ext.each(arr, function(v) {
1274 ret = comp(ret, v) == -1 ? ret : v;
1280 * Returns the maximum value in the Array
1281 * @param {Array|NodeList} arr The Array from which to select the maximum value.
1282 * @param {Function} comp (optional) a function to perform the comparision which determines maximization.
1283 * If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1
1284 * @return {Object} The maximum value in the Array.
1286 max : function(arr, comp){
1288 comp = comp || function(a,b){ return a > b ? 1 : -1; };
1289 Ext.each(arr, function(v) {
1290 ret = comp(ret, v) == 1 ? ret : v;
1296 * Calculates the mean of the Array
1297 * @param {Array} arr The Array to calculate the mean value of.
1298 * @return {Number} The mean.
1300 mean : function(arr){
1301 return Ext.sum(arr) / arr.length;
1305 * Calculates the sum of the Array
1306 * @param {Array} arr The Array to calculate the sum value of.
1307 * @return {Number} The sum.
1309 sum : function(arr){
1311 Ext.each(arr, function(v) {
1318 * Partitions the set into two sets: a true set and a false set.
1323 Ext.partition([true, false, true, true, false]); // [[true, true, true], [false, false]]
1329 return val.className == "class1"
1332 // true are those paragraph elements with a className of "class1",
1333 // false set are those that do not have that className.
1335 * @param {Array|NodeList} arr The array to partition
1336 * @param {Function} truth (optional) a function to determine truth. If this is omitted the element
1337 * itself must be able to be evaluated for its truthfulness.
1338 * @return {Array} [true<Array>,false<Array>]
1340 partition : function(arr, truth){
1342 Ext.each(arr, function(v, i, a) {
1343 ret[ (truth && truth(v, i, a)) || (!truth && v) ? 0 : 1].push(v);
1349 * Invokes a method on each item in an Array.
1352 Ext.invoke(Ext.query("p"), "getAttribute", "id");
1353 // [el1.getAttribute("id"), el2.getAttribute("id"), ..., elN.getAttribute("id")]
1355 * @param {Array|NodeList} arr The Array of items to invoke the method on.
1356 * @param {String} methodName The method name to invoke.
1357 * @param {Anything} ... Arguments to send into the method invocation.
1358 * @return {Array} The results of invoking the method on each item in the array.
1360 invoke : function(arr, methodName){
1362 args = Array.prototype.slice.call(arguments, 2);
1363 Ext.each(arr, function(v,i) {
1364 if (v && Ext.isFunction(v[methodName])) {
1365 ret.push(v[methodName].apply(v, args));
1367 ret.push(undefined);
1374 * Plucks the value of a property from each item in the Array
1377 Ext.pluck(Ext.query("p"), "className"); // [el1.className, el2.className, ..., elN.className]
1379 * @param {Array|NodeList} arr The Array of items to pluck the value from.
1380 * @param {String} prop The property name to pluck from each element.
1381 * @return {Array} The value from each item in the Array.
1383 pluck : function(arr, prop){
1385 Ext.each(arr, function(v) {
1386 ret.push( v[prop] );
1392 * <p>Zips N sets together.</p>
1395 Ext.zip([1,2,3],[4,5,6]); // [[1,4],[2,5],[3,6]]
1402 return "$" + a + "" + b + "." + c
1404 ); // ["$+12.43", "$-10.15", "$+22.96"]
1406 * @param {Arrays|NodeLists} arr This argument may be repeated. Array(s) to contribute values.
1407 * @param {Function} zipper (optional) The last item in the argument list. This will drive how the items are zipped together.
1408 * @return {Array} The zipped set.
1411 var parts = Ext.partition(arguments, function( val ){ return !Ext.isFunction(val); }),
1414 len = Ext.max(Ext.pluck(arrs, "length")),
1417 for (var i = 0; i < len; i++) {
1420 ret[i] = fn.apply(fn, Ext.pluck(arrs, i));
1422 for (var j = 0, aLen = arrs.length; j < aLen; j++){
1423 ret[i].push( arrs[j][i] );
1431 * This is shorthand reference to {@link Ext.ComponentMgr#get}.
1432 * Looks up an existing {@link Ext.Component Component} by {@link Ext.Component#id id}
1433 * @param {String} id The component {@link Ext.Component#id id}
1434 * @return Ext.Component The Component, <tt>undefined</tt> if not found, or <tt>null</tt> if a
1437 getCmp : function(id){
1438 return Ext.ComponentMgr.get(id);
1442 * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
1443 * you may want to set this to true.
1446 useShims: E.isIE6 || (E.isMac && E.isGecko2),
1448 // inpired by a similar function in mootools library
1450 * Returns the type of object that is passed in. If the object passed in is null or undefined it
1451 * return false otherwise it returns one of the following values:<div class="mdetail-params"><ul>
1452 * <li><b>string</b>: If the object passed is a string</li>
1453 * <li><b>number</b>: If the object passed is a number</li>
1454 * <li><b>boolean</b>: If the object passed is a boolean value</li>
1455 * <li><b>date</b>: If the object passed is a Date object</li>
1456 * <li><b>function</b>: If the object passed is a function reference</li>
1457 * <li><b>object</b>: If the object passed is an object</li>
1458 * <li><b>array</b>: If the object passed is an array</li>
1459 * <li><b>regexp</b>: If the object passed is a regular expression</li>
1460 * <li><b>element</b>: If the object passed is a DOM Element</li>
1461 * <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
1462 * <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
1463 * <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
1465 * @param {Mixed} object
1469 if(o === undefined || o === null){
1476 if(t == 'object' && o.nodeName) {
1477 switch(o.nodeType) {
1478 case 1: return 'element';
1479 case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
1482 if(t == 'object' || t == 'function') {
1483 switch(o.constructor) {
1484 case Array: return 'array';
1485 case RegExp: return 'regexp';
1486 case Date: return 'date';
1488 if(Ext.isNumber(o.length) && Ext.isFunction(o.item)) {
1495 intercept : function(o, name, fn, scope){
1496 o[name] = o[name].createInterceptor(fn, scope);
1500 callback : function(cb, scope, args, delay){
1501 if(Ext.isFunction(cb)){
1503 cb.defer(delay, scope, args || []);
1505 cb.apply(scope, args || []);
1514 * These functions are available on every Function object (any JavaScript function).
1516 Ext.apply(Function.prototype, {
1518 * Create a combined function call sequence of the original function + the passed function.
1519 * The resulting function returns the results of the original function.
1520 * The passed fcn is called with the parameters of the original function. Example usage:
1522 var sayHi = function(name){
1523 alert('Hi, ' + name);
1526 sayHi('Fred'); // alerts "Hi, Fred"
1528 var sayGoodbye = sayHi.createSequence(function(name){
1529 alert('Bye, ' + name);
1532 sayGoodbye('Fred'); // both alerts show
1534 * @param {Function} fcn The function to sequence
1535 * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
1536 * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
1537 * @return {Function} The new function
1539 createSequence : function(fcn, scope){
1541 return !Ext.isFunction(fcn) ?
1544 var retval = method.apply(this || window, arguments);
1545 fcn.apply(scope || this || window, arguments);
1554 * These functions are available as static methods on the JavaScript String object.
1556 Ext.applyIf(String, {
1559 * Escapes the passed string for ' and \
1560 * @param {String} string The string to escape
1561 * @return {String} The escaped string
1564 escape : function(string) {
1565 return string.replace(/('|\\)/g, "\\$1");
1569 * Pads the left side of a string with a specified character. This is especially useful
1570 * for normalizing number and date strings. Example usage:
1572 var s = String.leftPad('123', 5, '0');
1573 // s now contains the string: '00123'
1575 * @param {String} string The original string
1576 * @param {Number} size The total length of the output string
1577 * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
1578 * @return {String} The padded string
1581 leftPad : function (val, size, ch) {
1582 var result = String(val);
1586 while (result.length < size) {
1587 result = ch + result;
1594 * Utility function that allows you to easily switch a string between two alternating values. The passed value
1595 * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
1596 * they are already different, the first value passed in is returned. Note that this method returns the new value
1597 * but does not change the current string.
1599 // alternate sort directions
1600 sort = sort.toggle('ASC', 'DESC');
1602 // instead of conditional logic:
1603 sort = (sort == 'ASC' ? 'DESC' : 'ASC');
1605 * @param {String} value The value to compare to the current string
1606 * @param {String} other The new value to use if the string already equals the first value passed in
1607 * @return {String} The new value
1609 String.prototype.toggle = function(value, other){
1610 return this == value ? other : value;
1614 * Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
1616 var s = ' foo bar ';
1617 alert('-' + s + '-'); //alerts "- foo bar -"
1618 alert('-' + s.trim() + '-'); //alerts "-foo bar-"
1620 * @return {String} The trimmed string
1622 String.prototype.trim = function(){
1623 var re = /^\s+|\s+$/g;
1624 return function(){ return this.replace(re, ""); };
1627 // here to prevent dependency on Date.js
1629 Returns the number of milliseconds between this date and date
1630 @param {Date} date (optional) Defaults to now
1631 @return {Number} The diff in milliseconds
1632 @member Date getElapsed
1634 Date.prototype.getElapsed = function(date) {
1635 return Math.abs((date || new Date()).getTime()-this.getTime());
1642 Ext.applyIf(Number.prototype, {
1644 * Checks whether or not the current number is within a desired range. If the number is already within the
1645 * range it is returned, otherwise the min or max value is returned depending on which side of the range is
1646 * exceeded. Note that this method returns the constrained value but does not change the current number.
1647 * @param {Number} min The minimum number in the range
1648 * @param {Number} max The maximum number in the range
1649 * @return {Number} The constrained value if outside the range, otherwise the current value
1651 constrain : function(min, max){
1652 return Math.min(Math.max(this, min), max);
1656 * @class Ext.util.TaskRunner
1657 * Provides the ability to execute one or more arbitrary tasks in a multithreaded
1658 * manner. Generally, you can use the singleton {@link Ext.TaskMgr} instead, but
1659 * if needed, you can create separate instances of TaskRunner. Any number of
1660 * separate tasks can be started at any time and will run independently of each
1661 * other. Example usage:
1663 // Start a simple clock task that updates a div once per second
1664 var updateClock = function(){
1665 Ext.fly('clock').update(new Date().format('g:i:s A'));
1669 interval: 1000 //1 second
1671 var runner = new Ext.util.TaskRunner();
1674 // equivalent using TaskMgr
1681 * Also see {@link Ext.util.DelayedTask}.
1684 * @param {Number} interval (optional) The minimum precision in milliseconds supported by this TaskRunner instance
1687 Ext.util.TaskRunner = function(interval){
1688 interval = interval || 10;
1695 stopThread = function(){
1702 startThread = function(){
1705 id = setInterval(runTasks, interval);
1710 removeTask = function(t){
1711 removeQueue.push(t);
1713 t.onStop.apply(t.scope || t);
1718 runTasks = function(){
1719 var rqLen = removeQueue.length,
1720 now = new Date().getTime();
1723 for(var i = 0; i < rqLen; i++){
1724 tasks.remove(removeQueue[i]);
1727 if(tasks.length < 1){
1732 for(var i = 0, t, itime, rt, len = tasks.length; i < len; ++i){
1734 itime = now - t.taskRunTime;
1735 if(t.interval <= itime){
1736 rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
1737 t.taskRunTime = now;
1738 if(rt === false || t.taskRunCount === t.repeat){
1743 if(t.duration && t.duration <= (now - t.taskStartTime)){
1750 * Starts a new task.
1752 * @param {Object} task A config object that supports the following properties:<ul>
1753 * <li><code>run</code> : Function<div class="sub-desc">The function to execute each time the task is run. The
1754 * function will be called at each interval and passed the <code>args</code> argument if specified. If a
1755 * particular scope is required, be sure to specify it using the <code>scope</code> argument.</div></li>
1756 * <li><code>interval</code> : Number<div class="sub-desc">The frequency in milliseconds with which the task
1757 * should be executed.</div></li>
1758 * <li><code>args</code> : Array<div class="sub-desc">(optional) An array of arguments to be passed to the function
1759 * specified by <code>run</code>.</div></li>
1760 * <li><code>scope</code> : Object<div class="sub-desc">(optional) The scope (<tt>this</tt> reference) in which to execute the
1761 * <code>run</code> function. Defaults to the task config object.</div></li>
1762 * <li><code>duration</code> : Number<div class="sub-desc">(optional) The length of time in milliseconds to execute
1763 * the task before stopping automatically (defaults to indefinite).</div></li>
1764 * <li><code>repeat</code> : Number<div class="sub-desc">(optional) The number of times to execute the task before
1765 * stopping automatically (defaults to indefinite).</div></li>
1767 * @return {Object} The task
1769 this.start = function(task){
1771 task.taskStartTime = new Date().getTime();
1772 task.taskRunTime = 0;
1773 task.taskRunCount = 0;
1779 * Stops an existing running task.
1781 * @param {Object} task The task to stop
1782 * @return {Object} The task
1784 this.stop = function(task){
1790 * Stops all tasks that are currently running.
1793 this.stopAll = function(){
1795 for(var i = 0, len = tasks.length; i < len; i++){
1796 if(tasks[i].onStop){
1806 * @class Ext.TaskMgr
1807 * @extends Ext.util.TaskRunner
1808 * A static {@link Ext.util.TaskRunner} instance that can be used to start and stop arbitrary tasks. See
1809 * {@link Ext.util.TaskRunner} for supported methods and task config properties.
1811 // Start a simple clock task that updates a div once per second
1814 Ext.fly('clock').update(new Date().format('g:i:s A'));
1816 interval: 1000 //1 second
1818 Ext.TaskMgr.start(task);
1822 Ext.TaskMgr = new Ext.util.TaskRunner();if(typeof jQuery == "undefined"){
1823 throw "Unable to load Ext, jQuery not found.";
1830 getViewWidth : function(full){
1831 // jQuery doesn't report full window size on document query, so max both
1832 return full ? Math.max(jQuery(document).width(),jQuery(window).width()) : jQuery(window).width();
1835 getViewHeight : function(full){
1836 // jQuery doesn't report full window size on document query, so max both
1837 return full ? Math.max(jQuery(document).height(),jQuery(window).height()) : jQuery(window).height();
1840 isAncestor : function(p, c){
1847 return p.contains(c);
1848 } else if (p.compareDocumentPosition) {
1849 return !!(p.compareDocumentPosition(c) & 16);
1851 while (c = c.parentNode) {
1852 ret = c == p || ret;
1859 getRegion : function(el){
1860 return Ext.lib.Region.getRegion(el);
1863 //////////////////////////////////////////////////////////////////////////////////////
1864 // Use of jQuery.offset() removed to promote consistent behavior across libs.
1866 //////////////////////////////////////////////////////////////////////////////////////
1868 getY : function(el){
1869 return this.getXY(el)[1];
1872 getX : function(el){
1873 return this.getXY(el)[0];
1876 getXY : function(el) {
1877 var p, pe, b, scroll, bd = (document.body || document.documentElement);
1878 el = Ext.getDom(el);
1884 if (el.getBoundingClientRect) {
1885 b = el.getBoundingClientRect();
1886 scroll = fly(document).getScroll();
1887 return [Math.round(b.left + scroll.left), Math.round(b.top + scroll.top)];
1893 var hasAbsolute = fly(el).getStyle("position") == "absolute";
1900 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
1907 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
1908 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
1915 if (p != el && pe.getStyle('overflow') != 'visible') {
1923 if (Ext.isSafari && hasAbsolute) {
1928 if (Ext.isGecko && !hasAbsolute) {
1930 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
1931 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
1935 while (p && p != bd) {
1936 if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
1945 setXY : function(el, xy){
1946 el = Ext.fly(el, '_setXY');
1948 var pts = el.translatePoints(xy);
1949 if(xy[0] !== false){
1950 el.dom.style.left = pts.left + "px";
1952 if(xy[1] !== false){
1953 el.dom.style.top = pts.top + "px";
1957 setX : function(el, x){
1958 this.setXY(el, [x, false]);
1961 setY : function(el, y){
1962 this.setXY(el, [false, y]);
1966 // all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights
1969 libFlyweight = new Ext.Element.Flyweight();
1971 libFlyweight.dom = el;
1972 return libFlyweight;
1975 getPageX : function(e){
1976 e = e.browserEvent || e;
1980 getPageY : function(e){
1981 e = e.browserEvent || e;
1985 getXY : function(e){
1986 e = e.browserEvent || e;
1987 return [e.pageX, e.pageY];
1990 getTarget : function(e){
1994 // all Ext events will go through event manager which provides scoping
1995 on : function(el, eventName, fn, scope, override){
1996 jQuery(el).bind(eventName, fn);
1999 un : function(el, eventName, fn){
2000 jQuery(el).unbind(eventName, fn);
2003 purgeElement : function(el){
2004 jQuery(el).unbind();
2007 preventDefault : function(e){
2008 e = e.browserEvent || e;
2009 if(e.preventDefault){
2012 e.returnValue = false;
2016 stopPropagation : function(e){
2017 e = e.browserEvent || e;
2018 if(e.stopPropagation){
2019 e.stopPropagation();
2021 e.cancelBubble = true;
2025 stopEvent : function(e){
2026 this.preventDefault(e);
2027 this.stopPropagation(e);
2030 onAvailable : function(id, fn, scope){
2031 var start = new Date();
2033 if(start.getElapsed() > 10000){
2036 var el = document.getElementById(id);
2039 fn.call(scope||window, el);
2042 var iid = setInterval(f, 50);
2045 resolveTextNode: Ext.isGecko ? function(node){
2049 var s = HTMLElement.prototype.toString.call(node);
2050 if(s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]'){
2053 return node.nodeType == 3 ? node.parentNode : node;
2055 return node && node.nodeType == 3 ? node.parentNode : node;
2058 getRelatedTarget: function(ev) {
2059 ev = ev.browserEvent || ev;
2060 var t = ev.relatedTarget;
2062 if (ev.type == "mouseout") {
2064 } else if (ev.type == "mouseover") {
2069 return this.resolveTextNode(t);
2073 Ext.lib.Ajax = function(){
2074 var createComplete = function(cb){
2075 return function(xhr, status){
2076 if((status == 'error' || status == 'timeout') && cb.failure){
2077 cb.failure.call(cb.scope||window, createResponse(cb, xhr));
2078 }else if(cb.success){
2079 cb.success.call(cb.scope||window, createResponse(cb, xhr));
2084 var createResponse = function(cb, xhr){
2091 headerStr = xhr.getAllResponseHeaders();
2092 Ext.each(headerStr.replace(/\r\n/g, '\n').split('\n'), function(v){
2095 s = v.substr(0, t).toLowerCase();
2096 if(v.charAt(t + 1) == ' '){
2099 headerObj[s] = v.substr(t + 1);
2105 responseText: xhr.responseText,
2106 responseXML : xhr.responseXML,
2107 argument: cb.argument,
2109 statusText: xhr.statusText,
2110 getResponseHeader : function(header){return headerObj[header.toLowerCase()];},
2111 getAllResponseHeaders : function(){return headerStr}
2115 request : function(method, uri, cb, data, options){
2120 timeout: cb.timeout,
2121 complete: createComplete(cb)
2125 var hs = options.headers;
2126 if(options.xmlData){
2127 o.data = options.xmlData;
2128 o.processData = false;
2129 o.type = (method ? method : (options.method ? options.method : 'POST'));
2130 if (!hs || !hs['Content-Type']){
2131 o.contentType = 'text/xml';
2133 }else if(options.jsonData){
2134 o.data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
2135 o.processData = false;
2136 o.type = (method ? method : (options.method ? options.method : 'POST'));
2137 if (!hs || !hs['Content-Type']){
2138 o.contentType = 'application/json';
2142 o.beforeSend = function(xhr){
2144 if(hs.hasOwnProperty(h)){
2145 xhr.setRequestHeader(h, hs[h]);
2154 formRequest : function(form, uri, cb, data, isUpload, sslUri){
2156 type: Ext.getDom(form).method ||'POST',
2158 data: jQuery(form).serialize()+(data?'&'+data:''),
2159 timeout: cb.timeout,
2160 complete: createComplete(cb)
2164 isCallInProgress : function(trans){
2168 abort : function(trans){
2172 serializeForm : function(form){
2173 return jQuery(form.dom||form).serialize();
2178 Ext.lib.Anim = function(){
2179 var createAnim = function(cb, scope){
2180 var animated = true;
2182 stop : function(skipToLast){
2186 isAnimated : function(){
2190 proxyCallback : function(){
2192 Ext.callback(cb, scope);
2197 scroll : function(el, args, duration, easing, cb, scope){
2198 // scroll anim not supported so just scroll immediately
2199 var anim = createAnim(cb, scope);
2200 el = Ext.getDom(el);
2201 if(typeof args.scroll.to[0] == 'number'){
2202 el.scrollLeft = args.scroll.to[0];
2204 if(typeof args.scroll.to[1] == 'number'){
2205 el.scrollTop = args.scroll.to[1];
2207 anim.proxyCallback();
2211 motion : function(el, args, duration, easing, cb, scope){
2212 return this.run(el, args, duration, easing, cb, scope);
2215 color : function(el, args, duration, easing, cb, scope){
2216 // color anim not supported, so execute callback immediately
2217 var anim = createAnim(cb, scope);
2218 anim.proxyCallback();
2222 run : function(el, args, duration, easing, cb, scope, type){
2223 var anim = createAnim(cb, scope), e = Ext.fly(el, '_animrun');
2226 switch(k){ // jquery doesn't support, so convert
2230 if(by = args.points.by){
2232 pts = e.translatePoints([xy[0]+by[0], xy[1]+by[1]]);
2234 pts = e.translatePoints(args.points.to);
2238 if(!parseInt(e.getStyle('left'), 10)){ // auto bug
2241 if(!parseInt(e.getStyle('top'), 10)){
2244 if(args.points.from){
2245 e.setXY(args.points.from);
2249 o.width = args.width.to;
2250 if (args.width.from)
2251 e.setWidth(args.width.from);
2254 o.height = args.height.to;
2255 if (args.height.from)
2256 e.setHeight(args.height.from);
2259 o.opacity = args.opacity.to;
2260 if (args.opacity.from)
2261 e.setOpacity(args.opacity.from);
2264 o.left = args.left.to;
2266 e.setLeft(args.left.from);
2269 o.top = args.top.to;
2271 e.setTop(args.top.from);
2275 // jQuery can't handle callback and scope arguments, so break here
2281 e.setStyle(k, args[k].from);
2285 // TODO: find out about easing plug in?
2286 jQuery(el).animate(o, duration*1000, undefined, anim.proxyCallback);
2293 Ext.lib.Region = function(t, r, b, l) {
2302 Ext.lib.Region.prototype = {
2303 contains : function(region) {
2304 return ( region.left >= this.left &&
2305 region.right <= this.right &&
2306 region.top >= this.top &&
2307 region.bottom <= this.bottom );
2311 getArea : function() {
2312 return ( (this.bottom - this.top) * (this.right - this.left) );
2315 intersect : function(region) {
2316 var t = Math.max( this.top, region.top );
2317 var r = Math.min( this.right, region.right );
2318 var b = Math.min( this.bottom, region.bottom );
2319 var l = Math.max( this.left, region.left );
2321 if (b >= t && r >= l) {
2322 return new Ext.lib.Region(t, r, b, l);
2327 union : function(region) {
2328 var t = Math.min( this.top, region.top );
2329 var r = Math.max( this.right, region.right );
2330 var b = Math.max( this.bottom, region.bottom );
2331 var l = Math.min( this.left, region.left );
2333 return new Ext.lib.Region(t, r, b, l);
2336 constrainTo : function(r) {
2337 this.top = this.top.constrain(r.top, r.bottom);
2338 this.bottom = this.bottom.constrain(r.top, r.bottom);
2339 this.left = this.left.constrain(r.left, r.right);
2340 this.right = this.right.constrain(r.left, r.right);
2344 adjust : function(t, l, b, r){
2353 Ext.lib.Region.getRegion = function(el) {
2354 var p = Ext.lib.Dom.getXY(el);
2357 var r = p[0] + el.offsetWidth;
2358 var b = p[1] + el.offsetHeight;
2361 return new Ext.lib.Region(t, r, b, l);
2364 Ext.lib.Point = function(x, y) {
2365 if (Ext.isArray(x)) {
2369 this.x = this.right = this.left = this[0] = x;
2370 this.y = this.top = this.bottom = this[1] = y;
2373 Ext.lib.Point.prototype = new Ext.lib.Region();
2377 function fnCleanUp() {
2378 var p = Function.prototype;
2379 delete p.createSequence;
2381 delete p.createDelegate;
2382 delete p.createCallback;
2383 delete p.createInterceptor;
2385 window.detachEvent("onunload", fnCleanUp);
2387 window.attachEvent("onunload", fnCleanUp);