UNPKG

arrow-admin

Version:
1,401 lines (1,226 loc) 5.53 MB
/* Ext JS 4.1 - JavaScript Library Copyright (c) 2006-2012, Sencha Inc. All rights reserved. licensing@sencha.com http://www.sencha.com/license Open Source License ------------------------------------------------------------------------------------------ This version of Ext JS is licensed under the terms of the Open Source GPL 3.0 license. http://www.gnu.org/licenses/gpl.html There are several FLOSS exceptions available for use with this release for open source applications that are distributed under a license other than GPL. * Open Source License Exception for Applications http://www.sencha.com/products/floss-exception.php * Open Source License Exception for Development http://www.sencha.com/products/ux-exception.php Alternate Licensing ------------------------------------------------------------------------------------------ Commercial and OEM Licenses are available for an alternate download of Ext JS. This is the appropriate option if you are creating proprietary applications and you are not prepared to distribute and share the source code of your application under the GPL v3 license. Please visit http://www.sencha.com/license for more details. -- This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF THIRD-PARTY INTELLECTUAL PROPERTY RIGHTS. See the GNU General Public License for more details. */ //@tag foundation,core /** * @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 () {}, // This is the "$previous" method of a hook function on an instance. When called, it // calls through the class prototype by the name of the called method. callOverrideParent = function () { var method = callOverrideParent.caller.caller; // skip callParent (our caller) return method.$owner.prototype[method.$name].apply(this, arguments); }, 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); }; } if (!superclass) { Ext.Error.raise({ sourceClass: 'Ext', sourceMethod: 'extend', msg: 'Attempting to extend from a class which has not been loaded on the page.' }); } // 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; }; }()), /** * Overrides members of the specified `target` with the given values. * * If the `target` is a class declared using {@link Ext#define Ext.define}, the * `override` method of that class is called (see {@link Ext.Base#override}) given * the `overrides`. * * If the `target` is a function, it is assumed to be a constructor and the contents * of `overrides` are applied to its `prototype` using {@link Ext#apply Ext.apply}. * * If the `target` is an instance of a class declared using {@link Ext#define Ext.define}, * the `overrides` are applied to only that instance. In this case, methods are * specially processed to allow them to use {@link Ext.Base#callParent}. * * var panel = new Ext.Panel({ ... }); * * Ext.override(panel, { * initComponent: function () { * // extra processing... * * this.callParent(); * } * }); * * If the `target` is none of these, the `overrides` are applied to the `target` * using {@link Ext#apply Ext.apply}. * * Please refer to {@link Ext#define Ext.define} and {@link Ext.Base#override} for * further details. * * @param {Object} target The target to override. * @param {Object} overrides The properties to add or replace on `target`. * @method override */ override: function (target, overrides) { if (target.$isClass) { target.override(overrides); } else if (typeof target == 'function') { Ext.apply(target.prototype, overrides); } else { var owner = target.self, name, value; if (owner && owner.$isClass) { // if (instance of Ext.define'd class) for (name in overrides) { if (overrides.hasOwnProperty(name)) { value = overrides[name]; if (typeof value == 'function') { if (owner.$className) { value.displayName = owner.$className + '#' + name; } value.$name = name; value.$owner = owner; value.$previous = target.hasOwnProperty(name) ? target[name] // already hooked, so call previous hook : callOverrideParent; // calls by name on prototype } target[name] = value; } } } else { Ext.apply(target, overrides); } } return target; } }); // 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) { var type, typeToString; if (value === null) { return 'null'; } type = typeof value; if (type === 'undefined' || type === 'string' || type === 'number' || type === 'boolean') { return type; } 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'; } Ext.Error.raise({ sourceClass: 'Ext', sourceMethod: 'typeOf', msg: 'Failed to determine the type of the specified value "' + value + '". This is most likely a bug.' }); }, /** * 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 simple variables including array, {}-like objects, DOM nodes and Date without keeping the old reference. * A reference for the object itself is returned if it's not a direct decendant of Object. For model cloning, * see {@link Ext.data.Model#copy Model.copy}. * * @param {Object} item The variable to clone * @return {Object} clone */ clone: function(item) { var type, i, j, k, clone, key; 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); } type = toString.call(item); // Date if (type === '[object Date]') { return new Date(item.getTime()); } // 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, i; if (uniqueGlobalNamespace === undefined) { 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); }, /** * @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; }()); /* * This method evaluates the given code free of any local variable. In some browsers this * will be at global scope, in others it will be in a function. * @parma {String} code The code to evaluate. * @private * @method */ Ext.globalEval = Ext.global.execScript ? function(code) { execScript(code); } : function($$code) { // IMPORTANT: because we use eval we cannot place this in the above function or it // will break the compressor's ability to rename local variables... (function(){ eval($$code); }()); }; //@tag foundation,core //@require ../Ext.js /** * @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 * */ (function() { // Current core version var version = '4.1.1.1', Version; Ext.Version = Version = Ext.extend(Object, { /** * @param {String/Number} version The version number in the following standard format: * * major[.minor[.patch[.build[release]]]] * * Examples: * * 1.0 * 1.2.3beta * 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: * * 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 * * @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; } }); /** * @class Ext */ 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 (`this`) if the closure */ deprecate: function(packageName, since, closure, scope) { if (Version.compare(Ext.getVersion(packageName), since) < 1) { closure.call(scope); } } }); // End Versioning Ext.setVersion('core', version); }()); //@tag foundation,core //@require ../version/Version.js /** * @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, charToEntityRegex, entityToCharRegex, htmlEncodeReplaceFn = function(match, capture) { return charToEntity[capture]; }, htmlDecodeReplaceFn = function(match, capture) { return (capture in entityToChar) ? entityToChar[capture] : String.fromCharCode(parseInt(capture.substr(2), 10)); }; 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: function(value) { return (!value) ? value : String(value).replace(charToEntityRegex, htmlEncodeReplaceFn); }, /** * Convert certain characters (&, <, >, ', and ") from their HTML character equivalents. * @param {String} value The string to decode * @return {String} The decoded text * @method */ htmlDecode: function(value) { return (!value) ? value : String(value).replace(entityToCharRegex, htmlDecodeReplaceFn); }, /** * Adds a set of character entity definitions to the set used by * {@link Ext.String#htmlEncode} and {@link Ext.String#htmlDecode}. * * This object should be keyed by the entity name sequence, * with the value being the textual representation of the entity. * * Ext.String.addCharacterEntities({ * '&amp;Uuml;':'Ü', * '&amp;ccedil;':'ç', * '&amp;ntilde;':'ñ', * '&amp;egrave;':'è' * }); * var s = Ext.String.htmlEncode("A string with entities: èÜçñ"); * * Note: the values of the character entites defined on this object are expected * to be single character values. As such, the actual values represented by the * characters are sensitive to the character encoding of the javascript source * file when defined in string literal form. Script tasgs referencing server * resources with character entities must ensure that the 'charset' attribute * of the script node is consistent with the actual character encoding of the * server resource. * * The set of character entities may be reset back to the default state by using * the {@link Ext.String#resetCharacterEntities} method * * @param {Object} entities The set of character entities to add to the current * definitions. */ addCharacterEntities: function(newEntities) { var charKeys = [], entityKeys = [], key, echar; for (key in newEntities) { echar = newEntities[key]; entityToChar[key] = echar; charToEntity[echar] = key; charKeys.push(echar); entityKeys.push(key); } charToEntityRegex = new RegExp('(' + charKeys.join('|') + ')', 'g'); entityToCharRegex = new RegExp('(' + entityKeys.join('|') + '|&#[0-9]{1,5};' + ')', 'g'); }, /** * Resets the set of character entity definitions used by * {@link Ext.String#htmlEncode} and {@link Ext.String#htmlDecode} back to the * default state. */ resetCharacterEntities: function() { charToEntity = {}; entityToChar = {}; // add the default set this.addCharacterEntities({ '&amp;' : '&', '&gt;' : '>', '&lt;' : '<', '&quot;' : '"', '&#39;' : "'" }); }, /** * 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 arb