X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..25ef3491bd9ae007ff1fc2b0d7943e6eaaccf775:/src/core/core/Ext.js diff --git a/src/core/core/Ext.js b/src/core/core/Ext.js index 497694ec..bff96f0d 100644 --- a/src/core/core/Ext.js +++ b/src/core/core/Ext.js @@ -1,5 +1,5 @@ /*! - * Ext JS Library 3.0.0 + * Ext JS Library 3.0.3 * Copyright(c) 2006-2009 Ext JS, LLC * licensing@extjs.com * http://www.extjs.com/license @@ -19,7 +19,7 @@ Ext = { * The version of the framework * @type String */ - version : '3.0' + version : '3.0.1' }; /** @@ -46,20 +46,6 @@ Ext.apply = function(o, c, defaults){ (function(){ var idSeed = 0, toString = Object.prototype.toString, - //assume it's not null and not an array - isIterable = function(v){ - //check for array or arguments - if(Ext.isArray(v) || v.callee){ - return true; - } - //check for node list type - if(/NodeList|HTMLCollection/.test(toString.call(v))){ - return true; - } - //NodeList has an item and length property - //IXMLDOMNodeList has nextNode method, needs to be checked first. - return ((v.nextNode || v.item) && Ext.isNumber(v.length)); - }, ua = navigator.userAgent.toLowerCase(), check = function(r){ return r.test(ua); @@ -97,10 +83,10 @@ Ext.apply = function(o, c, defaults){ Ext.apply(Ext, { /** * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent - * the IE insecure content warning (defaults to javascript:false). + * the IE insecure content warning ('about:blank', except for IE in secure mode, which is 'javascript:""'). * @type String */ - SSL_SECURE_URL : 'javascript:false', + SSL_SECURE_URL : isSecure && isIE ? 'javascript:""' : 'about:blank', /** * True if the browser is in strict (standards-compliant) mode, as opposed to quirks mode * @type Boolean @@ -154,7 +140,7 @@ Ext.apply = function(o, c, defaults){ applyIf : function(o, c){ if(o){ for(var p in c){ - if(Ext.isEmpty(o[p])){ + if(!Ext.isDefined(o[p])){ o[p] = c[p]; } } @@ -173,30 +159,27 @@ Ext.apply = function(o, c, defaults){ }, /** - * Extends one class with another class and optionally overrides members with the passed literal. This class - * also adds the function "override()" to the class that can be used to override - * members on an instance. - * *

- * This function also supports a 2-argument call in which the subclass's constructor is - * not passed as an argument. In this form, the parameters are as follows:

- *

- * For example, to create a subclass of the Ext GridPanel: + *

Extends one class to create a subclass and optionally overrides members with the passed literal. This method + * also adds the function "override()" to the subclass that can be used to override members of the class.

+ * For example, to create a subclass of Ext GridPanel: *

 MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
     constructor: function(config) {
-        // Your preprocessing here
-        MyGridPanel.superclass.constructor.apply(this, arguments);
-        // Your postprocessing here
+
+//      Create configuration for this Grid.
+        var store = new Ext.data.Store({...});
+        var colModel = new Ext.grid.ColumnModel({...});
+
+//      Create a new config object containing our computed properties
+//      *plus* whatever was in the config parameter.
+        config = Ext.apply({
+            store: store,
+            colModel: colModel
+        }, config);
+
+        MyGridPanel.superclass.constructor.call(this, config);
+
+//      Your postprocessing here
     },
 
     yourMethod: function() {
@@ -204,13 +187,25 @@ MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
     }
 });
 
- *

- * @param {Function} subclass The class inheriting the functionality - * @param {Function} superclass The class being extended - * @param {Object} overrides (optional) A literal with members which are copied into the subclass's - * prototype, and are therefore shared between all instances of the new class. + * + *

This function also supports a 3-argument call in which the subclass's constructor is + * passed as an argument. In this form, the parameters are as follows:

+ *
+ * + * @param {Function} subclass The constructor of class being extended. + * @param {Object} overrides

A literal with members which are copied into the subclass's + * prototype, and are therefore shared between all instances of the new class.

+ *

This may contain a special member named constructor. This is used + * to define the constructor of the new class, and is returned. If this property is + * not specified, a constructor is generated and returned which just calls the + * superclass's constructor passing on its parameters.

+ *

It is essential that you call the superclass constructor in any provided constructor. See example code.

* @return {Function} The subclass constructor. - * @method extend */ extend : function(){ // inline overrides @@ -246,7 +241,7 @@ MyGridPanel = Ext.extend(Ext.grid.GridPanel, { }); sbp.override = io; Ext.override(sb, overrides); - sb.extend = function(o){Ext.extend(sb, o);}; + sb.extend = function(o){return Ext.extend(sb, o);}; return sb; }; }(), @@ -290,6 +285,7 @@ Company.data.CustomStore = function(config) { ... } * @param {String} namespace1 * @param {String} namespace2 * @param {String} etc + * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created) * @method namespace */ namespace : function(){ @@ -310,18 +306,20 @@ Company.data.CustomStore = function(config) { ... } * @param {String} pre (optional) A prefix to add to the url encoded string * @return {String} */ - urlEncode: function(o, pre){ - var undef, buf = [], key, e = encodeURIComponent; + urlEncode : function(o, pre){ + var empty, + buf = [], + e = encodeURIComponent; - for(key in o){ - undef = !Ext.isDefined(o[key]); - Ext.each(undef ? key : o[key], function(val, i){ - buf.push("&", e(key), "=", (val != key || !undef) ? e(val) : ""); + Ext.iterate(o, function(key, item){ + empty = Ext.isEmpty(item); + Ext.each(empty ? key : item, function(val){ + buf.push('&', e(key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : ''); }); - } + }); if(!pre){ buf.shift(); - pre = ""; + pre = ''; } return pre + buf.join(''); }, @@ -336,6 +334,9 @@ Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2" * @return {Object} A literal with members */ urlDecode : function(string, overwrite){ + if(Ext.isEmpty(string)){ + return {}; + } var obj = {}, pairs = string.split('&'), d = decodeURIComponent, @@ -352,11 +353,11 @@ Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2" }, /** - * Appends content to the query string of a URL, which handles logic for whether to place + * Appends content to the query string of a URL, handling logic for whether to place * a question mark or ampersand. - * @param {String} url The url to append to. - * @@param {String} s The content to append to the url. - * @return (String) The appended string + * @param {String} url The URL to append to. + * @param {String} s The content to append to the URL. + * @return (String) The resulting URL */ urlAppend : function(url, s){ if(!Ext.isEmpty(s)){ @@ -386,19 +387,48 @@ Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2" } }(), + isIterable : function(v){ + //check for array or arguments + if(Ext.isArray(v) || v.callee){ + return true; + } + //check for node list type + if(/NodeList|HTMLCollection/.test(toString.call(v))){ + return true; + } + //NodeList has an item and length property + //IXMLDOMNodeList has nextNode method, needs to be checked first. + return ((v.nextNode || v.item) && Ext.isNumber(v.length)); + }, + /** - * Iterates an array calling the passed function with each item, stopping if your function returns false. If the - * passed array is not really an array, your function is called once with it. - * The supplied function is called with (Object item, Number index, Array allItems). - * @param {Array/NodeList/Mixed} array - * @param {Function} fn - * @param {Object} scope + * Iterates an array calling the supplied function. + * @param {Array/NodeList/Mixed} array The array to be iterated. If this + * argument is not really an array, the supplied function is called once. + * @param {Function} fn The function to be called with each item. If the + * supplied function returns false, iteration stops and this method returns + * the current index. This function is called with + * the following arguments: + *
+ * @param {Object} scope The scope (this reference) in which the specified function is executed. + * Defaults to the item at the current index + * within the passed array. + * @return See description for the fn parameter. */ - each: function(array, fn, scope){ + each : function(array, fn, scope){ if(Ext.isEmpty(array, true)){ return; } - if(!isIterable(array) || Ext.isPrimitive(array)){ + if(!Ext.isIterable(array) || Ext.isPrimitive(array)){ array = [array]; } for(var i = 0, len = array.length; i < len; i++){ @@ -425,11 +455,14 @@ Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false); // returns {foo: "1", bar: ["2" * When iterating an object, the supplied function is called with each key-value pair in * the object. * - * @param {Object} scope The scope to call the supplied function with, defaults to - * the specified object + * @param {Object} scope The scope (this reference) in which the specified function is executed. Defaults to + * the object being iterated. */ iterate : function(obj, fn, scope){ - if(isIterable(obj)){ + if(Ext.isEmpty(obj)){ + return; + } + if(Ext.isIterable(obj)){ Ext.each(obj, fn, scope); return; }else if(Ext.isObject(obj)){ @@ -515,8 +548,8 @@ function(el){ }, /** - * Returns true if the passed object is a JavaScript array, otherwise false. - * @param {Object} object The object to test + * Returns true if the passed value is a JavaScript array, otherwise false. + * @param {Mixed} value The value to test * @return {Boolean} */ isArray : function(v){ @@ -524,16 +557,25 @@ function(el){ }, /** - * Returns true if the passed object is a JavaScript Object, otherwise false. + * Returns true if the passed object is a JavaScript date object, otherwise false. * @param {Object} object The object to test * @return {Boolean} */ + isDate : function(v){ + return toString.apply(v) === '[object Date]'; + }, + + /** + * Returns true if the passed value is a JavaScript Object, otherwise false. + * @param {Mixed} value The value to test + * @return {Boolean} + */ isObject : function(v){ return v && typeof v == "object"; }, /** - * Returns true if the passed object is a JavaScript 'primitive', a string, number or boolean. + * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean. * @param {Mixed} value The value to test * @return {Boolean} */ @@ -542,8 +584,8 @@ function(el){ }, /** - * Returns true if the passed object is a JavaScript Function, otherwise false. - * @param {Object} object The object to test + * Returns true if the passed value is a JavaScript Function, otherwise false. + * @param {Mixed} value The value to test * @return {Boolean} */ isFunction : function(v){ @@ -551,38 +593,38 @@ function(el){ }, /** - * Returns true if the passed object is a number. Returns false for non-finite numbers. - * @param {Object} v The object to test + * Returns true if the passed value is a number. Returns false for non-finite numbers. + * @param {Mixed} value The value to test * @return {Boolean} */ - isNumber: function(v){ + isNumber : function(v){ return typeof v === 'number' && isFinite(v); }, /** - * Returns true if the passed object is a string. - * @param {Object} v The object to test + * Returns true if the passed value is a string. + * @param {Mixed} value The value to test * @return {Boolean} */ - isString: function(v){ + isString : function(v){ return typeof v === 'string'; }, /** - * Returns true if the passed object is a boolean. - * @param {Object} v The object to test + * Returns true if the passed value is a boolean. + * @param {Mixed} value The value to test * @return {Boolean} */ - isBoolean: function(v){ + isBoolean : function(v){ return typeof v === 'boolean'; }, /** - * Returns true if the passed object is not undefined. - * @param {Object} v The object to test + * Returns true if the passed value is not undefined. + * @param {Mixed} value The value to test * @return {Boolean} */ - isDefined: function(v){ + isDefined : function(v){ return typeof v !== 'undefined'; }, @@ -595,7 +637,7 @@ function(el){ * True if the detected browser uses WebKit. * @type Boolean */ - isWebKit: isWebKit, + isWebKit : isWebKit, /** * True if the detected browser is Chrome. * @type Boolean @@ -695,7 +737,8 @@ Company.data.CustomStore = function(config) { ... } * @param {String} namespace1 * @param {String} namespace2 * @param {String} etc - * @method namespace + * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created) + * @method ns */ Ext.ns = Ext.namespace; })(); @@ -709,9 +752,9 @@ Ext.ns("Ext", "Ext.util", "Ext.lib", "Ext.data"); */ Ext.apply(Function.prototype, { /** - * Creates an interceptor function. The passed fcn is called before the original one. If it returns false, + * Creates an interceptor function. The passed function is called before the original one. If it returns false, * the original one is not called. The resulting function returns the results of the original function. - * The passed fcn is called with the parameters of the original function. Example usage: + * The passed function is called with the parameters of the original function. Example usage: *

 var sayHi = function(name){
     alert('Hi, ' + name);
@@ -729,7 +772,8 @@ sayHiToFriend('Fred');  // no alert
 sayHiToFriend('Brian'); // alerts "Hi, Brian"
 
* @param {Function} fcn The function to call before the original - * @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window) + * @param {Object} scope (optional) The scope (this reference) in which the passed function is executed. + * If omitted, defaults to the scope in which the original function is called or the browser window. * @return {Function} The new function */ createInterceptor : function(fcn, scope){ @@ -804,10 +848,11 @@ var btn = new Ext.Button({ // "Hi, Fred. You clicked the "Say Hi" button." btn.on('click', sayHi.createDelegate(btn, ['Fred'])); - * @param {Object} obj (optional) The object for which the scope is set + * @param {Object} scope (optional) The scope (this reference) in which the function is executed. + * If omitted, defaults to the browser window. * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller) * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding, - * if a number the args are inserted at the specified position + * if a number the args are inserted at the specified position * @return {Function} The new function */ createDelegate : function(obj, args, appendArgs){ @@ -846,10 +891,11 @@ sayHi.defer(2000, this, ['Fred']); }).defer(100); * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately) - * @param {Object} obj (optional) The object for which the scope is set + * @param {Object} scope (optional) The scope (this reference) in which the function is executed. + * If omitted, defaults to the browser window. * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller) * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding, - * if a number the args are inserted at the specified position + * if a number the args are inserted at the specified position * @return {Number} The timeout id that can be used with clearTimeout */ defer : function(millis, obj, args, appendArgs){ @@ -896,12 +942,16 @@ Ext.applyIf(Array.prototype, { /** * Checks whether or not the specified object exists in the array. * @param {Object} o The object to check for + * @param {Number} from (Optional) The index at which to begin the search * @return {Number} The index of o in the array (or -1 if it is not found) */ - indexOf : function(o){ - for (var i = 0, len = this.length; i < len; i++){ - if(this[i] == o){ - return i; + indexOf : function(o, from){ + var len = this.length; + from = from || 0; + from += (from < 0) ? len : 0; + for (; from < len; ++from){ + if(this[from] === o){ + return from; } } return -1;