/ext-4.1.0_b3/builds/ext-core-debug-w-comments.js
https://bitbucket.org/srogerf/javascript · JavaScript · 24770 lines · 12390 code · 2615 blank · 9765 comment · 2993 complexity · 52b43a9b21ab8a7a7a4aca5537b04488 MD5 · raw file
Large files are truncated click here to view the full file
- /*
- This file is part of Ext JS 4.1
- Copyright (c) 2011-2012 Sencha Inc
- Contact: http://www.sencha.com/contact
- Pre-release code in the Ext repository is intended for development purposes only and will
- not always be stable.
- Use of pre-release code is permitted with your application at your own risk under standard
- Ext license terms. Public redistribution is prohibited.
- For early licensing, please contact us at licensing@sencha.com
- Build date: 2012-02-21 23:18:31 (3a639ae9dd5443bffbde7bec9922e6fb07a923a8)
- */
- /**
- * @class Ext
- * @singleton
- */
- var Ext = Ext || {};
- Ext._startTime = new Date().getTime();
- (function() {
- var global = this,
- objectPrototype = Object.prototype,
- toString = objectPrototype.toString,
- enumerables = true,
- enumerablesTest = { toString: 1 },
- emptyFn = function(){},
- i;
- Ext.global = global;
- for (i in enumerablesTest) {
- enumerables = null;
- }
- if (enumerables) {
- enumerables = ['hasOwnProperty', 'valueOf', 'isPrototypeOf', 'propertyIsEnumerable',
- 'toLocaleString', 'toString', 'constructor'];
- }
- /**
- * An array containing extra enumerables for old browsers
- * @property {String[]}
- */
- Ext.enumerables = enumerables;
- /**
- * Copies all the properties of config to the specified object.
- * Note that if recursive merging and cloning without referencing the original objects / arrays is needed, use
- * {@link Ext.Object#merge} instead.
- * @param {Object} object The receiver of the properties
- * @param {Object} config The source of the properties
- * @param {Object} defaults A different object that will also be applied for default values
- * @return {Object} returns obj
- */
- Ext.apply = function(object, config, defaults) {
- if (defaults) {
- Ext.apply(object, defaults);
- }
- if (object && config && typeof config === 'object') {
- var i, j, k;
- for (i in config) {
- object[i] = config[i];
- }
- if (enumerables) {
- for (j = enumerables.length; j--;) {
- k = enumerables[j];
- if (config.hasOwnProperty(k)) {
- object[k] = config[k];
- }
- }
- }
- }
- return object;
- };
- Ext.buildSettings = Ext.apply({
- baseCSSPrefix: 'x-',
- scopeResetCSS: false
- }, Ext.buildSettings || {});
- Ext.apply(Ext, {
- /**
- * @property {String} [name='Ext']
- * <p>The name of the property in the global namespace (The <code>window</code> in browser environments) which refers to the current instance of Ext.</p>
- * <p>This is usually <code>"Ext"</code>, but if a sandboxed build of ExtJS is being used, this will be an alternative name.</p>
- * <p>If code is being generated for use by <code>eval</code> or to create a <code>new Function</code>, and the global instance
- * of Ext must be referenced, this is the name that should be built into the code.</p>
- */
- name: Ext.sandboxName || 'Ext',
- /**
- * A reusable empty function
- */
- emptyFn: emptyFn,
- /**
- * A zero length string which will pass a truth test. Useful for passing to methods
- * which use a truth test to reject <i>falsy</i> values where a string value must be cleared.
- */
- emptyString: new String(),
- baseCSSPrefix: Ext.buildSettings.baseCSSPrefix,
- /**
- * Copies all the properties of config to object if they don't already exist.
- * @param {Object} object The receiver of the properties
- * @param {Object} config The source of the properties
- * @return {Object} returns obj
- */
- applyIf: function(object, config) {
- var property;
- if (object) {
- for (property in config) {
- if (object[property] === undefined) {
- object[property] = config[property];
- }
- }
- }
- return object;
- },
- /**
- * Iterates either an array or an object. This method delegates to
- * {@link Ext.Array#each Ext.Array.each} if the given value is iterable, and {@link Ext.Object#each Ext.Object.each} otherwise.
- *
- * @param {Object/Array} object The object or array to be iterated.
- * @param {Function} fn The function to be called for each iteration. See and {@link Ext.Array#each Ext.Array.each} and
- * {@link Ext.Object#each Ext.Object.each} for detailed lists of arguments passed to this function depending on the given object
- * type that is being iterated.
- * @param {Object} scope (Optional) The scope (`this` reference) in which the specified function is executed.
- * Defaults to the object being iterated itself.
- * @markdown
- */
- iterate: function(object, fn, scope) {
- if (Ext.isEmpty(object)) {
- return;
- }
- if (scope === undefined) {
- scope = object;
- }
- if (Ext.isIterable(object)) {
- Ext.Array.each.call(Ext.Array, object, fn, scope);
- }
- else {
- Ext.Object.each.call(Ext.Object, object, fn, scope);
- }
- }
- });
- Ext.apply(Ext, {
- /**
- * This method deprecated. Use {@link Ext#define Ext.define} instead.
- * @method
- * @param {Function} superclass
- * @param {Object} overrides
- * @return {Function} The subclass constructor from the <tt>overrides</tt> parameter, or a generated one if not provided.
- * @deprecated 4.0.0 Use {@link Ext#define Ext.define} instead
- */
- extend: function() {
- // inline overrides
- var objectConstructor = objectPrototype.constructor,
- inlineOverrides = function(o) {
- for (var m in o) {
- if (!o.hasOwnProperty(m)) {
- continue;
- }
- this[m] = o[m];
- }
- };
- return function(subclass, superclass, overrides) {
- // First we check if the user passed in just the superClass with overrides
- if (Ext.isObject(superclass)) {
- overrides = superclass;
- superclass = subclass;
- subclass = overrides.constructor !== objectConstructor ? overrides.constructor : function() {
- superclass.apply(this, arguments);
- };
- }
- // We create a new temporary class
- var F = function() {},
- subclassProto, superclassProto = superclass.prototype;
- F.prototype = superclassProto;
- subclassProto = subclass.prototype = new F();
- subclassProto.constructor = subclass;
- subclass.superclass = superclassProto;
- if (superclassProto.constructor === objectConstructor) {
- superclassProto.constructor = superclass;
- }
- subclass.override = function(overrides) {
- Ext.override(subclass, overrides);
- };
- subclassProto.override = inlineOverrides;
- subclassProto.proto = subclassProto;
- subclass.override(overrides);
- subclass.extend = function(o) {
- return Ext.extend(subclass, o);
- };
- return subclass;
- };
- }(),
- /**
- * Proxy to {@link Ext.Base#override}. Please refer {@link Ext.Base#override} for further details.
- *
- * @param {Object} cls The class to override
- * @param {Object} overrides The properties to add to origClass. This should be specified as an object literal
- * containing one or more properties.
- * @method override
- * @markdown
- * @deprecated 4.1.0 Use {@link Ext#define Ext.define} instead
- */
- override: function(cls, overrides) {
- if (cls.$isClass) {
- return cls.override(overrides);
- }
- else {
- Ext.apply(cls.prototype, overrides);
- }
- }
- });
- // A full set of static methods to do type checking
- Ext.apply(Ext, {
- /**
- * Returns the given value itself if it's not empty, as described in {@link Ext#isEmpty}; returns the default
- * value (second argument) otherwise.
- *
- * @param {Object} value The value to test
- * @param {Object} defaultValue The value to return if the original value is empty
- * @param {Boolean} allowBlank (optional) true to allow zero length strings to qualify as non-empty (defaults to false)
- * @return {Object} value, if non-empty, else defaultValue
- */
- valueFrom: function(value, defaultValue, allowBlank){
- return Ext.isEmpty(value, allowBlank) ? defaultValue : value;
- },
- /**
- * Returns the type of the given variable in string format. List of possible values are:
- *
- * - `undefined`: If the given value is `undefined`
- * - `null`: If the given value is `null`
- * - `string`: If the given value is a string
- * - `number`: If the given value is a number
- * - `boolean`: If the given value is a boolean value
- * - `date`: If the given value is a `Date` object
- * - `function`: If the given value is a function reference
- * - `object`: If the given value is an object
- * - `array`: If the given value is an array
- * - `regexp`: If the given value is a regular expression
- * - `element`: If the given value is a DOM Element
- * - `textnode`: If the given value is a DOM text node and contains something other than whitespace
- * - `whitespace`: If the given value is a DOM text node and contains only whitespace
- *
- * @param {Object} value
- * @return {String}
- * @markdown
- */
- typeOf: function(value) {
- if (value === null) {
- return 'null';
- }
- var type = typeof value;
- if (type === 'undefined' || type === 'string' || type === 'number' || type === 'boolean') {
- return type;
- }
- var typeToString = toString.call(value);
- switch(typeToString) {
- case '[object Array]':
- return 'array';
- case '[object Date]':
- return 'date';
- case '[object Boolean]':
- return 'boolean';
- case '[object Number]':
- return 'number';
- case '[object RegExp]':
- return 'regexp';
- }
- if (type === 'function') {
- return 'function';
- }
- if (type === 'object') {
- if (value.nodeType !== undefined) {
- if (value.nodeType === 3) {
- return (/\S/).test(value.nodeValue) ? 'textnode' : 'whitespace';
- }
- else {
- return 'element';
- }
- }
- return 'object';
- }
- },
- /**
- * Returns true if the passed value is empty, false otherwise. The value is deemed to be empty if it is either:
- *
- * - `null`
- * - `undefined`
- * - a zero-length array
- * - a zero-length string (Unless the `allowEmptyString` parameter is set to `true`)
- *
- * @param {Object} value The value to test
- * @param {Boolean} allowEmptyString (optional) true to allow empty strings (defaults to false)
- * @return {Boolean}
- * @markdown
- */
- isEmpty: function(value, allowEmptyString) {
- return (value === null) || (value === undefined) || (!allowEmptyString ? value === '' : false) || (Ext.isArray(value) && value.length === 0);
- },
- /**
- * Returns true if the passed value is a JavaScript Array, false otherwise.
- *
- * @param {Object} target The target to test
- * @return {Boolean}
- * @method
- */
- isArray: ('isArray' in Array) ? Array.isArray : function(value) {
- return toString.call(value) === '[object Array]';
- },
- /**
- * Returns true if the passed value is a JavaScript Date object, false otherwise.
- * @param {Object} object The object to test
- * @return {Boolean}
- */
- isDate: function(value) {
- return toString.call(value) === '[object Date]';
- },
- /**
- * Returns true if the passed value is a JavaScript Object, false otherwise.
- * @param {Object} value The value to test
- * @return {Boolean}
- * @method
- */
- isObject: (toString.call(null) === '[object Object]') ?
- function(value) {
- // check ownerDocument here as well to exclude DOM nodes
- return value !== null && value !== undefined && toString.call(value) === '[object Object]' && value.ownerDocument === undefined;
- } :
- function(value) {
- return toString.call(value) === '[object Object]';
- },
- /**
- * @private
- */
- isSimpleObject: function(value) {
- return value instanceof Object && value.constructor === Object;
- },
- /**
- * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean.
- * @param {Object} value The value to test
- * @return {Boolean}
- */
- isPrimitive: function(value) {
- var type = typeof value;
- return type === 'string' || type === 'number' || type === 'boolean';
- },
- /**
- * Returns true if the passed value is a JavaScript Function, false otherwise.
- * @param {Object} value The value to test
- * @return {Boolean}
- * @method
- */
- isFunction:
- // Safari 3.x and 4.x returns 'function' for typeof <NodeList>, hence we need to fall back to using
- // Object.prototype.toString (slower)
- (typeof document !== 'undefined' && typeof document.getElementsByTagName('body') === 'function') ? function(value) {
- return toString.call(value) === '[object Function]';
- } : function(value) {
- return typeof value === 'function';
- },
- /**
- * Returns true if the passed value is a number. Returns false for non-finite numbers.
- * @param {Object} value The value to test
- * @return {Boolean}
- */
- isNumber: function(value) {
- return typeof value === 'number' && isFinite(value);
- },
- /**
- * Validates that a value is numeric.
- * @param {Object} value Examples: 1, '1', '2.34'
- * @return {Boolean} True if numeric, false otherwise
- */
- isNumeric: function(value) {
- return !isNaN(parseFloat(value)) && isFinite(value);
- },
- /**
- * Returns true if the passed value is a string.
- * @param {Object} value The value to test
- * @return {Boolean}
- */
- isString: function(value) {
- return typeof value === 'string';
- },
- /**
- * Returns true if the passed value is a boolean.
- *
- * @param {Object} value The value to test
- * @return {Boolean}
- */
- isBoolean: function(value) {
- return typeof value === 'boolean';
- },
- /**
- * Returns true if the passed value is an HTMLElement
- * @param {Object} value The value to test
- * @return {Boolean}
- */
- isElement: function(value) {
- return value ? value.nodeType === 1 : false;
- },
- /**
- * Returns true if the passed value is a TextNode
- * @param {Object} value The value to test
- * @return {Boolean}
- */
- isTextNode: function(value) {
- return value ? value.nodeName === "#text" : false;
- },
- /**
- * Returns true if the passed value is defined.
- * @param {Object} value The value to test
- * @return {Boolean}
- */
- isDefined: function(value) {
- return typeof value !== 'undefined';
- },
- /**
- * Returns true if the passed value is iterable, false otherwise
- * @param {Object} value The value to test
- * @return {Boolean}
- */
- isIterable: function(value) {
- var type = typeof value,
- checkLength = false;
- if (value && type != 'string') {
- // Functions have a length property, so we need to filter them out
- if (type == 'function') {
- // In Safari, NodeList/HTMLCollection both return "function" when using typeof, so we need
- // to explicitly check them here.
- if (Ext.isSafari) {
- checkLength = value instanceof NodeList || value instanceof HTMLCollection;
- }
- } else {
- checkLength = true;
- }
- }
- return checkLength ? value.length !== undefined : false;
- }
- });
- Ext.apply(Ext, {
- /**
- * Clone almost any type of variable including array, object, DOM nodes and Date without keeping the old reference
- * @param {Object} item The variable to clone
- * @return {Object} clone
- */
- clone: function(item) {
- if (item === null || item === undefined) {
- return item;
- }
- // DOM nodes
- // TODO proxy this to Ext.Element.clone to handle automatic id attribute changing
- // recursively
- if (item.nodeType && item.cloneNode) {
- return item.cloneNode(true);
- }
- var type = toString.call(item);
- // Date
- if (type === '[object Date]') {
- return new Date(item.getTime());
- }
- var i, j, k, clone, key;
- // Array
- if (type === '[object Array]') {
- i = item.length;
- clone = [];
- while (i--) {
- clone[i] = Ext.clone(item[i]);
- }
- }
- // Object
- else if (type === '[object Object]' && item.constructor === Object) {
- clone = {};
- for (key in item) {
- clone[key] = Ext.clone(item[key]);
- }
- if (enumerables) {
- for (j = enumerables.length; j--;) {
- k = enumerables[j];
- clone[k] = item[k];
- }
- }
- }
- return clone || item;
- },
- /**
- * @private
- * Generate a unique reference of Ext in the global scope, useful for sandboxing
- */
- getUniqueGlobalNamespace: function() {
- var uniqueGlobalNamespace = this.uniqueGlobalNamespace;
- if (uniqueGlobalNamespace === undefined) {
- var i = 0;
- do {
- uniqueGlobalNamespace = 'ExtBox' + (++i);
- } while (Ext.global[uniqueGlobalNamespace] !== undefined);
- Ext.global[uniqueGlobalNamespace] = Ext;
- this.uniqueGlobalNamespace = uniqueGlobalNamespace;
- }
- return uniqueGlobalNamespace;
- },
-
- /**
- * @private
- */
- functionFactoryCache: {},
-
- cacheableFunctionFactory: function() {
- var me = this,
- args = Array.prototype.slice.call(arguments),
- cache = me.functionFactoryCache,
- idx, fn, ln;
-
- if (Ext.isSandboxed) {
- ln = args.length;
- if (ln > 0) {
- ln--;
- args[ln] = 'var Ext=window.' + Ext.name + ';' + args[ln];
- }
- }
- idx = args.join('');
- fn = cache[idx];
- if (!fn) {
- fn = Function.prototype.constructor.apply(Function.prototype, args);
-
- cache[idx] = fn;
- }
- return fn;
- },
-
- functionFactory: function() {
- var me = this,
- args = Array.prototype.slice.call(arguments),
- ln;
-
- if (Ext.isSandboxed) {
- ln = args.length;
- if (ln > 0) {
- ln--;
- args[ln] = 'var Ext=window.' + Ext.name + ';' + args[ln];
- }
- }
-
- return Function.prototype.constructor.apply(Function.prototype, args);
- },
- /**
- * @property
- * @private
- */
- globalEval: ('execScript' in global) ? function(code) {
- global.execScript(code)
- } : function(code) {
- (function(){
- eval(code);
- })();
- },
- /**
- * @private
- * @property
- */
- Logger: {
- verbose: emptyFn,
- log: emptyFn,
- info: emptyFn,
- warn: emptyFn,
- error: function(message) {
- throw new Error(message);
- },
- deprecate: emptyFn
- }
- });
- /**
- * Old alias to {@link Ext#typeOf}
- * @deprecated 4.0.0 Use {@link Ext#typeOf} instead
- * @method
- * @inheritdoc Ext#typeOf
- */
- Ext.type = Ext.typeOf;
- })();
- /**
- * @author Jacky Nguyen <jacky@sencha.com>
- * @docauthor Jacky Nguyen <jacky@sencha.com>
- * @class Ext.Version
- *
- * A utility class that wrap around a string version number and provide convenient
- * method to perform comparison. See also: {@link Ext.Version#compare compare}. Example:
- var version = new Ext.Version('1.0.2beta');
- console.log("Version is " + version); // Version is 1.0.2beta
- console.log(version.getMajor()); // 1
- console.log(version.getMinor()); // 0
- console.log(version.getPatch()); // 2
- console.log(version.getBuild()); // 0
- console.log(version.getRelease()); // beta
- console.log(version.isGreaterThan('1.0.1')); // True
- console.log(version.isGreaterThan('1.0.2alpha')); // True
- console.log(version.isGreaterThan('1.0.2RC')); // False
- console.log(version.isGreaterThan('1.0.2')); // False
- console.log(version.isLessThan('1.0.2')); // True
- console.log(version.match(1.0)); // True
- console.log(version.match('1.0.2')); // True
- * @markdown
- */
- (function() {
- // Current core version
- var version = '4.1.0beta', Version;
- Ext.Version = Version = Ext.extend(Object, {
- /**
- * @param {String/Number} version The version number in the follow standard format: major[.minor[.patch[.build[release]]]]
- * Examples: 1.0 or 1.2.3beta or 1.2.3.4RC
- * @return {Ext.Version} this
- */
- constructor: function(version) {
- var parts, releaseStartIndex;
- if (version instanceof Version) {
- return version;
- }
- this.version = this.shortVersion = String(version).toLowerCase().replace(/_/g, '.').replace(/[\-+]/g, '');
- releaseStartIndex = this.version.search(/([^\d\.])/);
- if (releaseStartIndex !== -1) {
- this.release = this.version.substr(releaseStartIndex, version.length);
- this.shortVersion = this.version.substr(0, releaseStartIndex);
- }
- this.shortVersion = this.shortVersion.replace(/[^\d]/g, '');
- parts = this.version.split('.');
- this.major = parseInt(parts.shift() || 0, 10);
- this.minor = parseInt(parts.shift() || 0, 10);
- this.patch = parseInt(parts.shift() || 0, 10);
- this.build = parseInt(parts.shift() || 0, 10);
- return this;
- },
- /**
- * Override the native toString method
- * @private
- * @return {String} version
- */
- toString: function() {
- return this.version;
- },
- /**
- * Override the native valueOf method
- * @private
- * @return {String} version
- */
- valueOf: function() {
- return this.version;
- },
- /**
- * Returns the major component value
- * @return {Number} major
- */
- getMajor: function() {
- return this.major || 0;
- },
- /**
- * Returns the minor component value
- * @return {Number} minor
- */
- getMinor: function() {
- return this.minor || 0;
- },
- /**
- * Returns the patch component value
- * @return {Number} patch
- */
- getPatch: function() {
- return this.patch || 0;
- },
- /**
- * Returns the build component value
- * @return {Number} build
- */
- getBuild: function() {
- return this.build || 0;
- },
- /**
- * Returns the release component value
- * @return {Number} release
- */
- getRelease: function() {
- return this.release || '';
- },
- /**
- * Returns whether this version if greater than the supplied argument
- * @param {String/Number} target The version to compare with
- * @return {Boolean} True if this version if greater than the target, false otherwise
- */
- isGreaterThan: function(target) {
- return Version.compare(this.version, target) === 1;
- },
- /**
- * Returns whether this version if greater than or equal to the supplied argument
- * @param {String/Number} target The version to compare with
- * @return {Boolean} True if this version if greater than or equal to the target, false otherwise
- */
- isGreaterThanOrEqual: function(target) {
- return Version.compare(this.version, target) >= 0;
- },
- /**
- * Returns whether this version if smaller than the supplied argument
- * @param {String/Number} target The version to compare with
- * @return {Boolean} True if this version if smaller than the target, false otherwise
- */
- isLessThan: function(target) {
- return Version.compare(this.version, target) === -1;
- },
- /**
- * Returns whether this version if less than or equal to the supplied argument
- * @param {String/Number} target The version to compare with
- * @return {Boolean} True if this version if less than or equal to the target, false otherwise
- */
- isLessThanOrEqual: function(target) {
- return Version.compare(this.version, target) <= 0;
- },
- /**
- * Returns whether this version equals to the supplied argument
- * @param {String/Number} target The version to compare with
- * @return {Boolean} True if this version equals to the target, false otherwise
- */
- equals: function(target) {
- return Version.compare(this.version, target) === 0;
- },
- /**
- * Returns whether this version matches the supplied argument. Example:
- * <pre><code>
- * var version = new Ext.Version('1.0.2beta');
- * console.log(version.match(1)); // True
- * console.log(version.match(1.0)); // True
- * console.log(version.match('1.0.2')); // True
- * console.log(version.match('1.0.2RC')); // False
- * </code></pre>
- * @param {String/Number} target The version to compare with
- * @return {Boolean} True if this version matches the target, false otherwise
- */
- match: function(target) {
- target = String(target);
- return this.version.substr(0, target.length) === target;
- },
- /**
- * Returns this format: [major, minor, patch, build, release]. Useful for comparison
- * @return {Number[]}
- */
- toArray: function() {
- return [this.getMajor(), this.getMinor(), this.getPatch(), this.getBuild(), this.getRelease()];
- },
- /**
- * Returns shortVersion version without dots and release
- * @return {String}
- */
- getShortVersion: function() {
- return this.shortVersion;
- },
- /**
- * Convenient alias to {@link Ext.Version#isGreaterThan isGreaterThan}
- * @param {String/Number} target
- * @return {Boolean}
- */
- gt: function() {
- return this.isGreaterThan.apply(this, arguments);
- },
- /**
- * Convenient alias to {@link Ext.Version#isLessThan isLessThan}
- * @param {String/Number} target
- * @return {Boolean}
- */
- lt: function() {
- return this.isLessThan.apply(this, arguments);
- },
- /**
- * Convenient alias to {@link Ext.Version#isGreaterThanOrEqual isGreaterThanOrEqual}
- * @param {String/Number} target
- * @return {Boolean}
- */
- gtEq: function() {
- return this.isGreaterThanOrEqual.apply(this, arguments);
- },
- /**
- * Convenient alias to {@link Ext.Version#isLessThanOrEqual isLessThanOrEqual}
- * @param {String/Number} target
- * @return {Boolean}
- */
- ltEq: function() {
- return this.isLessThanOrEqual.apply(this, arguments);
- }
- });
- Ext.apply(Version, {
- // @private
- releaseValueMap: {
- 'dev': -6,
- 'alpha': -5,
- 'a': -5,
- 'beta': -4,
- 'b': -4,
- 'rc': -3,
- '#': -2,
- 'p': -1,
- 'pl': -1
- },
- /**
- * Converts a version component to a comparable value
- *
- * @static
- * @param {Object} value The value to convert
- * @return {Object}
- */
- getComponentValue: function(value) {
- return !value ? 0 : (isNaN(value) ? this.releaseValueMap[value] || value : parseInt(value, 10));
- },
- /**
- * Compare 2 specified versions, starting from left to right. If a part contains special version strings,
- * they are handled in the following order:
- * 'dev' < 'alpha' = 'a' < 'beta' = 'b' < 'RC' = 'rc' < '#' < 'pl' = 'p' < 'anything else'
- *
- * @static
- * @param {String} current The current version to compare to
- * @param {String} target The target version to compare to
- * @return {Number} Returns -1 if the current version is smaller than the target version, 1 if greater, and 0 if they're equivalent
- */
- compare: function(current, target) {
- var currentValue, targetValue, i;
- current = new Version(current).toArray();
- target = new Version(target).toArray();
- for (i = 0; i < Math.max(current.length, target.length); i++) {
- currentValue = this.getComponentValue(current[i]);
- targetValue = this.getComponentValue(target[i]);
- if (currentValue < targetValue) {
- return -1;
- } else if (currentValue > targetValue) {
- return 1;
- }
- }
- return 0;
- }
- });
- Ext.apply(Ext, {
- /**
- * @private
- */
- versions: {},
- /**
- * @private
- */
- lastRegisteredVersion: null,
- /**
- * Set version number for the given package name.
- *
- * @param {String} packageName The package name, for example: 'core', 'touch', 'extjs'
- * @param {String/Ext.Version} version The version, for example: '1.2.3alpha', '2.4.0-dev'
- * @return {Ext}
- */
- setVersion: function(packageName, version) {
- Ext.versions[packageName] = new Version(version);
- Ext.lastRegisteredVersion = Ext.versions[packageName];
- return this;
- },
- /**
- * Get the version number of the supplied package name; will return the last registered version
- * (last Ext.setVersion call) if there's no package name given.
- *
- * @param {String} packageName (Optional) The package name, for example: 'core', 'touch', 'extjs'
- * @return {Ext.Version} The version
- */
- getVersion: function(packageName) {
- if (packageName === undefined) {
- return Ext.lastRegisteredVersion;
- }
- return Ext.versions[packageName];
- },
- /**
- * Create a closure for deprecated code.
- *
- // This means Ext.oldMethod is only supported in 4.0.0beta and older.
- // If Ext.getVersion('extjs') returns a version that is later than '4.0.0beta', for example '4.0.0RC',
- // the closure will not be invoked
- Ext.deprecate('extjs', '4.0.0beta', function() {
- Ext.oldMethod = Ext.newMethod;
- ...
- });
- * @param {String} packageName The package name
- * @param {String} since The last version before it's deprecated
- * @param {Function} closure The callback function to be executed with the specified version is less than the current version
- * @param {Object} scope The execution scope (<tt>this</tt>) if the closure
- * @markdown
- */
- deprecate: function(packageName, since, closure, scope) {
- if (Version.compare(Ext.getVersion(packageName), since) < 1) {
- closure.call(scope);
- }
- }
- }); // End Versioning
- Ext.setVersion('core', version);
- })();
- /**
- * @class Ext.String
- *
- * A collection of useful static methods to deal with strings
- * @singleton
- */
- Ext.String = (function() {
- var trimRegex = /^[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000]+|[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000]+$/g,
- escapeRe = /('|\\)/g,
- formatRe = /\{(\d+)\}/g,
- escapeRegexRe = /([-.*+?^${}()|[\]\/\\])/g,
- basicTrimRe = /^\s+|\s+$/g,
- whitespaceRe = /\s+/,
- varReplace = /(^[^a-z]*|[^\w])/gi,
- charToEntity = {
- '&': '&',
- '>': '>',
- '<': '<',
- '"': '"'
- },
- entityToChar = {
- '&': '&',
- '>': '>',
- '<': '<',
- '"': '"'
- },
- keys = [],
- key,
- charToEntityRegex,
- entityToCharRegex,
- htmlEncodeReplaceFn = function(match, capture) {
- return charToEntity[capture];
- },
- htmlEncode = function(value) {
- return (!value) ? value : String(value).replace(charToEntityRegex, htmlEncodeReplaceFn);
- },
- htmlDecodeReplaceFn = function(match, capture) {
- return (capture in entityToChar) ? entityToChar[capture] : String.fromCharCode(parseInt(capture.substr(2), 10));
- },
- htmlDecode = function(value) {
- return (!value) ? value : String(value).replace(entityToCharRegex, htmlDecodeReplaceFn);
- };
- // Compile RexExps for HTML encode and decode functions
- for (key in charToEntity) {
- keys.push(key);
- }
- charToEntityRegex = new RegExp('(' + keys.join('|') + ')', 'g');
- keys = [];
- for (key in entityToChar) {
- keys.push(key);
- }
- entityToCharRegex = new RegExp('(' + keys.join('|') + '|&#[0-9]{1,5};' + ')', 'g');
- return {
- /**
- * Converts a string of characters into a legal, parseable Javascript `var` name as long as the passed
- * string contains at least one alphabetic character. Non alphanumeric characters, and *leading* non alphabetic
- * characters will be removed.
- * @param {String} s A string to be converted into a `var` name.
- * @return {String} A legal Javascript `var` name.
- */
- createVarName: function(s) {
- return s.replace(varReplace, '');
- },
- /**
- * Convert certain characters (&, <, >, and ") to their HTML character equivalents for literal display in web pages.
- * @param {String} value The string to encode
- * @return {String} The encoded text
- * @method
- */
- htmlEncode: htmlEncode,
- /**
- * Convert certain characters (&, <, >, and ") from their HTML character equivalents.
- * @param {String} value The string to decode
- * @return {String} The decoded text
- * @method
- */
- htmlDecode: htmlDecode,
- /**
- * 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} string The content to append to the URL.
- * @return {String} The resulting URL
- */
- urlAppend : function(url, string) {
- if (!Ext.isEmpty(string)) {
- return url + (url.indexOf('?') === -1 ? '?' : '&') + string;
- }
- return url;
- },
- /**
- * Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
- * @example
- var s = ' foo bar ';
- alert('-' + s + '-'); //alerts "- foo bar -"
- alert('-' + Ext.String.trim(s) + '-'); //alerts "-foo bar-"
- * @param {String} string The string to escape
- * @return {String} The trimmed string
- */
- trim: function(string) {
- return string.replace(trimRegex, "");
- },
- /**
- * Capitalize the given string
- * @param {String} string
- * @return {String}
- */
- capitalize: function(string) {
- return string.charAt(0).toUpperCase() + string.substr(1);
- },
- /**
- * Uncapitalize the given string
- * @param {String} string
- * @return {String}
- */
- uncapitalize: function(string) {
- return string.charAt(0).toLowerCase() + string.substr(1);
- },
- /**
- * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
- * @param {String} value The string to truncate
- * @param {Number} length The maximum length to allow before truncating
- * @param {Boolean} word True to try to find a common word break
- * @return {String} The converted text
- */
- ellipsis: function(value, len, word) {
- if (value && value.length > len) {
- if (word) {
- var vs = value.substr(0, len - 2),
- index = Math.max(vs.lastIndexOf(' '), vs.lastIndexOf('.'), vs.lastIndexOf('!'), vs.lastIndexOf('?'));
- if (index !== -1 && index >= (len - 15)) {
- return vs.substr(0, index) + "...";
- }
- }
- return value.substr(0, len - 3) + "...";
- }
- return value;
- },
- /**
- * Escapes the passed string for use in a regular expression
- * @param {String} string
- * @return {String}
- */
- escapeRegex: function(string) {
- return string.replace(escapeRegexRe, "\\$1");
- },
- /**
- * Escapes the passed string for ' and \
- * @param {String} string The string to escape
- * @return {String} The escaped string
- */
- escape: function(string) {
- return string.replace(escapeRe, "\\$1");
- },
- /**
- * Utility function that allows you to easily switch a string between two alternating values. The passed value
- * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
- * they are already different, the first value passed in is returned. Note that this method returns the new value
- * but does not change the current string.
- * <pre><code>
- // alternate sort directions
- sort = Ext.String.toggle(sort, 'ASC', 'DESC');
- // instead of conditional logic:
- sort = (sort == 'ASC' ? 'DESC' : 'ASC');
- </code></pre>
- * @param {String} string The current string
- * @param {String} value The value to compare to the current string
- * @param {String} other The new value to use if the string already equals the first value passed in
- * @return {String} The new value
- */
- toggle: function(string, value, other) {
- return string === value ? other : value;
- },
- /**
- * Pads the left side of a string with a specified character. This is especially useful
- * for normalizing number and date strings. Example usage:
- *
- * <pre><code>
- var s = Ext.String.leftPad('123', 5, '0');
- // s now contains the string: '00123'
- </code></pre>
- * @param {String} string The original string
- * @param {Number} size The total length of the output string
- * @param {String} character (optional) The character with which to pad the original string (defaults to empty string " ")
- * @return {String} The padded string
- */
- leftPad: function(string, size, character) {
- var result = String(string);
- character = character || " ";
- while (result.length < size) {
- result = character + result;
- }
- return result;
- },
- /**
- * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
- * token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
- * <pre><code>
- var cls = 'my-class', text = 'Some text';
- var s = Ext.String.format('<div class="{0}">{1}</div>', cls, text);
- // s now contains the string: '<div class="my-class">Some text</div>'
- </code></pre>
- * @param {String} string The tokenized string to be formatted
- * @param {String} value1 The value to replace token {0}
- * @param {String} value2 Etc...
- * @return {String} The formatted string
- */
- format: function(format) {
- var args = Ext.Array.toArray(arguments, 1);
- return format.replace(formatRe, function(m, i) {
- return args[i];
- });
- },
- /**
- * Returns a string with a specified number of repititions a given string pattern.
- * The pattern be separated by a different string.
- *
- * var s = Ext.String.repeat('---', 4); // = '------------'
- * var t = Ext.String.repeat('--', 3, '/'); // = '--/--/--'
- *
- * @param {String} pattern The pattern to repeat.
- * @param {Number} count The number of times to repeat the pattern (may be 0).
- * @param {String} sep An option string to separate each pattern.
- */
- repeat: function(pattern, count, sep) {
- for (var buf = [], i = count; i--; ) {
- buf.push(pattern);
- }
- return buf.join(sep || '');
- },
- /**
- * Splits a string of space separated words into an array, trimming as needed. If the
- * words are already an array, it is returned.
- *
- * @param {String/Array} words
- */
- splitWords: function (words) {
- if (words && typeof words == 'string') {
- return words.replace(basicTrimRe, '').split(whitespaceRe);
- }
- return words || [];
- }
- };
- })();
- /**
- * Old alias to {@link Ext.String#htmlEncode}
- * @deprecated Use {@link Ext.String#htmlEncode} instead
- * @method
- * @member Ext
- * @inheritdoc Ext.String#htmlEncode
- */
- Ext.htmlEncode = Ext.String.htmlEncode;
- /**
- * Old alias to {@link Ext.String#htmlDecode}
- * @deprecated Use {@link Ext.String#htmlDecode} instead
- * @method
- * @member Ext
- * @inheritdoc Ext.String#htmlDecode
- */
- Ext.htmlDecode = Ext.String.htmlDecode;
- /**
- * Old alias to {@link Ext.String#urlAppend}
- * @deprecated Use {@link Ext.String#urlAppend} instead
- * @method
- * @member Ext
- * @inheritdoc Ext.String#urlAppend
- */
- Ext.urlAppend = Ext.String.urlAppend;
- /**
- * @class Ext.Number
- *
- * A collection of useful static methods to deal with numbers
- * @singleton
- */
- Ext.Number = new function() {
- var me = this,
- isToFixedBroken = (0.9).toFixed() !== '1',
- math = Math;
- Ext.apply(this, {
- /**
- * Checks whether or not the passed number is within a desired range. If the number is already within the
- * range it is returned, otherwise the min or max value is returned depending on which side of the range is
- * exceeded. Note that this method returns the constrained value but does not change the current number.
- * @param {Number} number The number to check
- * @param {Number} min The minimum number in the range
- * @param {Number} max The maximum number in the range
- * @return {Number} The constrained value if outside the range, otherwise the current value
- */
- constrain: function(number, min, max) {
- number = parseFloat(number);
- if (!isNaN(min)) {
- number = math.max(number, min);
- }
- if (!isNaN(max)) {
- number = math.min(number, max);
- }
- return number;
- },
- /**
- * Snaps the passed number between stopping points based upon a passed increment value.
- *
- * The difference between this and {@link #snapInRange} is that {@link #snapInRange} uses the minValue
- * when calculating snap points:
- *
- * r = Ext.Number.snap(56, 2, 55, 65); // Returns 56 - snap points are zero based
- *
- * r = Ext.Number.snapInRange(56, 2, 55, 65); // Returns 57 - snap points are based from minValue
- *
- * @param {Number} value The unsnapped value.
- * @param {Number} increment The increment by which the value must move.
- * @param {Number} minValue The minimum value to which the returned value must be constrained. Overrides the increment.
- * @param {Number} maxValue The maximum value to which the returned value must be constrained. Overrides the increment.
- * @return {Number} The value of the nearest snap target.
- */
- snap : function(value, increment, minValue, maxValue) {
- var m;
- // If no value passed, or minValue was passed and value is less than minValue (anything < undefined is false)
- // Then use the minValue (or zero if the value was undefined)
- if (value === undefined || value < minValue) {
- return minValue || 0;
- }
- if (increment) {
- m = value % increment;
- if (m !== 0) {
- value -= m;
- if (m * 2 >= increment) {
- value += increment;
- } else if (m * 2 < -increment) {
- value -= increment;
- }
- }
- }
- return me.constrain(value, minValue, maxValue);
- },
- /**
- * Snaps the passed number between stopping points based upon a passed increment value.
- *
- * The difference between this and {@link #snap} is that {@link #snap} does not use the minValue
- * when calculating snap points:
- *
- * r = Ext.Number.snap(56, 2, 55, 65); // Returns 56 - snap points are zero based
- *
- * r = Ext.Number.snapInRange(56, 2, 55, 65); // Returns 57 - snap points are based from minValue
- *
- * @param {Number} value The unsnapped value.
- * @param {Number} increment The increment by which the value must move.
- * @param {Number} [minValue=0] The minimum value to which the returned value must be constrained.
- * @param {Number} [maxValue=Infinity] The maximum value to which the returned value must be constrained.
- * @return {Number} The value of the nearest snap target.
- */
- snapInRange : function(value, increment, minValue, maxValue) {
- var tween;
- // default minValue to zero
- minValue = (minValue || 0);
- // If value is undefined, or less than minValue, use minValue
- if (value === undefined || value < minValue) {
- return minValue;
- }
- // Calculate how many snap points from the minValue the passed value is.
- if (increment && (tween = ((value - minValue) % increment))) {
- value…