/ext-4.0.7/ext-all-debug-w-comments.js
https://bitbucket.org/srogerf/javascript · JavaScript · 27823 lines · 14877 code · 2469 blank · 10477 comment · 3006 complexity · cd31a3bae62ba15b08ea7e8779ed7476 MD5 · raw file
- /*
- This file is part of Ext JS 4
- Copyright (c) 2011 Sencha Inc
- Contact: http://www.sencha.com/contact
- GNU General Public License Usage
- This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
- If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
- */
- /**
- * @class Ext
- * @singleton
- */
- (function() {
- var global = this,
- objectPrototype = Object.prototype,
- toString = objectPrototype.toString,
- enumerables = true,
- enumerablesTest = { toString: 1 },
- i;
- if (typeof Ext === 'undefined') {
- global.Ext = {};
- }
- 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, {
- /**
- * A reusable empty function
- */
- emptyFn: function() {},
- 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.
- Ext.define('My.cool.Class', {
- sayHi: function() {
- alert('Hi!');
- }
- }
- Ext.override(My.cool.Class, {
- sayHi: function() {
- alert('About to say...');
- this.callOverridden();
- }
- });
- var cool = new My.cool.Class();
- cool.sayHi(); // alerts 'About to say...'
- // alerts 'Hi!'
- * Please note that `this.callOverridden()` only works if the class was previously
- * created with {@link Ext#define)
- *
- * @param {Object} cls The class to override
- * @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
- * containing one or more methods.
- * @method override
- * @markdown
- */
- override: function(cls, overrides) {
- if (cls.prototype.$className) {
- 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]';
- },
- /**
- * 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.prorotype.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) {
- return (value && typeof value !== 'string') ? 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
- */
- functionFactory: function() {
- var args = Array.prototype.slice.call(arguments);
- if (args.length > 0) {
- args[args.length - 1] = 'var Ext=window.' + this.getUniqueGlobalNamespace() + ';' +
- args[args.length - 1];
- }
- return Function.prototype.constructor.apply(Function.prototype, args);
- }
- });
- /**
- * Old alias to {@link Ext#typeOf}
- * @deprecated 4.0.0 Use {@link Ext#typeOf} instead
- * @method
- * @alias 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.0.7', 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 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 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;
- }
- });
- 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 = {
- 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,
- /**
- * 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() {
- var entities = {
- '&': '&',
- '>': '>',
- '<': '<',
- '"': '"'
- }, keys = [], p, regex;
-
- for (p in entities) {
- keys.push(p);
- }
-
- regex = new RegExp('(' + keys.join('|') + ')', 'g');
-
- return function(value) {
- return (!value) ? value : String(value).replace(regex, function(match, capture) {
- return entities[capture];
- });
- };
- })(),
- /**
- * Convert certain characters (&, <, >, and ") from their HTML character equivalents.
- * @param {String} value The string to decode
- * @return {String} The decoded text
- * @method
- */
- htmlDecode: (function() {
- var entities = {
- '&': '&',
- '>': '>',
- '<': '<',
- '"': '"'
- }, keys = [], p, regex;
-
- for (p in entities) {
- keys.push(p);
- }
-
- regex = new RegExp('(' + keys.join('|') + '|&#[0-9]{1,5};' + ')', 'g');
-
- return function(value) {
- return (!value) ? value : String(value).replace(regex, function(match, capture) {
- if (capture in entities) {
- return entities[capture];
- } else {
- return String.fromCharCode(parseInt(capture.substr(2), 10));
- }
- });
- };
- })(),
- /**
- * 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(Ext.String.trimRegex, "");
- },
- /**
- * Capitalize the given string
- * @param {String} string
- * @return {String}
- */
- capitalize: function(string) {
- return string.charAt(0).toUpperCase() + 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(Ext.String.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(Ext.String.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(Ext.String.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 || '');
- }
- };
- /**
- * @class Ext.Number
- *
- * A collection of useful static methods to deal with numbers
- * @singleton
- */
- (function() {
- var isToFixedBroken = (0.9).toFixed() !== '1';
- Ext.Number = {
- /**
- * 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.
- * @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 newValue = value,
- m;
- if (!(increment && value)) {
- return value;
- }
- m = value % increment;
- if (m !== 0) {
- newValue -= m;
- if (m * 2 >= increment) {
- newValue += increment;
- } else if (m * 2 < -increment) {
- newValue -= increment;
- }
- }
- return Ext.Number.constrain(newValue, minValue, maxValue);
- },
- /**
- * Formats a number using fixed-point notation
- * @param {Number} value The number to format
- * @param {Number} precision The number of digits to show after the decimal point
- */
- toFixed: function(value, precision) {
- if (isToFixedBroken) {
- precision = precision || 0;
- var pow = Math.pow(10, precision);
- return (Math.round(value * pow) / pow).toFixed(precision);
- }
- return value.toFixed(precision);
- },
- /**
- * Validate that a value is numeric and convert it to a number if necessary. Returns the specified default value if
- * it is not.
- Ext.Number.from('1.23', 1); // returns 1.23
- Ext.Number.from('abc', 1); // returns 1
- * @param {Object} value
- * @param {Number} defaultValue The value to return if the original value is non-numeric
- * @return {Number} value, if numeric, defaultValue otherwise
- */
- from: function(value, defaultValue) {
- if (isFinite(value)) {
- value = parseFloat(value);
- }
- return !isNaN(value) ? value : defaultValue;
- }
- };
- })();
- /**
- * @deprecated 4.0.0 Please use {@link Ext.Number#from} instead.
- * @member Ext
- * @method num
- * @alias Ext.Number#from
- */
- Ext.num = function() {
- return Ext.Number.from.apply(this, arguments);
- };
- /**
- * @class Ext.Array
- * @singleton
- * @author Jacky Nguyen <jacky@sencha.com>
- * @docauthor Jacky Nguyen <jacky@sencha.com>
- *
- * A set of useful static methods to deal with arrays; provide missing methods for older browsers.
- */
- (function() {
- var arrayPrototype = Array.prototype,
- slice = arrayPrototype.slice,
- supportsSplice = function () {
- var array = [],
- lengthBefore,
- j = 20;
- if (!array.splice) {
- return false;
- }
- // This detects a bug in IE8 splice method:
- // see http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/6e946d03-e09f-4b22-a4dd-cd5e276bf05a/
- while (j--) {
- array.push("A");
- }
- array.splice(15, 0, "F", "F", "F", "F", "F","F","F","F","F","F","F","F","F","F","F","F","F","F","F","F","F");
- lengthBefore = array.length; //41
- array.splice(13, 0, "XXX"); // add one element
- if (lengthBefore+1 != array.length) {
- return false;
- }
- // end IE8 bug
- return true;
- }(),
- supportsForEach = 'forEach' in arrayPrototype,
- supportsMap = 'map' in arrayPrototype,
- supportsIndexOf = 'indexOf' in arrayPrototype,
- supportsEvery = 'every' in arrayPrototype,
- supportsSome = 'some' in arrayPrototype,
- supportsFilter = 'filter' in arrayPrototype,
- supportsSort = function() {
- var a = [1,2,3,4,5].sort(function(){ return 0; });
- return a[0] === 1 && a[1] === 2 && a[2] === 3 && a[3] === 4 && a[4] === 5;
- }(),
- supportsSliceOnNodeList = true,
- ExtArray;
- try {
- // IE 6 - 8 will throw an error when using Array.prototype.slice on NodeList
- if (typeof document !== 'undefined') {
- slice.call(document.getElementsByTagName('body'));
- }
- } catch (e) {
- supportsSliceOnNodeList = false;
- }
- function fixArrayIndex (array, index) {
- return (index < 0) ? Math.max(0, array.length + index)
- : Math.min(array.length, index);
- }
- /*
- Does the same work as splice, but with a slightly more convenient signature. The splice
- method has bugs in IE8, so this is the implementation we use on that platform.
- The rippling of items in the array can be tricky. Consider two use cases:
- index=2
- removeCount=2
- /=====\
- +---+---+---+---+---+---+---+---+
- | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
- +---+---+---+---+---+---+---+---+
- / \/ \/ \/ \
- / /\ /\ /\ \
- / / \/ \/ \ +--------------------------+
- / / /\ /\ +--------------------------+ \
- / / / \/ +--------------------------+ \ \
- / / / /+--------------------------+ \ \ \
- / / / / \ \ \ \
- v v v v v v v v
- +---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+---+
- | 0 | 1 | 4 | 5 | 6 | 7 | | 0 | 1 | a | b | c | 4 | 5 | 6 | 7 |
- +---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+---+
- A B \=========/
- insert=[a,b,c]
- In case A, it is obvious that copying of [4,5,6,7] must be left-to-right so
- that we don't end up with [0,1,6,7,6,7]. In case B, we have the opposite; we
- must go right-to-left or else we would end up with [0,1,a,b,c,4,4,4,4].
- */
- function replaceSim (array, index, removeCount, insert) {
- var add = insert ? insert.length : 0,
- length = array.length,
- pos = fixArrayIndex(array, index);
- // we try to use Array.push when we can for efficiency...
- if (pos === length) {
- if (add) {
- array.push.apply(array, insert);
- }
- } else {
- var remove = Math.min(removeCount, length - pos),
- tailOldPos = pos + remove,
- tailNewPos = tailOldPos + add - remove,
- tailCount = length - tailOldPos,
- lengthAfterRemove = length - remove,
- i;
- if (tailNewPos < tailOldPos) { // case A
- for (i = 0; i < tailCount; ++i) {
- array[tailNewPos+i] = array[tailOldPos+i];
- }
- } else if (tailNewPos > tailOldPos) { // case B
- for (i = tailCount; i--; ) {
- array[tailNewPos+i] = array[tailOldPos+i];
- }
- } // else, add == remove (nothing to do)
- if (add && pos === lengthAfterRemove) {
- array.length = lengthAfterRemove; // truncate array
- array.push.apply(array, insert);
- } else {
- array.length = lengthAfterRemove + add; // reserves space
- for (i = 0; i < add; ++i) {
- array[pos+i] = insert[i];
- }
- }
- }
- return array;
- }
- function replaceNative (array, index, removeCount, insert) {
- if (insert && insert.length) {
- if (index < array.length) {
- array.splice.apply(array, [index, removeCount].concat(insert));
- } else {
- array.push.apply(array, insert);
- }
- } else {
- array.splice(index, removeCount);
- }
- return array;
- }
- function eraseSim (array, index, removeCount) {
- return replaceSim(array, index, removeCount);
- }
- function eraseNative (array, index, removeCount) {
- array.splice(index, removeCount);
- return array;
- }
- function spliceSim (array, index, removeCount) {
- var pos = fixArrayIndex(array, index),
- removed = array.slice(index, fixArrayIndex(array, pos+removeCount));
- if (arguments.length < 4) {
- replaceSim(array, pos, removeCount);
- } else {
- replaceSim(array, pos, removeCount, slice.call(arguments, 3));
- }
- return removed;
- }
- function spliceNative (array) {
- return array.splice.apply(array, slice.call(arguments, 1));
- }
- var erase = supportsSplice ? eraseNative : eraseSim,
- replace = supportsSplice ? replaceNative : replaceSim,
- splice = supportsSplice ? spliceNative : spliceSim;
- // NOTE: from here on, use erase, replace or splice (not native methods)...
- ExtArray = Ext.Array = {
- /**
- * Iterates an array or an iterable value and invoke the given callback function for each item.
- *
- * var countries = ['Vietnam', 'Singapore', 'United States', 'Russia'];
- *
- * Ext.Array.each(countries, function(name, index, countriesItSelf) {
- * console.log(name);
- * });
- *
- * var sum = function() {
- * var sum = 0;
- *
- * Ext.Array.each(arguments, function(value) {
- * sum += value;
- * });
- *
- * return sum;
- * };
- *
- * sum(1, 2, 3); // returns 6
- *
- * The iteration can be stopped by returning false in the function callback.
- *
- * Ext.Array.each(countries, function(name, index, countriesItSelf) {
- * if (name === 'Singapore') {
- * return false; // break here
- * }
- * });
- *
- * {@link Ext#each Ext.each} is alias for {@link Ext.Array#each Ext.Array.each}
- *
- * @param {Array/NodeList/Object} iterable The value to be iterated. If this
- * argument is not iterable, the callback function is called once.
- * @param {Function} fn The callback function. If it returns false, the iteration stops and this method returns
- * the current `index`.
- * @param {Object} fn.item The item at the current `index` in the passed `array`
- * @param {Number} fn.index The current `index` within the `array`
- * @param {Array} fn.allItems The `array` itself which was passed as the first argument
- * @param {Boolean} fn.return Return false to stop iteration.
- * @param {Object} scope (Optional) The scope (`this` reference) in which the specified function is executed.
- * @param {Boolean} reverse (Optional) Reverse the iteration order (loop from the end to the beginning)
- * Defaults false
- * @return {Boolean} See description for the `fn` parameter.
- */
- each: function(array, fn, scope, reverse) {
- array = ExtArray.from(array);
- var i,
- ln = array.length;
- if (reverse !== true) {
- for (i = 0; i < ln; i++) {
- if (fn.call(scope || array[i], array[i], i, array) === false) {
- return i;
- }
- }
- }
- else {
- for (i = ln - 1; i > -1; i--) {
- if (fn.call(scope || array[i], array[i], i, array) === false) {
- return i;
- }
- }
- }
- return true;
- },
- /**
- * Iterates an array and invoke the given callback function for each item. Note that this will simply
- * delegate to the native Array.prototype.forEach method if supported. It doesn't support stopping the
- * iteration by returning false in the callback function like {@link Ext.Array#each}. However, performance
- * could be much better in modern browsers comparing with {@link Ext.Array#each}
- *
- * @param {Array} array The array to iterate
- * @param {Function} fn The callback function.
- * @param {Object} fn.item The item at the current `index` in the passed `array`
- * @param {Number} fn.index The current `index` within the `array`
- * @param {Array} fn.allItems The `array` itself which was passed as the first argument
- * @param {Object} scope (Optional) The execution scope (`this`) in which the specified function is executed.
- */
- forEach: function(array, fn, scope) {
- if (supportsForEach) {
- return array.forEach(fn, scope);
- }
- var i = 0,
- ln = array.length;
- for (; i < ln; i++) {
- fn.call(scope, array[i], i, array);
- }
- },
- /**
- * Get the index of the provided `item` in the given `array`, a supplement for the
- * missing arrayPrototype.indexOf in Internet Explorer.
- *
- * @param {Array} array The array to check
- * @param {Object} item The item to look for
- * @param {Number} from (Optional) The index at which to begin the search
- * @return {Number} The index of item in the array (or -1 if it is not found)
- */
- indexOf: function(array, item, from) {
- if (supportsIndexOf) {
- return array.indexOf(item, from);
- }
- var i, length = array.length;
- for (i = (from < 0) ? Math.max(0, length + from) : from || 0; i < length; i++) {
- if (array[i] === item) {
- return i;
- }
- }
- return -1;
- },
- /**
- * Checks whether or not the given `array` contains the specified `item`
- *
- * @param {Array} array The array to check
- * @param {Object} item The item to look for
- * @return {Boolean} True if the array contains the item, false otherwise
- */
- contains: function(array, item) {
- if (supportsIndexOf) {
- return array.indexOf(item) !== -1;
- }
- var i, ln;
- for (i = 0, ln = array.length; i < ln; i++) {
- if (array[i] === item) {
- return true;
- }
- }
- return false;
- },
- /**
- * Converts any iterable (numeric indices and a length property) into a true array.
- *
- * function test() {
- * var args = Ext.Array.toArray(arguments),
- * fromSecondToLastArgs = Ext.Array.toArray(arguments, 1);
- *
- * alert(args.join(' '));
- * alert(fromSecondToLastArgs.join(' '));
- * }
- *
- * test('just', 'testing', 'here'); // alerts 'just testing here';
- * // alerts 'testing here';
- *
- * Ext.Array.toArray(document.getElementsByTagName('div')); // will convert the NodeList into an array
- * Ext.Array.toArray('splitted'); // returns ['s', 'p', 'l', 'i', 't', 't', 'e', 'd']
- * Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
- *
- * {@link Ext#toArray Ext.toArray} is alias for {@link Ext.Array#toArray Ext.Array.toArray}
- *
- * @param {Object} iterable the iterable object to be turned into a true Array.
- * @param {Number} start (Optional) a zero-based index that specifies the start of extraction. Defaults to 0
- * @param {Number} end (Optional) a zero-based index that specifies the end of extraction. Defaults to the last
- * index of the iterable value
- * @return {Array} array
- */
- toArray: function(iterable, start, end){
- if (!iterable || !iterable.length) {
- return [];
- }
- if (typeof iterable === 'string') {
- iterable = iterable.split('');
- }
- if (supportsSliceOnNodeList) {
- return slice.call(iterable, start || 0, end || iterable.length);
- }
- var array = [],
- i;
- start = start || 0;
- end = end ? ((end < 0) ? iterable.length + end : end) : iterable.length;
- for (i = start; i < end; i++) {
- array.push(iterable[i]);
- }
- return array;
- },
- /**
- * Plucks the value of a property from each item in the Array. Example:
- *
- * Ext.Array.pluck(Ext.query("p"), "className"); // [el1.className, el2.className, ..., elN.className]
- *
- * @param {Array/NodeList} array The Array of items to pluck the value from.
- * @param {String} propertyName The property name to pluck from each element.
- * @return {Array} The value from each item in the Array.
- */
- pluck: function(array, propertyName) {
- var ret = [],
- i, ln, item;
- for (i = 0, ln = array.length; i < ln; i++) {
- item = array[i];
- ret.push(item[propertyName]);
- }
- return ret;
- },
- /**
- * Creates a new array with the results of calling a provided function on every element in this array.
- *
- * @param {Array} array
- * @param {Function} fn Callback function for each item
- * @param {Object} scope Callback function scope
- * @return {Array} results
- */
- map: function(array, fn, scope) {
- if (supportsMap) {
- return array.map(fn, scope);
- }
- var results = [],
- i = 0,
- len = array.length;
- for (; i < len; i++) {
- results[i] = fn.call(scope, array[i], i, array);
- }
- return results;
- },
- /**
- * Executes the specified function for each array element until the function returns a falsy value.
- * If such an item is found, the function will return false immediately.
- * Otherwise, it will return true.
- *
- * @param {Array} array
- * @param {Function} fn Callback function for each item
- * @param {Object} scope Callback function scope
- * @return {Boolean} True if no false value is returned by the callback function.
- */
- every: function(array, fn, scope) {
- if (supportsEvery) {
- return array.every(fn, scope);
- }
- var i = 0,
- ln = array.length;
- for (; i < ln; ++i) {
- if (!fn.call(scope, array[i], i, array)) {
- return false;
- }
- }
- return true;
- },
- /**
- * Executes the specified function for each array element until the function returns a truthy value.
- * If such an item is found, the function will return true immediately. Otherwise, it will return false.
- *
- * @param {Array} array
- * @param {Function} fn Callback function for each item
- * @param {Object} scope Callback function scope
- * @return {Boolean} True if the callback function returns a truthy value.
- */
- some: function(array, fn, scope) {
- if (supportsSome) {
- return array.some(fn, scope);
- }
- var i = 0,
- ln = array.length;
- for (; i < ln; ++i) {
- if (fn.call(scope, array[i], i, array)) {
- return true;
- }
- }
- return false;
- },
- /**
- * Filter through an array and remove empty item as defined in {@link Ext#isEmpty Ext.isEmpty}
- *
- * See {@link Ext.Array#filter}
- *
- * @param {Array} array
- * @return {Array} results
- */
- clean: function(array) {
- var results = [],
- i = 0,
- ln = array.length,
- item;
- for (; i < ln; i++) {
- item = array[i];
- if (!Ext.isEmpty(item)) {
- results.push(item);
- }
- }
- return results;
- },
- /**
- * Returns a new array with unique items
- *
- * @param {Array} array
- * @return {Array} results
- */
- unique: function(array) {
- var clone = [],
- i = 0,
- ln = array.length,
- item;
- for (; i < ln; i++) {
- item = array[i];
- if (ExtArray.indexOf(clone, item) === -1) {
- clone.push(item);
- }
- }
- return clone;
- },
- /**
- * Creates a new array with all of the elements of this array for which
- * the provided filtering function returns true.
- *
- * @param {Array} array
- * @param {Function} fn Callback function for each item
- * @param {Object} scope Callback function scope
- * @return {Array} results
- */
- filter: function(array, fn, scope) {
- if (supportsFilter) {
- return array.filter(fn, scope);
- }
- var results = [],
- i = 0,
- ln = array.length;
- for (; i < ln; i++) {
- if (fn.call(scope, array[i], i, array)) {
- results.push(array[i]);
- }
- }
- return results;
- },
- /**
- * Converts a value to an array if it's not already an array; returns:
- *
- * - An empty array if given value is `undefined` or `null`
- * - Itself if given value is already an array
- * - An array copy if given value is {@link Ext#isIterable iterable} (arguments, NodeList and alike)
- * - An array with one item which is the given value, otherwise
- *
- * @param {Object} value The value to convert to an array if it's not already is an array
- * @param {Boolean} newReference (Optional) True to clone the given array and return a new reference if necessary,
- * defaults to false
- * @return {Array} array
- */
- from: function(value, newReference) {
- if (value === undefined || value === null) {
- return [];
- }
- if (Ext.isArray(value)) {
- return (newReference) ? slice.call(value) : value;
- }
- if (value && value.length !== undefined && typeof value !== 'string') {
- return Ext.toArray(value);
- }
- return [value];
- },
- /**
- * Removes the specified item from the array if it exists
- *
- * @param {Array} array The array
- * @param {Object} item The item to remove
- * @return {Array} The passed array itself
- */
- remove: function(array, item) {
- var index = ExtArray.indexOf(array, item);
- if (index !== -1) {
- erase(array, index, 1);
- }
- return array;
- },
- /**
- * Push an item into the array only if the array doesn't contain it yet
- *
- * @param {Array} array The array
- * @param {Object} item The item to include
- */
- include: function(array, item) {
- if (!ExtArray.contains(array, item)) {
- array.push(item);
- }
- },
- /**
- * Clone a flat array without referencing the previous one. Note that this is different
- * from Ext.clone since it doesn't handle recursive cloning. It's simply a convenient, easy-to-remember method
- * for Array.prototype.slice.call(array)
- *
- * @param {Array} array The array
- * @return {Array} The clone array
- */
- clone: function(array) {
- return slice.call(array);
- },
- /**
- * Merge multiple arrays into one with unique items.
- *
- * {@link Ext.Array#union} is alias for {@link Ext.Array#merge}
- *
- * @param {Array} array1
- * @param {Array} array2
- * @param {Array} etc
- * @return {Array} merged
- */
- merge: function() {
- var args = slice.call(arguments),
- array = [],
- i, ln;
- for (i = 0, ln = args.length; i < ln; i++) {
- array = array.concat(args[i]);
- }
- return ExtArray.unique(array);
- },
- /**
- * Merge multiple arrays into one with unique items that exist in all of the arrays.
- *
- * @param {Array} array1
- * @param {Array} array2
- * @param {Array} etc
- * @return {Array} intersect
- */
- intersect: function() {
- var intersect = [],
- arrays = slice.call(arguments),
- i, j, k, minArray, array, x, y, ln, arraysLn, arrayLn;
- if (!arrays.length) {
- return intersect;
- }
- // Find the smallest array
- for (i = x = 0,ln = arrays.length; i < ln,array = arrays[i]; i++) {
- if (!minArray || array.length < minArray.length) {
- minArray = array;
- x = i;
- }
- }
- minArray = ExtArray.unique(minArray);
- erase(arrays, x, 1);
- // Use the smallest unique'd array as the anchor loop. If the other array(s) do contain
- // an item in the small array, we're likely to find it before reaching the end
- // of the inner loop and can terminate the search early.
- for (i = 0,ln = minArray.length; i < ln,x = minArray[i]; i++) {
- var count = 0;
- for (j = 0,arraysLn = arrays.length; j < arraysLn,array = arrays[j]; j++) {
- for (k = 0,arrayLn = array.length; k < arrayLn,y = array[k]; k++) {
- if (x === y) {
- count++;
- break;
- }
- }
- }
- if (count === arraysLn) {
- intersect.push(x);
- }
- }
- return intersect;
- },
- /**
- * Perform a set difference A-B by subtracting all items in array B from array A.
- *
- * @param {Array} arrayA
- * @param {Array} arrayB
- * @return {Array} difference
- */
- difference: function(arrayA, arrayB) {
- var clone = slice.call(arrayA),
- ln = clone.length,
- i, j, lnB;
- for (i = 0,lnB = arrayB.length; i < lnB; i++) {
- for (j = 0; j < ln; j++) {
- if (clone[j] === arrayB[i]) {
- erase(clone, j, 1);
- j--;
- ln--;
- }
- }
- }
- return clone;
- },
- /**
- * Returns a shallow copy of a part of an array. This is equivalent to the native
- * call "Array.prototype.slice.call(array, begin, end)". This is often used when "array"
- * is "arguments" since the arguments object does not supply a slice method but can
- * be the context object to Array.prototype.slice.
- *
- * @param {Array} array The array (or arguments object).
- * @param {Number} begin The index at which to begin. Negative values are offsets from
- * the end of the array.
- * @param {Number} end The index at which to end. The copied items do not include
- * end. Negative values are offsets from the end of the array. If end is omitted,
- * all items up to the end of the array are copied.
- * @return {Array} The copied piece of the array.
- */
- // Note: IE6 will return [] on slice.call(x, undefined).
- slice: ([1,2].slice(1, undefined).length ?
- function (array, begin, end) {
- return slice.call(array, begin, end);
- } :
- // at least IE6 uses arguments.length for variadic signature
- function (array, begin, end) {
- // After tested for IE 6, the one below is of the best performance
- // see http://jsperf.com/slice-fix
- if (typeof begin === 'undefined') {
- return slice.call(array);
- }
- if (typeof end === 'undefined') {
- return slice.call(array, begin);
- }
- return slice.call(array, begin, end);
- }
- ),
- /**
- * Sorts the elements of an Array.
- * By default, this method sorts the elements alphabetically and ascending.
- *
- * @param {Array} array The array to sort.
- * @param {Function} sortFn (optional) The comparison function.
- * @return {Array} The sorted array.
- */
- sort: function(array, sortFn) {
- if (supportsSort) {
- if (sortFn) {
- return array.sort(sortFn);
- } else {
- return array.sort();
- }
- }
- var length = array.length,
- i = 0,
- comparison,
- j, min, tmp;
- for (; i < length; i++) {
- min = i;
- for (j = i + 1; j < length; j++) {
- if (sortFn) {
- comparison = sortFn(array[j], array[min]);
- if (comparison < 0) {
- min = j;
- }
- } else if (array[j] < array[min]) {
- min = j;
- }
- }
- if (min !== i) {
- tmp = array[i];
- array[i] = array[min];
- array[min] = tmp;
- }
- }
- return array;
- },
- /**
- * Recursively flattens into 1-d Array. Injects Arrays inline.
- *
- * @param {Array} array The array to flatten
- * @return {Array} The 1-d array.
- */
- flatten: function(array) {
- var worker = [];
- function rFlatten(a) {
- var i, ln, v;
- for (i = 0, ln = a.length; i < ln; i++) {
- v = a[i];
- if (Ext.isArray(v)) {
- rFlatten(v);
- } else {
- worker.push(v);
- }
- }
- return worker;
- }
- return rFlatten(array);
- },
- /**
- * Returns the minimum value in the Array.
- *
- * @param {Array/NodeList} array The Array from which to select the minimum value.
- * @param {Function} comparisonFn (optional) a function to perform the comparision which determines minimization.
- * If omitted the "<" operator will be used. Note: gt = 1; eq = 0; lt = -1
- * @return {Object} minValue The minimum value
- */
- min: function(array, comparisonFn) {
- var min = array[0],
- i, ln, item;
- for (i = 0, ln = array.length; i < ln; i++) {
- item = array[i];
- if (comparisonFn) {
- if (comparisonFn(min, item) === 1) {
- min = item;
- }
- }
- else {
- if (item < min) {
- min = item;
- }
- }
- }
- return min;
- },
- /**
- * Returns the maximum value in the Array.
- *
- * @param {Array/NodeList} array The Array from which to select the maximum value.
- * @param {Function} comparisonFn (optional) a function to perform the comparision which determines maximization.
- * If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1
- * @return {Object} maxValue The maximum value
- */
- max: function(array, comparisonFn) {
- var max = array[0],
- i, ln, item;
- for (i = 0, ln = array.length; i < ln; i++) {
- item = array[i];
- if (comparisonFn) {
- if (comparisonFn(max, item) === -1) {
- max = item;
- }
- }
- else {
- if (item > max) {
- max = item;
- }
- }
- }
- return max;
- },
- /**
- * Calculates the mean of all items in the array.
- *
- * @param {Array} array The Array to calculate the mean value of.
- * @return {Number} The mean.
- */
- mean: function(array) {
- return array.length > 0 ? ExtArray.sum(array) / array.length : undefined;
- },
- /**
- * Calculates the sum of all items in the given array.
- *
- * @param {Array} array The Array to calculate the sum value of.
- * @return {Number} The sum.
- */
- sum: function(array) {
- var sum = 0,
- i, ln, item;
- for (i = 0,ln = array.length; i < ln; i++) {
- item = array[i];
- sum += item;
- }
- return sum;
- },
- /**
- * Removes items from an array. This is functionally equivalent to the splice method
- * of Array, but works around bugs in IE8's splice method and does not copy the
- * removed elements in order to return them (because very often they are ignored).
- *
- * @param {Array} array The Array on which to replace.
- * @param {Number} index The index in the array at which to operate.
- * @param {Number} removeCount The number of items to remove at index.
- * @return {Array} The array passed.
- * @method
- */
- erase: erase,
- /**
- * Inserts items in to an array.
- *
- * @param {Array} array The Array on which to replace.
- * @param {Number} index The index in the array at which to operate.
- * @param {Array} items The array of items to insert at index.
- * @return {Array} The array passed.
- */
- insert: function (array, index, items) {
- return replace(array, index, 0, items);
- },
- /**
- * Replaces items in an array. This is functionally equivalent to the splice method
- * of Array, but works around bugs in IE8's splice method and is often more convenient
- * to call because it accepts an array of items to insert rather than use a variadic
- * argument list.
- *
- * @param {Array} array The Array on which to replace.
- * @param {Number} index The index in the array at which to operate.
- * @param {Number} removeCount The number of items to remove at index (can be 0).
- * @param {Array} insert (optional) An array of items to insert at index.
- * @return {Array} The array passed.
- * @method
- */
- replace: replace,
- /**
- * Replaces items in an array. This is equivalent to the splice method of Array, but
- * works around bugs in IE8's splice method. The signature is exactly the same as the
- * splice method except that the array is the first argument. All arguments following
- * removeCount are inserted in the array at index.
- *
- * @param {Array} array The Array on which to replace.
- * @param {Number} index The index in the array at which to operate.
- * @param {Number} removeCount The number of items to remove at index (can be 0).
- * @return {Array} An array containing the removed items.
- * @method
- */
- splice: splice
- };
- /**
- * @method
- * @member Ext
- * @alias Ext.Array#each
- */
- Ext.each = ExtArray.each;
- /**
- * @method
- * @member Ext.Array
- * @alias Ext.Array#merge
- */
- ExtArray.union = ExtArray.merge;
- /**
- * Old alias to {@link Ext.Array#min}
- * @deprecated 4.0.0 Use {@link Ext.Array#min} instead
- * @method
- * @member Ext
- * @alias Ext.Array#min
- */
- Ext.min = ExtArray.min;
- /**
- * Old alias to {@link Ext.Array#max}
- * @deprecated 4.0.0 Use {@link Ext.Array#max} instead
- * @method
- * @member Ext
- * @alias Ext.Array#max
- */
- Ext.max = ExtArray.max;
- /**
- * Old alias to {@link Ext.Array#sum}
- * @deprecated 4.0.0 Use {@link Ext.Array#sum} instead
- * @method
- * @member Ext
- * @alias Ext.Array#sum
- */
- Ext.sum = ExtArray.sum;
- /**
- * Old alias to {@link Ext.Array#mean}
- * @deprecated 4.0.0 Use {@link Ext.Array#mean} instead
- * @method
- * @member Ext
- * @alias Ext.Array#mean
- */
- Ext.mean = ExtArray.mean;
- /**
- * Old alias to {@link Ext.Array#flatten}
- * @deprecated 4.0.0 Use {@link Ext.Array#flatten} instead
- * @method
- * @member Ext
- * @alias Ext.Array#flatten
- */
- Ext.flatten = ExtArray.flatten;
- /**
- * Old alias to {@link Ext.Array#clean}
- * @deprecated 4.0.0 Use {@link Ext.Array#clean} instead
- * @method
- * @member Ext
- * @alias Ext.Array#clean
- */
- Ext.clean = ExtArray.clean;
- /**
- * Old alias to {@link Ext.Array#unique}
- * @deprecated 4.0.0 Use {@link Ext.Array#unique} instead
- * @method
- * @member Ext
- * @alias Ext.Array#unique
- */
- Ext.unique = ExtArray.unique;
- /**
- * Old alias to {@link Ext.Array#pluck Ext.Array.pluck}
- * @deprecated 4.0.0 Use {@link Ext.Array#pluck Ext.Array.pluck} instead
- * @method
- * @member Ext
- * @alias Ext.Array#pluck
- */
- Ext.pluck = ExtArray.pluck;
- /**
- * @method
- * @member Ext
- * @alias Ext.Array#toArray
- */
- Ext.toArray = function() {
- return ExtArray.toArray.apply(ExtArray, arguments);
- };
- })();
- /**
- * @class Ext.Function
- *
- * A collection of useful static methods to deal with function callbacks
- * @singleton
- */
- Ext.Function = {
- /**
- * A very commonly used method throughout the framework. It acts as a wrapper around another method
- * which originally accepts 2 arguments for `name` and `value`.
- * The wrapped function then allows "flexible" value setting of either:
- *
- * - `name` and `value` as 2 arguments
- * - one single object argument with multiple key - value pairs
- *
- * For example:
- *
- * var setValue = Ext.Function.flexSetter(function(name, value) {
- * this[name] = value;
- * });
- *
- * // Afterwards
- * // Setting a single name - value
- * setValue('name1', 'value1');
- *
- * // Settings multiple name - value pairs
- * setValue({
- * name1: 'value1',
- * name2: 'value2',
- * name3: 'value3'
- * });
- *
- * @param {Function} setter
- * @returns {Function} flexSetter
- */
- flexSetter: function(fn) {
- return function(a, b) {
- var k, i;
- if (a === null) {
- return this;
- }
- if (typeof a !== 'string') {
- for (k in a) {
- if (a.hasOwnProperty(k)) {
- fn.call(this, k, a[k]);
- }
- }
- if (Ext.enumerables) {
- for (i = Ext.enumerables.length; i--;) {
- k = Ext.enumerables[i];
- if (a.hasOwnProperty(k)) {
- fn.call(this, k, a[k]);
- }
- }
- }
- } else {
- fn.call(this, a, b);
- }
- return this;
- };
- },
- /**
- * Create a new function from the provided `fn`, change `this` to the provided scope, optionally
- * overrides arguments for the call. (Defaults to the arguments passed by the caller)
- *
- * {@link Ext#bind Ext.bind} is alias for {@link Ext.Function#bind Ext.Function.bind}
- *
- * @param {Function} fn The function to delegate.
- * @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
- * @return {Function} The new function
- */
- bind: function(fn, scope, args, appendArgs) {
- if (arguments.length === 2) {
- return function() {
- return fn.apply(scope, arguments);
- }
- }
- var method = fn,
- slice = Array.prototype.slice;
- return function() {
- var callArgs = args || arguments;
- if (appendArgs === true) {
- callArgs = slice.call(arguments, 0);
- callArgs = callArgs.concat(args);
- }
- else if (typeof appendArgs == 'number') {
- callArgs = slice.call(arguments, 0); // copy arguments first
- Ext.Array.insert(callArgs, appendArgs, args);
- }
- return method.apply(scope || window, callArgs);
- };
- },
- /**
- * Create a new function from the provided `fn`, the arguments of which are pre-set to `args`.
- * New arguments passed to the newly created callback when it's invoked are appended after the pre-set ones.
- * This is especially useful when creating callbacks.
- *
- * For example:
- *
- * var originalFunction = function(){
- * alert(Ext.Array.from(arguments).join(' '));
- * };
- *
- * var callback = Ext.Function.pass(originalFunction, ['Hello', 'World']);
- *
- * callback(); // alerts 'Hello World'
- * callback('by Me'); // alerts 'Hello World by Me'
- *
- * {@link Ext#pass Ext.pass} is alias for {@link Ext.Function#pass Ext.Function.pass}
- *
- * @param {Function} fn The original function
- * @param {Array} args The arguments to pass to new callback
- * @param {Object} scope (optional) The scope (`this` reference) in which the function is executed.
- * @return {Function} The new callback function
- */
- pass: function(fn, args, scope) {
- if (args) {
- args = Ext.Array.from(args);
- }
- return function() {
- return fn.apply(scope, args.concat(Ext.Array.toArray(arguments)));
- };
- },
- /**
- * Create an alias to the provided method property with name `methodName` of `object`.
- * Note that the execution scope will still be bound to the provided `object` itself.
- *
- * @param {Object/Function} object
- * @param {String} methodName
- * @return {Function} aliasFn
- */
- alias: function(object, methodName) {
- return function() {
- return object[methodName].apply(object, arguments);
- };
- },
- /**
- * 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 function is called with the parameters of the original function. Example usage:
- *
- * var sayHi = function(name){
- * alert('Hi, ' + name);
- * }
- *
- * sayHi('Fred'); // alerts "Hi, Fred"
- *
- * // create a new function that validates input without
- * // directly modifying the original function:
- * var sayHiToFriend = Ext.Function.createInterceptor(sayHi, function(name){
- * return name == 'Brian';
- * });
- *
- * sayHiToFriend('Fred'); // no alert
- * sayHiToFriend('Brian'); // alerts "Hi, Brian"
- *
- * @param {Function} origFn The original function.
- * @param {Function} newFn The function to call before the original
- * @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.**
- * @param {Object} returnValue (optional) The value to return if the passed function return false (defaults to null).
- * @return {Function} The new function
- */
- createInterceptor: function(origFn, newFn, scope, returnValue) {
- var method = origFn;
- if (!Ext.isFunction(newFn)) {
- return origFn;
- }
- else {
- return function() {
- var me = this,
- args = arguments;
- newFn.target = me;
- newFn.method = origFn;
- return (newFn.apply(scope || me || window, args) !== false) ? origFn.apply(me || window, args) : returnValue || null;
- };
- }
- },
- /**
- * Creates a delegate (callback) which, when called, executes after a specific delay.
- *
- * @param {Function} fn The function which will be called on a delay when the returned function is called.
- * Optionally, a replacement (or additional) argument list may be specified.
- * @param {Number} delay The number of milliseconds to defer execution by whenever called.
- * @param {Object} scope (optional) The scope (`this` reference) used by the function at execution time.
- * @param {Array} args (optional) Override 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.
- * @return {Function} A function which, when called, executes the original function after the specified delay.
- */
- createDelayed: function(fn, delay, scope, args, appendArgs) {
- if (scope || args) {
- fn = Ext.Function.bind(fn, scope, args, appendArgs);
- }
- return function() {
- var me = this;
- setTimeout(function() {
- fn.apply(me, arguments);
- }, delay);
- };
- },
- /**
- * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
- *
- * var sayHi = function(name){
- * alert('Hi, ' + name);
- * }
- *
- * // executes immediately:
- * sayHi('Fred');
- *
- * // executes after 2 seconds:
- * Ext.Function.defer(sayHi, 2000, this, ['Fred']);
- *
- * // this syntax is sometimes useful for deferring
- * // execution of an anonymous function:
- * Ext.Function.defer(function(){
- * alert('Anonymous');
- * }, 100);
- *
- * {@link Ext#defer Ext.defer} is alias for {@link Ext.Function#defer Ext.Function.defer}
- *
- * @param {Function} fn The function to defer.
- * @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} 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
- * @return {Number} The timeout id that can be used with clearTimeout
- */
- defer: function(fn, millis, obj, args, appendArgs) {
- fn = Ext.Function.bind(fn, obj, args, appendArgs);
- if (millis > 0) {
- return setTimeout(fn, millis);
- }
- fn();
- return 0;
- },
- /**
- * Create a combined function call sequence of the original function + the passed function.
- * The resulting function returns the results of the original function.
- * The passed function is called with the parameters of the original function. Example usage:
- *
- * var sayHi = function(name){
- * alert('Hi, ' + name);
- * }
- *
- * sayHi('Fred'); // alerts "Hi, Fred"
- *
- * var sayGoodbye = Ext.Function.createSequence(sayHi, function(name){
- * alert('Bye, ' + name);
- * });
- *
- * sayGoodbye('Fred'); // both alerts show
- *
- * @param {Function} origFn The original function.
- * @param {Function} newFn The function to sequence
- * @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
- */
- createSequence: function(origFn, newFn, scope) {
- if (!Ext.isFunction(newFn)) {
- return origFn;
- }
- else {
- return function() {
- var retval = origFn.apply(this || window, arguments);
- newFn.apply(scope || this || window, arguments);
- return retval;
- };
- }
- },
- /**
- * Creates a delegate function, optionally with a bound scope which, when called, buffers
- * the execution of the passed function for the configured number of milliseconds.
- * If called again within that period, the impending invocation will be canceled, and the
- * timeout period will begin again.
- *
- * @param {Function} fn The function to invoke on a buffered timer.
- * @param {Number} buffer The number of milliseconds by which to buffer the invocation of the
- * function.
- * @param {Object} scope (optional) The scope (`this` reference) in which
- * the passed function is executed. If omitted, defaults to the scope specified by the caller.
- * @param {Array} args (optional) Override arguments for the call. Defaults to the arguments
- * passed by the caller.
- * @return {Function} A function which invokes the passed function after buffering for the specified time.
- */
- createBuffered: function(fn, buffer, scope, args) {
- return function(){
- var timerId;
- return function() {
- var me = this;
- if (timerId) {
- clearTimeout(timerId);
- timerId = null;
- }
- timerId = setTimeout(function(){
- fn.apply(scope || me, args || arguments);
- }, buffer);
- };
- }();
- },
- /**
- * Creates a throttled version of the passed function which, when called repeatedly and
- * rapidly, invokes the passed function only after a certain interval has elapsed since the
- * previous invocation.
- *
- * This is useful for wrapping functions which may be called repeatedly, such as
- * a handler of a mouse move event when the processing is expensive.
- *
- * @param {Function} fn The function to execute at a regular time interval.
- * @param {Number} interval The interval **in milliseconds** on which the passed function is executed.
- * @param {Object} scope (optional) The scope (`this` reference) in which
- * the passed function is executed. If omitted, defaults to the scope specified by the caller.
- * @returns {Function} A function which invokes the passed function at the specified interval.
- */
- createThrottled: function(fn, interval, scope) {
- var lastCallTime, elapsed, lastArgs, timer, execute = function() {
- fn.apply(scope || this, lastArgs);
- lastCallTime = new Date().getTime();
- };
- return function() {
- elapsed = new Date().getTime() - lastCallTime;
- lastArgs = arguments;
- clearTimeout(timer);
- if (!lastCallTime || (elapsed >= interval)) {
- execute();
- } else {
- timer = setTimeout(execute, interval - elapsed);
- }
- };
- },
- /**
- * Adds behavior to an existing method that is executed before the
- * original behavior of the function. For example:
- *
- * var soup = {
- * contents: [],
- * add: function(ingredient) {
- * this.contents.push(ingredient);
- * }
- * };
- * Ext.Function.interceptBefore(soup, "add", function(ingredient){
- * if (!this.contents.length && ingredient !== "water") {
- * // Always add water to start with
- * this.contents.push("water");
- * }
- * });
- * soup.add("onions");
- * soup.add("salt");
- * soup.contents; // will contain: water, onions, salt
- *
- * @param {Object} object The target object
- * @param {String} methodName Name of the method to override
- * @param {Function} fn Function with the new behavior. It will
- * be called with the same arguments as the original method. The
- * return value of this function will be the return value of the
- * new method.
- * @return {Function} The new function just created.
- */
- interceptBefore: function(object, methodName, fn) {
- var method = object[methodName] || Ext.emptyFn;
- return object[methodName] = function() {
- var ret = fn.apply(this, arguments);
- method.apply(this, arguments);
- return ret;
- };
- },
- /**
- * Adds behavior to an existing method that is executed after the
- * original behavior of the function. For example:
- *
- * var soup = {
- * contents: [],
- * add: function(ingredient) {
- * this.contents.push(ingredient);
- * }
- * };
- * Ext.Function.interceptAfter(soup, "add", function(ingredient){
- * // Always add a bit of extra salt
- * this.contents.push("salt");
- * });
- * soup.add("water");
- * soup.add("onions");
- * soup.contents; // will contain: water, salt, onions, salt
- *
- * @param {Object} object The target object
- * @param {String} methodName Name of the method to override
- * @param {Function} fn Function with the new behavior. It will
- * be called with the same arguments as the original method. The
- * return value of this function will be the return value of the
- * new method.
- * @return {Function} The new function just created.
- */
- interceptAfter: function(object, methodName, fn) {
- var method = object[methodName] || Ext.emptyFn;
- return object[methodName] = function() {
- method.apply(this, arguments);
- return fn.apply(this, arguments);
- };
- }
- };
- /**
- * @method
- * @member Ext
- * @alias Ext.Function#defer
- */
- Ext.defer = Ext.Function.alias(Ext.Function, 'defer');
- /**
- * @method
- * @member Ext
- * @alias Ext.Function#pass
- */
- Ext.pass = Ext.Function.alias(Ext.Function, 'pass');
- /**
- * @method
- * @member Ext
- * @alias Ext.Function#bind
- */
- Ext.bind = Ext.Function.alias(Ext.Function, 'bind');
- /**
- * @author Jacky Nguyen <jacky@sencha.com>
- * @docauthor Jacky Nguyen <jacky@sencha.com>
- * @class Ext.Object
- *
- * A collection of useful static methods to deal with objects.
- *
- * @singleton
- */
- (function() {
- var ExtObject = Ext.Object = {
- /**
- * Converts a `name` - `value` pair to an array of objects with support for nested structures. Useful to construct
- * query strings. For example:
- *
- * var objects = Ext.Object.toQueryObjects('hobbies', ['reading', 'cooking', 'swimming']);
- *
- * // objects then equals:
- * [
- * { name: 'hobbies', value: 'reading' },
- * { name: 'hobbies', value: 'cooking' },
- * { name: 'hobbies', value: 'swimming' },
- * ];
- *
- * var objects = Ext.Object.toQueryObjects('dateOfBirth', {
- * day: 3,
- * month: 8,
- * year: 1987,
- * extra: {
- * hour: 4
- * minute: 30
- * }
- * }, true); // Recursive
- *
- * // objects then equals:
- * [
- * { name: 'dateOfBirth[day]', value: 3 },
- * { name: 'dateOfBirth[month]', value: 8 },
- * { name: 'dateOfBirth[year]', value: 1987 },
- * { name: 'dateOfBirth[extra][hour]', value: 4 },
- * { name: 'dateOfBirth[extra][minute]', value: 30 },
- * ];
- *
- * @param {String} name
- * @param {Object/Array} value
- * @param {Boolean} [recursive=false] True to traverse object recursively
- * @return {Array}
- */
- toQueryObjects: function(name, value, recursive) {
- var self = ExtObject.toQueryObjects,
- objects = [],
- i, ln;
- if (Ext.isArray(value)) {
- for (i = 0, ln = value.length; i < ln; i++) {
- if (recursive) {
- objects = objects.concat(self(name + '[' + i + ']', value[i], true));
- }
- else {
- objects.push({
- name: name,
- value: value[i]
- });
- }
- }
- }
- else if (Ext.isObject(value)) {
- for (i in value) {
- if (value.hasOwnProperty(i)) {
- if (recursive) {
- objects = objects.concat(self(name + '[' + i + ']', value[i], true));
- }
- else {
- objects.push({
- name: name,
- value: value[i]
- });
- }
- }
- }
- }
- else {
- objects.push({
- name: name,
- value: value
- });
- }
- return objects;
- },
- /**
- * Takes an object and converts it to an encoded query string.
- *
- * Non-recursive:
- *
- * Ext.Object.toQueryString({foo: 1, bar: 2}); // returns "foo=1&bar=2"
- * Ext.Object.toQueryString({foo: null, bar: 2}); // returns "foo=&bar=2"
- * Ext.Object.toQueryString({'some price': '$300'}); // returns "some%20price=%24300"
- * Ext.Object.toQueryString({date: new Date(2011, 0, 1)}); // returns "date=%222011-01-01T00%3A00%3A00%22"
- * Ext.Object.toQueryString({colors: ['red', 'green', 'blue']}); // returns "colors=red&colors=green&colors=blue"
- *
- * Recursive:
- *
- * Ext.Object.toQueryString({
- * username: 'Jacky',
- * dateOfBirth: {
- * day: 1,
- * month: 2,
- * year: 1911
- * },
- * hobbies: ['coding', 'eating', 'sleeping', ['nested', 'stuff']]
- * }, true); // returns the following string (broken down and url-decoded for ease of reading purpose):
- * // username=Jacky
- * // &dateOfBirth[day]=1&dateOfBirth[month]=2&dateOfBirth[year]=1911
- * // &hobbies[0]=coding&hobbies[1]=eating&hobbies[2]=sleeping&hobbies[3][0]=nested&hobbies[3][1]=stuff
- *
- * @param {Object} object The object to encode
- * @param {Boolean} [recursive=false] Whether or not to interpret the object in recursive format.
- * (PHP / Ruby on Rails servers and similar).
- * @return {String} queryString
- */
- toQueryString: function(object, recursive) {
- var paramObjects = [],
- params = [],
- i, j, ln, paramObject, value;
- for (i in object) {
- if (object.hasOwnProperty(i)) {
- paramObjects = paramObjects.concat(ExtObject.toQueryObjects(i, object[i], recursive));
- }
- }
- for (j = 0, ln = paramObjects.length; j < ln; j++) {
- paramObject = paramObjects[j];
- value = paramObject.value;
- if (Ext.isEmpty(value)) {
- value = '';
- }
- else if (Ext.isDate(value)) {
- value = Ext.Date.toString(value);
- }
- params.push(encodeURIComponent(paramObject.name) + '=' + encodeURIComponent(String(value)));
- }
- return params.join('&');
- },
- /**
- * Converts a query string back into an object.
- *
- * Non-recursive:
- *
- * Ext.Object.fromQueryString(foo=1&bar=2); // returns {foo: 1, bar: 2}
- * Ext.Object.fromQueryString(foo=&bar=2); // returns {foo: null, bar: 2}
- * Ext.Object.fromQueryString(some%20price=%24300); // returns {'some price': '$300'}
- * Ext.Object.fromQueryString(colors=red&colors=green&colors=blue); // returns {colors: ['red', 'green', 'blue']}
- *
- * Recursive:
- *
- * Ext.Object.fromQueryString("username=Jacky&dateOfBirth[day]=1&dateOfBirth[month]=2&dateOfBirth[year]=1911&hobbies[0]=coding&hobbies[1]=eating&hobbies[2]=sleeping&hobbies[3][0]=nested&hobbies[3][1]=stuff", true);
- * // returns
- * {
- * username: 'Jacky',
- * dateOfBirth: {
- * day: '1',
- * month: '2',
- * year: '1911'
- * },
- * hobbies: ['coding', 'eating', 'sleeping', ['nested', 'stuff']]
- * }
- *
- * @param {String} queryString The query string to decode
- * @param {Boolean} [recursive=false] Whether or not to recursively decode the string. This format is supported by
- * PHP / Ruby on Rails servers and similar.
- * @return {Object}
- */
- fromQueryString: function(queryString, recursive) {
- var parts = queryString.replace(/^\?/, '').split('&'),
- object = {},
- temp, components, name, value, i, ln,
- part, j, subLn, matchedKeys, matchedName,
- keys, key, nextKey;
- for (i = 0, ln = parts.length; i < ln; i++) {
- part = parts[i];
- if (part.length > 0) {
- components = part.split('=');
- name = decodeURIComponent(components[0]);
- value = (components[1] !== undefined) ? decodeURIComponent(components[1]) : '';
- if (!recursive) {
- if (object.hasOwnProperty(name)) {
- if (!Ext.isArray(object[name])) {
- object[name] = [object[name]];
- }
- object[name].push(value);
- }
- else {
- object[name] = value;
- }
- }
- else {
- matchedKeys = name.match(/(\[):?([^\]]*)\]/g);
- matchedName = name.match(/^([^\[]+)/);
- name = matchedName[0];
- keys = [];
- if (matchedKeys === null) {
- object[name] = value;
- continue;
- }
- for (j = 0, subLn = matchedKeys.length; j < subLn; j++) {
- key = matchedKeys[j];
- key = (key.length === 2) ? '' : key.substring(1, key.length - 1);
- keys.push(key);
- }
- keys.unshift(name);
- temp = object;
- for (j = 0, subLn = keys.length; j < subLn; j++) {
- key = keys[j];
- if (j === subLn - 1) {
- if (Ext.isArray(temp) && key === '') {
- temp.push(value);
- }
- else {
- temp[key] = value;
- }
- }
- else {
- if (temp[key] === undefined || typeof temp[key] === 'string') {
- nextKey = keys[j+1];
- temp[key] = (Ext.isNumeric(nextKey) || nextKey === '') ? [] : {};
- }
- temp = temp[key];
- }
- }
- }
- }
- }
- return object;
- },
- /**
- * Iterates through an object and invokes the given callback function for each iteration.
- * The iteration can be stopped by returning `false` in the callback function. For example:
- *
- * var person = {
- * name: 'Jacky'
- * hairColor: 'black'
- * loves: ['food', 'sleeping', 'wife']
- * };
- *
- * Ext.Object.each(person, function(key, value, myself) {
- * console.log(key + ":" + value);
- *
- * if (key === 'hairColor') {
- * return false; // stop the iteration
- * }
- * });
- *
- * @param {Object} object The object to iterate
- * @param {Function} fn The callback function.
- * @param {String} fn.key
- * @param {Object} fn.value
- * @param {Object} fn.object The object itself
- * @param {Object} [scope] The execution scope (`this`) of the callback function
- */
- each: function(object, fn, scope) {
- for (var property in object) {
- if (object.hasOwnProperty(property)) {
- if (fn.call(scope || object, property, object[property], object) === false) {
- return;
- }
- }
- }
- },
- /**
- * Merges any number of objects recursively without referencing them or their children.
- *
- * var extjs = {
- * companyName: 'Ext JS',
- * products: ['Ext JS', 'Ext GWT', 'Ext Designer'],
- * isSuperCool: true
- * office: {
- * size: 2000,
- * location: 'Palo Alto',
- * isFun: true
- * }
- * };
- *
- * var newStuff = {
- * companyName: 'Sencha Inc.',
- * products: ['Ext JS', 'Ext GWT', 'Ext Designer', 'Sencha Touch', 'Sencha Animator'],
- * office: {
- * size: 40000,
- * location: 'Redwood City'
- * }
- * };
- *
- * var sencha = Ext.Object.merge(extjs, newStuff);
- *
- * // extjs and sencha then equals to
- * {
- * companyName: 'Sencha Inc.',
- * products: ['Ext JS', 'Ext GWT', 'Ext Designer', 'Sencha Touch', 'Sencha Animator'],
- * isSuperCool: true
- * office: {
- * size: 30000,
- * location: 'Redwood City'
- * isFun: true
- * }
- * }
- *
- * @param {Object...} object Any number of objects to merge.
- * @return {Object} merged The object that is created as a result of merging all the objects passed in.
- */
- merge: function(source, key, value) {
- if (typeof key === 'string') {
- if (value && value.constructor === Object) {
- if (source[key] && source[key].constructor === Object) {
- ExtObject.merge(source[key], value);
- }
- else {
- source[key] = Ext.clone(value);
- }
- }
- else {
- source[key] = value;
- }
- return source;
- }
- var i = 1,
- ln = arguments.length,
- object, property;
- for (; i < ln; i++) {
- object = arguments[i];
- for (property in object) {
- if (object.hasOwnProperty(property)) {
- ExtObject.merge(source, property, object[property]);
- }
- }
- }
- return source;
- },
- /**
- * Returns the first matching key corresponding to the given value.
- * If no matching value is found, null is returned.
- *
- * var person = {
- * name: 'Jacky',
- * loves: 'food'
- * };
- *
- * alert(Ext.Object.getKey(person, 'food')); // alerts 'loves'
- *
- * @param {Object} object
- * @param {Object} value The value to find
- */
- getKey: function(object, value) {
- for (var property in object) {
- if (object.hasOwnProperty(property) && object[property] === value) {
- return property;
- }
- }
- return null;
- },
- /**
- * Gets all values of the given object as an array.
- *
- * var values = Ext.Object.getValues({
- * name: 'Jacky',
- * loves: 'food'
- * }); // ['Jacky', 'food']
- *
- * @param {Object} object
- * @return {Array} An array of values from the object
- */
- getValues: function(object) {
- var values = [],
- property;
- for (property in object) {
- if (object.hasOwnProperty(property)) {
- values.push(object[property]);
- }
- }
- return values;
- },
- /**
- * Gets all keys of the given object as an array.
- *
- * var values = Ext.Object.getKeys({
- * name: 'Jacky',
- * loves: 'food'
- * }); // ['name', 'loves']
- *
- * @param {Object} object
- * @return {String[]} An array of keys from the object
- * @method
- */
- getKeys: ('keys' in Object.prototype) ? Object.keys : function(object) {
- var keys = [],
- property;
- for (property in object) {
- if (object.hasOwnProperty(property)) {
- keys.push(property);
- }
- }
- return keys;
- },
- /**
- * Gets the total number of this object's own properties
- *
- * var size = Ext.Object.getSize({
- * name: 'Jacky',
- * loves: 'food'
- * }); // size equals 2
- *
- * @param {Object} object
- * @return {Number} size
- */
- getSize: function(object) {
- var size = 0,
- property;
- for (property in object) {
- if (object.hasOwnProperty(property)) {
- size++;
- }
- }
- return size;
- }
- };
- /**
- * A convenient alias method for {@link Ext.Object#merge}.
- *
- * @member Ext
- * @method merge
- * @alias Ext.Object#merge
- */
- Ext.merge = Ext.Object.merge;
- /**
- * Alias for {@link Ext.Object#toQueryString}.
- *
- * @member Ext
- * @method urlEncode
- * @alias Ext.Object#toQueryString
- * @deprecated 4.0.0 Use {@link Ext.Object#toQueryString} instead
- */
- Ext.urlEncode = function() {
- var args = Ext.Array.from(arguments),
- prefix = '';
- // Support for the old `pre` argument
- if ((typeof args[1] === 'string')) {
- prefix = args[1] + '&';
- args[1] = false;
- }
- return prefix + Ext.Object.toQueryString.apply(Ext.Object, args);
- };
- /**
- * Alias for {@link Ext.Object#fromQueryString}.
- *
- * @member Ext
- * @method urlDecode
- * @alias Ext.Object#fromQueryString
- * @deprecated 4.0.0 Use {@link Ext.Object#fromQueryString} instead
- */
- Ext.urlDecode = function() {
- return Ext.Object.fromQueryString.apply(Ext.Object, arguments);
- };
- })();
- /**
- * @class Ext.Date
- * A set of useful static methods to deal with date
- * Note that if Ext.Date is required and loaded, it will copy all methods / properties to
- * this object for convenience
- *
- * The date parsing and formatting syntax contains a subset of
- * <a href="http://www.php.net/date">PHP's date() function</a>, and the formats that are
- * supported will provide results equivalent to their PHP versions.
- *
- * The following is a list of all currently supported formats:
- * <pre class="">
- Format Description Example returned values
- ------ ----------------------------------------------------------------------- -----------------------
- d Day of the month, 2 digits with leading zeros 01 to 31
- D A short textual representation of the day of the week Mon to Sun
- j Day of the month without leading zeros 1 to 31
- l A full textual representation of the day of the week Sunday to Saturday
- N ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday)
- S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
- w Numeric representation of the day of the week 0 (for Sunday) to 6 (for Saturday)
- z The day of the year (starting from 0) 0 to 364 (365 in leap years)
- W ISO-8601 week number of year, weeks starting on Monday 01 to 53
- F A full textual representation of a month, such as January or March January to December
- m Numeric representation of a month, with leading zeros 01 to 12
- M A short textual representation of a month Jan to Dec
- n Numeric representation of a month, without leading zeros 1 to 12
- t Number of days in the given month 28 to 31
- L Whether it's a leap year 1 if it is a leap year, 0 otherwise.
- o ISO-8601 year number (identical to (Y), but if the ISO week number (W) Examples: 1998 or 2004
- belongs to the previous or next year, that year is used instead)
- Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003
- y A two digit representation of a year Examples: 99 or 03
- a Lowercase Ante meridiem and Post meridiem am or pm
- A Uppercase Ante meridiem and Post meridiem AM or PM
- g 12-hour format of an hour without leading zeros 1 to 12
- G 24-hour format of an hour without leading zeros 0 to 23
- h 12-hour format of an hour with leading zeros 01 to 12
- H 24-hour format of an hour with leading zeros 00 to 23
- i Minutes, with leading zeros 00 to 59
- s Seconds, with leading zeros 00 to 59
- u Decimal fraction of a second Examples:
- (minimum 1 digit, arbitrary number of digits allowed) 001 (i.e. 0.001s) or
- 100 (i.e. 0.100s) or
- 999 (i.e. 0.999s) or
- 999876543210 (i.e. 0.999876543210s)
- O Difference to Greenwich time (GMT) in hours and minutes Example: +1030
- P Difference to Greenwich time (GMT) with colon between hours and minutes Example: -08:00
- T Timezone abbreviation of the machine running the code Examples: EST, MDT, PDT ...
- Z Timezone offset in seconds (negative if west of UTC, positive if east) -43200 to 50400
- c ISO 8601 date
- Notes: Examples:
- 1) If unspecified, the month / day defaults to the current month / day, 1991 or
- the time defaults to midnight, while the timezone defaults to the 1992-10 or
- browser's timezone. If a time is specified, it must include both hours 1993-09-20 or
- and minutes. The "T" delimiter, seconds, milliseconds and timezone 1994-08-19T16:20+01:00 or
- are optional. 1995-07-18T17:21:28-02:00 or
- 2) The decimal fraction of a second, if specified, must contain at 1996-06-17T18:22:29.98765+03:00 or
- least 1 digit (there is no limit to the maximum number 1997-05-16T19:23:30,12345-0400 or
- of digits allowed), and may be delimited by either a '.' or a ',' 1998-04-15T20:24:31.2468Z or
- Refer to the examples on the right for the various levels of 1999-03-14T20:24:32Z or
- date-time granularity which are supported, or see 2000-02-13T21:25:33
- http://www.w3.org/TR/NOTE-datetime for more info. 2001-01-12 22:26:34
- U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 1193432466 or -2138434463
- MS Microsoft AJAX serialized dates \/Date(1238606590509)\/ (i.e. UTC milliseconds since epoch) or
- \/Date(1238606590509+0800)\/
- </pre>
- *
- * Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
- * <pre><code>
- // Sample date:
- // 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
- var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
- console.log(Ext.Date.format(dt, 'Y-m-d')); // 2007-01-10
- console.log(Ext.Date.format(dt, 'F j, Y, g:i a')); // January 10, 2007, 3:05 pm
- console.log(Ext.Date.format(dt, 'l, \\t\\he jS \\of F Y h:i:s A')); // Wednesday, the 10th of January 2007 03:05:01 PM
- </code></pre>
- *
- * Here are some standard date/time patterns that you might find helpful. They
- * are not part of the source of Ext.Date, but to use them you can simply copy this
- * block of code into any script that is included after Ext.Date and they will also become
- * globally available on the Date object. Feel free to add or remove patterns as needed in your code.
- * <pre><code>
- Ext.Date.patterns = {
- ISO8601Long:"Y-m-d H:i:s",
- ISO8601Short:"Y-m-d",
- ShortDate: "n/j/Y",
- LongDate: "l, F d, Y",
- FullDateTime: "l, F d, Y g:i:s A",
- MonthDay: "F d",
- ShortTime: "g:i A",
- LongTime: "g:i:s A",
- SortableDateTime: "Y-m-d\\TH:i:s",
- UniversalSortableDateTime: "Y-m-d H:i:sO",
- YearMonth: "F, Y"
- };
- </code></pre>
- *
- * Example usage:
- * <pre><code>
- var dt = new Date();
- console.log(Ext.Date.format(dt, Ext.Date.patterns.ShortDate));
- </code></pre>
- * <p>Developer-written, custom formats may be used by supplying both a formatting and a parsing function
- * which perform to specialized requirements. The functions are stored in {@link #parseFunctions} and {@link #formatFunctions}.</p>
- * @singleton
- */
- /*
- * Most of the date-formatting functions below are the excellent work of Baron Schwartz.
- * (see http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/)
- * They generate precompiled functions from format patterns instead of parsing and
- * processing each pattern every time a date is formatted. These functions are available
- * on every Date object.
- */
- (function() {
- // create private copy of Ext's Ext.util.Format.format() method
- // - to remove unnecessary dependency
- // - to resolve namespace conflict with MS-Ajax's implementation
- function xf(format) {
- var args = Array.prototype.slice.call(arguments, 1);
- return format.replace(/\{(\d+)\}/g, function(m, i) {
- return args[i];
- });
- }
- Ext.Date = {
- /**
- * Returns the current timestamp
- * @return {Date} The current timestamp
- * @method
- */
- now: Date.now || function() {
- return +new Date();
- },
- /**
- * @private
- * Private for now
- */
- toString: function(date) {
- var pad = Ext.String.leftPad;
- return date.getFullYear() + "-"
- + pad(date.getMonth() + 1, 2, '0') + "-"
- + pad(date.getDate(), 2, '0') + "T"
- + pad(date.getHours(), 2, '0') + ":"
- + pad(date.getMinutes(), 2, '0') + ":"
- + pad(date.getSeconds(), 2, '0');
- },
- /**
- * Returns the number of milliseconds between two dates
- * @param {Date} dateA The first date
- * @param {Date} dateB (optional) The second date, defaults to now
- * @return {Number} The difference in milliseconds
- */
- getElapsed: function(dateA, dateB) {
- return Math.abs(dateA - (dateB || new Date()));
- },
- /**
- * Global flag which determines if strict date parsing should be used.
- * Strict date parsing will not roll-over invalid dates, which is the
- * default behaviour of javascript Date objects.
- * (see {@link #parse} for more information)
- * Defaults to <tt>false</tt>.
- * @type Boolean
- */
- useStrict: false,
- // private
- formatCodeToRegex: function(character, currentGroup) {
- // Note: currentGroup - position in regex result array (see notes for Ext.Date.parseCodes below)
- var p = utilDate.parseCodes[character];
- if (p) {
- p = typeof p == 'function'? p() : p;
- utilDate.parseCodes[character] = p; // reassign function result to prevent repeated execution
- }
- return p ? Ext.applyIf({
- c: p.c ? xf(p.c, currentGroup || "{0}") : p.c
- }, p) : {
- g: 0,
- c: null,
- s: Ext.String.escapeRegex(character) // treat unrecognised characters as literals
- };
- },
- /**
- * <p>An object hash in which each property is a date parsing function. The property name is the
- * format string which that function parses.</p>
- * <p>This object is automatically populated with date parsing functions as
- * date formats are requested for Ext standard formatting strings.</p>
- * <p>Custom parsing functions may be inserted into this object, keyed by a name which from then on
- * may be used as a format string to {@link #parse}.<p>
- * <p>Example:</p><pre><code>
- Ext.Date.parseFunctions['x-date-format'] = myDateParser;
- </code></pre>
- * <p>A parsing function should return a Date object, and is passed the following parameters:<div class="mdetail-params"><ul>
- * <li><code>date</code> : String<div class="sub-desc">The date string to parse.</div></li>
- * <li><code>strict</code> : Boolean<div class="sub-desc">True to validate date strings while parsing
- * (i.e. prevent javascript Date "rollover") (The default must be false).
- * Invalid date strings should return null when parsed.</div></li>
- * </ul></div></p>
- * <p>To enable Dates to also be <i>formatted</i> according to that format, a corresponding
- * formatting function must be placed into the {@link #formatFunctions} property.
- * @property parseFunctions
- * @type Object
- */
- parseFunctions: {
- "MS": function(input, strict) {
- // note: the timezone offset is ignored since the MS Ajax server sends
- // a UTC milliseconds-since-Unix-epoch value (negative values are allowed)
- var re = new RegExp('\\/Date\\(([-+])?(\\d+)(?:[+-]\\d{4})?\\)\\/');
- var r = (input || '').match(re);
- return r? new Date(((r[1] || '') + r[2]) * 1) : null;
- }
- },
- parseRegexes: [],
- /**
- * <p>An object hash in which each property is a date formatting function. The property name is the
- * format string which corresponds to the produced formatted date string.</p>
- * <p>This object is automatically populated with date formatting functions as
- * date formats are requested for Ext standard formatting strings.</p>
- * <p>Custom formatting functions may be inserted into this object, keyed by a name which from then on
- * may be used as a format string to {@link #format}. Example:</p><pre><code>
- Ext.Date.formatFunctions['x-date-format'] = myDateFormatter;
- </code></pre>
- * <p>A formatting function should return a string representation of the passed Date object, and is passed the following parameters:<div class="mdetail-params"><ul>
- * <li><code>date</code> : Date<div class="sub-desc">The Date to format.</div></li>
- * </ul></div></p>
- * <p>To enable date strings to also be <i>parsed</i> according to that format, a corresponding
- * parsing function must be placed into the {@link #parseFunctions} property.
- * @property formatFunctions
- * @type Object
- */
- formatFunctions: {
- "MS": function() {
- // UTC milliseconds since Unix epoch (MS-AJAX serialized date format (MRSF))
- return '\\/Date(' + this.getTime() + ')\\/';
- }
- },
- y2kYear : 50,
- /**
- * Date interval constant
- * @type String
- */
- MILLI : "ms",
- /**
- * Date interval constant
- * @type String
- */
- SECOND : "s",
- /**
- * Date interval constant
- * @type String
- */
- MINUTE : "mi",
- /** Date interval constant
- * @type String
- */
- HOUR : "h",
- /**
- * Date interval constant
- * @type String
- */
- DAY : "d",
- /**
- * Date interval constant
- * @type String
- */
- MONTH : "mo",
- /**
- * Date interval constant
- * @type String
- */
- YEAR : "y",
- /**
- * <p>An object hash containing default date values used during date parsing.</p>
- * <p>The following properties are available:<div class="mdetail-params"><ul>
- * <li><code>y</code> : Number<div class="sub-desc">The default year value. (defaults to undefined)</div></li>
- * <li><code>m</code> : Number<div class="sub-desc">The default 1-based month value. (defaults to undefined)</div></li>
- * <li><code>d</code> : Number<div class="sub-desc">The default day value. (defaults to undefined)</div></li>
- * <li><code>h</code> : Number<div class="sub-desc">The default hour value. (defaults to undefined)</div></li>
- * <li><code>i</code> : Number<div class="sub-desc">The default minute value. (defaults to undefined)</div></li>
- * <li><code>s</code> : Number<div class="sub-desc">The default second value. (defaults to undefined)</div></li>
- * <li><code>ms</code> : Number<div class="sub-desc">The default millisecond value. (defaults to undefined)</div></li>
- * </ul></div></p>
- * <p>Override these properties to customize the default date values used by the {@link #parse} method.</p>
- * <p><b>Note: In countries which experience Daylight Saving Time (i.e. DST), the <tt>h</tt>, <tt>i</tt>, <tt>s</tt>
- * and <tt>ms</tt> properties may coincide with the exact time in which DST takes effect.
- * It is the responsiblity of the developer to account for this.</b></p>
- * Example Usage:
- * <pre><code>
- // set default day value to the first day of the month
- Ext.Date.defaults.d = 1;
- // parse a February date string containing only year and month values.
- // setting the default day value to 1 prevents weird date rollover issues
- // when attempting to parse the following date string on, for example, March 31st 2009.
- Ext.Date.parse('2009-02', 'Y-m'); // returns a Date object representing February 1st 2009
- </code></pre>
- * @property defaults
- * @type Object
- */
- defaults: {},
- /**
- * @property {String[]} dayNames
- * An array of textual day names.
- * Override these values for international dates.
- * Example:
- * <pre><code>
- Ext.Date.dayNames = [
- 'SundayInYourLang',
- 'MondayInYourLang',
- ...
- ];
- </code></pre>
- */
- dayNames : [
- "Sunday",
- "Monday",
- "Tuesday",
- "Wednesday",
- "Thursday",
- "Friday",
- "Saturday"
- ],
- /**
- * @property {String[]} monthNames
- * An array of textual month names.
- * Override these values for international dates.
- * Example:
- * <pre><code>
- Ext.Date.monthNames = [
- 'JanInYourLang',
- 'FebInYourLang',
- ...
- ];
- </code></pre>
- */
- monthNames : [
- "January",
- "February",
- "March",
- "April",
- "May",
- "June",
- "July",
- "August",
- "September",
- "October",
- "November",
- "December"
- ],
- /**
- * @property {Object} monthNumbers
- * An object hash of zero-based javascript month numbers (with short month names as keys. note: keys are case-sensitive).
- * Override these values for international dates.
- * Example:
- * <pre><code>
- Ext.Date.monthNumbers = {
- 'ShortJanNameInYourLang':0,
- 'ShortFebNameInYourLang':1,
- ...
- };
- </code></pre>
- */
- monthNumbers : {
- Jan:0,
- Feb:1,
- Mar:2,
- Apr:3,
- May:4,
- Jun:5,
- Jul:6,
- Aug:7,
- Sep:8,
- Oct:9,
- Nov:10,
- Dec:11
- },
- /**
- * @property {String} defaultFormat
- * <p>The date format string that the {@link Ext.util.Format#dateRenderer}
- * and {@link Ext.util.Format#date} functions use. See {@link Ext.Date} for details.</p>
- * <p>This may be overridden in a locale file.</p>
- */
- defaultFormat : "m/d/Y",
- /**
- * Get the short month name for the given month number.
- * Override this function for international dates.
- * @param {Number} month A zero-based javascript month number.
- * @return {String} The short month name.
- */
- getShortMonthName : function(month) {
- return utilDate.monthNames[month].substring(0, 3);
- },
- /**
- * Get the short day name for the given day number.
- * Override this function for international dates.
- * @param {Number} day A zero-based javascript day number.
- * @return {String} The short day name.
- */
- getShortDayName : function(day) {
- return utilDate.dayNames[day].substring(0, 3);
- },
- /**
- * Get the zero-based javascript month number for the given short/full month name.
- * Override this function for international dates.
- * @param {String} name The short/full month name.
- * @return {Number} The zero-based javascript month number.
- */
- getMonthNumber : function(name) {
- // handle camel casing for english month names (since the keys for the Ext.Date.monthNumbers hash are case sensitive)
- return utilDate.monthNumbers[name.substring(0, 1).toUpperCase() + name.substring(1, 3).toLowerCase()];
- },
- /**
- * Checks if the specified format contains hour information
- * @param {String} format The format to check
- * @return {Boolean} True if the format contains hour information
- * @method
- */
- formatContainsHourInfo : (function(){
- var stripEscapeRe = /(\\.)/g,
- hourInfoRe = /([gGhHisucUOPZ]|MS)/;
- return function(format){
- return hourInfoRe.test(format.replace(stripEscapeRe, ''));
- };
- })(),
- /**
- * Checks if the specified format contains information about
- * anything other than the time.
- * @param {String} format The format to check
- * @return {Boolean} True if the format contains information about
- * date/day information.
- * @method
- */
- formatContainsDateInfo : (function(){
- var stripEscapeRe = /(\\.)/g,
- dateInfoRe = /([djzmnYycU]|MS)/;
- return function(format){
- return dateInfoRe.test(format.replace(stripEscapeRe, ''));
- };
- })(),
- /**
- * The base format-code to formatting-function hashmap used by the {@link #format} method.
- * Formatting functions are strings (or functions which return strings) which
- * will return the appropriate value when evaluated in the context of the Date object
- * from which the {@link #format} method is called.
- * Add to / override these mappings for custom date formatting.
- * Note: Ext.Date.format() treats characters as literals if an appropriate mapping cannot be found.
- * Example:
- * <pre><code>
- Ext.Date.formatCodes.x = "Ext.util.Format.leftPad(this.getDate(), 2, '0')";
- console.log(Ext.Date.format(new Date(), 'X'); // returns the current day of the month
- </code></pre>
- * @type Object
- */
- formatCodes : {
- d: "Ext.String.leftPad(this.getDate(), 2, '0')",
- D: "Ext.Date.getShortDayName(this.getDay())", // get localised short day name
- j: "this.getDate()",
- l: "Ext.Date.dayNames[this.getDay()]",
- N: "(this.getDay() ? this.getDay() : 7)",
- S: "Ext.Date.getSuffix(this)",
- w: "this.getDay()",
- z: "Ext.Date.getDayOfYear(this)",
- W: "Ext.String.leftPad(Ext.Date.getWeekOfYear(this), 2, '0')",
- F: "Ext.Date.monthNames[this.getMonth()]",
- m: "Ext.String.leftPad(this.getMonth() + 1, 2, '0')",
- M: "Ext.Date.getShortMonthName(this.getMonth())", // get localised short month name
- n: "(this.getMonth() + 1)",
- t: "Ext.Date.getDaysInMonth(this)",
- L: "(Ext.Date.isLeapYear(this) ? 1 : 0)",
- o: "(this.getFullYear() + (Ext.Date.getWeekOfYear(this) == 1 && this.getMonth() > 0 ? +1 : (Ext.Date.getWeekOfYear(this) >= 52 && this.getMonth() < 11 ? -1 : 0)))",
- Y: "Ext.String.leftPad(this.getFullYear(), 4, '0')",
- y: "('' + this.getFullYear()).substring(2, 4)",
- a: "(this.getHours() < 12 ? 'am' : 'pm')",
- A: "(this.getHours() < 12 ? 'AM' : 'PM')",
- g: "((this.getHours() % 12) ? this.getHours() % 12 : 12)",
- G: "this.getHours()",
- h: "Ext.String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0')",
- H: "Ext.String.leftPad(this.getHours(), 2, '0')",
- i: "Ext.String.leftPad(this.getMinutes(), 2, '0')",
- s: "Ext.String.leftPad(this.getSeconds(), 2, '0')",
- u: "Ext.String.leftPad(this.getMilliseconds(), 3, '0')",
- O: "Ext.Date.getGMTOffset(this)",
- P: "Ext.Date.getGMTOffset(this, true)",
- T: "Ext.Date.getTimezone(this)",
- Z: "(this.getTimezoneOffset() * -60)",
- c: function() { // ISO-8601 -- GMT format
- for (var c = "Y-m-dTH:i:sP", code = [], i = 0, l = c.length; i < l; ++i) {
- var e = c.charAt(i);
- code.push(e == "T" ? "'T'" : utilDate.getFormatCode(e)); // treat T as a character literal
- }
- return code.join(" + ");
- },
- /*
- c: function() { // ISO-8601 -- UTC format
- return [
- "this.getUTCFullYear()", "'-'",
- "Ext.util.Format.leftPad(this.getUTCMonth() + 1, 2, '0')", "'-'",
- "Ext.util.Format.leftPad(this.getUTCDate(), 2, '0')",
- "'T'",
- "Ext.util.Format.leftPad(this.getUTCHours(), 2, '0')", "':'",
- "Ext.util.Format.leftPad(this.getUTCMinutes(), 2, '0')", "':'",
- "Ext.util.Format.leftPad(this.getUTCSeconds(), 2, '0')",
- "'Z'"
- ].join(" + ");
- },
- */
- U: "Math.round(this.getTime() / 1000)"
- },
- /**
- * Checks if the passed Date parameters will cause a javascript Date "rollover".
- * @param {Number} year 4-digit year
- * @param {Number} month 1-based month-of-year
- * @param {Number} day Day of month
- * @param {Number} hour (optional) Hour
- * @param {Number} minute (optional) Minute
- * @param {Number} second (optional) Second
- * @param {Number} millisecond (optional) Millisecond
- * @return {Boolean} true if the passed parameters do not cause a Date "rollover", false otherwise.
- */
- isValid : function(y, m, d, h, i, s, ms) {
- // setup defaults
- h = h || 0;
- i = i || 0;
- s = s || 0;
- ms = ms || 0;
- // Special handling for year < 100
- var dt = utilDate.add(new Date(y < 100 ? 100 : y, m - 1, d, h, i, s, ms), utilDate.YEAR, y < 100 ? y - 100 : 0);
- return y == dt.getFullYear() &&
- m == dt.getMonth() + 1 &&
- d == dt.getDate() &&
- h == dt.getHours() &&
- i == dt.getMinutes() &&
- s == dt.getSeconds() &&
- ms == dt.getMilliseconds();
- },
- /**
- * Parses the passed string using the specified date format.
- * Note that this function expects normal calendar dates, meaning that months are 1-based (i.e. 1 = January).
- * The {@link #defaults} hash will be used for any date value (i.e. year, month, day, hour, minute, second or millisecond)
- * which cannot be found in the passed string. If a corresponding default date value has not been specified in the {@link #defaults} hash,
- * the current date's year, month, day or DST-adjusted zero-hour time value will be used instead.
- * Keep in mind that the input date string must precisely match the specified format string
- * in order for the parse operation to be successful (failed parse operations return a null value).
- * <p>Example:</p><pre><code>
- //dt = Fri May 25 2007 (current date)
- var dt = new Date();
- //dt = Thu May 25 2006 (today's month/day in 2006)
- dt = Ext.Date.parse("2006", "Y");
- //dt = Sun Jan 15 2006 (all date parts specified)
- dt = Ext.Date.parse("2006-01-15", "Y-m-d");
- //dt = Sun Jan 15 2006 15:20:01
- dt = Ext.Date.parse("2006-01-15 3:20:01 PM", "Y-m-d g:i:s A");
- // attempt to parse Sun Feb 29 2006 03:20:01 in strict mode
- dt = Ext.Date.parse("2006-02-29 03:20:01", "Y-m-d H:i:s", true); // returns null
- </code></pre>
- * @param {String} input The raw date string.
- * @param {String} format The expected date string format.
- * @param {Boolean} strict (optional) True to validate date strings while parsing (i.e. prevents javascript Date "rollover")
- (defaults to false). Invalid date strings will return null when parsed.
- * @return {Date} The parsed Date.
- */
- parse : function(input, format, strict) {
- var p = utilDate.parseFunctions;
- if (p[format] == null) {
- utilDate.createParser(format);
- }
- return p[format](input, Ext.isDefined(strict) ? strict : utilDate.useStrict);
- },
- // Backwards compat
- parseDate: function(input, format, strict){
- return utilDate.parse(input, format, strict);
- },
- // private
- getFormatCode : function(character) {
- var f = utilDate.formatCodes[character];
- if (f) {
- f = typeof f == 'function'? f() : f;
- utilDate.formatCodes[character] = f; // reassign function result to prevent repeated execution
- }
- // note: unknown characters are treated as literals
- return f || ("'" + Ext.String.escape(character) + "'");
- },
- // private
- createFormat : function(format) {
- var code = [],
- special = false,
- ch = '';
- for (var i = 0; i < format.length; ++i) {
- ch = format.charAt(i);
- if (!special && ch == "\\") {
- special = true;
- } else if (special) {
- special = false;
- code.push("'" + Ext.String.escape(ch) + "'");
- } else {
- code.push(utilDate.getFormatCode(ch));
- }
- }
- utilDate.formatFunctions[format] = Ext.functionFactory("return " + code.join('+'));
- },
- // private
- createParser : (function() {
- var code = [
- "var dt, y, m, d, h, i, s, ms, o, z, zz, u, v,",
- "def = Ext.Date.defaults,",
- "results = String(input).match(Ext.Date.parseRegexes[{0}]);", // either null, or an array of matched strings
- "if(results){",
- "{1}",
- "if(u != null){", // i.e. unix time is defined
- "v = new Date(u * 1000);", // give top priority to UNIX time
- "}else{",
- // create Date object representing midnight of the current day;
- // this will provide us with our date defaults
- // (note: clearTime() handles Daylight Saving Time automatically)
- "dt = Ext.Date.clearTime(new Date);",
- // date calculations (note: these calculations create a dependency on Ext.Number.from())
- "y = Ext.Number.from(y, Ext.Number.from(def.y, dt.getFullYear()));",
- "m = Ext.Number.from(m, Ext.Number.from(def.m - 1, dt.getMonth()));",
- "d = Ext.Number.from(d, Ext.Number.from(def.d, dt.getDate()));",
- // time calculations (note: these calculations create a dependency on Ext.Number.from())
- "h = Ext.Number.from(h, Ext.Number.from(def.h, dt.getHours()));",
- "i = Ext.Number.from(i, Ext.Number.from(def.i, dt.getMinutes()));",
- "s = Ext.Number.from(s, Ext.Number.from(def.s, dt.getSeconds()));",
- "ms = Ext.Number.from(ms, Ext.Number.from(def.ms, dt.getMilliseconds()));",
- "if(z >= 0 && y >= 0){",
- // both the year and zero-based day of year are defined and >= 0.
- // these 2 values alone provide sufficient info to create a full date object
- // create Date object representing January 1st for the given year
- // handle years < 100 appropriately
- "v = Ext.Date.add(new Date(y < 100 ? 100 : y, 0, 1, h, i, s, ms), Ext.Date.YEAR, y < 100 ? y - 100 : 0);",
- // then add day of year, checking for Date "rollover" if necessary
- "v = !strict? v : (strict === true && (z <= 364 || (Ext.Date.isLeapYear(v) && z <= 365))? Ext.Date.add(v, Ext.Date.DAY, z) : null);",
- "}else if(strict === true && !Ext.Date.isValid(y, m + 1, d, h, i, s, ms)){", // check for Date "rollover"
- "v = null;", // invalid date, so return null
- "}else{",
- // plain old Date object
- // handle years < 100 properly
- "v = Ext.Date.add(new Date(y < 100 ? 100 : y, m, d, h, i, s, ms), Ext.Date.YEAR, y < 100 ? y - 100 : 0);",
- "}",
- "}",
- "}",
- "if(v){",
- // favour UTC offset over GMT offset
- "if(zz != null){",
- // reset to UTC, then add offset
- "v = Ext.Date.add(v, Ext.Date.SECOND, -v.getTimezoneOffset() * 60 - zz);",
- "}else if(o){",
- // reset to GMT, then add offset
- "v = Ext.Date.add(v, Ext.Date.MINUTE, -v.getTimezoneOffset() + (sn == '+'? -1 : 1) * (hr * 60 + mn));",
- "}",
- "}",
- "return v;"
- ].join('\n');
- return function(format) {
- var regexNum = utilDate.parseRegexes.length,
- currentGroup = 1,
- calc = [],
- regex = [],
- special = false,
- ch = "";
- for (var i = 0; i < format.length; ++i) {
- ch = format.charAt(i);
- if (!special && ch == "\\") {
- special = true;
- } else if (special) {
- special = false;
- regex.push(Ext.String.escape(ch));
- } else {
- var obj = utilDate.formatCodeToRegex(ch, currentGroup);
- currentGroup += obj.g;
- regex.push(obj.s);
- if (obj.g && obj.c) {
- calc.push(obj.c);
- }
- }
- }
- utilDate.parseRegexes[regexNum] = new RegExp("^" + regex.join('') + "$", 'i');
- utilDate.parseFunctions[format] = Ext.functionFactory("input", "strict", xf(code, regexNum, calc.join('')));
- };
- })(),
- // private
- parseCodes : {
- /*
- * Notes:
- * g = {Number} calculation group (0 or 1. only group 1 contributes to date calculations.)
- * c = {String} calculation method (required for group 1. null for group 0. {0} = currentGroup - position in regex result array)
- * s = {String} regex pattern. all matches are stored in results[], and are accessible by the calculation mapped to 'c'
- */
- d: {
- g:1,
- c:"d = parseInt(results[{0}], 10);\n",
- s:"(\\d{2})" // day of month with leading zeroes (01 - 31)
- },
- j: {
- g:1,
- c:"d = parseInt(results[{0}], 10);\n",
- s:"(\\d{1,2})" // day of month without leading zeroes (1 - 31)
- },
- D: function() {
- for (var a = [], i = 0; i < 7; a.push(utilDate.getShortDayName(i)), ++i); // get localised short day names
- return {
- g:0,
- c:null,
- s:"(?:" + a.join("|") +")"
- };
- },
- l: function() {
- return {
- g:0,
- c:null,
- s:"(?:" + utilDate.dayNames.join("|") + ")"
- };
- },
- N: {
- g:0,
- c:null,
- s:"[1-7]" // ISO-8601 day number (1 (monday) - 7 (sunday))
- },
- S: {
- g:0,
- c:null,
- s:"(?:st|nd|rd|th)"
- },
- w: {
- g:0,
- c:null,
- s:"[0-6]" // javascript day number (0 (sunday) - 6 (saturday))
- },
- z: {
- g:1,
- c:"z = parseInt(results[{0}], 10);\n",
- s:"(\\d{1,3})" // day of the year (0 - 364 (365 in leap years))
- },
- W: {
- g:0,
- c:null,
- s:"(?:\\d{2})" // ISO-8601 week number (with leading zero)
- },
- F: function() {
- return {
- g:1,
- c:"m = parseInt(Ext.Date.getMonthNumber(results[{0}]), 10);\n", // get localised month number
- s:"(" + utilDate.monthNames.join("|") + ")"
- };
- },
- M: function() {
- for (var a = [], i = 0; i < 12; a.push(utilDate.getShortMonthName(i)), ++i); // get localised short month names
- return Ext.applyIf({
- s:"(" + a.join("|") + ")"
- }, utilDate.formatCodeToRegex("F"));
- },
- m: {
- g:1,
- c:"m = parseInt(results[{0}], 10) - 1;\n",
- s:"(\\d{2})" // month number with leading zeros (01 - 12)
- },
- n: {
- g:1,
- c:"m = parseInt(results[{0}], 10) - 1;\n",
- s:"(\\d{1,2})" // month number without leading zeros (1 - 12)
- },
- t: {
- g:0,
- c:null,
- s:"(?:\\d{2})" // no. of days in the month (28 - 31)
- },
- L: {
- g:0,
- c:null,
- s:"(?:1|0)"
- },
- o: function() {
- return utilDate.formatCodeToRegex("Y");
- },
- Y: {
- g:1,
- c:"y = parseInt(results[{0}], 10);\n",
- s:"(\\d{4})" // 4-digit year
- },
- y: {
- g:1,
- c:"var ty = parseInt(results[{0}], 10);\n"
- + "y = ty > Ext.Date.y2kYear ? 1900 + ty : 2000 + ty;\n", // 2-digit year
- s:"(\\d{1,2})"
- },
- /*
- * In the am/pm parsing routines, we allow both upper and lower case
- * even though it doesn't exactly match the spec. It gives much more flexibility
- * in being able to specify case insensitive regexes.
- */
- a: {
- g:1,
- c:"if (/(am)/i.test(results[{0}])) {\n"
- + "if (!h || h == 12) { h = 0; }\n"
- + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
- s:"(am|pm|AM|PM)"
- },
- A: {
- g:1,
- c:"if (/(am)/i.test(results[{0}])) {\n"
- + "if (!h || h == 12) { h = 0; }\n"
- + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
- s:"(AM|PM|am|pm)"
- },
- g: function() {
- return utilDate.formatCodeToRegex("G");
- },
- G: {
- g:1,
- c:"h = parseInt(results[{0}], 10);\n",
- s:"(\\d{1,2})" // 24-hr format of an hour without leading zeroes (0 - 23)
- },
- h: function() {
- return utilDate.formatCodeToRegex("H");
- },
- H: {
- g:1,
- c:"h = parseInt(results[{0}], 10);\n",
- s:"(\\d{2})" // 24-hr format of an hour with leading zeroes (00 - 23)
- },
- i: {
- g:1,
- c:"i = parseInt(results[{0}], 10);\n",
- s:"(\\d{2})" // minutes with leading zeros (00 - 59)
- },
- s: {
- g:1,
- c:"s = parseInt(results[{0}], 10);\n",
- s:"(\\d{2})" // seconds with leading zeros (00 - 59)
- },
- u: {
- g:1,
- c:"ms = results[{0}]; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n",
- s:"(\\d+)" // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
- },
- O: {
- g:1,
- c:[
- "o = results[{0}];",
- "var sn = o.substring(0,1),", // get + / - sign
- "hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
- "mn = o.substring(3,5) % 60;", // get minutes
- "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + Ext.String.leftPad(hr, 2, '0') + Ext.String.leftPad(mn, 2, '0')) : null;\n" // -12hrs <= GMT offset <= 14hrs
- ].join("\n"),
- s: "([+\-]\\d{4})" // GMT offset in hrs and mins
- },
- P: {
- g:1,
- c:[
- "o = results[{0}];",
- "var sn = o.substring(0,1),", // get + / - sign
- "hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
- "mn = o.substring(4,6) % 60;", // get minutes
- "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + Ext.String.leftPad(hr, 2, '0') + Ext.String.leftPad(mn, 2, '0')) : null;\n" // -12hrs <= GMT offset <= 14hrs
- ].join("\n"),
- s: "([+\-]\\d{2}:\\d{2})" // GMT offset in hrs and mins (with colon separator)
- },
- T: {
- g:0,
- c:null,
- s:"[A-Z]{1,4}" // timezone abbrev. may be between 1 - 4 chars
- },
- Z: {
- g:1,
- c:"zz = results[{0}] * 1;\n" // -43200 <= UTC offset <= 50400
- + "zz = (-43200 <= zz && zz <= 50400)? zz : null;\n",
- s:"([+\-]?\\d{1,5})" // leading '+' sign is optional for UTC offset
- },
- c: function() {
- var calc = [],
- arr = [
- utilDate.formatCodeToRegex("Y", 1), // year
- utilDate.formatCodeToRegex("m", 2), // month
- utilDate.formatCodeToRegex("d", 3), // day
- utilDate.formatCodeToRegex("h", 4), // hour
- utilDate.formatCodeToRegex("i", 5), // minute
- utilDate.formatCodeToRegex("s", 6), // second
- {c:"ms = results[7] || '0'; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n"}, // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
- {c:[ // allow either "Z" (i.e. UTC) or "-0530" or "+08:00" (i.e. UTC offset) timezone delimiters. assumes local timezone if no timezone is specified
- "if(results[8]) {", // timezone specified
- "if(results[8] == 'Z'){",
- "zz = 0;", // UTC
- "}else if (results[8].indexOf(':') > -1){",
- utilDate.formatCodeToRegex("P", 8).c, // timezone offset with colon separator
- "}else{",
- utilDate.formatCodeToRegex("O", 8).c, // timezone offset without colon separator
- "}",
- "}"
- ].join('\n')}
- ];
- for (var i = 0, l = arr.length; i < l; ++i) {
- calc.push(arr[i].c);
- }
- return {
- g:1,
- c:calc.join(""),
- s:[
- arr[0].s, // year (required)
- "(?:", "-", arr[1].s, // month (optional)
- "(?:", "-", arr[2].s, // day (optional)
- "(?:",
- "(?:T| )?", // time delimiter -- either a "T" or a single blank space
- arr[3].s, ":", arr[4].s, // hour AND minute, delimited by a single colon (optional). MUST be preceded by either a "T" or a single blank space
- "(?::", arr[5].s, ")?", // seconds (optional)
- "(?:(?:\\.|,)(\\d+))?", // decimal fraction of a second (e.g. ",12345" or ".98765") (optional)
- "(Z|(?:[-+]\\d{2}(?::)?\\d{2}))?", // "Z" (UTC) or "-0530" (UTC offset without colon delimiter) or "+08:00" (UTC offset with colon delimiter) (optional)
- ")?",
- ")?",
- ")?"
- ].join("")
- };
- },
- U: {
- g:1,
- c:"u = parseInt(results[{0}], 10);\n",
- s:"(-?\\d+)" // leading minus sign indicates seconds before UNIX epoch
- }
- },
- //Old Ext.Date prototype methods.
- // private
- dateFormat: function(date, format) {
- return utilDate.format(date, format);
- },
- /**
- * Formats a date given the supplied format string.
- * @param {Date} date The date to format
- * @param {String} format The format string
- * @return {String} The formatted date
- */
- format: function(date, format) {
- if (utilDate.formatFunctions[format] == null) {
- utilDate.createFormat(format);
- }
- var result = utilDate.formatFunctions[format].call(date);
- return result + '';
- },
- /**
- * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
- *
- * Note: The date string returned by the javascript Date object's toString() method varies
- * between browsers (e.g. FF vs IE) and system region settings (e.g. IE in Asia vs IE in America).
- * For a given date string e.g. "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)",
- * getTimezone() first tries to get the timezone abbreviation from between a pair of parentheses
- * (which may or may not be present), failing which it proceeds to get the timezone abbreviation
- * from the GMT offset portion of the date string.
- * @param {Date} date The date
- * @return {String} The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).
- */
- getTimezone : function(date) {
- // the following list shows the differences between date strings from different browsers on a WinXP SP2 machine from an Asian locale:
- //
- // Opera : "Thu, 25 Oct 2007 22:53:45 GMT+0800" -- shortest (weirdest) date string of the lot
- // Safari : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone (same as FF)
- // FF : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone
- // IE : "Thu Oct 25 22:54:35 UTC+0800 2007" -- (Asian system setting) look for 3-4 letter timezone abbrev
- // IE : "Thu Oct 25 17:06:37 PDT 2007" -- (American system setting) look for 3-4 letter timezone abbrev
- //
- // this crazy regex attempts to guess the correct timezone abbreviation despite these differences.
- // step 1: (?:\((.*)\) -- find timezone in parentheses
- // step 2: ([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?) -- if nothing was found in step 1, find timezone from timezone offset portion of date string
- // step 3: remove all non uppercase characters found in step 1 and 2
- return date.toString().replace(/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/, "$1$2").replace(/[^A-Z]/g, "");
- },
- /**
- * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
- * @param {Date} date The date
- * @param {Boolean} colon (optional) true to separate the hours and minutes with a colon (defaults to false).
- * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600').
- */
- getGMTOffset : function(date, colon) {
- var offset = date.getTimezoneOffset();
- return (offset > 0 ? "-" : "+")
- + Ext.String.leftPad(Math.floor(Math.abs(offset) / 60), 2, "0")
- + (colon ? ":" : "")
- + Ext.String.leftPad(Math.abs(offset % 60), 2, "0");
- },
- /**
- * Get the numeric day number of the year, adjusted for leap year.
- * @param {Date} date The date
- * @return {Number} 0 to 364 (365 in leap years).
- */
- getDayOfYear: function(date) {
- var num = 0,
- d = Ext.Date.clone(date),
- m = date.getMonth(),
- i;
- for (i = 0, d.setDate(1), d.setMonth(0); i < m; d.setMonth(++i)) {
- num += utilDate.getDaysInMonth(d);
- }
- return num + date.getDate() - 1;
- },
- /**
- * Get the numeric ISO-8601 week number of the year.
- * (equivalent to the format specifier 'W', but without a leading zero).
- * @param {Date} date The date
- * @return {Number} 1 to 53
- * @method
- */
- getWeekOfYear : (function() {
- // adapted from http://www.merlyn.demon.co.uk/weekcalc.htm
- var ms1d = 864e5, // milliseconds in a day
- ms7d = 7 * ms1d; // milliseconds in a week
- return function(date) { // return a closure so constants get calculated only once
- var DC3 = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate() + 3) / ms1d, // an Absolute Day Number
- AWN = Math.floor(DC3 / 7), // an Absolute Week Number
- Wyr = new Date(AWN * ms7d).getUTCFullYear();
- return AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1;
- };
- })(),
- /**
- * Checks if the current date falls within a leap year.
- * @param {Date} date The date
- * @return {Boolean} True if the current date falls within a leap year, false otherwise.
- */
- isLeapYear : function(date) {
- var year = date.getFullYear();
- return !!((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
- },
- /**
- * Get the first day of the current month, adjusted for leap year. The returned value
- * is the numeric day index within the week (0-6) which can be used in conjunction with
- * the {@link #monthNames} array to retrieve the textual day name.
- * Example:
- * <pre><code>
- var dt = new Date('1/10/2007'),
- firstDay = Ext.Date.getFirstDayOfMonth(dt);
- console.log(Ext.Date.dayNames[firstDay]); //output: 'Monday'
- * </code></pre>
- * @param {Date} date The date
- * @return {Number} The day number (0-6).
- */
- getFirstDayOfMonth : function(date) {
- var day = (date.getDay() - (date.getDate() - 1)) % 7;
- return (day < 0) ? (day + 7) : day;
- },
- /**
- * Get the last day of the current month, adjusted for leap year. The returned value
- * is the numeric day index within the week (0-6) which can be used in conjunction with
- * the {@link #monthNames} array to retrieve the textual day name.
- * Example:
- * <pre><code>
- var dt = new Date('1/10/2007'),
- lastDay = Ext.Date.getLastDayOfMonth(dt);
- console.log(Ext.Date.dayNames[lastDay]); //output: 'Wednesday'
- * </code></pre>
- * @param {Date} date The date
- * @return {Number} The day number (0-6).
- */
- getLastDayOfMonth : function(date) {
- return utilDate.getLastDateOfMonth(date).getDay();
- },
- /**
- * Get the date of the first day of the month in which this date resides.
- * @param {Date} date The date
- * @return {Date}
- */
- getFirstDateOfMonth : function(date) {
- return new Date(date.getFullYear(), date.getMonth(), 1);
- },
- /**
- * Get the date of the last day of the month in which this date resides.
- * @param {Date} date The date
- * @return {Date}
- */
- getLastDateOfMonth : function(date) {
- return new Date(date.getFullYear(), date.getMonth(), utilDate.getDaysInMonth(date));
- },
- /**
- * Get the number of days in the current month, adjusted for leap year.
- * @param {Date} date The date
- * @return {Number} The number of days in the month.
- * @method
- */
- getDaysInMonth: (function() {
- var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
- return function(date) { // return a closure for efficiency
- var m = date.getMonth();
- return m == 1 && utilDate.isLeapYear(date) ? 29 : daysInMonth[m];
- };
- })(),
- /**
- * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
- * @param {Date} date The date
- * @return {String} 'st, 'nd', 'rd' or 'th'.
- */
- getSuffix : function(date) {
- switch (date.getDate()) {
- case 1:
- case 21:
- case 31:
- return "st";
- case 2:
- case 22:
- return "nd";
- case 3:
- case 23:
- return "rd";
- default:
- return "th";
- }
- },
- /**
- * Creates and returns a new Date instance with the exact same date value as the called instance.
- * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
- * variable will also be changed. When the intention is to create a new variable that will not
- * modify the original instance, you should create a clone.
- *
- * Example of correctly cloning a date:
- * <pre><code>
- //wrong way:
- var orig = new Date('10/1/2006');
- var copy = orig;
- copy.setDate(5);
- console.log(orig); //returns 'Thu Oct 05 2006'!
- //correct way:
- var orig = new Date('10/1/2006'),
- copy = Ext.Date.clone(orig);
- copy.setDate(5);
- console.log(orig); //returns 'Thu Oct 01 2006'
- * </code></pre>
- * @param {Date} date The date
- * @return {Date} The new Date instance.
- */
- clone : function(date) {
- return new Date(date.getTime());
- },
- /**
- * Checks if the current date is affected by Daylight Saving Time (DST).
- * @param {Date} date The date
- * @return {Boolean} True if the current date is affected by DST.
- */
- isDST : function(date) {
- // adapted from http://sencha.com/forum/showthread.php?p=247172#post247172
- // courtesy of @geoffrey.mcgill
- return new Date(date.getFullYear(), 0, 1).getTimezoneOffset() != date.getTimezoneOffset();
- },
- /**
- * Attempts to clear all time information from this Date by setting the time to midnight of the same day,
- * automatically adjusting for Daylight Saving Time (DST) where applicable.
- * (note: DST timezone information for the browser's host operating system is assumed to be up-to-date)
- * @param {Date} date The date
- * @param {Boolean} clone true to create a clone of this date, clear the time and return it (defaults to false).
- * @return {Date} this or the clone.
- */
- clearTime : function(date, clone) {
- if (clone) {
- return Ext.Date.clearTime(Ext.Date.clone(date));
- }
- // get current date before clearing time
- var d = date.getDate();
- // clear time
- date.setHours(0);
- date.setMinutes(0);
- date.setSeconds(0);
- date.setMilliseconds(0);
- if (date.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
- // note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the case)
- // refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule
- // increment hour until cloned date == current date
- for (var hr = 1, c = utilDate.add(date, Ext.Date.HOUR, hr); c.getDate() != d; hr++, c = utilDate.add(date, Ext.Date.HOUR, hr));
- date.setDate(d);
- date.setHours(c.getHours());
- }
- return date;
- },
- /**
- * Provides a convenient method for performing basic date arithmetic. This method
- * does not modify the Date instance being called - it creates and returns
- * a new Date instance containing the resulting date value.
- *
- * Examples:
- * <pre><code>
- // Basic usage:
- var dt = Ext.Date.add(new Date('10/29/2006'), Ext.Date.DAY, 5);
- console.log(dt); //returns 'Fri Nov 03 2006 00:00:00'
- // Negative values will be subtracted:
- var dt2 = Ext.Date.add(new Date('10/1/2006'), Ext.Date.DAY, -5);
- console.log(dt2); //returns 'Tue Sep 26 2006 00:00:00'
- * </code></pre>
- *
- * @param {Date} date The date to modify
- * @param {String} interval A valid date interval enum value.
- * @param {Number} value The amount to add to the current date.
- * @return {Date} The new Date instance.
- */
- add : function(date, interval, value) {
- var d = Ext.Date.clone(date),
- Date = Ext.Date;
- if (!interval || value === 0) return d;
- switch(interval.toLowerCase()) {
- case Ext.Date.MILLI:
- d.setMilliseconds(d.getMilliseconds() + value);
- break;
- case Ext.Date.SECOND:
- d.setSeconds(d.getSeconds() + value);
- break;
- case Ext.Date.MINUTE:
- d.setMinutes(d.getMinutes() + value);
- break;
- case Ext.Date.HOUR:
- d.setHours(d.getHours() + value);
- break;
- case Ext.Date.DAY:
- d.setDate(d.getDate() + value);
- break;
- case Ext.Date.MONTH:
- var day = date.getDate();
- if (day > 28) {
- day = Math.min(day, Ext.Date.getLastDateOfMonth(Ext.Date.add(Ext.Date.getFirstDateOfMonth(date), 'mo', value)).getDate());
- }
- d.setDate(day);
- d.setMonth(date.getMonth() + value);
- break;
- case Ext.Date.YEAR:
- d.setFullYear(date.getFullYear() + value);
- break;
- }
- return d;
- },
- /**
- * Checks if a date falls on or between the given start and end dates.
- * @param {Date} date The date to check
- * @param {Date} start Start date
- * @param {Date} end End date
- * @return {Boolean} true if this date falls on or between the given start and end dates.
- */
- between : function(date, start, end) {
- var t = date.getTime();
- return start.getTime() <= t && t <= end.getTime();
- },
- //Maintains compatibility with old static and prototype window.Date methods.
- compat: function() {
- var nativeDate = window.Date,
- p, u,
- statics = ['useStrict', 'formatCodeToRegex', 'parseFunctions', 'parseRegexes', 'formatFunctions', 'y2kYear', 'MILLI', 'SECOND', 'MINUTE', 'HOUR', 'DAY', 'MONTH', 'YEAR', 'defaults', 'dayNames', 'monthNames', 'monthNumbers', 'getShortMonthName', 'getShortDayName', 'getMonthNumber', 'formatCodes', 'isValid', 'parseDate', 'getFormatCode', 'createFormat', 'createParser', 'parseCodes'],
- proto = ['dateFormat', 'format', 'getTimezone', 'getGMTOffset', 'getDayOfYear', 'getWeekOfYear', 'isLeapYear', 'getFirstDayOfMonth', 'getLastDayOfMonth', 'getDaysInMonth', 'getSuffix', 'clone', 'isDST', 'clearTime', 'add', 'between'];
- //Append statics
- Ext.Array.forEach(statics, function(s) {
- nativeDate[s] = utilDate[s];
- });
- //Append to prototype
- Ext.Array.forEach(proto, function(s) {
- nativeDate.prototype[s] = function() {
- var args = Array.prototype.slice.call(arguments);
- args.unshift(this);
- return utilDate[s].apply(utilDate, args);
- };
- });
- }
- };
- var utilDate = Ext.Date;
- })();
- /**
- * @author Jacky Nguyen <jacky@sencha.com>
- * @docauthor Jacky Nguyen <jacky@sencha.com>
- * @class Ext.Base
- *
- * The root of all classes created with {@link Ext#define}.
- *
- * Ext.Base is the building block of all Ext classes. All classes in Ext inherit from Ext.Base.
- * All prototype and static members of this class are inherited by all other classes.
- */
- (function(flexSetter) {
- var Base = Ext.Base = function() {};
- Base.prototype = {
- $className: 'Ext.Base',
- $class: Base,
- /**
- * Get the reference to the current class from which this object was instantiated. Unlike {@link Ext.Base#statics},
- * `this.self` is scope-dependent and it's meant to be used for dynamic inheritance. See {@link Ext.Base#statics}
- * for a detailed comparison
- *
- * Ext.define('My.Cat', {
- * statics: {
- * speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
- * },
- *
- * constructor: function() {
- * alert(this.self.speciesName); / dependent on 'this'
- *
- * return this;
- * },
- *
- * clone: function() {
- * return new this.self();
- * }
- * });
- *
- *
- * Ext.define('My.SnowLeopard', {
- * extend: 'My.Cat',
- * statics: {
- * speciesName: 'Snow Leopard' // My.SnowLeopard.speciesName = 'Snow Leopard'
- * }
- * });
- *
- * var cat = new My.Cat(); // alerts 'Cat'
- * var snowLeopard = new My.SnowLeopard(); // alerts 'Snow Leopard'
- *
- * var clone = snowLeopard.clone();
- * alert(Ext.getClassName(clone)); // alerts 'My.SnowLeopard'
- *
- * @type Ext.Class
- * @protected
- */
- self: Base,
- // Default constructor, simply returns `this`
- constructor: function() {
- return this;
- },
- //<feature classSystem.config>
- /**
- * Initialize configuration for this class. a typical example:
- *
- * Ext.define('My.awesome.Class', {
- * // The default config
- * config: {
- * name: 'Awesome',
- * isAwesome: true
- * },
- *
- * constructor: function(config) {
- * this.initConfig(config);
- *
- * return this;
- * }
- * });
- *
- * var awesome = new My.awesome.Class({
- * name: 'Super Awesome'
- * });
- *
- * alert(awesome.getName()); // 'Super Awesome'
- *
- * @protected
- * @param {Object} config
- * @return {Object} mixins The mixin prototypes as key - value pairs
- */
- initConfig: function(config) {
- if (!this.$configInited) {
- this.config = Ext.Object.merge({}, this.config || {}, config || {});
- this.applyConfig(this.config);
- this.$configInited = true;
- }
- return this;
- },
- /**
- * @private
- */
- setConfig: function(config) {
- this.applyConfig(config || {});
- return this;
- },
- /**
- * @private
- */
- applyConfig: flexSetter(function(name, value) {
- var setter = 'set' + Ext.String.capitalize(name);
- if (typeof this[setter] === 'function') {
- this[setter].call(this, value);
- }
- return this;
- }),
- //</feature>
- /**
- * Call the parent's overridden method. For example:
- *
- * Ext.define('My.own.A', {
- * constructor: function(test) {
- * alert(test);
- * }
- * });
- *
- * Ext.define('My.own.B', {
- * extend: 'My.own.A',
- *
- * constructor: function(test) {
- * alert(test);
- *
- * this.callParent([test + 1]);
- * }
- * });
- *
- * Ext.define('My.own.C', {
- * extend: 'My.own.B',
- *
- * constructor: function() {
- * alert("Going to call parent's overriden constructor...");
- *
- * this.callParent(arguments);
- * }
- * });
- *
- * var a = new My.own.A(1); // alerts '1'
- * var b = new My.own.B(1); // alerts '1', then alerts '2'
- * var c = new My.own.C(2); // alerts "Going to call parent's overriden constructor..."
- * // alerts '2', then alerts '3'
- *
- * @protected
- * @param {Array/Arguments} args The arguments, either an array or the `arguments` object
- * from the current method, for example: `this.callParent(arguments)`
- * @return {Object} Returns the result from the superclass' method
- */
- callParent: function(args) {
- var method = this.callParent.caller,
- parentClass, methodName;
- if (!method.$owner) {
- method = method.caller;
- }
- parentClass = method.$owner.superclass;
- methodName = method.$name;
- return parentClass[methodName].apply(this, args || []);
- },
- /**
- * Get the reference to the class from which this object was instantiated. Note that unlike {@link Ext.Base#self},
- * `this.statics()` is scope-independent and it always returns the class from which it was called, regardless of what
- * `this` points to during run-time
- *
- * Ext.define('My.Cat', {
- * statics: {
- * totalCreated: 0,
- * speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
- * },
- *
- * constructor: function() {
- * var statics = this.statics();
- *
- * alert(statics.speciesName); // always equals to 'Cat' no matter what 'this' refers to
- * // equivalent to: My.Cat.speciesName
- *
- * alert(this.self.speciesName); // dependent on 'this'
- *
- * statics.totalCreated++;
- *
- * return this;
- * },
- *
- * clone: function() {
- * var cloned = new this.self; // dependent on 'this'
- *
- * cloned.groupName = this.statics().speciesName; // equivalent to: My.Cat.speciesName
- *
- * return cloned;
- * }
- * });
- *
- *
- * Ext.define('My.SnowLeopard', {
- * extend: 'My.Cat',
- *
- * statics: {
- * speciesName: 'Snow Leopard' // My.SnowLeopard.speciesName = 'Snow Leopard'
- * },
- *
- * constructor: function() {
- * this.callParent();
- * }
- * });
- *
- * var cat = new My.Cat(); // alerts 'Cat', then alerts 'Cat'
- *
- * var snowLeopard = new My.SnowLeopard(); // alerts 'Cat', then alerts 'Snow Leopard'
- *
- * var clone = snowLeopard.clone();
- * alert(Ext.getClassName(clone)); // alerts 'My.SnowLeopard'
- * alert(clone.groupName); // alerts 'Cat'
- *
- * alert(My.Cat.totalCreated); // alerts 3
- *
- * @protected
- * @return {Ext.Class}
- */
- statics: function() {
- var method = this.statics.caller,
- self = this.self;
- if (!method) {
- return self;
- }
- return method.$owner;
- },
- /**
- * Call the original method that was previously overridden with {@link Ext.Base#override}
- *
- * Ext.define('My.Cat', {
- * constructor: function() {
- * alert("I'm a cat!");
- *
- * return this;
- * }
- * });
- *
- * My.Cat.override({
- * constructor: function() {
- * alert("I'm going to be a cat!");
- *
- * var instance = this.callOverridden();
- *
- * alert("Meeeeoooowwww");
- *
- * return instance;
- * }
- * });
- *
- * var kitty = new My.Cat(); // alerts "I'm going to be a cat!"
- * // alerts "I'm a cat!"
- * // alerts "Meeeeoooowwww"
- *
- * @param {Array/Arguments} args The arguments, either an array or the `arguments` object
- * @return {Object} Returns the result after calling the overridden method
- * @protected
- */
- callOverridden: function(args) {
- var method = this.callOverridden.caller;
- return method.$previous.apply(this, args || []);
- },
- destroy: function() {}
- };
- // These static properties will be copied to every newly created class with {@link Ext#define}
- Ext.apply(Ext.Base, {
- /**
- * Create a new instance of this Class.
- *
- * Ext.define('My.cool.Class', {
- * ...
- * });
- *
- * My.cool.Class.create({
- * someConfig: true
- * });
- *
- * All parameters are passed to the constructor of the class.
- *
- * @return {Object} the created instance.
- * @static
- * @inheritable
- */
- create: function() {
- return Ext.create.apply(Ext, [this].concat(Array.prototype.slice.call(arguments, 0)));
- },
- /**
- * @private
- * @inheritable
- */
- own: function(name, value) {
- if (typeof value == 'function') {
- this.ownMethod(name, value);
- }
- else {
- this.prototype[name] = value;
- }
- },
- /**
- * @private
- * @inheritable
- */
- ownMethod: function(name, fn) {
- var originalFn;
- if (typeof fn.$owner !== 'undefined' && fn !== Ext.emptyFn) {
- originalFn = fn;
- fn = function() {
- return originalFn.apply(this, arguments);
- };
- }
- fn.$owner = this;
- fn.$name = name;
- this.prototype[name] = fn;
- },
- /**
- * Add / override static properties of this class.
- *
- * Ext.define('My.cool.Class', {
- * ...
- * });
- *
- * My.cool.Class.addStatics({
- * someProperty: 'someValue', // My.cool.Class.someProperty = 'someValue'
- * method1: function() { ... }, // My.cool.Class.method1 = function() { ... };
- * method2: function() { ... } // My.cool.Class.method2 = function() { ... };
- * });
- *
- * @param {Object} members
- * @return {Ext.Base} this
- * @static
- * @inheritable
- */
- addStatics: function(members) {
- for (var name in members) {
- if (members.hasOwnProperty(name)) {
- this[name] = members[name];
- }
- }
- return this;
- },
- /**
- * @private
- * @param {Object} members
- */
- addInheritableStatics: function(members) {
- var inheritableStatics,
- hasInheritableStatics,
- prototype = this.prototype,
- name, member;
- inheritableStatics = prototype.$inheritableStatics;
- hasInheritableStatics = prototype.$hasInheritableStatics;
- if (!inheritableStatics) {
- inheritableStatics = prototype.$inheritableStatics = [];
- hasInheritableStatics = prototype.$hasInheritableStatics = {};
- }
- for (name in members) {
- if (members.hasOwnProperty(name)) {
- member = members[name];
- this[name] = member;
- if (!hasInheritableStatics[name]) {
- hasInheritableStatics[name] = true;
- inheritableStatics.push(name);
- }
- }
- }
- return this;
- },
- /**
- * Add methods / properties to the prototype of this class.
- *
- * Ext.define('My.awesome.Cat', {
- * constructor: function() {
- * ...
- * }
- * });
- *
- * My.awesome.Cat.implement({
- * meow: function() {
- * alert('Meowww...');
- * }
- * });
- *
- * var kitty = new My.awesome.Cat;
- * kitty.meow();
- *
- * @param {Object} members
- * @static
- * @inheritable
- */
- implement: function(members) {
- var prototype = this.prototype,
- enumerables = Ext.enumerables,
- name, i, member;
- for (name in members) {
- if (members.hasOwnProperty(name)) {
- member = members[name];
- if (typeof member === 'function') {
- member.$owner = this;
- member.$name = name;
- }
- prototype[name] = member;
- }
- }
- if (enumerables) {
- for (i = enumerables.length; i--;) {
- name = enumerables[i];
- if (members.hasOwnProperty(name)) {
- member = members[name];
- member.$owner = this;
- member.$name = name;
- prototype[name] = member;
- }
- }
- }
- },
- /**
- * Borrow another class' members to the prototype of this class.
- *
- * Ext.define('Bank', {
- * money: '$$$',
- * printMoney: function() {
- * alert('$$$$$$$');
- * }
- * });
- *
- * Ext.define('Thief', {
- * ...
- * });
- *
- * Thief.borrow(Bank, ['money', 'printMoney']);
- *
- * var steve = new Thief();
- *
- * alert(steve.money); // alerts '$$$'
- * steve.printMoney(); // alerts '$$$$$$$'
- *
- * @param {Ext.Base} fromClass The class to borrow members from
- * @param {String/String[]} members The names of the members to borrow
- * @return {Ext.Base} this
- * @static
- * @inheritable
- */
- borrow: function(fromClass, members) {
- var fromPrototype = fromClass.prototype,
- i, ln, member;
- members = Ext.Array.from(members);
- for (i = 0, ln = members.length; i < ln; i++) {
- member = members[i];
- this.own(member, fromPrototype[member]);
- }
- return this;
- },
- /**
- * Override prototype members of this class. Overridden methods can be invoked via
- * {@link Ext.Base#callOverridden}
- *
- * Ext.define('My.Cat', {
- * constructor: function() {
- * alert("I'm a cat!");
- *
- * return this;
- * }
- * });
- *
- * My.Cat.override({
- * constructor: function() {
- * alert("I'm going to be a cat!");
- *
- * var instance = this.callOverridden();
- *
- * alert("Meeeeoooowwww");
- *
- * return instance;
- * }
- * });
- *
- * var kitty = new My.Cat(); // alerts "I'm going to be a cat!"
- * // alerts "I'm a cat!"
- * // alerts "Meeeeoooowwww"
- *
- * @param {Object} members
- * @return {Ext.Base} this
- * @static
- * @inheritable
- */
- override: function(members) {
- var prototype = this.prototype,
- enumerables = Ext.enumerables,
- name, i, member, previous;
- if (arguments.length === 2) {
- name = members;
- member = arguments[1];
- if (typeof member == 'function') {
- if (typeof prototype[name] == 'function') {
- previous = prototype[name];
- member.$previous = previous;
- }
- this.ownMethod(name, member);
- }
- else {
- prototype[name] = member;
- }
- return this;
- }
- for (name in members) {
- if (members.hasOwnProperty(name)) {
- member = members[name];
- if (typeof member === 'function') {
- if (typeof prototype[name] === 'function') {
- previous = prototype[name];
- member.$previous = previous;
- }
- this.ownMethod(name, member);
- }
- else {
- prototype[name] = member;
- }
- }
- }
- if (enumerables) {
- for (i = enumerables.length; i--;) {
- name = enumerables[i];
- if (members.hasOwnProperty(name)) {
- if (typeof prototype[name] !== 'undefined') {
- previous = prototype[name];
- members[name].$previous = previous;
- }
- this.ownMethod(name, members[name]);
- }
- }
- }
- return this;
- },
- //<feature classSystem.mixins>
- /**
- * Used internally by the mixins pre-processor
- * @private
- * @inheritable
- */
- mixin: function(name, cls) {
- var mixin = cls.prototype,
- my = this.prototype,
- key, fn;
- for (key in mixin) {
- if (mixin.hasOwnProperty(key)) {
- if (typeof my[key] === 'undefined' && key !== 'mixins' && key !== 'mixinId') {
- if (typeof mixin[key] === 'function') {
- fn = mixin[key];
- if (typeof fn.$owner === 'undefined') {
- this.ownMethod(key, fn);
- }
- else {
- my[key] = fn;
- }
- }
- else {
- my[key] = mixin[key];
- }
- }
- //<feature classSystem.config>
- else if (key === 'config' && my.config && mixin.config) {
- Ext.Object.merge(my.config, mixin.config);
- }
- //</feature>
- }
- }
- if (typeof mixin.onClassMixedIn !== 'undefined') {
- mixin.onClassMixedIn.call(cls, this);
- }
- if (!my.hasOwnProperty('mixins')) {
- if ('mixins' in my) {
- my.mixins = Ext.Object.merge({}, my.mixins);
- }
- else {
- my.mixins = {};
- }
- }
- my.mixins[name] = mixin;
- },
- //</feature>
- /**
- * Get the current class' name in string format.
- *
- * Ext.define('My.cool.Class', {
- * constructor: function() {
- * alert(this.self.getName()); // alerts 'My.cool.Class'
- * }
- * });
- *
- * My.cool.Class.getName(); // 'My.cool.Class'
- *
- * @return {String} className
- * @static
- * @inheritable
- */
- getName: function() {
- return Ext.getClassName(this);
- },
- /**
- * Create aliases for existing prototype methods. Example:
- *
- * Ext.define('My.cool.Class', {
- * method1: function() { ... },
- * method2: function() { ... }
- * });
- *
- * var test = new My.cool.Class();
- *
- * My.cool.Class.createAlias({
- * method3: 'method1',
- * method4: 'method2'
- * });
- *
- * test.method3(); // test.method1()
- *
- * My.cool.Class.createAlias('method5', 'method3');
- *
- * test.method5(); // test.method3() -> test.method1()
- *
- * @param {String/Object} alias The new method name, or an object to set multiple aliases. See
- * {@link Ext.Function#flexSetter flexSetter}
- * @param {String/Object} origin The original method name
- * @static
- * @inheritable
- * @method
- */
- createAlias: flexSetter(function(alias, origin) {
- this.prototype[alias] = function() {
- return this[origin].apply(this, arguments);
- }
- })
- });
- })(Ext.Function.flexSetter);
- /**
- * @author Jacky Nguyen <jacky@sencha.com>
- * @docauthor Jacky Nguyen <jacky@sencha.com>
- * @class Ext.Class
- *
- * Handles class creation throughout the framework. This is a low level factory that is used by Ext.ClassManager and generally
- * should not be used directly. If you choose to use Ext.Class you will lose out on the namespace, aliasing and depency loading
- * features made available by Ext.ClassManager. The only time you would use Ext.Class directly is to create an anonymous class.
- *
- * If you wish to create a class you should use {@link Ext#define Ext.define} which aliases
- * {@link Ext.ClassManager#create Ext.ClassManager.create} to enable namespacing and dynamic dependency resolution.
- *
- * Ext.Class is the factory and **not** the superclass of everything. For the base class that **all** Ext classes inherit
- * from, see {@link Ext.Base}.
- */
- (function() {
- var Class,
- Base = Ext.Base,
- baseStaticProperties = [],
- baseStaticProperty;
- for (baseStaticProperty in Base) {
- if (Base.hasOwnProperty(baseStaticProperty)) {
- baseStaticProperties.push(baseStaticProperty);
- }
- }
- /**
- * @method constructor
- * Creates new class.
- * @param {Object} classData An object represent the properties of this class
- * @param {Function} createdFn (Optional) The callback function to be executed when this class is fully created.
- * Note that the creation process can be asynchronous depending on the pre-processors used.
- * @return {Ext.Base} The newly created class
- */
- Ext.Class = Class = function(newClass, classData, onClassCreated) {
- if (typeof newClass != 'function') {
- onClassCreated = classData;
- classData = newClass;
- newClass = function() {
- return this.constructor.apply(this, arguments);
- };
- }
- if (!classData) {
- classData = {};
- }
- var preprocessorStack = classData.preprocessors || Class.getDefaultPreprocessors(),
- registeredPreprocessors = Class.getPreprocessors(),
- index = 0,
- preprocessors = [],
- preprocessor, staticPropertyName, process, i, j, ln;
- for (i = 0, ln = baseStaticProperties.length; i < ln; i++) {
- staticPropertyName = baseStaticProperties[i];
- newClass[staticPropertyName] = Base[staticPropertyName];
- }
- delete classData.preprocessors;
- for (j = 0, ln = preprocessorStack.length; j < ln; j++) {
- preprocessor = preprocessorStack[j];
- if (typeof preprocessor == 'string') {
- preprocessor = registeredPreprocessors[preprocessor];
- if (!preprocessor.always) {
- if (classData.hasOwnProperty(preprocessor.name)) {
- preprocessors.push(preprocessor.fn);
- }
- }
- else {
- preprocessors.push(preprocessor.fn);
- }
- }
- else {
- preprocessors.push(preprocessor);
- }
- }
- classData.onClassCreated = onClassCreated || Ext.emptyFn;
- classData.onBeforeClassCreated = function(cls, data) {
- onClassCreated = data.onClassCreated;
- delete data.onBeforeClassCreated;
- delete data.onClassCreated;
- cls.implement(data);
- onClassCreated.call(cls, cls);
- };
- process = function(cls, data) {
- preprocessor = preprocessors[index++];
- if (!preprocessor) {
- data.onBeforeClassCreated.apply(this, arguments);
- return;
- }
- if (preprocessor.call(this, cls, data, process) !== false) {
- process.apply(this, arguments);
- }
- };
- process.call(Class, newClass, classData);
- return newClass;
- };
- Ext.apply(Class, {
- /** @private */
- preprocessors: {},
- /**
- * Register a new pre-processor to be used during the class creation process
- *
- * @member Ext.Class
- * @param {String} name The pre-processor's name
- * @param {Function} fn The callback function to be executed. Typical format:
- *
- * function(cls, data, fn) {
- * // Your code here
- *
- * // Execute this when the processing is finished.
- * // Asynchronous processing is perfectly ok
- * if (fn) {
- * fn.call(this, cls, data);
- * }
- * });
- *
- * @param {Function} fn.cls The created class
- * @param {Object} fn.data The set of properties passed in {@link Ext.Class} constructor
- * @param {Function} fn.fn The callback function that **must** to be executed when this pre-processor finishes,
- * regardless of whether the processing is synchronous or aynchronous
- *
- * @return {Ext.Class} this
- * @static
- */
- registerPreprocessor: function(name, fn, always) {
- this.preprocessors[name] = {
- name: name,
- always: always || false,
- fn: fn
- };
- return this;
- },
- /**
- * Retrieve a pre-processor callback function by its name, which has been registered before
- *
- * @param {String} name
- * @return {Function} preprocessor
- * @static
- */
- getPreprocessor: function(name) {
- return this.preprocessors[name];
- },
- getPreprocessors: function() {
- return this.preprocessors;
- },
- /**
- * Retrieve the array stack of default pre-processors
- *
- * @return {Function[]} defaultPreprocessors
- * @static
- */
- getDefaultPreprocessors: function() {
- return this.defaultPreprocessors || [];
- },
- /**
- * Set the default array stack of default pre-processors
- *
- * @param {Function/Function[]} preprocessors
- * @return {Ext.Class} this
- * @static
- */
- setDefaultPreprocessors: function(preprocessors) {
- this.defaultPreprocessors = Ext.Array.from(preprocessors);
- return this;
- },
- /**
- * Inserts this pre-processor at a specific position in the stack, optionally relative to
- * any existing pre-processor. For example:
- *
- * Ext.Class.registerPreprocessor('debug', function(cls, data, fn) {
- * // Your code here
- *
- * if (fn) {
- * fn.call(this, cls, data);
- * }
- * }).setDefaultPreprocessorPosition('debug', 'last');
- *
- * @param {String} name The pre-processor name. Note that it needs to be registered with
- * {@link #registerPreprocessor registerPreprocessor} before this
- * @param {String} offset The insertion position. Four possible values are:
- * 'first', 'last', or: 'before', 'after' (relative to the name provided in the third argument)
- * @param {String} relativeName
- * @return {Ext.Class} this
- * @static
- */
- setDefaultPreprocessorPosition: function(name, offset, relativeName) {
- var defaultPreprocessors = this.defaultPreprocessors,
- index;
- if (typeof offset == 'string') {
- if (offset === 'first') {
- defaultPreprocessors.unshift(name);
- return this;
- }
- else if (offset === 'last') {
- defaultPreprocessors.push(name);
- return this;
- }
- offset = (offset === 'after') ? 1 : -1;
- }
- index = Ext.Array.indexOf(defaultPreprocessors, relativeName);
- if (index !== -1) {
- Ext.Array.splice(defaultPreprocessors, Math.max(0, index + offset), 0, name);
- }
- return this;
- }
- });
- /**
- * @cfg {String} extend
- * The parent class that this class extends. For example:
- *
- * Ext.define('Person', {
- * say: function(text) { alert(text); }
- * });
- *
- * Ext.define('Developer', {
- * extend: 'Person',
- * say: function(text) { this.callParent(["print "+text]); }
- * });
- */
- Class.registerPreprocessor('extend', function(cls, data) {
- var extend = data.extend,
- base = Ext.Base,
- basePrototype = base.prototype,
- prototype = function() {},
- parent, i, k, ln, staticName, parentStatics,
- parentPrototype, clsPrototype;
- if (extend && extend !== Object) {
- parent = extend;
- }
- else {
- parent = base;
- }
- parentPrototype = parent.prototype;
- prototype.prototype = parentPrototype;
- clsPrototype = cls.prototype = new prototype();
- if (!('$class' in parent)) {
- for (i in basePrototype) {
- if (!parentPrototype[i]) {
- parentPrototype[i] = basePrototype[i];
- }
- }
- }
- clsPrototype.self = cls;
- cls.superclass = clsPrototype.superclass = parentPrototype;
- delete data.extend;
- //<feature classSystem.inheritableStatics>
- // Statics inheritance
- parentStatics = parentPrototype.$inheritableStatics;
- if (parentStatics) {
- for (k = 0, ln = parentStatics.length; k < ln; k++) {
- staticName = parentStatics[k];
- if (!cls.hasOwnProperty(staticName)) {
- cls[staticName] = parent[staticName];
- }
- }
- }
- //</feature>
- //<feature classSystem.config>
- // Merge the parent class' config object without referencing it
- if (parentPrototype.config) {
- clsPrototype.config = Ext.Object.merge({}, parentPrototype.config);
- }
- else {
- clsPrototype.config = {};
- }
- //</feature>
- //<feature classSystem.onClassExtended>
- if (clsPrototype.$onExtended) {
- clsPrototype.$onExtended.call(cls, cls, data);
- }
- if (data.onClassExtended) {
- clsPrototype.$onExtended = data.onClassExtended;
- delete data.onClassExtended;
- }
- //</feature>
- }, true);
- //<feature classSystem.statics>
- /**
- * @cfg {Object} statics
- * List of static methods for this class. For example:
- *
- * Ext.define('Computer', {
- * statics: {
- * factory: function(brand) {
- * // 'this' in static methods refer to the class itself
- * return new this(brand);
- * }
- * },
- *
- * constructor: function() { ... }
- * });
- *
- * var dellComputer = Computer.factory('Dell');
- */
- Class.registerPreprocessor('statics', function(cls, data) {
- cls.addStatics(data.statics);
- delete data.statics;
- });
- //</feature>
- //<feature classSystem.inheritableStatics>
- /**
- * @cfg {Object} inheritableStatics
- * List of inheritable static methods for this class.
- * Otherwise just like {@link #statics} but subclasses inherit these methods.
- */
- Class.registerPreprocessor('inheritableStatics', function(cls, data) {
- cls.addInheritableStatics(data.inheritableStatics);
- delete data.inheritableStatics;
- });
- //</feature>
- //<feature classSystem.config>
- /**
- * @cfg {Object} config
- * List of configuration options with their default values, for which automatically
- * accessor methods are generated. For example:
- *
- * Ext.define('SmartPhone', {
- * config: {
- * hasTouchScreen: false,
- * operatingSystem: 'Other',
- * price: 500
- * },
- * constructor: function(cfg) {
- * this.initConfig(cfg);
- * }
- * });
- *
- * var iPhone = new SmartPhone({
- * hasTouchScreen: true,
- * operatingSystem: 'iOS'
- * });
- *
- * iPhone.getPrice(); // 500;
- * iPhone.getOperatingSystem(); // 'iOS'
- * iPhone.getHasTouchScreen(); // true;
- * iPhone.hasTouchScreen(); // true
- */
- Class.registerPreprocessor('config', function(cls, data) {
- var prototype = cls.prototype;
- Ext.Object.each(data.config, function(name) {
- var cName = name.charAt(0).toUpperCase() + name.substr(1),
- pName = name,
- apply = 'apply' + cName,
- setter = 'set' + cName,
- getter = 'get' + cName;
- if (!(apply in prototype) && !data.hasOwnProperty(apply)) {
- data[apply] = function(val) {
- return val;
- };
- }
- if (!(setter in prototype) && !data.hasOwnProperty(setter)) {
- data[setter] = function(val) {
- var ret = this[apply].call(this, val, this[pName]);
- if (typeof ret != 'undefined') {
- this[pName] = ret;
- }
- return this;
- };
- }
- if (!(getter in prototype) && !data.hasOwnProperty(getter)) {
- data[getter] = function() {
- return this[pName];
- };
- }
- });
- Ext.Object.merge(prototype.config, data.config);
- delete data.config;
- });
- //</feature>
- //<feature classSystem.mixins>
- /**
- * @cfg {Object} mixins
- * List of classes to mix into this class. For example:
- *
- * Ext.define('CanSing', {
- * sing: function() {
- * alert("I'm on the highway to hell...")
- * }
- * });
- *
- * Ext.define('Musician', {
- * extend: 'Person',
- *
- * mixins: {
- * canSing: 'CanSing'
- * }
- * })
- */
- Class.registerPreprocessor('mixins', function(cls, data) {
- var mixins = data.mixins,
- name, mixin, i, ln;
- delete data.mixins;
- Ext.Function.interceptBefore(data, 'onClassCreated', function(cls) {
- if (mixins instanceof Array) {
- for (i = 0,ln = mixins.length; i < ln; i++) {
- mixin = mixins[i];
- name = mixin.prototype.mixinId || mixin.$className;
- cls.mixin(name, mixin);
- }
- }
- else {
- for (name in mixins) {
- if (mixins.hasOwnProperty(name)) {
- cls.mixin(name, mixins[name]);
- }
- }
- }
- });
- });
- //</feature>
- Class.setDefaultPreprocessors([
- 'extend'
- //<feature classSystem.statics>
- ,'statics'
- //</feature>
- //<feature classSystem.inheritableStatics>
- ,'inheritableStatics'
- //</feature>
- //<feature classSystem.config>
- ,'config'
- //</feature>
- //<feature classSystem.mixins>
- ,'mixins'
- //</feature>
- ]);
- //<feature classSystem.backwardsCompatible>
- // Backwards compatible
- Ext.extend = function(subclass, superclass, members) {
- if (arguments.length === 2 && Ext.isObject(superclass)) {
- members = superclass;
- superclass = subclass;
- subclass = null;
- }
- var cls;
- if (!superclass) {
- Ext.Error.raise("Attempting to extend from a class which has not been loaded on the page.");
- }
- members.extend = superclass;
- members.preprocessors = [
- 'extend'
- //<feature classSystem.statics>
- ,'statics'
- //</feature>
- //<feature classSystem.inheritableStatics>
- ,'inheritableStatics'
- //</feature>
- //<feature classSystem.mixins>
- ,'mixins'
- //</feature>
- //<feature classSystem.config>
- ,'config'
- //</feature>
- ];
- if (subclass) {
- cls = new Class(subclass, members);
- }
- else {
- cls = new Class(members);
- }
- cls.prototype.override = function(o) {
- for (var m in o) {
- if (o.hasOwnProperty(m)) {
- this[m] = o[m];
- }
- }
- };
- return cls;
- };
- //</feature>
- })();
- /**
- * @author Jacky Nguyen <jacky@sencha.com>
- * @docauthor Jacky Nguyen <jacky@sencha.com>
- * @class Ext.ClassManager
- *
- * Ext.ClassManager manages all classes and handles mapping from string class name to
- * actual class objects throughout the whole framework. It is not generally accessed directly, rather through
- * these convenient shorthands:
- *
- * - {@link Ext#define Ext.define}
- * - {@link Ext#create Ext.create}
- * - {@link Ext#widget Ext.widget}
- * - {@link Ext#getClass Ext.getClass}
- * - {@link Ext#getClassName Ext.getClassName}
- *
- * # Basic syntax:
- *
- * Ext.define(className, properties);
- *
- * in which `properties` is an object represent a collection of properties that apply to the class. See
- * {@link Ext.ClassManager#create} for more detailed instructions.
- *
- * Ext.define('Person', {
- * name: 'Unknown',
- *
- * constructor: function(name) {
- * if (name) {
- * this.name = name;
- * }
- *
- * return this;
- * },
- *
- * eat: function(foodType) {
- * alert("I'm eating: " + foodType);
- *
- * return this;
- * }
- * });
- *
- * var aaron = new Person("Aaron");
- * aaron.eat("Sandwich"); // alert("I'm eating: Sandwich");
- *
- * Ext.Class has a powerful set of extensible {@link Ext.Class#registerPreprocessor pre-processors} which takes care of
- * everything related to class creation, including but not limited to inheritance, mixins, configuration, statics, etc.
- *
- * # Inheritance:
- *
- * Ext.define('Developer', {
- * extend: 'Person',
- *
- * constructor: function(name, isGeek) {
- * this.isGeek = isGeek;
- *
- * // Apply a method from the parent class' prototype
- * this.callParent([name]);
- *
- * return this;
- *
- * },
- *
- * code: function(language) {
- * alert("I'm coding in: " + language);
- *
- * this.eat("Bugs");
- *
- * return this;
- * }
- * });
- *
- * var jacky = new Developer("Jacky", true);
- * jacky.code("JavaScript"); // alert("I'm coding in: JavaScript");
- * // alert("I'm eating: Bugs");
- *
- * See {@link Ext.Base#callParent} for more details on calling superclass' methods
- *
- * # Mixins:
- *
- * Ext.define('CanPlayGuitar', {
- * playGuitar: function() {
- * alert("F#...G...D...A");
- * }
- * });
- *
- * Ext.define('CanComposeSongs', {
- * composeSongs: function() { ... }
- * });
- *
- * Ext.define('CanSing', {
- * sing: function() {
- * alert("I'm on the highway to hell...")
- * }
- * });
- *
- * Ext.define('Musician', {
- * extend: 'Person',
- *
- * mixins: {
- * canPlayGuitar: 'CanPlayGuitar',
- * canComposeSongs: 'CanComposeSongs',
- * canSing: 'CanSing'
- * }
- * })
- *
- * Ext.define('CoolPerson', {
- * extend: 'Person',
- *
- * mixins: {
- * canPlayGuitar: 'CanPlayGuitar',
- * canSing: 'CanSing'
- * },
- *
- * sing: function() {
- * alert("Ahem....");
- *
- * this.mixins.canSing.sing.call(this);
- *
- * alert("[Playing guitar at the same time...]");
- *
- * this.playGuitar();
- * }
- * });
- *
- * var me = new CoolPerson("Jacky");
- *
- * me.sing(); // alert("Ahem...");
- * // alert("I'm on the highway to hell...");
- * // alert("[Playing guitar at the same time...]");
- * // alert("F#...G...D...A");
- *
- * # Config:
- *
- * Ext.define('SmartPhone', {
- * config: {
- * hasTouchScreen: false,
- * operatingSystem: 'Other',
- * price: 500
- * },
- *
- * isExpensive: false,
- *
- * constructor: function(config) {
- * this.initConfig(config);
- *
- * return this;
- * },
- *
- * applyPrice: function(price) {
- * this.isExpensive = (price > 500);
- *
- * return price;
- * },
- *
- * applyOperatingSystem: function(operatingSystem) {
- * if (!(/^(iOS|Android|BlackBerry)$/i).test(operatingSystem)) {
- * return 'Other';
- * }
- *
- * return operatingSystem;
- * }
- * });
- *
- * var iPhone = new SmartPhone({
- * hasTouchScreen: true,
- * operatingSystem: 'iOS'
- * });
- *
- * iPhone.getPrice(); // 500;
- * iPhone.getOperatingSystem(); // 'iOS'
- * iPhone.getHasTouchScreen(); // true;
- * iPhone.hasTouchScreen(); // true
- *
- * iPhone.isExpensive; // false;
- * iPhone.setPrice(600);
- * iPhone.getPrice(); // 600
- * iPhone.isExpensive; // true;
- *
- * iPhone.setOperatingSystem('AlienOS');
- * iPhone.getOperatingSystem(); // 'Other'
- *
- * # Statics:
- *
- * Ext.define('Computer', {
- * statics: {
- * factory: function(brand) {
- * // 'this' in static methods refer to the class itself
- * return new this(brand);
- * }
- * },
- *
- * constructor: function() { ... }
- * });
- *
- * var dellComputer = Computer.factory('Dell');
- *
- * Also see {@link Ext.Base#statics} and {@link Ext.Base#self} for more details on accessing
- * static properties within class methods
- *
- * @singleton
- */
- (function(Class, alias) {
- var slice = Array.prototype.slice;
- var Manager = Ext.ClassManager = {
- /**
- * @property {Object} classes
- * All classes which were defined through the ClassManager. Keys are the
- * name of the classes and the values are references to the classes.
- * @private
- */
- classes: {},
- /**
- * @private
- */
- existCache: {},
- /**
- * @private
- */
- namespaceRewrites: [{
- from: 'Ext.',
- to: Ext
- }],
- /**
- * @private
- */
- maps: {
- alternateToName: {},
- aliasToName: {},
- nameToAliases: {}
- },
- /** @private */
- enableNamespaceParseCache: true,
- /** @private */
- namespaceParseCache: {},
- /** @private */
- instantiators: [],
- /**
- * Checks if a class has already been created.
- *
- * @param {String} className
- * @return {Boolean} exist
- */
- isCreated: function(className) {
- var i, ln, part, root, parts;
- if (this.classes.hasOwnProperty(className) || this.existCache.hasOwnProperty(className)) {
- return true;
- }
- root = Ext.global;
- parts = this.parseNamespace(className);
- for (i = 0, ln = parts.length; i < ln; i++) {
- part = parts[i];
- if (typeof part !== 'string') {
- root = part;
- } else {
- if (!root || !root[part]) {
- return false;
- }
- root = root[part];
- }
- }
- Ext.Loader.historyPush(className);
- this.existCache[className] = true;
- return true;
- },
- /**
- * Supports namespace rewriting
- * @private
- */
- parseNamespace: function(namespace) {
- var cache = this.namespaceParseCache;
- if (this.enableNamespaceParseCache) {
- if (cache.hasOwnProperty(namespace)) {
- return cache[namespace];
- }
- }
- var parts = [],
- rewrites = this.namespaceRewrites,
- rewrite, from, to, i, ln, root = Ext.global;
- for (i = 0, ln = rewrites.length; i < ln; i++) {
- rewrite = rewrites[i];
- from = rewrite.from;
- to = rewrite.to;
- if (namespace === from || namespace.substring(0, from.length) === from) {
- namespace = namespace.substring(from.length);
- if (typeof to !== 'string') {
- root = to;
- } else {
- parts = parts.concat(to.split('.'));
- }
- break;
- }
- }
- parts.push(root);
- parts = parts.concat(namespace.split('.'));
- if (this.enableNamespaceParseCache) {
- cache[namespace] = parts;
- }
- return parts;
- },
- /**
- * Creates a namespace and assign the `value` to the created object
- *
- * Ext.ClassManager.setNamespace('MyCompany.pkg.Example', someObject);
- *
- * alert(MyCompany.pkg.Example === someObject); // alerts true
- *
- * @param {String} name
- * @param {Object} value
- */
- setNamespace: function(name, value) {
- var root = Ext.global,
- parts = this.parseNamespace(name),
- ln = parts.length - 1,
- leaf = parts[ln],
- i, part;
- for (i = 0; i < ln; i++) {
- part = parts[i];
- if (typeof part !== 'string') {
- root = part;
- } else {
- if (!root[part]) {
- root[part] = {};
- }
- root = root[part];
- }
- }
- root[leaf] = value;
- return root[leaf];
- },
- /**
- * The new Ext.ns, supports namespace rewriting
- * @private
- */
- createNamespaces: function() {
- var root = Ext.global,
- parts, part, i, j, ln, subLn;
- for (i = 0, ln = arguments.length; i < ln; i++) {
- parts = this.parseNamespace(arguments[i]);
- for (j = 0, subLn = parts.length; j < subLn; j++) {
- part = parts[j];
- if (typeof part !== 'string') {
- root = part;
- } else {
- if (!root[part]) {
- root[part] = {};
- }
- root = root[part];
- }
- }
- }
- return root;
- },
- /**
- * Sets a name reference to a class.
- *
- * @param {String} name
- * @param {Object} value
- * @return {Ext.ClassManager} this
- */
- set: function(name, value) {
- var targetName = this.getName(value);
- this.classes[name] = this.setNamespace(name, value);
- if (targetName && targetName !== name) {
- this.maps.alternateToName[name] = targetName;
- }
- return this;
- },
- /**
- * Retrieve a class by its name.
- *
- * @param {String} name
- * @return {Ext.Class} class
- */
- get: function(name) {
- if (this.classes.hasOwnProperty(name)) {
- return this.classes[name];
- }
- var root = Ext.global,
- parts = this.parseNamespace(name),
- part, i, ln;
- for (i = 0, ln = parts.length; i < ln; i++) {
- part = parts[i];
- if (typeof part !== 'string') {
- root = part;
- } else {
- if (!root || !root[part]) {
- return null;
- }
- root = root[part];
- }
- }
- return root;
- },
- /**
- * Register the alias for a class.
- *
- * @param {Ext.Class/String} cls a reference to a class or a className
- * @param {String} alias Alias to use when referring to this class
- */
- setAlias: function(cls, alias) {
- var aliasToNameMap = this.maps.aliasToName,
- nameToAliasesMap = this.maps.nameToAliases,
- className;
- if (typeof cls === 'string') {
- className = cls;
- } else {
- className = this.getName(cls);
- }
- if (alias && aliasToNameMap[alias] !== className) {
- aliasToNameMap[alias] = className;
- }
- if (!nameToAliasesMap[className]) {
- nameToAliasesMap[className] = [];
- }
- if (alias) {
- Ext.Array.include(nameToAliasesMap[className], alias);
- }
- return this;
- },
- /**
- * Get a reference to the class by its alias.
- *
- * @param {String} alias
- * @return {Ext.Class} class
- */
- getByAlias: function(alias) {
- return this.get(this.getNameByAlias(alias));
- },
- /**
- * Get the name of a class by its alias.
- *
- * @param {String} alias
- * @return {String} className
- */
- getNameByAlias: function(alias) {
- return this.maps.aliasToName[alias] || '';
- },
- /**
- * Get the name of a class by its alternate name.
- *
- * @param {String} alternate
- * @return {String} className
- */
- getNameByAlternate: function(alternate) {
- return this.maps.alternateToName[alternate] || '';
- },
- /**
- * Get the aliases of a class by the class name
- *
- * @param {String} name
- * @return {String[]} aliases
- */
- getAliasesByName: function(name) {
- return this.maps.nameToAliases[name] || [];
- },
- /**
- * Get the name of the class by its reference or its instance.
- *
- * Ext.ClassManager.getName(Ext.Action); // returns "Ext.Action"
- *
- * {@link Ext#getClassName Ext.getClassName} is alias for {@link Ext.ClassManager#getName Ext.ClassManager.getName}.
- *
- * @param {Ext.Class/Object} object
- * @return {String} className
- */
- getName: function(object) {
- return object && object.$className || '';
- },
- /**
- * Get the class of the provided object; returns null if it's not an instance
- * of any class created with Ext.define.
- *
- * var component = new Ext.Component();
- *
- * Ext.ClassManager.getClass(component); // returns Ext.Component
- *
- * {@link Ext#getClass Ext.getClass} is alias for {@link Ext.ClassManager#getClass Ext.ClassManager.getClass}.
- *
- * @param {Object} object
- * @return {Ext.Class} class
- */
- getClass: function(object) {
- return object && object.self || null;
- },
- /**
- * Defines a class.
- *
- * {@link Ext#define Ext.define} and {@link Ext.ClassManager#create Ext.ClassManager.create} are almost aliases
- * of each other, with the only exception that Ext.define allows definition of {@link Ext.Class#override overrides}.
- * To avoid trouble, always use Ext.define.
- *
- * Ext.define('My.awesome.Class', {
- * someProperty: 'something',
- * someMethod: function() { ... }
- * ...
- *
- * }, function() {
- * alert('Created!');
- * alert(this === My.awesome.Class); // alerts true
- *
- * var myInstance = new this();
- * });
- *
- * @param {String} className The class name to create in string dot-namespaced format, for example:
- * `My.very.awesome.Class`, `FeedViewer.plugin.CoolPager`. It is highly recommended to follow this simple convention:
- *
- * - The root and the class name are 'CamelCased'
- * - Everything else is lower-cased
- *
- * @param {Object} data The key-value pairs of properties to apply to this class. Property names can be of any valid
- * strings, except those in the reserved list below:
- *
- * - {@link Ext.Base#self self}
- * - {@link Ext.Class#alias alias}
- * - {@link Ext.Class#alternateClassName alternateClassName}
- * - {@link Ext.Class#config config}
- * - {@link Ext.Class#extend extend}
- * - {@link Ext.Class#inheritableStatics inheritableStatics}
- * - {@link Ext.Class#mixins mixins}
- * - {@link Ext.Class#override override} (only when using {@link Ext#define Ext.define})
- * - {@link Ext.Class#requires requires}
- * - {@link Ext.Class#singleton singleton}
- * - {@link Ext.Class#statics statics}
- * - {@link Ext.Class#uses uses}
- *
- * @param {Function} [createdFn] callback to execute after the class is created, the execution scope of which
- * (`this`) will be the newly created class itself.
- *
- * @return {Ext.Base}
- */
- create: function(className, data, createdFn) {
- var manager = this;
- data.$className = className;
- return new Class(data, function() {
- var postprocessorStack = data.postprocessors || manager.defaultPostprocessors,
- registeredPostprocessors = manager.postprocessors,
- index = 0,
- postprocessors = [],
- postprocessor, process, i, ln;
- delete data.postprocessors;
- for (i = 0, ln = postprocessorStack.length; i < ln; i++) {
- postprocessor = postprocessorStack[i];
- if (typeof postprocessor === 'string') {
- postprocessor = registeredPostprocessors[postprocessor];
- if (!postprocessor.always) {
- if (data[postprocessor.name] !== undefined) {
- postprocessors.push(postprocessor.fn);
- }
- }
- else {
- postprocessors.push(postprocessor.fn);
- }
- }
- else {
- postprocessors.push(postprocessor);
- }
- }
- process = function(clsName, cls, clsData) {
- postprocessor = postprocessors[index++];
- if (!postprocessor) {
- manager.set(className, cls);
- Ext.Loader.historyPush(className);
- if (createdFn) {
- createdFn.call(cls, cls);
- }
- return;
- }
- if (postprocessor.call(this, clsName, cls, clsData, process) !== false) {
- process.apply(this, arguments);
- }
- };
- process.call(manager, className, this, data);
- });
- },
- /**
- * Instantiate a class by its alias.
- *
- * If {@link Ext.Loader} is {@link Ext.Loader#setConfig enabled} and the class has not been defined yet, it will
- * attempt to load the class via synchronous loading.
- *
- * var window = Ext.ClassManager.instantiateByAlias('widget.window', { width: 600, height: 800, ... });
- *
- * {@link Ext#createByAlias Ext.createByAlias} is alias for {@link Ext.ClassManager#instantiateByAlias Ext.ClassManager.instantiateByAlias}.
- *
- * @param {String} alias
- * @param {Object...} args Additional arguments after the alias will be passed to the
- * class constructor.
- * @return {Object} instance
- */
- instantiateByAlias: function() {
- var alias = arguments[0],
- args = slice.call(arguments),
- className = this.getNameByAlias(alias);
- if (!className) {
- className = this.maps.aliasToName[alias];
- Ext.syncRequire(className);
- }
- args[0] = className;
- return this.instantiate.apply(this, args);
- },
- /**
- * Instantiate a class by either full name, alias or alternate name.
- *
- * If {@link Ext.Loader} is {@link Ext.Loader#setConfig enabled} and the class has not been defined yet, it will
- * attempt to load the class via synchronous loading.
- *
- * For example, all these three lines return the same result:
- *
- * // alias
- * var window = Ext.ClassManager.instantiate('widget.window', { width: 600, height: 800, ... });
- *
- * // alternate name
- * var window = Ext.ClassManager.instantiate('Ext.Window', { width: 600, height: 800, ... });
- *
- * // full class name
- * var window = Ext.ClassManager.instantiate('Ext.window.Window', { width: 600, height: 800, ... });
- *
- * {@link Ext#create Ext.create} is alias for {@link Ext.ClassManager#instantiate Ext.ClassManager.instantiate}.
- *
- * @param {String} name
- * @param {Object...} args Additional arguments after the name will be passed to the class' constructor.
- * @return {Object} instance
- */
- instantiate: function() {
- var name = arguments[0],
- args = slice.call(arguments, 1),
- alias = name,
- possibleName, cls;
- if (typeof name !== 'function') {
- cls = this.get(name);
- }
- else {
- cls = name;
- }
- // No record of this class name, it's possibly an alias, so look it up
- if (!cls) {
- possibleName = this.getNameByAlias(name);
- if (possibleName) {
- name = possibleName;
- cls = this.get(name);
- }
- }
- // Still no record of this class name, it's possibly an alternate name, so look it up
- if (!cls) {
- possibleName = this.getNameByAlternate(name);
- if (possibleName) {
- name = possibleName;
- cls = this.get(name);
- }
- }
- // Still not existing at this point, try to load it via synchronous mode as the last resort
- if (!cls) {
- Ext.syncRequire(name);
- cls = this.get(name);
- }
- return this.getInstantiator(args.length)(cls, args);
- },
- /**
- * @private
- * @param name
- * @param args
- */
- dynInstantiate: function(name, args) {
- args = Ext.Array.from(args, true);
- args.unshift(name);
- return this.instantiate.apply(this, args);
- },
- /**
- * @private
- * @param length
- */
- getInstantiator: function(length) {
- if (!this.instantiators[length]) {
- var i = length,
- args = [];
- for (i = 0; i < length; i++) {
- args.push('a['+i+']');
- }
- this.instantiators[length] = new Function('c', 'a', 'return new c('+args.join(',')+')');
- }
- return this.instantiators[length];
- },
- /**
- * @private
- */
- postprocessors: {},
- /**
- * @private
- */
- defaultPostprocessors: [],
- /**
- * Register a post-processor function.
- *
- * @param {String} name
- * @param {Function} postprocessor
- */
- registerPostprocessor: function(name, fn, always) {
- this.postprocessors[name] = {
- name: name,
- always: always || false,
- fn: fn
- };
- return this;
- },
- /**
- * Set the default post processors array stack which are applied to every class.
- *
- * @param {String/String[]} The name of a registered post processor or an array of registered names.
- * @return {Ext.ClassManager} this
- */
- setDefaultPostprocessors: function(postprocessors) {
- this.defaultPostprocessors = Ext.Array.from(postprocessors);
- return this;
- },
- /**
- * Insert this post-processor at a specific position in the stack, optionally relative to
- * any existing post-processor
- *
- * @param {String} name The post-processor name. Note that it needs to be registered with
- * {@link Ext.ClassManager#registerPostprocessor} before this
- * @param {String} offset The insertion position. Four possible values are:
- * 'first', 'last', or: 'before', 'after' (relative to the name provided in the third argument)
- * @param {String} relativeName
- * @return {Ext.ClassManager} this
- */
- setDefaultPostprocessorPosition: function(name, offset, relativeName) {
- var defaultPostprocessors = this.defaultPostprocessors,
- index;
- if (typeof offset === 'string') {
- if (offset === 'first') {
- defaultPostprocessors.unshift(name);
- return this;
- }
- else if (offset === 'last') {
- defaultPostprocessors.push(name);
- return this;
- }
- offset = (offset === 'after') ? 1 : -1;
- }
- index = Ext.Array.indexOf(defaultPostprocessors, relativeName);
- if (index !== -1) {
- Ext.Array.splice(defaultPostprocessors, Math.max(0, index + offset), 0, name);
- }
- return this;
- },
- /**
- * Converts a string expression to an array of matching class names. An expression can either refers to class aliases
- * or class names. Expressions support wildcards:
- *
- * // returns ['Ext.window.Window']
- * var window = Ext.ClassManager.getNamesByExpression('widget.window');
- *
- * // returns ['widget.panel', 'widget.window', ...]
- * var allWidgets = Ext.ClassManager.getNamesByExpression('widget.*');
- *
- * // returns ['Ext.data.Store', 'Ext.data.ArrayProxy', ...]
- * var allData = Ext.ClassManager.getNamesByExpression('Ext.data.*');
- *
- * @param {String} expression
- * @return {String[]} classNames
- */
- getNamesByExpression: function(expression) {
- var nameToAliasesMap = this.maps.nameToAliases,
- names = [],
- name, alias, aliases, possibleName, regex, i, ln;
- if (expression.indexOf('*') !== -1) {
- expression = expression.replace(/\*/g, '(.*?)');
- regex = new RegExp('^' + expression + '$');
- for (name in nameToAliasesMap) {
- if (nameToAliasesMap.hasOwnProperty(name)) {
- aliases = nameToAliasesMap[name];
- if (name.search(regex) !== -1) {
- names.push(name);
- }
- else {
- for (i = 0, ln = aliases.length; i < ln; i++) {
- alias = aliases[i];
- if (alias.search(regex) !== -1) {
- names.push(name);
- break;
- }
- }
- }
- }
- }
- } else {
- possibleName = this.getNameByAlias(expression);
- if (possibleName) {
- names.push(possibleName);
- } else {
- possibleName = this.getNameByAlternate(expression);
- if (possibleName) {
- names.push(possibleName);
- } else {
- names.push(expression);
- }
- }
- }
- return names;
- }
- };
- var defaultPostprocessors = Manager.defaultPostprocessors;
- //<feature classSystem.alias>
- /**
- * @cfg {String[]} alias
- * @member Ext.Class
- * List of short aliases for class names. Most useful for defining xtypes for widgets:
- *
- * Ext.define('MyApp.CoolPanel', {
- * extend: 'Ext.panel.Panel',
- * alias: ['widget.coolpanel'],
- * title: 'Yeah!'
- * });
- *
- * // Using Ext.create
- * Ext.widget('widget.coolpanel');
- * // Using the shorthand for widgets and in xtypes
- * Ext.widget('panel', {
- * items: [
- * {xtype: 'coolpanel', html: 'Foo'},
- * {xtype: 'coolpanel', html: 'Bar'}
- * ]
- * });
- */
- Manager.registerPostprocessor('alias', function(name, cls, data) {
- var aliases = data.alias,
- i, ln;
- delete data.alias;
- for (i = 0, ln = aliases.length; i < ln; i++) {
- alias = aliases[i];
- this.setAlias(cls, alias);
- }
- });
- /**
- * @cfg {Boolean} singleton
- * @member Ext.Class
- * When set to true, the class will be instantiated as singleton. For example:
- *
- * Ext.define('Logger', {
- * singleton: true,
- * log: function(msg) {
- * console.log(msg);
- * }
- * });
- *
- * Logger.log('Hello');
- */
- Manager.registerPostprocessor('singleton', function(name, cls, data, fn) {
- fn.call(this, name, new cls(), data);
- return false;
- });
- /**
- * @cfg {String/String[]} alternateClassName
- * @member Ext.Class
- * Defines alternate names for this class. For example:
- *
- * Ext.define('Developer', {
- * alternateClassName: ['Coder', 'Hacker'],
- * code: function(msg) {
- * alert('Typing... ' + msg);
- * }
- * });
- *
- * var joe = Ext.create('Developer');
- * joe.code('stackoverflow');
- *
- * var rms = Ext.create('Hacker');
- * rms.code('hack hack');
- */
- Manager.registerPostprocessor('alternateClassName', function(name, cls, data) {
- var alternates = data.alternateClassName,
- i, ln, alternate;
- if (!(alternates instanceof Array)) {
- alternates = [alternates];
- }
- for (i = 0, ln = alternates.length; i < ln; i++) {
- alternate = alternates[i];
- this.set(alternate, cls);
- }
- });
- Manager.setDefaultPostprocessors(['alias', 'singleton', 'alternateClassName']);
- Ext.apply(Ext, {
- /**
- * @method
- * @member Ext
- * @alias Ext.ClassManager#instantiate
- */
- create: alias(Manager, 'instantiate'),
- /**
- * @private
- * API to be stablized
- *
- * @param {Object} item
- * @param {String} namespace
- */
- factory: function(item, namespace) {
- if (item instanceof Array) {
- var i, ln;
- for (i = 0, ln = item.length; i < ln; i++) {
- item[i] = Ext.factory(item[i], namespace);
- }
- return item;
- }
- var isString = (typeof item === 'string');
- if (isString || (item instanceof Object && item.constructor === Object)) {
- var name, config = {};
- if (isString) {
- name = item;
- }
- else {
- name = item.className;
- config = item;
- delete config.className;
- }
- if (namespace !== undefined && name.indexOf(namespace) === -1) {
- name = namespace + '.' + Ext.String.capitalize(name);
- }
- return Ext.create(name, config);
- }
- if (typeof item === 'function') {
- return Ext.create(item);
- }
- return item;
- },
- /**
- * Convenient shorthand to create a widget by its xtype, also see {@link Ext.ClassManager#instantiateByAlias}
- *
- * var button = Ext.widget('button'); // Equivalent to Ext.create('widget.button')
- * var panel = Ext.widget('panel'); // Equivalent to Ext.create('widget.panel')
- *
- * @method
- * @member Ext
- * @param {String} name xtype of the widget to create.
- * @param {Object...} args arguments for the widget constructor.
- * @return {Object} widget instance
- */
- widget: function(name) {
- var args = slice.call(arguments);
- args[0] = 'widget.' + name;
- return Manager.instantiateByAlias.apply(Manager, args);
- },
- /**
- * @method
- * @member Ext
- * @alias Ext.ClassManager#instantiateByAlias
- */
- createByAlias: alias(Manager, 'instantiateByAlias'),
- /**
- * @cfg {String} override
- * @member Ext.Class
- *
- * Defines an override applied to a class. Note that **overrides can only be created using
- * {@link Ext#define}.** {@link Ext.ClassManager#create} only creates classes.
- *
- * To define an override, include the override property. The content of an override is
- * aggregated with the specified class in order to extend or modify that class. This can be
- * as simple as setting default property values or it can extend and/or replace methods.
- * This can also extend the statics of the class.
- *
- * One use for an override is to break a large class into manageable pieces.
- *
- * // File: /src/app/Panel.js
- *
- * Ext.define('My.app.Panel', {
- * extend: 'Ext.panel.Panel',
- * requires: [
- * 'My.app.PanelPart2',
- * 'My.app.PanelPart3'
- * ]
- *
- * constructor: function (config) {
- * this.callSuper(arguments); // calls Ext.panel.Panel's constructor
- * //...
- * },
- *
- * statics: {
- * method: function () {
- * return 'abc';
- * }
- * }
- * });
- *
- * // File: /src/app/PanelPart2.js
- * Ext.define('My.app.PanelPart2', {
- * override: 'My.app.Panel',
- *
- * constructor: function (config) {
- * this.callSuper(arguments); // calls My.app.Panel's constructor
- * //...
- * }
- * });
- *
- * Another use of overrides is to provide optional parts of classes that can be
- * independently required. In this case, the class may even be unaware of the
- * override altogether.
- *
- * Ext.define('My.ux.CoolTip', {
- * override: 'Ext.tip.ToolTip',
- *
- * constructor: function (config) {
- * this.callSuper(arguments); // calls Ext.tip.ToolTip's constructor
- * //...
- * }
- * });
- *
- * The above override can now be required as normal.
- *
- * Ext.define('My.app.App', {
- * requires: [
- * 'My.ux.CoolTip'
- * ]
- * });
- *
- * Overrides can also contain statics:
- *
- * Ext.define('My.app.BarMod', {
- * override: 'Ext.foo.Bar',
- *
- * statics: {
- * method: function (x) {
- * return this.callSuper([x * 2]); // call Ext.foo.Bar.method
- * }
- * }
- * });
- *
- * IMPORTANT: An override is only included in a build if the class it overrides is
- * required. Otherwise, the override, like the target class, is not included.
- */
-
- /**
- * @method
- *
- * @member Ext
- * @alias Ext.ClassManager#create
- */
- define: function (className, data, createdFn) {
- if (!data.override) {
- return Manager.create.apply(Manager, arguments);
- }
- var requires = data.requires,
- uses = data.uses,
- overrideName = className;
- className = data.override;
- // hoist any 'requires' or 'uses' from the body onto the faux class:
- data = Ext.apply({}, data);
- delete data.requires;
- delete data.uses;
- delete data.override;
- // make sure className is in the requires list:
- if (typeof requires == 'string') {
- requires = [ className, requires ];
- } else if (requires) {
- requires = requires.slice(0);
- requires.unshift(className);
- } else {
- requires = [ className ];
- }
- // TODO - we need to rework this to allow the override to not require the target class
- // and rather 'wait' for it in such a way that if the target class is not in the build,
- // neither are any of its overrides.
- //
- // Also, this should process the overrides for a class ASAP (ideally before any derived
- // classes) if the target class 'requires' the overrides. Without some special handling, the
- // overrides so required will be processed before the class and have to be bufferred even
- // in a build.
- //
- // TODO - we should probably support the "config" processor on an override (to config new
- // functionaliy like Aria) and maybe inheritableStatics (although static is now supported
- // by callSuper). If inheritableStatics causes those statics to be included on derived class
- // constructors, that probably means "no" to this since an override can come after other
- // classes extend the target.
- return Manager.create(overrideName, {
- requires: requires,
- uses: uses,
- isPartial: true,
- constructor: function () {
- }
- }, function () {
- var cls = Manager.get(className);
- if (cls.override) { // if (normal class)
- cls.override(data);
- } else { // else (singleton)
- cls.self.override(data);
- }
- if (createdFn) {
- // called once the override is applied and with the context of the
- // overridden class (the override itself is a meaningless, name-only
- // thing).
- createdFn.call(cls);
- }
- });
- },
- /**
- * @method
- * @member Ext
- * @alias Ext.ClassManager#getName
- */
- getClassName: alias(Manager, 'getName'),
- /**
- * Returns the displayName property or className or object.
- * When all else fails, returns "Anonymous".
- * @param {Object} object
- * @return {String}
- */
- getDisplayName: function(object) {
- if (object.displayName) {
- return object.displayName;
- }
- if (object.$name && object.$class) {
- return Ext.getClassName(object.$class) + '#' + object.$name;
- }
- if (object.$className) {
- return object.$className;
- }
- return 'Anonymous';
- },
- /**
- * @method
- * @member Ext
- * @alias Ext.ClassManager#getClass
- */
- getClass: alias(Manager, 'getClass'),
- /**
- * Creates namespaces to be used for scoping variables and classes so that they are not global.
- * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
- *
- * Ext.namespace('Company', 'Company.data');
- *
- * // equivalent and preferable to the above syntax
- * Ext.namespace('Company.data');
- *
- * Company.Widget = function() { ... };
- *
- * Company.data.CustomStore = function(config) { ... };
- *
- * @method
- * @member Ext
- * @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)
- */
- namespace: alias(Manager, 'createNamespaces')
- });
- /**
- * Old name for {@link Ext#widget}.
- * @deprecated 4.0.0 Use {@link Ext#widget} instead.
- * @method
- * @member Ext
- * @alias Ext#widget
- */
- Ext.createWidget = Ext.widget;
- /**
- * Convenient alias for {@link Ext#namespace Ext.namespace}
- * @method
- * @member Ext
- * @alias Ext#namespace
- */
- Ext.ns = Ext.namespace;
- Class.registerPreprocessor('className', function(cls, data) {
- if (data.$className) {
- cls.$className = data.$className;
- }
- }, true);
- Class.setDefaultPreprocessorPosition('className', 'first');
- Class.registerPreprocessor('xtype', function(cls, data) {
- var xtypes = Ext.Array.from(data.xtype),
- widgetPrefix = 'widget.',
- aliases = Ext.Array.from(data.alias),
- i, ln, xtype;
- data.xtype = xtypes[0];
- data.xtypes = xtypes;
- aliases = data.alias = Ext.Array.from(data.alias);
- for (i = 0,ln = xtypes.length; i < ln; i++) {
- xtype = xtypes[i];
- aliases.push(widgetPrefix + xtype);
- }
- data.alias = aliases;
- });
- Class.setDefaultPreprocessorPosition('xtype', 'last');
- Class.registerPreprocessor('alias', function(cls, data) {
- var aliases = Ext.Array.from(data.alias),
- xtypes = Ext.Array.from(data.xtypes),
- widgetPrefix = 'widget.',
- widgetPrefixLength = widgetPrefix.length,
- i, ln, alias, xtype;
- for (i = 0, ln = aliases.length; i < ln; i++) {
- alias = aliases[i];
- if (alias.substring(0, widgetPrefixLength) === widgetPrefix) {
- xtype = alias.substring(widgetPrefixLength);
- Ext.Array.include(xtypes, xtype);
- if (!cls.xtype) {
- cls.xtype = data.xtype = xtype;
- }
- }
- }
- data.alias = aliases;
- data.xtypes = xtypes;
- });
- Class.setDefaultPreprocessorPosition('alias', 'last');
- })(Ext.Class, Ext.Function.alias);
- /**
- * @class Ext.Loader
- * @singleton
- * @author Jacky Nguyen <jacky@sencha.com>
- * @docauthor Jacky Nguyen <jacky@sencha.com>
- *
- * Ext.Loader is the heart of the new dynamic dependency loading capability in Ext JS 4+. It is most commonly used
- * via the {@link Ext#require} shorthand. Ext.Loader supports both asynchronous and synchronous loading
- * approaches, and leverage their advantages for the best development flow. We'll discuss about the pros and cons
- * of each approach:
- *
- * # Asynchronous Loading
- *
- * - Advantages:
- * + Cross-domain
- * + No web server needed: you can run the application via the file system protocol
- * (i.e: `file://path/to/your/index.html`)
- * + Best possible debugging experience: error messages come with the exact file name and line number
- *
- * - Disadvantages:
- * + Dependencies need to be specified before-hand
- *
- * ### Method 1: Explicitly include what you need:
- *
- * // Syntax
- * Ext.require({String/Array} expressions);
- *
- * // Example: Single alias
- * Ext.require('widget.window');
- *
- * // Example: Single class name
- * Ext.require('Ext.window.Window');
- *
- * // Example: Multiple aliases / class names mix
- * Ext.require(['widget.window', 'layout.border', 'Ext.data.Connection']);
- *
- * // Wildcards
- * Ext.require(['widget.*', 'layout.*', 'Ext.data.*']);
- *
- * ### Method 2: Explicitly exclude what you don't need:
- *
- * // Syntax: Note that it must be in this chaining format.
- * Ext.exclude({String/Array} expressions)
- * .require({String/Array} expressions);
- *
- * // Include everything except Ext.data.*
- * Ext.exclude('Ext.data.*').require('*');
- *
- * // Include all widgets except widget.checkbox*,
- * // which will match widget.checkbox, widget.checkboxfield, widget.checkboxgroup, etc.
- * Ext.exclude('widget.checkbox*').require('widget.*');
- *
- * # Synchronous Loading on Demand
- *
- * - Advantages:
- * + There's no need to specify dependencies before-hand, which is always the convenience of including
- * ext-all.js before
- *
- * - Disadvantages:
- * + Not as good debugging experience since file name won't be shown (except in Firebug at the moment)
- * + Must be from the same domain due to XHR restriction
- * + Need a web server, same reason as above
- *
- * There's one simple rule to follow: Instantiate everything with Ext.create instead of the `new` keyword
- *
- * Ext.create('widget.window', { ... }); // Instead of new Ext.window.Window({...});
- *
- * Ext.create('Ext.window.Window', {}); // Same as above, using full class name instead of alias
- *
- * Ext.widget('window', {}); // Same as above, all you need is the traditional `xtype`
- *
- * Behind the scene, {@link Ext.ClassManager} will automatically check whether the given class name / alias has already
- * existed on the page. If it's not, Ext.Loader will immediately switch itself to synchronous mode and automatic load
- * the given class and all its dependencies.
- *
- * # Hybrid Loading - The Best of Both Worlds
- *
- * It has all the advantages combined from asynchronous and synchronous loading. The development flow is simple:
- *
- * ### Step 1: Start writing your application using synchronous approach.
- *
- * Ext.Loader will automatically fetch all dependencies on demand as they're needed during run-time. For example:
- *
- * Ext.onReady(function(){
- * var window = Ext.createWidget('window', {
- * width: 500,
- * height: 300,
- * layout: {
- * type: 'border',
- * padding: 5
- * },
- * title: 'Hello Dialog',
- * items: [{
- * title: 'Navigation',
- * collapsible: true,
- * region: 'west',
- * width: 200,
- * html: 'Hello',
- * split: true
- * }, {
- * title: 'TabPanel',
- * region: 'center'
- * }]
- * });
- *
- * window.show();
- * })
- *
- * ### Step 2: Along the way, when you need better debugging ability, watch the console for warnings like these:
- *
- * [Ext.Loader] Synchronously loading 'Ext.window.Window'; consider adding Ext.require('Ext.window.Window') before your application's code ClassManager.js:432
- * [Ext.Loader] Synchronously loading 'Ext.layout.container.Border'; consider adding Ext.require('Ext.layout.container.Border') before your application's code
- *
- * Simply copy and paste the suggested code above `Ext.onReady`, e.g.:
- *
- * Ext.require('Ext.window.Window');
- * Ext.require('Ext.layout.container.Border');
- *
- * Ext.onReady(...);
- *
- * Everything should now load via asynchronous mode.
- *
- * # Deployment
- *
- * It's important to note that dynamic loading should only be used during development on your local machines.
- * During production, all dependencies should be combined into one single JavaScript file. Ext.Loader makes
- * the whole process of transitioning from / to between development / maintenance and production as easy as
- * possible. Internally {@link Ext.Loader#history Ext.Loader.history} maintains the list of all dependencies
- * your application needs in the exact loading sequence. It's as simple as concatenating all files in this
- * array into one, then include it on top of your application.
- *
- * This process will be automated with Sencha Command, to be released and documented towards Ext JS 4 Final.
- */
- (function(Manager, Class, flexSetter, alias) {
- var
- dependencyProperties = ['extend', 'mixins', 'requires'],
- Loader;
- Loader = Ext.Loader = {
- /**
- * @private
- */
- documentHead: typeof document !== 'undefined' && (document.head || document.getElementsByTagName('head')[0]),
- /**
- * Flag indicating whether there are still files being loaded
- * @private
- */
- isLoading: false,
- /**
- * Maintain the queue for all dependencies. Each item in the array is an object of the format:
- * {
- * requires: [...], // The required classes for this queue item
- * callback: function() { ... } // The function to execute when all classes specified in requires exist
- * }
- * @private
- */
- queue: [],
- /**
- * Maintain the list of files that have already been handled so that they never get double-loaded
- * @private
- */
- isFileLoaded: {},
- /**
- * Maintain the list of listeners to execute when all required scripts are fully loaded
- * @private
- */
- readyListeners: [],
- /**
- * Contains optional dependencies to be loaded last
- * @private
- */
- optionalRequires: [],
- /**
- * Map of fully qualified class names to an array of dependent classes.
- * @private
- */
- requiresMap: {},
- /**
- * @private
- */
- numPendingFiles: 0,
- /**
- * @private
- */
- numLoadedFiles: 0,
- /** @private */
- hasFileLoadError: false,
- /**
- * @private
- */
- classNameToFilePathMap: {},
- /**
- * @property {String[]} history
- * An array of class names to keep track of the dependency loading order.
- * This is not guaranteed to be the same everytime due to the asynchronous nature of the Loader.
- */
- history: [],
- /**
- * Configuration
- * @private
- */
- config: {
- /**
- * @cfg {Boolean} enabled
- * Whether or not to enable the dynamic dependency loading feature.
- */
- enabled: false,
- /**
- * @cfg {Boolean} disableCaching
- * Appends current timestamp to script files to prevent caching.
- */
- disableCaching: true,
- /**
- * @cfg {String} disableCachingParam
- * The get parameter name for the cache buster's timestamp.
- */
- disableCachingParam: '_dc',
- /**
- * @cfg {Object} paths
- * The mapping from namespaces to file paths
- *
- * {
- * 'Ext': '.', // This is set by default, Ext.layout.container.Container will be
- * // loaded from ./layout/Container.js
- *
- * 'My': './src/my_own_folder' // My.layout.Container will be loaded from
- * // ./src/my_own_folder/layout/Container.js
- * }
- *
- * Note that all relative paths are relative to the current HTML document.
- * If not being specified, for example, `Other.awesome.Class`
- * will simply be loaded from `./Other/awesome/Class.js`
- */
- paths: {
- 'Ext': '.'
- }
- },
- /**
- * Set the configuration for the loader. This should be called right after ext-core.js
- * (or ext-core-debug.js) is included in the page, e.g.:
- *
- * <script type="text/javascript" src="ext-core-debug.js"></script>
- * <script type="text/javascript">
- * Ext.Loader.setConfig({
- * enabled: true,
- * paths: {
- * 'My': 'my_own_path'
- * }
- * });
- * <script>
- * <script type="text/javascript">
- * Ext.require(...);
- *
- * Ext.onReady(function() {
- * // application code here
- * });
- * </script>
- *
- * Refer to config options of {@link Ext.Loader} for the list of possible properties.
- *
- * @param {String/Object} name Name of the value to override, or a config object to override multiple values.
- * @param {Object} value (optional) The new value to set, needed if first parameter is String.
- * @return {Ext.Loader} this
- */
- setConfig: function(name, value) {
- if (Ext.isObject(name) && arguments.length === 1) {
- Ext.Object.merge(this.config, name);
- }
- else {
- this.config[name] = (Ext.isObject(value)) ? Ext.Object.merge(this.config[name], value) : value;
- }
- return this;
- },
- /**
- * Get the config value corresponding to the specified name.
- * If no name is given, will return the config object.
- * @param {String} name The config property name
- * @return {Object}
- */
- getConfig: function(name) {
- if (name) {
- return this.config[name];
- }
- return this.config;
- },
- /**
- * Sets the path of a namespace. For Example:
- *
- * Ext.Loader.setPath('Ext', '.');
- *
- * @param {String/Object} name See {@link Ext.Function#flexSetter flexSetter}
- * @param {String} path See {@link Ext.Function#flexSetter flexSetter}
- * @return {Ext.Loader} this
- * @method
- */
- setPath: flexSetter(function(name, path) {
- this.config.paths[name] = path;
- return this;
- }),
- /**
- * Translates a className to a file path by adding the the proper prefix and converting the .'s to /'s.
- * For example:
- *
- * Ext.Loader.setPath('My', '/path/to/My');
- *
- * alert(Ext.Loader.getPath('My.awesome.Class')); // alerts '/path/to/My/awesome/Class.js'
- *
- * Note that the deeper namespace levels, if explicitly set, are always resolved first. For example:
- *
- * Ext.Loader.setPath({
- * 'My': '/path/to/lib',
- * 'My.awesome': '/other/path/for/awesome/stuff',
- * 'My.awesome.more': '/more/awesome/path'
- * });
- *
- * alert(Ext.Loader.getPath('My.awesome.Class')); // alerts '/other/path/for/awesome/stuff/Class.js'
- *
- * alert(Ext.Loader.getPath('My.awesome.more.Class')); // alerts '/more/awesome/path/Class.js'
- *
- * alert(Ext.Loader.getPath('My.cool.Class')); // alerts '/path/to/lib/cool/Class.js'
- *
- * alert(Ext.Loader.getPath('Unknown.strange.Stuff')); // alerts 'Unknown/strange/Stuff.js'
- *
- * @param {String} className
- * @return {String} path
- */
- getPath: function(className) {
- var path = '',
- paths = this.config.paths,
- prefix = this.getPrefix(className);
- if (prefix.length > 0) {
- if (prefix === className) {
- return paths[prefix];
- }
- path = paths[prefix];
- className = className.substring(prefix.length + 1);
- }
- if (path.length > 0) {
- path += '/';
- }
- return path.replace(/\/\.\//g, '/') + className.replace(/\./g, "/") + '.js';
- },
- /**
- * @private
- * @param {String} className
- */
- getPrefix: function(className) {
- var paths = this.config.paths,
- prefix, deepestPrefix = '';
- if (paths.hasOwnProperty(className)) {
- return className;
- }
- for (prefix in paths) {
- if (paths.hasOwnProperty(prefix) && prefix + '.' === className.substring(0, prefix.length + 1)) {
- if (prefix.length > deepestPrefix.length) {
- deepestPrefix = prefix;
- }
- }
- }
- return deepestPrefix;
- },
- /**
- * Refresh all items in the queue. If all dependencies for an item exist during looping,
- * it will execute the callback and call refreshQueue again. Triggers onReady when the queue is
- * empty
- * @private
- */
- refreshQueue: function() {
- var ln = this.queue.length,
- i, item, j, requires;
- if (ln === 0) {
- this.triggerReady();
- return;
- }
- for (i = 0; i < ln; i++) {
- item = this.queue[i];
- if (item) {
- requires = item.requires;
- // Don't bother checking when the number of files loaded
- // is still less than the array length
- if (requires.length > this.numLoadedFiles) {
- continue;
- }
- j = 0;
- do {
- if (Manager.isCreated(requires[j])) {
- // Take out from the queue
- Ext.Array.erase(requires, j, 1);
- }
- else {
- j++;
- }
- } while (j < requires.length);
- if (item.requires.length === 0) {
- Ext.Array.erase(this.queue, i, 1);
- item.callback.call(item.scope);
- this.refreshQueue();
- break;
- }
- }
- }
- return this;
- },
- /**
- * Inject a script element to document's head, call onLoad and onError accordingly
- * @private
- */
- injectScriptElement: function(url, onLoad, onError, scope) {
- var script = document.createElement('script'),
- me = this,
- onLoadFn = function() {
- me.cleanupScriptElement(script);
- onLoad.call(scope);
- },
- onErrorFn = function() {
- me.cleanupScriptElement(script);
- onError.call(scope);
- };
- script.type = 'text/javascript';
- script.src = url;
- script.onload = onLoadFn;
- script.onerror = onErrorFn;
- script.onreadystatechange = function() {
- if (this.readyState === 'loaded' || this.readyState === 'complete') {
- onLoadFn();
- }
- };
- this.documentHead.appendChild(script);
- return script;
- },
- /**
- * @private
- */
- cleanupScriptElement: function(script) {
- script.onload = null;
- script.onreadystatechange = null;
- script.onerror = null;
- return this;
- },
- /**
- * Load a script file, supports both asynchronous and synchronous approaches
- *
- * @param {String} url
- * @param {Function} onLoad
- * @param {Object} scope
- * @param {Boolean} synchronous
- * @private
- */
- loadScriptFile: function(url, onLoad, onError, scope, synchronous) {
- var me = this,
- noCacheUrl = url + (this.getConfig('disableCaching') ? ('?' + this.getConfig('disableCachingParam') + '=' + Ext.Date.now()) : ''),
- fileName = url.split('/').pop(),
- isCrossOriginRestricted = false,
- xhr, status, onScriptError;
- scope = scope || this;
- this.isLoading = true;
- if (!synchronous) {
- onScriptError = function() {
- onError.call(scope, "Failed loading '" + url + "', please verify that the file exists", synchronous);
- };
- if (!Ext.isReady && Ext.onDocumentReady) {
- Ext.onDocumentReady(function() {
- me.injectScriptElement(noCacheUrl, onLoad, onScriptError, scope);
- });
- }
- else {
- this.injectScriptElement(noCacheUrl, onLoad, onScriptError, scope);
- }
- }
- else {
- if (typeof XMLHttpRequest !== 'undefined') {
- xhr = new XMLHttpRequest();
- } else {
- xhr = new ActiveXObject('Microsoft.XMLHTTP');
- }
- try {
- xhr.open('GET', noCacheUrl, false);
- xhr.send(null);
- } catch (e) {
- isCrossOriginRestricted = true;
- }
- status = (xhr.status === 1223) ? 204 : xhr.status;
- if (!isCrossOriginRestricted) {
- isCrossOriginRestricted = (status === 0);
- }
- if (isCrossOriginRestricted
- ) {
- onError.call(this, "Failed loading synchronously via XHR: '" + url + "'; It's likely that the file is either " +
- "being loaded from a different domain or from the local file system whereby cross origin " +
- "requests are not allowed due to security reasons. Use asynchronous loading with " +
- "Ext.require instead.", synchronous);
- }
- else if (status >= 200 && status < 300
- ) {
- // Firebug friendly, file names are still shown even though they're eval'ed code
- new Function(xhr.responseText + "\n//@ sourceURL=" + fileName)();
- onLoad.call(scope);
- }
- else {
- onError.call(this, "Failed loading synchronously via XHR: '" + url + "'; please " +
- "verify that the file exists. " +
- "XHR status code: " + status, synchronous);
- }
- // Prevent potential IE memory leak
- xhr = null;
- }
- },
- /**
- * Explicitly exclude files from being loaded. Useful when used in conjunction with a broad include expression.
- * Can be chained with more `require` and `exclude` methods, e.g.:
- *
- * Ext.exclude('Ext.data.*').require('*');
- *
- * Ext.exclude('widget.button*').require('widget.*');
- *
- * {@link Ext#exclude Ext.exclude} is alias for {@link Ext.Loader#exclude Ext.Loader.exclude} for convenience.
- *
- * @param {String/String[]} excludes
- * @return {Object} object contains `require` method for chaining
- */
- exclude: function(excludes) {
- var me = this;
- return {
- require: function(expressions, fn, scope) {
- return me.require(expressions, fn, scope, excludes);
- },
- syncRequire: function(expressions, fn, scope) {
- return me.syncRequire(expressions, fn, scope, excludes);
- }
- };
- },
- /**
- * Synchronously loads all classes by the given names and all their direct dependencies;
- * optionally executes the given callback function when finishes, within the optional scope.
- *
- * {@link Ext#syncRequire Ext.syncRequire} is alias for {@link Ext.Loader#syncRequire Ext.Loader.syncRequire} for convenience.
- *
- * @param {String/String[]} expressions Can either be a string or an array of string
- * @param {Function} fn (Optional) The callback function
- * @param {Object} scope (Optional) The execution scope (`this`) of the callback function
- * @param {String/String[]} excludes (Optional) Classes to be excluded, useful when being used with expressions
- */
- syncRequire: function() {
- this.syncModeEnabled = true;
- this.require.apply(this, arguments);
- this.refreshQueue();
- this.syncModeEnabled = false;
- },
- /**
- * Loads all classes by the given names and all their direct dependencies;
- * optionally executes the given callback function when finishes, within the optional scope.
- *
- * {@link Ext#require Ext.require} is alias for {@link Ext.Loader#require Ext.Loader.require} for convenience.
- *
- * @param {String/String[]} expressions Can either be a string or an array of string
- * @param {Function} fn (Optional) The callback function
- * @param {Object} scope (Optional) The execution scope (`this`) of the callback function
- * @param {String/String[]} excludes (Optional) Classes to be excluded, useful when being used with expressions
- */
- require: function(expressions, fn, scope, excludes) {
- var filePath, expression, exclude, className, excluded = {},
- excludedClassNames = [],
- possibleClassNames = [],
- possibleClassName, classNames = [],
- i, j, ln, subLn;
- expressions = Ext.Array.from(expressions);
- excludes = Ext.Array.from(excludes);
- fn = fn || Ext.emptyFn;
- scope = scope || Ext.global;
- for (i = 0, ln = excludes.length; i < ln; i++) {
- exclude = excludes[i];
- if (typeof exclude === 'string' && exclude.length > 0) {
- excludedClassNames = Manager.getNamesByExpression(exclude);
- for (j = 0, subLn = excludedClassNames.length; j < subLn; j++) {
- excluded[excludedClassNames[j]] = true;
- }
- }
- }
- for (i = 0, ln = expressions.length; i < ln; i++) {
- expression = expressions[i];
- if (typeof expression === 'string' && expression.length > 0) {
- possibleClassNames = Manager.getNamesByExpression(expression);
- for (j = 0, subLn = possibleClassNames.length; j < subLn; j++) {
- possibleClassName = possibleClassNames[j];
- if (!excluded.hasOwnProperty(possibleClassName) && !Manager.isCreated(possibleClassName)) {
- Ext.Array.include(classNames, possibleClassName);
- }
- }
- }
- }
- // If the dynamic dependency feature is not being used, throw an error
- // if the dependencies are not defined
- if (!this.config.enabled) {
- if (classNames.length > 0) {
- Ext.Error.raise({
- sourceClass: "Ext.Loader",
- sourceMethod: "require",
- msg: "Ext.Loader is not enabled, so dependencies cannot be resolved dynamically. " +
- "Missing required class" + ((classNames.length > 1) ? "es" : "") + ": " + classNames.join(', ')
- });
- }
- }
- if (classNames.length === 0) {
- fn.call(scope);
- return this;
- }
- this.queue.push({
- requires: classNames,
- callback: fn,
- scope: scope
- });
- classNames = classNames.slice();
- for (i = 0, ln = classNames.length; i < ln; i++) {
- className = classNames[i];
- if (!this.isFileLoaded.hasOwnProperty(className)) {
- this.isFileLoaded[className] = false;
- filePath = this.getPath(className);
- this.classNameToFilePathMap[className] = filePath;
- this.numPendingFiles++;
- this.loadScriptFile(
- filePath,
- Ext.Function.pass(this.onFileLoaded, [className, filePath], this),
- Ext.Function.pass(this.onFileLoadError, [className, filePath]),
- this,
- this.syncModeEnabled
- );
- }
- }
- return this;
- },
- /**
- * @private
- * @param {String} className
- * @param {String} filePath
- */
- onFileLoaded: function(className, filePath) {
- this.numLoadedFiles++;
- this.isFileLoaded[className] = true;
- this.numPendingFiles--;
- if (this.numPendingFiles === 0) {
- this.refreshQueue();
- }
- },
- /**
- * @private
- */
- onFileLoadError: function(className, filePath, errorMessage, isSynchronous) {
- this.numPendingFiles--;
- this.hasFileLoadError = true;
- },
- /**
- * @private
- */
- addOptionalRequires: function(requires) {
- var optionalRequires = this.optionalRequires,
- i, ln, require;
- requires = Ext.Array.from(requires);
- for (i = 0, ln = requires.length; i < ln; i++) {
- require = requires[i];
- Ext.Array.include(optionalRequires, require);
- }
- return this;
- },
- /**
- * @private
- */
- triggerReady: function(force) {
- var readyListeners = this.readyListeners,
- optionalRequires, listener;
- if (this.isLoading || force) {
- this.isLoading = false;
- if (this.optionalRequires.length) {
- // Clone then empty the array to eliminate potential recursive loop issue
- optionalRequires = Ext.Array.clone(this.optionalRequires);
- // Empty the original array
- this.optionalRequires.length = 0;
- this.require(optionalRequires, Ext.Function.pass(this.triggerReady, [true], this), this);
- return this;
- }
- while (readyListeners.length) {
- listener = readyListeners.shift();
- listener.fn.call(listener.scope);
- if (this.isLoading) {
- return this;
- }
- }
- }
- return this;
- },
- /**
- * Adds new listener to be executed when all required scripts are fully loaded.
- *
- * @param {Function} fn The function callback to be executed
- * @param {Object} scope The execution scope (`this`) of the callback function
- * @param {Boolean} withDomReady Whether or not to wait for document dom ready as well
- */
- onReady: function(fn, scope, withDomReady, options) {
- var oldFn;
- if (withDomReady !== false && Ext.onDocumentReady) {
- oldFn = fn;
- fn = function() {
- Ext.onDocumentReady(oldFn, scope, options);
- };
- }
- if (!this.isLoading) {
- fn.call(scope);
- }
- else {
- this.readyListeners.push({
- fn: fn,
- scope: scope
- });
- }
- },
- /**
- * @private
- * @param {String} className
- */
- historyPush: function(className) {
- if (className && this.isFileLoaded.hasOwnProperty(className)) {
- Ext.Array.include(this.history, className);
- }
- return this;
- }
- };
- /**
- * @member Ext
- * @method require
- * @alias Ext.Loader#require
- */
- Ext.require = alias(Loader, 'require');
- /**
- * @member Ext
- * @method syncRequire
- * @alias Ext.Loader#syncRequire
- */
- Ext.syncRequire = alias(Loader, 'syncRequire');
- /**
- * @member Ext
- * @method exclude
- * @alias Ext.Loader#exclude
- */
- Ext.exclude = alias(Loader, 'exclude');
- /**
- * @member Ext
- * @method onReady
- * @alias Ext.Loader#onReady
- */
- Ext.onReady = function(fn, scope, options) {
- Loader.onReady(fn, scope, true, options);
- };
- /**
- * @cfg {String[]} requires
- * @member Ext.Class
- * List of classes that have to be loaded before instantiating this class.
- * For example:
- *
- * Ext.define('Mother', {
- * requires: ['Child'],
- * giveBirth: function() {
- * // we can be sure that child class is available.
- * return new Child();
- * }
- * });
- */
- Class.registerPreprocessor('loader', function(cls, data, continueFn) {
- var me = this,
- dependencies = [],
- className = Manager.getName(cls),
- i, j, ln, subLn, value, propertyName, propertyValue;
- /*
- Basically loop through the dependencyProperties, look for string class names and push
- them into a stack, regardless of whether the property's value is a string, array or object. For example:
- {
- extend: 'Ext.MyClass',
- requires: ['Ext.some.OtherClass'],
- mixins: {
- observable: 'Ext.util.Observable';
- }
- }
- which will later be transformed into:
- {
- extend: Ext.MyClass,
- requires: [Ext.some.OtherClass],
- mixins: {
- observable: Ext.util.Observable;
- }
- }
- */
- for (i = 0, ln = dependencyProperties.length; i < ln; i++) {
- propertyName = dependencyProperties[i];
- if (data.hasOwnProperty(propertyName)) {
- propertyValue = data[propertyName];
- if (typeof propertyValue === 'string') {
- dependencies.push(propertyValue);
- }
- else if (propertyValue instanceof Array) {
- for (j = 0, subLn = propertyValue.length; j < subLn; j++) {
- value = propertyValue[j];
- if (typeof value === 'string') {
- dependencies.push(value);
- }
- }
- }
- else if (typeof propertyValue != 'function') {
- for (j in propertyValue) {
- if (propertyValue.hasOwnProperty(j)) {
- value = propertyValue[j];
- if (typeof value === 'string') {
- dependencies.push(value);
- }
- }
- }
- }
- }
- }
- if (dependencies.length === 0) {
- // Loader.historyPush(className);
- return;
- }
- Loader.require(dependencies, function() {
- for (i = 0, ln = dependencyProperties.length; i < ln; i++) {
- propertyName = dependencyProperties[i];
- if (data.hasOwnProperty(propertyName)) {
- propertyValue = data[propertyName];
- if (typeof propertyValue === 'string') {
- data[propertyName] = Manager.get(propertyValue);
- }
- else if (propertyValue instanceof Array) {
- for (j = 0, subLn = propertyValue.length; j < subLn; j++) {
- value = propertyValue[j];
- if (typeof value === 'string') {
- data[propertyName][j] = Manager.get(value);
- }
- }
- }
- else if (typeof propertyValue != 'function') {
- for (var k in propertyValue) {
- if (propertyValue.hasOwnProperty(k)) {
- value = propertyValue[k];
- if (typeof value === 'string') {
- data[propertyName][k] = Manager.get(value);
- }
- }
- }
- }
- }
- }
- continueFn.call(me, cls, data);
- });
- return false;
- }, true);
- Class.setDefaultPreprocessorPosition('loader', 'after', 'className');
- /**
- * @cfg {String[]} uses
- * @member Ext.Class
- * List of classes to load together with this class. These aren't neccessarily loaded before
- * this class is instantiated. For example:
- *
- * Ext.define('Mother', {
- * uses: ['Child'],
- * giveBirth: function() {
- * // This code might, or might not work:
- * // return new Child();
- *
- * // Instead use Ext.create() to load the class at the spot if not loaded already:
- * return Ext.create('Child');
- * }
- * });
- */
- Manager.registerPostprocessor('uses', function(name, cls, data) {
- var uses = Ext.Array.from(data.uses),
- items = [],
- i, ln, item;
- for (i = 0, ln = uses.length; i < ln; i++) {
- item = uses[i];
- if (typeof item === 'string') {
- items.push(item);
- }
- }
- Loader.addOptionalRequires(items);
- });
- Manager.setDefaultPostprocessorPosition('uses', 'last');
- })(Ext.ClassManager, Ext.Class, Ext.Function.flexSetter, Ext.Function.alias);
- /**
- * @author Brian Moeskau <brian@sencha.com>
- * @docauthor Brian Moeskau <brian@sencha.com>
- *
- * A wrapper class for the native JavaScript Error object that adds a few useful capabilities for handling
- * errors in an Ext application. When you use Ext.Error to {@link #raise} an error from within any class that
- * uses the Ext 4 class system, the Error class can automatically add the source class and method from which
- * the error was raised. It also includes logic to automatically log the eroor to the console, if available,
- * with additional metadata about the error. In all cases, the error will always be thrown at the end so that
- * execution will halt.
- *
- * Ext.Error also offers a global error {@link #handle handling} method that can be overridden in order to
- * handle application-wide errors in a single spot. You can optionally {@link #ignore} errors altogether,
- * although in a real application it's usually a better idea to override the handling function and perform
- * logging or some other method of reporting the errors in a way that is meaningful to the application.
- *
- * At its simplest you can simply raise an error as a simple string from within any code:
- *
- * Example usage:
- *
- * Ext.Error.raise('Something bad happened!');
- *
- * If raised from plain JavaScript code, the error will be logged to the console (if available) and the message
- * displayed. In most cases however you'll be raising errors from within a class, and it may often be useful to add
- * additional metadata about the error being raised. The {@link #raise} method can also take a config object.
- * In this form the `msg` attribute becomes the error description, and any other data added to the config gets
- * added to the error object and, if the console is available, logged to the console for inspection.
- *
- * Example usage:
- *
- * Ext.define('Ext.Foo', {
- * doSomething: function(option){
- * if (someCondition === false) {
- * Ext.Error.raise({
- * msg: 'You cannot do that!',
- * option: option, // whatever was passed into the method
- * 'error code': 100 // other arbitrary info
- * });
- * }
- * }
- * });
- *
- * If a console is available (that supports the `console.dir` function) you'll see console output like:
- *
- * An error was raised with the following data:
- * option: Object { foo: "bar"}
- * foo: "bar"
- * error code: 100
- * msg: "You cannot do that!"
- * sourceClass: "Ext.Foo"
- * sourceMethod: "doSomething"
- *
- * uncaught exception: You cannot do that!
- *
- * As you can see, the error will report exactly where it was raised and will include as much information as the
- * raising code can usefully provide.
- *
- * If you want to handle all application errors globally you can simply override the static {@link #handle} method
- * and provide whatever handling logic you need. If the method returns true then the error is considered handled
- * and will not be thrown to the browser. If anything but true is returned then the error will be thrown normally.
- *
- * Example usage:
- *
- * Ext.Error.handle = function(err) {
- * if (err.someProperty == 'NotReallyAnError') {
- * // maybe log something to the application here if applicable
- * return true;
- * }
- * // any non-true return value (including none) will cause the error to be thrown
- * }
- *
- */
- Ext.Error = Ext.extend(Error, {
- statics: {
- /**
- * @property {Boolean} ignore
- * Static flag that can be used to globally disable error reporting to the browser if set to true
- * (defaults to false). Note that if you ignore Ext errors it's likely that some other code may fail
- * and throw a native JavaScript error thereafter, so use with caution. In most cases it will probably
- * be preferable to supply a custom error {@link #handle handling} function instead.
- *
- * Example usage:
- *
- * Ext.Error.ignore = true;
- *
- * @static
- */
- ignore: false,
- /**
- * @property {Boolean} notify
- * Static flag that can be used to globally control error notification to the user. Unlike
- * Ex.Error.ignore, this does not effect exceptions. They are still thrown. This value can be
- * set to false to disable the alert notification (default is true for IE6 and IE7).
- *
- * Only the first error will generate an alert. Internally this flag is set to false when the
- * first error occurs prior to displaying the alert.
- *
- * This flag is not used in a release build.
- *
- * Example usage:
- *
- * Ext.Error.notify = false;
- *
- * @static
- */
- //notify: Ext.isIE6 || Ext.isIE7,
- /**
- * Raise an error that can include additional data and supports automatic console logging if available.
- * You can pass a string error message or an object with the `msg` attribute which will be used as the
- * error message. The object can contain any other name-value attributes (or objects) to be logged
- * along with the error.
- *
- * Note that after displaying the error message a JavaScript error will ultimately be thrown so that
- * execution will halt.
- *
- * Example usage:
- *
- * Ext.Error.raise('A simple string error message');
- *
- * // or...
- *
- * Ext.define('Ext.Foo', {
- * doSomething: function(option){
- * if (someCondition === false) {
- * Ext.Error.raise({
- * msg: 'You cannot do that!',
- * option: option, // whatever was passed into the method
- * 'error code': 100 // other arbitrary info
- * });
- * }
- * }
- * });
- *
- * @param {String/Object} err The error message string, or an object containing the attribute "msg" that will be
- * used as the error message. Any other data included in the object will also be logged to the browser console,
- * if available.
- * @static
- */
- raise: function(err){
- err = err || {};
- if (Ext.isString(err)) {
- err = { msg: err };
- }
- var method = this.raise.caller;
- if (method) {
- if (method.$name) {
- err.sourceMethod = method.$name;
- }
- if (method.$owner) {
- err.sourceClass = method.$owner.$className;
- }
- }
- if (Ext.Error.handle(err) !== true) {
- var msg = Ext.Error.prototype.toString.call(err);
- Ext.log({
- msg: msg,
- level: 'error',
- dump: err,
- stack: true
- });
- throw new Ext.Error(err);
- }
- },
- /**
- * Globally handle any Ext errors that may be raised, optionally providing custom logic to
- * handle different errors individually. Return true from the function to bypass throwing the
- * error to the browser, otherwise the error will be thrown and execution will halt.
- *
- * Example usage:
- *
- * Ext.Error.handle = function(err) {
- * if (err.someProperty == 'NotReallyAnError') {
- * // maybe log something to the application here if applicable
- * return true;
- * }
- * // any non-true return value (including none) will cause the error to be thrown
- * }
- *
- * @param {Ext.Error} err The Ext.Error object being raised. It will contain any attributes that were originally
- * raised with it, plus properties about the method and class from which the error originated (if raised from a
- * class that uses the Ext 4 class system).
- * @static
- */
- handle: function(){
- return Ext.Error.ignore;
- }
- },
- // This is the standard property that is the name of the constructor.
- name: 'Ext.Error',
- /**
- * Creates new Error object.
- * @param {String/Object} config The error message string, or an object containing the
- * attribute "msg" that will be used as the error message. Any other data included in
- * the object will be applied to the error instance and logged to the browser console, if available.
- */
- constructor: function(config){
- if (Ext.isString(config)) {
- config = { msg: config };
- }
- var me = this;
- Ext.apply(me, config);
- me.message = me.message || me.msg; // 'message' is standard ('msg' is non-standard)
- // note: the above does not work in old WebKit (me.message is readonly) (Safari 4)
- },
- /**
- * Provides a custom string representation of the error object. This is an override of the base JavaScript
- * `Object.toString` method, which is useful so that when logged to the browser console, an error object will
- * be displayed with a useful message instead of `[object Object]`, the default `toString` result.
- *
- * The default implementation will include the error message along with the raising class and method, if available,
- * but this can be overridden with a custom implementation either at the prototype level (for all errors) or on
- * a particular error instance, if you want to provide a custom description that will show up in the console.
- * @return {String} The error message. If raised from within the Ext 4 class system, the error message will also
- * include the raising class and method names, if available.
- */
- toString: function(){
- var me = this,
- className = me.className ? me.className : '',
- methodName = me.methodName ? '.' + me.methodName + '(): ' : '',
- msg = me.msg || '(No description provided)';
- return className + methodName + msg;
- }
- });
- /*
- * This mechanism is used to notify the user of the first error encountered on the page. This
- * was previously internal to Ext.Error.raise and is a desirable feature since errors often
- * slip silently under the radar. It cannot live in Ext.Error.raise since there are times
- * where exceptions are handled in a try/catch.
- */
- /*
- This file is part of Ext JS 4
- Copyright (c) 2011 Sencha Inc
- Contact: http://www.sencha.com/contact
- GNU General Public License Usage
- This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
- If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
- */
- /**
- * @class Ext.JSON
- * Modified version of Douglas Crockford's JSON.js that doesn't
- * mess with the Object prototype
- * http://www.json.org/js.html
- * @singleton
- */
- Ext.JSON = new(function() {
- var useHasOwn = !! {}.hasOwnProperty,
- isNative = function() {
- var useNative = null;
- return function() {
- if (useNative === null) {
- useNative = Ext.USE_NATIVE_JSON && window.JSON && JSON.toString() == '[object JSON]';
- }
- return useNative;
- };
- }(),
- pad = function(n) {
- return n < 10 ? "0" + n : n;
- },
- doDecode = function(json) {
- return eval("(" + json + ')');
- },
- doEncode = function(o) {
- if (!Ext.isDefined(o) || o === null) {
- return "null";
- } else if (Ext.isArray(o)) {
- return encodeArray(o);
- } else if (Ext.isDate(o)) {
- return Ext.JSON.encodeDate(o);
- } else if (Ext.isString(o)) {
- return encodeString(o);
- } else if (typeof o == "number") {
- //don't use isNumber here, since finite checks happen inside isNumber
- return isFinite(o) ? String(o) : "null";
- } else if (Ext.isBoolean(o)) {
- return String(o);
- } else if (Ext.isObject(o)) {
- return encodeObject(o);
- } else if (typeof o === "function") {
- return "null";
- }
- return 'undefined';
- },
- m = {
- "\b": '\\b',
- "\t": '\\t',
- "\n": '\\n',
- "\f": '\\f',
- "\r": '\\r',
- '"': '\\"',
- "\\": '\\\\',
- '\x0b': '\\u000b' //ie doesn't handle \v
- },
- charToReplace = /[\\\"\x00-\x1f\x7f-\uffff]/g,
- encodeString = function(s) {
- return '"' + s.replace(charToReplace, function(a) {
- var c = m[a];
- return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
- }) + '"';
- },
- encodeArray = function(o) {
- var a = ["[", ""],
- // Note empty string in case there are no serializable members.
- len = o.length,
- i;
- for (i = 0; i < len; i += 1) {
- a.push(doEncode(o[i]), ',');
- }
- // Overwrite trailing comma (or empty string)
- a[a.length - 1] = ']';
- return a.join("");
- },
- encodeObject = function(o) {
- var a = ["{", ""],
- // Note empty string in case there are no serializable members.
- i;
- for (i in o) {
- if (!useHasOwn || o.hasOwnProperty(i)) {
- a.push(doEncode(i), ":", doEncode(o[i]), ',');
- }
- }
- // Overwrite trailing comma (or empty string)
- a[a.length - 1] = '}';
- return a.join("");
- };
- /**
- * <p>Encodes a Date. This returns the actual string which is inserted into the JSON string as the literal expression.
- * <b>The returned value includes enclosing double quotation marks.</b></p>
- * <p>The default return format is "yyyy-mm-ddThh:mm:ss".</p>
- * <p>To override this:</p><pre><code>
- Ext.JSON.encodeDate = function(d) {
- return Ext.Date.format(d, '"Y-m-d"');
- };
- </code></pre>
- * @param {Date} d The Date to encode
- * @return {String} The string literal to use in a JSON string.
- */
- this.encodeDate = function(o) {
- return '"' + o.getFullYear() + "-"
- + pad(o.getMonth() + 1) + "-"
- + pad(o.getDate()) + "T"
- + pad(o.getHours()) + ":"
- + pad(o.getMinutes()) + ":"
- + pad(o.getSeconds()) + '"';
- };
- /**
- * Encodes an Object, Array or other value
- * @param {Object} o The variable to encode
- * @return {String} The JSON string
- */
- this.encode = function() {
- var ec;
- return function(o) {
- if (!ec) {
- // setup encoding function on first access
- ec = isNative() ? JSON.stringify : doEncode;
- }
- return ec(o);
- };
- }();
- /**
- * Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws a SyntaxError unless the safe option is set.
- * @param {String} json The JSON string
- * @param {Boolean} safe (optional) Whether to return null or throw an exception if the JSON is invalid.
- * @return {Object} The resulting object
- */
- this.decode = function() {
- var dc;
- return function(json, safe) {
- if (!dc) {
- // setup decoding function on first access
- dc = isNative() ? JSON.parse : doDecode;
- }
- try {
- return dc(json);
- } catch (e) {
- if (safe === true) {
- return null;
- }
- Ext.Error.raise({
- sourceClass: "Ext.JSON",
- sourceMethod: "decode",
- msg: "You're trying to decode an invalid JSON String: " + json
- });
- }
- };
- }();
- })();
- /**
- * Shorthand for {@link Ext.JSON#encode}
- * @member Ext
- * @method encode
- * @alias Ext.JSON#encode
- */
- Ext.encode = Ext.JSON.encode;
- /**
- * Shorthand for {@link Ext.JSON#decode}
- * @member Ext
- * @method decode
- * @alias Ext.JSON#decode
- */
- Ext.decode = Ext.JSON.decode;
- /**
- * @class Ext
- The Ext namespace (global object) encapsulates all classes, singletons, and utility methods provided by Sencha's libraries.</p>
- Most user interface Components are at a lower level of nesting in the namespace, but many common utility functions are provided
- as direct properties of the Ext namespace.
- Also many frequently used methods from other classes are provided as shortcuts within the Ext namespace.
- For example {@link Ext#getCmp Ext.getCmp} aliases {@link Ext.ComponentManager#get Ext.ComponentManager.get}.
- Many applications are initiated with {@link Ext#onReady Ext.onReady} which is called once the DOM is ready.
- This ensures all scripts have been loaded, preventing dependency issues. For example
- Ext.onReady(function(){
- new Ext.Component({
- renderTo: document.body,
- html: 'DOM ready!'
- });
- });
- For more information about how to use the Ext classes, see
- - <a href="http://www.sencha.com/learn/">The Learning Center</a>
- - <a href="http://www.sencha.com/learn/Ext_FAQ">The FAQ</a>
- - <a href="http://www.sencha.com/forum/">The forums</a>
- * @singleton
- * @markdown
- */
- Ext.apply(Ext, {
- userAgent: navigator.userAgent.toLowerCase(),
- cache: {},
- idSeed: 1000,
- windowId: 'ext-window',
- documentId: 'ext-document',
- /**
- * True when the document is fully initialized and ready for action
- * @type Boolean
- */
- isReady: false,
- /**
- * True to automatically uncache orphaned Ext.Elements periodically
- * @type Boolean
- */
- enableGarbageCollector: true,
- /**
- * True to automatically purge event listeners during garbageCollection.
- * @type Boolean
- */
- enableListenerCollection: true,
- /**
- * Generates unique ids. If the element already has an id, it is unchanged
- * @param {HTMLElement/Ext.Element} el (optional) The element to generate an id for
- * @param {String} prefix (optional) Id prefix (defaults "ext-gen")
- * @return {String} The generated Id.
- */
- id: function(el, prefix) {
- var me = this,
- sandboxPrefix = '';
- el = Ext.getDom(el, true) || {};
- if (el === document) {
- el.id = me.documentId;
- }
- else if (el === window) {
- el.id = me.windowId;
- }
- if (!el.id) {
- if (me.isSandboxed) {
- if (!me.uniqueGlobalNamespace) {
- me.getUniqueGlobalNamespace();
- }
- sandboxPrefix = me.uniqueGlobalNamespace + '-';
- }
- el.id = sandboxPrefix + (prefix || "ext-gen") + (++Ext.idSeed);
- }
- return el.id;
- },
- /**
- * Returns the current document body as an {@link Ext.Element}.
- * @return Ext.Element The document body
- */
- getBody: function() {
- return Ext.get(document.body || false);
- },
- /**
- * Returns the current document head as an {@link Ext.Element}.
- * @return Ext.Element The document head
- * @method
- */
- getHead: function() {
- var head;
- return function() {
- if (head == undefined) {
- head = Ext.get(document.getElementsByTagName("head")[0]);
- }
- return head;
- };
- }(),
- /**
- * Returns the current HTML document object as an {@link Ext.Element}.
- * @return Ext.Element The document
- */
- getDoc: function() {
- return Ext.get(document);
- },
- /**
- * This is shorthand reference to {@link Ext.ComponentManager#get}.
- * Looks up an existing {@link Ext.Component Component} by {@link Ext.Component#id id}
- * @param {String} id The component {@link Ext.Component#id id}
- * @return Ext.Component The Component, <tt>undefined</tt> if not found, or <tt>null</tt> if a
- * Class was found.
- */
- getCmp: function(id) {
- return Ext.ComponentManager.get(id);
- },
- /**
- * Returns the current orientation of the mobile device
- * @return {String} Either 'portrait' or 'landscape'
- */
- getOrientation: function() {
- return window.innerHeight > window.innerWidth ? 'portrait' : 'landscape';
- },
- /**
- * Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
- * DOM (if applicable) and calling their destroy functions (if available). This method is primarily
- * intended for arguments of type {@link Ext.Element} and {@link Ext.Component}, but any subclass of
- * {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
- * passed into this function in a single call as separate arguments.
- * @param {Ext.Element/Ext.Component/Ext.Element[]/Ext.Component[]...} arg1
- * An {@link Ext.Element}, {@link Ext.Component}, or an Array of either of these to destroy
- */
- destroy: function() {
- var ln = arguments.length,
- i, arg;
- for (i = 0; i < ln; i++) {
- arg = arguments[i];
- if (arg) {
- if (Ext.isArray(arg)) {
- this.destroy.apply(this, arg);
- }
- else if (Ext.isFunction(arg.destroy)) {
- arg.destroy();
- }
- else if (arg.dom) {
- arg.remove();
- }
- }
- }
- },
- /**
- * Execute a callback function in a particular scope. If no function is passed the call is ignored.
- *
- * For example, these lines are equivalent:
- *
- * Ext.callback(myFunc, this, [arg1, arg2]);
- * Ext.isFunction(myFunc) && myFunc.apply(this, [arg1, arg2]);
- *
- * @param {Function} callback The callback to execute
- * @param {Object} scope (optional) The scope to execute in
- * @param {Array} args (optional) The arguments to pass to the function
- * @param {Number} delay (optional) Pass a number to delay the call by a number of milliseconds.
- */
- callback: function(callback, scope, args, delay){
- if(Ext.isFunction(callback)){
- args = args || [];
- scope = scope || window;
- if (delay) {
- Ext.defer(callback, delay, scope, args);
- } else {
- callback.apply(scope, args);
- }
- }
- },
- /**
- * 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
- */
- htmlEncode : function(value) {
- return Ext.String.htmlEncode(value);
- },
- /**
- * Convert certain characters (&, <, >, and ') from their HTML character equivalents.
- * @param {String} value The string to decode
- * @return {String} The decoded text
- */
- htmlDecode : function(value) {
- return Ext.String.htmlDecode(value);
- },
- /**
- * 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 resulting URL
- */
- urlAppend : function(url, s) {
- if (!Ext.isEmpty(s)) {
- return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
- }
- return url;
- }
- });
- Ext.ns = Ext.namespace;
- // for old browsers
- window.undefined = window.undefined;
- /**
- * @class Ext
- * Ext core utilities and functions.
- * @singleton
- */
- (function(){
- /*
- FF 3.6 - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17
- FF 4.0.1 - Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
- FF 5.0 - Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0
- IE6 - Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;)
- IE7 - Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1;)
- IE8 - Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
- IE9 - Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
- Chrome 11 - Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.60 Safari/534.24
- Safari 5 - Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1
- Opera 11.11 - Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
- */
- var check = function(regex){
- return regex.test(Ext.userAgent);
- },
- isStrict = document.compatMode == "CSS1Compat",
- version = function (is, regex) {
- var m;
- return (is && (m = regex.exec(Ext.userAgent))) ? parseFloat(m[1]) : 0;
- },
- docMode = document.documentMode,
- isOpera = check(/opera/),
- isOpera10_5 = isOpera && check(/version\/10\.5/),
- isChrome = check(/\bchrome\b/),
- isWebKit = check(/webkit/),
- isSafari = !isChrome && check(/safari/),
- isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
- isSafari3 = isSafari && check(/version\/3/),
- isSafari4 = isSafari && check(/version\/4/),
- isSafari5 = isSafari && check(/version\/5/),
- isIE = !isOpera && check(/msie/),
- isIE7 = isIE && (check(/msie 7/) || docMode == 7),
- isIE8 = isIE && (check(/msie 8/) && docMode != 7 && docMode != 9 || docMode == 8),
- isIE9 = isIE && (check(/msie 9/) && docMode != 7 && docMode != 8 || docMode == 9),
- isIE6 = isIE && check(/msie 6/),
- isGecko = !isWebKit && check(/gecko/),
- isGecko3 = isGecko && check(/rv:1\.9/),
- isGecko4 = isGecko && check(/rv:2\.0/),
- isGecko5 = isGecko && check(/rv:5\./),
- isFF3_0 = isGecko3 && check(/rv:1\.9\.0/),
- isFF3_5 = isGecko3 && check(/rv:1\.9\.1/),
- isFF3_6 = isGecko3 && check(/rv:1\.9\.2/),
- isWindows = check(/windows|win32/),
- isMac = check(/macintosh|mac os x/),
- isLinux = check(/linux/),
- scrollbarSize = null,
- chromeVersion = version(true, /\bchrome\/(\d+\.\d+)/),
- firefoxVersion = version(true, /\bfirefox\/(\d+\.\d+)/),
- ieVersion = version(isIE, /msie (\d+\.\d+)/),
- operaVersion = version(isOpera, /version\/(\d+\.\d+)/),
- safariVersion = version(isSafari, /version\/(\d+\.\d+)/),
- webKitVersion = version(isWebKit, /webkit\/(\d+\.\d+)/),
- isSecure = /^https/i.test(window.location.protocol);
- // remove css image flicker
- try {
- document.execCommand("BackgroundImageCache", false, true);
- } catch(e) {}
- Ext.setVersion('extjs', '4.0.7');
- 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 (<tt>'about:blank'</tt>, except for IE in secure mode, which is <tt>'javascript:""'</tt>).
- * @type String
- */
- SSL_SECURE_URL : isSecure && isIE ? 'javascript:""' : 'about:blank',
- /**
- * True if the {@link Ext.fx.Anim} Class is available
- * @type Boolean
- * @property enableFx
- */
- /**
- * True to scope the reset CSS to be just applied to Ext components. Note that this wraps root containers
- * with an additional element. Also remember that when you turn on this option, you have to use ext-all-scoped {
- * unless you use the bootstrap.js to load your javascript, in which case it will be handled for you.
- * @type Boolean
- */
- scopeResetCSS : Ext.buildSettings.scopeResetCSS,
- /**
- * EXPERIMENTAL - True to cascade listener removal to child elements when an element is removed.
- * Currently not optimized for performance.
- * @type Boolean
- */
- enableNestedListenerRemoval : false,
- /**
- * Indicates whether to use native browser parsing for JSON methods.
- * This option is ignored if the browser does not support native JSON methods.
- * <b>Note: Native JSON methods will not work with objects that have functions.
- * Also, property names must be quoted, otherwise the data will not parse.</b> (Defaults to false)
- * @type Boolean
- */
- USE_NATIVE_JSON : false,
- /**
- * Return the dom node for the passed String (id), dom node, or Ext.Element.
- * Optional 'strict' flag is needed for IE since it can return 'name' and
- * 'id' elements by using getElementById.
- * Here are some examples:
- * <pre><code>
- // gets dom node based on id
- var elDom = Ext.getDom('elId');
- // gets dom node based on the dom node
- var elDom1 = Ext.getDom(elDom);
- // If we don't know if we are working with an
- // Ext.Element or a dom node use Ext.getDom
- function(el){
- var dom = Ext.getDom(el);
- // do something with the dom node
- }
- * </code></pre>
- * <b>Note</b>: the dom node to be found actually needs to exist (be rendered, etc)
- * when this method is called to be successful.
- * @param {String/HTMLElement/Ext.Element} el
- * @return HTMLElement
- */
- getDom : function(el, strict) {
- if (!el || !document) {
- return null;
- }
- if (el.dom) {
- return el.dom;
- } else {
- if (typeof el == 'string') {
- var e = document.getElementById(el);
- // IE returns elements with the 'name' and 'id' attribute.
- // we do a strict check to return the element with only the id attribute
- if (e && isIE && strict) {
- if (el == e.getAttribute('id')) {
- return e;
- } else {
- return null;
- }
- }
- return e;
- } else {
- return el;
- }
- }
- },
- /**
- * Removes a DOM node from the document.
- * <p>Removes this element from the document, removes all DOM event listeners, and deletes the cache reference.
- * All DOM event listeners are removed from this element. If {@link Ext#enableNestedListenerRemoval Ext.enableNestedListenerRemoval} is
- * <code>true</code>, then DOM event listeners are also removed from all child nodes. The body node
- * will be ignored if passed in.</p>
- * @param {HTMLElement} node The node to remove
- * @method
- */
- removeNode : isIE6 || isIE7 ? function() {
- var d;
- return function(n){
- if(n && n.tagName != 'BODY'){
- (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n) : Ext.EventManager.removeAll(n);
- d = d || document.createElement('div');
- d.appendChild(n);
- d.innerHTML = '';
- delete Ext.cache[n.id];
- }
- };
- }() : function(n) {
- if (n && n.parentNode && n.tagName != 'BODY') {
- (Ext.enableNestedListenerRemoval) ? Ext.EventManager.purgeElement(n) : Ext.EventManager.removeAll(n);
- n.parentNode.removeChild(n);
- delete Ext.cache[n.id];
- }
- },
- isStrict: isStrict,
- isIEQuirks: isIE && !isStrict,
- /**
- * True if the detected browser is Opera.
- * @type Boolean
- */
- isOpera : isOpera,
- /**
- * True if the detected browser is Opera 10.5x.
- * @type Boolean
- */
- isOpera10_5 : isOpera10_5,
- /**
- * True if the detected browser uses WebKit.
- * @type Boolean
- */
- isWebKit : isWebKit,
- /**
- * True if the detected browser is Chrome.
- * @type Boolean
- */
- isChrome : isChrome,
- /**
- * True if the detected browser is Safari.
- * @type Boolean
- */
- isSafari : isSafari,
- /**
- * True if the detected browser is Safari 3.x.
- * @type Boolean
- */
- isSafari3 : isSafari3,
- /**
- * True if the detected browser is Safari 4.x.
- * @type Boolean
- */
- isSafari4 : isSafari4,
- /**
- * True if the detected browser is Safari 5.x.
- * @type Boolean
- */
- isSafari5 : isSafari5,
- /**
- * True if the detected browser is Safari 2.x.
- * @type Boolean
- */
- isSafari2 : isSafari2,
- /**
- * True if the detected browser is Internet Explorer.
- * @type Boolean
- */
- isIE : isIE,
- /**
- * True if the detected browser is Internet Explorer 6.x.
- * @type Boolean
- */
- isIE6 : isIE6,
- /**
- * True if the detected browser is Internet Explorer 7.x.
- * @type Boolean
- */
- isIE7 : isIE7,
- /**
- * True if the detected browser is Internet Explorer 8.x.
- * @type Boolean
- */
- isIE8 : isIE8,
- /**
- * True if the detected browser is Internet Explorer 9.x.
- * @type Boolean
- */
- isIE9 : isIE9,
- /**
- * True if the detected browser uses the Gecko layout engine (e.g. Mozilla, Firefox).
- * @type Boolean
- */
- isGecko : isGecko,
- /**
- * True if the detected browser uses a Gecko 1.9+ layout engine (e.g. Firefox 3.x).
- * @type Boolean
- */
- isGecko3 : isGecko3,
- /**
- * True if the detected browser uses a Gecko 2.0+ layout engine (e.g. Firefox 4.x).
- * @type Boolean
- */
- isGecko4 : isGecko4,
- /**
- * True if the detected browser uses a Gecko 5.0+ layout engine (e.g. Firefox 5.x).
- * @type Boolean
- */
- isGecko5 : isGecko5,
- /**
- * True if the detected browser uses FireFox 3.0
- * @type Boolean
- */
- isFF3_0 : isFF3_0,
- /**
- * True if the detected browser uses FireFox 3.5
- * @type Boolean
- */
- isFF3_5 : isFF3_5,
- /**
- * True if the detected browser uses FireFox 3.6
- * @type Boolean
- */
- isFF3_6 : isFF3_6,
- /**
- * True if the detected browser uses FireFox 4
- * @type Boolean
- */
- isFF4 : 4 <= firefoxVersion && firefoxVersion < 5,
- /**
- * True if the detected browser uses FireFox 5
- * @type Boolean
- */
- isFF5 : 5 <= firefoxVersion && firefoxVersion < 6,
- /**
- * True if the detected platform is Linux.
- * @type Boolean
- */
- isLinux : isLinux,
- /**
- * True if the detected platform is Windows.
- * @type Boolean
- */
- isWindows : isWindows,
- /**
- * True if the detected platform is Mac OS.
- * @type Boolean
- */
- isMac : isMac,
- /**
- * The current version of Chrome (0 if the browser is not Chrome).
- * @type Number
- */
- chromeVersion: chromeVersion,
- /**
- * The current version of Firefox (0 if the browser is not Firefox).
- * @type Number
- */
- firefoxVersion: firefoxVersion,
- /**
- * The current version of IE (0 if the browser is not IE). This does not account
- * for the documentMode of the current page, which is factored into {@link #isIE7},
- * {@link #isIE8} and {@link #isIE9}. Thus this is not always true:
- *
- * Ext.isIE8 == (Ext.ieVersion == 8)
- *
- * @type Number
- * @markdown
- */
- ieVersion: ieVersion,
- /**
- * The current version of Opera (0 if the browser is not Opera).
- * @type Number
- */
- operaVersion: operaVersion,
- /**
- * The current version of Safari (0 if the browser is not Safari).
- * @type Number
- */
- safariVersion: safariVersion,
- /**
- * The current version of WebKit (0 if the browser does not use WebKit).
- * @type Number
- */
- webKitVersion: webKitVersion,
- /**
- * True if the page is running over SSL
- * @type Boolean
- */
- isSecure: isSecure,
- /**
- * URL to a 1x1 transparent gif image used by Ext to create inline icons with CSS background images.
- * In older versions of IE, this defaults to "http://sencha.com/s.gif" and you should change this to a URL on your server.
- * For other browsers it uses an inline data URL.
- * @type String
- */
- BLANK_IMAGE_URL : (isIE6 || isIE7) ? '/' + '/www.sencha.com/s.gif' : 'data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==',
- /**
- * <p>Utility method for returning a default value if the passed value is empty.</p>
- * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
- * <li>null</li>
- * <li>undefined</li>
- * <li>an empty array</li>
- * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
- * </ul></div>
- * @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
- * @deprecated 4.0.0 Use {@link Ext#valueFrom} instead
- */
- value : function(v, defaultValue, allowBlank){
- return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
- },
- /**
- * Escapes the passed string for use in a regular expression
- * @param {String} str
- * @return {String}
- * @deprecated 4.0.0 Use {@link Ext.String#escapeRegex} instead
- */
- escapeRe : function(s) {
- return s.replace(/([-.*+?^${}()|[\]\/\\])/g, "\\$1");
- },
- /**
- * Applies event listeners to elements by selectors when the document is ready.
- * The event name is specified with an <tt>@</tt> suffix.
- * <pre><code>
- Ext.addBehaviors({
- // add a listener for click on all anchors in element with id foo
- '#foo a@click' : function(e, t){
- // do something
- },
- // add the same listener to multiple selectors (separated by comma BEFORE the @)
- '#foo a, #bar span.some-class@mouseover' : function(){
- // do something
- }
- });
- * </code></pre>
- * @param {Object} obj The list of behaviors to apply
- */
- addBehaviors : function(o){
- if(!Ext.isReady){
- Ext.onReady(function(){
- Ext.addBehaviors(o);
- });
- } else {
- var cache = {}, // simple cache for applying multiple behaviors to same selector does query multiple times
- parts,
- b,
- s;
- for (b in o) {
- if ((parts = b.split('@'))[1]) { // for Object prototype breakers
- s = parts[0];
- if(!cache[s]){
- cache[s] = Ext.select(s);
- }
- cache[s].on(parts[1], o[b]);
- }
- }
- cache = null;
- }
- },
- /**
- * Returns the size of the browser scrollbars. This can differ depending on
- * operating system settings, such as the theme or font size.
- * @param {Boolean} force (optional) true to force a recalculation of the value.
- * @return {Object} An object containing the width of a vertical scrollbar and the
- * height of a horizontal scrollbar.
- */
- getScrollbarSize: function (force) {
- if(!Ext.isReady){
- return 0;
- }
- if(force === true || scrollbarSize === null){
- // BrowserBug: IE9
- // When IE9 positions an element offscreen via offsets, the offsetWidth is
- // inaccurately reported. For IE9 only, we render on screen before removing.
- var cssClass = Ext.isIE9 ? '' : Ext.baseCSSPrefix + 'hide-offsets',
- // Append our div, do our calculation and then remove it
- div = Ext.getBody().createChild('<div class="' + cssClass + '" style="width:100px;height:50px;overflow:hidden;"><div style="height:200px;"></div></div>'),
- child = div.child('div', true),
- w1 = child.offsetWidth;
- div.setStyle('overflow', (Ext.isWebKit || Ext.isGecko) ? 'auto' : 'scroll');
- var w2 = child.offsetWidth, width = w1 - w2;
- div.remove();
- // We assume width == height for now. TODO: is this always true?
- scrollbarSize = { width: width, height: width };
- }
- return scrollbarSize;
- },
- /**
- * Utility method for getting the width of the browser's vertical scrollbar. This
- * can differ depending on operating system settings, such as the theme or font size.
- *
- * This method is deprected in favor of {@link #getScrollbarSize}.
- *
- * @param {Boolean} force (optional) true to force a recalculation of the value.
- * @return {Number} The width of a vertical scrollbar.
- * @deprecated
- */
- getScrollBarWidth: function(force){
- var size = Ext.getScrollbarSize(force);
- return size.width + 2; // legacy fudge factor
- },
- /**
- * Copies a set of named properties fom the source object to the destination object.
- *
- * Example:
- *
- * ImageComponent = Ext.extend(Ext.Component, {
- * initComponent: function() {
- * this.autoEl = { tag: 'img' };
- * MyComponent.superclass.initComponent.apply(this, arguments);
- * this.initialBox = Ext.copyTo({}, this.initialConfig, 'x,y,width,height');
- * }
- * });
- *
- * Important note: To borrow class prototype methods, use {@link Ext.Base#borrow} instead.
- *
- * @param {Object} dest The destination object.
- * @param {Object} source The source object.
- * @param {String/String[]} names Either an Array of property names, or a comma-delimited list
- * of property names to copy.
- * @param {Boolean} usePrototypeKeys (Optional) Defaults to false. Pass true to copy keys off of the prototype as well as the instance.
- * @return {Object} The modified object.
- */
- copyTo : function(dest, source, names, usePrototypeKeys){
- if(typeof names == 'string'){
- names = names.split(/[,;\s]/);
- }
- Ext.each(names, function(name){
- if(usePrototypeKeys || source.hasOwnProperty(name)){
- dest[name] = source[name];
- }
- }, this);
- return dest;
- },
- /**
- * Attempts to destroy and then remove a set of named properties of the passed object.
- * @param {Object} o The object (most likely a Component) who's properties you wish to destroy.
- * @param {String...} args One or more names of the properties to destroy and remove from the object.
- */
- destroyMembers : function(o){
- for (var i = 1, a = arguments, len = a.length; i < len; i++) {
- Ext.destroy(o[a[i]]);
- delete o[a[i]];
- }
- },
- /**
- * Logs a message. If a console is present it will be used. On Opera, the method
- * "opera.postError" is called. In other cases, the message is logged to an array
- * "Ext.log.out". An attached debugger can watch this array and view the log. The
- * log buffer is limited to a maximum of "Ext.log.max" entries (defaults to 250).
- * The `Ext.log.out` array can also be written to a popup window by entering the
- * following in the URL bar (a "bookmarklet"):
- *
- * javascript:void(Ext.log.show());
- *
- * If additional parameters are passed, they are joined and appended to the message.
- * A technique for tracing entry and exit of a function is this:
- *
- * function foo () {
- * Ext.log({ indent: 1 }, '>> foo');
- *
- * // log statements in here or methods called from here will be indented
- * // by one step
- *
- * Ext.log({ outdent: 1 }, '<< foo');
- * }
- *
- * This method does nothing in a release build.
- *
- * @param {String/Object} message The message to log or an options object with any
- * of the following properties:
- *
- * - `msg`: The message to log (required).
- * - `level`: One of: "error", "warn", "info" or "log" (the default is "log").
- * - `dump`: An object to dump to the log as part of the message.
- * - `stack`: True to include a stack trace in the log.
- * - `indent`: Cause subsequent log statements to be indented one step.
- * - `outdent`: Cause this and following statements to be one step less indented.
- * @markdown
- */
- log :
- Ext.emptyFn,
- /**
- * Partitions the set into two sets: a true set and a false set.
- * Example:
- * Example2:
- * <pre><code>
- // Example 1:
- Ext.partition([true, false, true, true, false]); // [[true, true, true], [false, false]]
- // Example 2:
- Ext.partition(
- Ext.query("p"),
- function(val){
- return val.className == "class1"
- }
- );
- // true are those paragraph elements with a className of "class1",
- // false set are those that do not have that className.
- * </code></pre>
- * @param {Array/NodeList} arr The array to partition
- * @param {Function} truth (optional) a function to determine truth. If this is omitted the element
- * itself must be able to be evaluated for its truthfulness.
- * @return {Array} [array of truish values, array of falsy values]
- * @deprecated 4.0.0 Will be removed in the next major version
- */
- partition : function(arr, truth){
- var ret = [[],[]];
- Ext.each(arr, function(v, i, a) {
- ret[ (truth && truth(v, i, a)) || (!truth && v) ? 0 : 1].push(v);
- });
- return ret;
- },
- /**
- * Invokes a method on each item in an Array.
- * <pre><code>
- // Example:
- Ext.invoke(Ext.query("p"), "getAttribute", "id");
- // [el1.getAttribute("id"), el2.getAttribute("id"), ..., elN.getAttribute("id")]
- * </code></pre>
- * @param {Array/NodeList} arr The Array of items to invoke the method on.
- * @param {String} methodName The method name to invoke.
- * @param {Object...} args Arguments to send into the method invocation.
- * @return {Array} The results of invoking the method on each item in the array.
- * @deprecated 4.0.0 Will be removed in the next major version
- */
- invoke : function(arr, methodName){
- var ret = [],
- args = Array.prototype.slice.call(arguments, 2);
- Ext.each(arr, function(v,i) {
- if (v && typeof v[methodName] == 'function') {
- ret.push(v[methodName].apply(v, args));
- } else {
- ret.push(undefined);
- }
- });
- return ret;
- },
- /**
- * <p>Zips N sets together.</p>
- * <pre><code>
- // Example 1:
- Ext.zip([1,2,3],[4,5,6]); // [[1,4],[2,5],[3,6]]
- // Example 2:
- Ext.zip(
- [ "+", "-", "+"],
- [ 12, 10, 22],
- [ 43, 15, 96],
- function(a, b, c){
- return "$" + a + "" + b + "." + c
- }
- ); // ["$+12.43", "$-10.15", "$+22.96"]
- * </code></pre>
- * @param {Array/NodeList...} arr This argument may be repeated. Array(s) to contribute values.
- * @param {Function} zipper (optional) The last item in the argument list. This will drive how the items are zipped together.
- * @return {Array} The zipped set.
- * @deprecated 4.0.0 Will be removed in the next major version
- */
- zip : function(){
- var parts = Ext.partition(arguments, function( val ){ return typeof val != 'function'; }),
- arrs = parts[0],
- fn = parts[1][0],
- len = Ext.max(Ext.pluck(arrs, "length")),
- ret = [];
- for (var i = 0; i < len; i++) {
- ret[i] = [];
- if(fn){
- ret[i] = fn.apply(fn, Ext.pluck(arrs, i));
- }else{
- for (var j = 0, aLen = arrs.length; j < aLen; j++){
- ret[i].push( arrs[j][i] );
- }
- }
- }
- return ret;
- },
- /**
- * Turns an array into a sentence, joined by a specified connector - e.g.:
- * Ext.toSentence(['Adama', 'Tigh', 'Roslin']); //'Adama, Tigh and Roslin'
- * Ext.toSentence(['Adama', 'Tigh', 'Roslin'], 'or'); //'Adama, Tigh or Roslin'
- * @param {String[]} items The array to create a sentence from
- * @param {String} connector The string to use to connect the last two words. Usually 'and' or 'or' - defaults to 'and'.
- * @return {String} The sentence string
- * @deprecated 4.0.0 Will be removed in the next major version
- */
- toSentence: function(items, connector) {
- var length = items.length;
- if (length <= 1) {
- return items[0];
- } else {
- var head = items.slice(0, length - 1),
- tail = items[length - 1];
- return Ext.util.Format.format("{0} {1} {2}", head.join(", "), connector || 'and', tail);
- }
- },
- /**
- * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
- * you may want to set this to true.
- * @type Boolean
- */
- useShims: isIE6
- });
- })();
- /**
- * Loads Ext.app.Application class and starts it up with given configuration after the page is ready.
- *
- * See Ext.app.Application for details.
- *
- * @param {Object} config
- */
- Ext.application = function(config) {
- Ext.require('Ext.app.Application');
- Ext.onReady(function() {
- Ext.create('Ext.app.Application', config);
- });
- };
- /**
- * @class Ext.util.Format
- This class is a centralized place for formatting functions. It includes
- functions to format various different types of data, such as text, dates and numeric values.
- __Localization__
- This class contains several options for localization. These can be set once the library has loaded,
- all calls to the functions from that point will use the locale settings that were specified.
- Options include:
- - thousandSeparator
- - decimalSeparator
- - currenyPrecision
- - currencySign
- - currencyAtEnd
- This class also uses the default date format defined here: {@link Ext.Date#defaultFormat}.
- __Using with renderers__
- There are two helper functions that return a new function that can be used in conjunction with
- grid renderers:
- columns: [{
- dataIndex: 'date',
- renderer: Ext.util.Format.dateRenderer('Y-m-d')
- }, {
- dataIndex: 'time',
- renderer: Ext.util.Format.numberRenderer('0.000')
- }]
- Functions that only take a single argument can also be passed directly:
- columns: [{
- dataIndex: 'cost',
- renderer: Ext.util.Format.usMoney
- }, {
- dataIndex: 'productCode',
- renderer: Ext.util.Format.uppercase
- }]
- __Using with XTemplates__
- XTemplates can also directly use Ext.util.Format functions:
- new Ext.XTemplate([
- 'Date: {startDate:date("Y-m-d")}',
- 'Cost: {cost:usMoney}'
- ]);
- * @markdown
- * @singleton
- */
- (function() {
- Ext.ns('Ext.util');
- Ext.util.Format = {};
- var UtilFormat = Ext.util.Format,
- stripTagsRE = /<\/?[^>]+>/gi,
- stripScriptsRe = /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig,
- nl2brRe = /\r?\n/g,
- // A RegExp to remove from a number format string, all characters except digits and '.'
- formatCleanRe = /[^\d\.]/g,
- // A RegExp to remove from a number format string, all characters except digits and the local decimal separator.
- // Created on first use. The local decimal separator character must be initialized for this to be created.
- I18NFormatCleanRe;
- Ext.apply(UtilFormat, {
- /**
- * @property {String} thousandSeparator
- * <p>The character that the {@link #number} function uses as a thousand separator.</p>
- * <p>This may be overridden in a locale file.</p>
- */
- thousandSeparator: ',',
- /**
- * @property {String} decimalSeparator
- * <p>The character that the {@link #number} function uses as a decimal point.</p>
- * <p>This may be overridden in a locale file.</p>
- */
- decimalSeparator: '.',
- /**
- * @property {Number} currencyPrecision
- * <p>The number of decimal places that the {@link #currency} function displays.</p>
- * <p>This may be overridden in a locale file.</p>
- */
- currencyPrecision: 2,
- /**
- * @property {String} currencySign
- * <p>The currency sign that the {@link #currency} function displays.</p>
- * <p>This may be overridden in a locale file.</p>
- */
- currencySign: '$',
- /**
- * @property {Boolean} currencyAtEnd
- * <p>This may be set to <code>true</code> to make the {@link #currency} function
- * append the currency sign to the formatted value.</p>
- * <p>This may be overridden in a locale file.</p>
- */
- currencyAtEnd: false,
- /**
- * Checks a reference and converts it to empty string if it is undefined
- * @param {Object} value Reference to check
- * @return {Object} Empty string if converted, otherwise the original value
- */
- undef : function(value) {
- return value !== undefined ? value : "";
- },
- /**
- * Checks a reference and converts it to the default value if it's empty
- * @param {Object} value Reference to check
- * @param {String} defaultValue The value to insert of it's undefined (defaults to "")
- * @return {String}
- */
- defaultValue : function(value, defaultValue) {
- return value !== undefined && value !== '' ? value : defaultValue;
- },
- /**
- * Returns a substring from within an original string
- * @param {String} value The original text
- * @param {Number} start The start index of the substring
- * @param {Number} length The length of the substring
- * @return {String} The substring
- */
- substr : function(value, start, length) {
- return String(value).substr(start, length);
- },
- /**
- * Converts a string to all lower case letters
- * @param {String} value The text to convert
- * @return {String} The converted text
- */
- lowercase : function(value) {
- return String(value).toLowerCase();
- },
- /**
- * Converts a string to all upper case letters
- * @param {String} value The text to convert
- * @return {String} The converted text
- */
- uppercase : function(value) {
- return String(value).toUpperCase();
- },
- /**
- * Format a number as US currency
- * @param {Number/String} value The numeric value to format
- * @return {String} The formatted currency string
- */
- usMoney : function(v) {
- return UtilFormat.currency(v, '$', 2);
- },
- /**
- * Format a number as a currency
- * @param {Number/String} value The numeric value to format
- * @param {String} sign The currency sign to use (defaults to {@link #currencySign})
- * @param {Number} decimals The number of decimals to use for the currency (defaults to {@link #currencyPrecision})
- * @param {Boolean} end True if the currency sign should be at the end of the string (defaults to {@link #currencyAtEnd})
- * @return {String} The formatted currency string
- */
- currency: function(v, currencySign, decimals, end) {
- var negativeSign = '',
- format = ",0",
- i = 0;
- v = v - 0;
- if (v < 0) {
- v = -v;
- negativeSign = '-';
- }
- decimals = decimals || UtilFormat.currencyPrecision;
- format += format + (decimals > 0 ? '.' : '');
- for (; i < decimals; i++) {
- format += '0';
- }
- v = UtilFormat.number(v, format);
- if ((end || UtilFormat.currencyAtEnd) === true) {
- return Ext.String.format("{0}{1}{2}", negativeSign, v, currencySign || UtilFormat.currencySign);
- } else {
- return Ext.String.format("{0}{1}{2}", negativeSign, currencySign || UtilFormat.currencySign, v);
- }
- },
- /**
- * Formats the passed date using the specified format pattern.
- * @param {String/Date} value The value to format. If a string is passed, it is converted to a Date by the Javascript
- * Date object's <a href="http://www.w3schools.com/jsref/jsref_parse.asp">parse()</a> method.
- * @param {String} format (Optional) Any valid date format string. Defaults to {@link Ext.Date#defaultFormat}.
- * @return {String} The formatted date string.
- */
- date: function(v, format) {
- if (!v) {
- return "";
- }
- if (!Ext.isDate(v)) {
- v = new Date(Date.parse(v));
- }
- return Ext.Date.dateFormat(v, format || Ext.Date.defaultFormat);
- },
- /**
- * Returns a date rendering function that can be reused to apply a date format multiple times efficiently
- * @param {String} format Any valid date format string. Defaults to {@link Ext.Date#defaultFormat}.
- * @return {Function} The date formatting function
- */
- dateRenderer : function(format) {
- return function(v) {
- return UtilFormat.date(v, format);
- };
- },
- /**
- * Strips all HTML tags
- * @param {Object} value The text from which to strip tags
- * @return {String} The stripped text
- */
- stripTags : function(v) {
- return !v ? v : String(v).replace(stripTagsRE, "");
- },
- /**
- * Strips all script tags
- * @param {Object} value The text from which to strip script tags
- * @return {String} The stripped text
- */
- stripScripts : function(v) {
- return !v ? v : String(v).replace(stripScriptsRe, "");
- },
- /**
- * Simple format for a file size (xxx bytes, xxx KB, xxx MB)
- * @param {Number/String} size The numeric value to format
- * @return {String} The formatted file size
- */
- fileSize : function(size) {
- if (size < 1024) {
- return size + " bytes";
- } else if (size < 1048576) {
- return (Math.round(((size*10) / 1024))/10) + " KB";
- } else {
- return (Math.round(((size*10) / 1048576))/10) + " MB";
- }
- },
- /**
- * It does simple math for use in a template, for example:<pre><code>
- * var tpl = new Ext.Template('{value} * 10 = {value:math("* 10")}');
- * </code></pre>
- * @return {Function} A function that operates on the passed value.
- * @method
- */
- math : function(){
- var fns = {};
- return function(v, a){
- if (!fns[a]) {
- fns[a] = Ext.functionFactory('v', 'return v ' + a + ';');
- }
- return fns[a](v);
- };
- }(),
- /**
- * Rounds the passed number to the required decimal precision.
- * @param {Number/String} value The numeric value to round.
- * @param {Number} precision The number of decimal places to which to round the first parameter's value.
- * @return {Number} The rounded value.
- */
- round : function(value, precision) {
- var result = Number(value);
- if (typeof precision == 'number') {
- precision = Math.pow(10, precision);
- result = Math.round(value * precision) / precision;
- }
- return result;
- },
- /**
- * <p>Formats the passed number according to the passed format string.</p>
- * <p>The number of digits after the decimal separator character specifies the number of
- * decimal places in the resulting string. The <u>local-specific</u> decimal character is used in the result.</p>
- * <p>The <i>presence</i> of a thousand separator character in the format string specifies that
- * the <u>locale-specific</u> thousand separator (if any) is inserted separating thousand groups.</p>
- * <p>By default, "," is expected as the thousand separator, and "." is expected as the decimal separator.</p>
- * <p><b>New to Ext JS 4</b></p>
- * <p>Locale-specific characters are always used in the formatted output when inserting
- * thousand and decimal separators.</p>
- * <p>The format string must specify separator characters according to US/UK conventions ("," as the
- * thousand separator, and "." as the decimal separator)</p>
- * <p>To allow specification of format strings according to local conventions for separator characters, add
- * the string <code>/i</code> to the end of the format string.</p>
- * <div style="margin-left:40px">examples (123456.789):
- * <div style="margin-left:10px">
- * 0 - (123456) show only digits, no precision<br>
- * 0.00 - (123456.78) show only digits, 2 precision<br>
- * 0.0000 - (123456.7890) show only digits, 4 precision<br>
- * 0,000 - (123,456) show comma and digits, no precision<br>
- * 0,000.00 - (123,456.78) show comma and digits, 2 precision<br>
- * 0,0.00 - (123,456.78) shortcut method, show comma and digits, 2 precision<br>
- * To allow specification of the formatting string using UK/US grouping characters (,) and decimal (.) for international numbers, add /i to the end.
- * For example: 0.000,00/i
- * </div></div>
- * @param {Number} v The number to format.
- * @param {String} format The way you would like to format this text.
- * @return {String} The formatted number.
- */
- number: function(v, formatString) {
- if (!formatString) {
- return v;
- }
- v = Ext.Number.from(v, NaN);
- if (isNaN(v)) {
- return '';
- }
- var comma = UtilFormat.thousandSeparator,
- dec = UtilFormat.decimalSeparator,
- i18n = false,
- neg = v < 0,
- hasComma,
- psplit;
- v = Math.abs(v);
- // The "/i" suffix allows caller to use a locale-specific formatting string.
- // Clean the format string by removing all but numerals and the decimal separator.
- // Then split the format string into pre and post decimal segments according to *what* the
- // decimal separator is. If they are specifying "/i", they are using the local convention in the format string.
- if (formatString.substr(formatString.length - 2) == '/i') {
- if (!I18NFormatCleanRe) {
- I18NFormatCleanRe = new RegExp('[^\\d\\' + UtilFormat.decimalSeparator + ']','g');
- }
- formatString = formatString.substr(0, formatString.length - 2);
- i18n = true;
- hasComma = formatString.indexOf(comma) != -1;
- psplit = formatString.replace(I18NFormatCleanRe, '').split(dec);
- } else {
- hasComma = formatString.indexOf(',') != -1;
- psplit = formatString.replace(formatCleanRe, '').split('.');
- }
- if (1 < psplit.length) {
- v = v.toFixed(psplit[1].length);
- } else if(2 < psplit.length) {
- } else {
- v = v.toFixed(0);
- }
- var fnum = v.toString();
- psplit = fnum.split('.');
- if (hasComma) {
- var cnum = psplit[0],
- parr = [],
- j = cnum.length,
- m = Math.floor(j / 3),
- n = cnum.length % 3 || 3,
- i;
- for (i = 0; i < j; i += n) {
- if (i !== 0) {
- n = 3;
- }
- parr[parr.length] = cnum.substr(i, n);
- m -= 1;
- }
- fnum = parr.join(comma);
- if (psplit[1]) {
- fnum += dec + psplit[1];
- }
- } else {
- if (psplit[1]) {
- fnum = psplit[0] + dec + psplit[1];
- }
- }
- if (neg) {
- /*
- * Edge case. If we have a very small negative number it will get rounded to 0,
- * however the initial check at the top will still report as negative. Replace
- * everything but 1-9 and check if the string is empty to determine a 0 value.
- */
- neg = fnum.replace(/[^1-9]/g, '') !== '';
- }
- return (neg ? '-' : '') + formatString.replace(/[\d,?\.?]+/, fnum);
- },
- /**
- * Returns a number rendering function that can be reused to apply a number format multiple times efficiently
- * @param {String} format Any valid number format string for {@link #number}
- * @return {Function} The number formatting function
- */
- numberRenderer : function(format) {
- return function(v) {
- return UtilFormat.number(v, format);
- };
- },
- /**
- * Selectively do a plural form of a word based on a numeric value. For example, in a template,
- * {commentCount:plural("Comment")} would result in "1 Comment" if commentCount was 1 or would be "x Comments"
- * if the value is 0 or greater than 1.
- * @param {Number} value The value to compare against
- * @param {String} singular The singular form of the word
- * @param {String} plural (optional) The plural form of the word (defaults to the singular with an "s")
- */
- plural : function(v, s, p) {
- return v +' ' + (v == 1 ? s : (p ? p : s+'s'));
- },
- /**
- * Converts newline characters to the HTML tag <br/>
- * @param {String} The string value to format.
- * @return {String} The string with embedded <br/> tags in place of newlines.
- */
- nl2br : function(v) {
- return Ext.isEmpty(v) ? '' : v.replace(nl2brRe, '<br/>');
- },
- /**
- * Alias for {@link Ext.String#capitalize}.
- * @method
- * @alias Ext.String#capitalize
- */
- capitalize: Ext.String.capitalize,
- /**
- * Alias for {@link Ext.String#ellipsis}.
- * @method
- * @alias Ext.String#ellipsis
- */
- ellipsis: Ext.String.ellipsis,
- /**
- * Alias for {@link Ext.String#format}.
- * @method
- * @alias Ext.String#format
- */
- format: Ext.String.format,
- /**
- * Alias for {@link Ext.String#htmlDecode}.
- * @method
- * @alias Ext.String#htmlDecode
- */
- htmlDecode: Ext.String.htmlDecode,
- /**
- * Alias for {@link Ext.String#htmlEncode}.
- * @method
- * @alias Ext.String#htmlEncode
- */
- htmlEncode: Ext.String.htmlEncode,
- /**
- * Alias for {@link Ext.String#leftPad}.
- * @method
- * @alias Ext.String#leftPad
- */
- leftPad: Ext.String.leftPad,
- /**
- * Alias for {@link Ext.String#trim}.
- * @method
- * @alias Ext.String#trim
- */
- trim : Ext.String.trim,
- /**
- * Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations
- * (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result)
- * @param {Number/String} v The encoded margins
- * @return {Object} An object with margin sizes for top, right, bottom and left
- */
- parseBox : function(box) {
- if (Ext.isNumber(box)) {
- box = box.toString();
- }
- var parts = box.split(' '),
- ln = parts.length;
- if (ln == 1) {
- parts[1] = parts[2] = parts[3] = parts[0];
- }
- else if (ln == 2) {
- parts[2] = parts[0];
- parts[3] = parts[1];
- }
- else if (ln == 3) {
- parts[3] = parts[1];
- }
- return {
- top :parseInt(parts[0], 10) || 0,
- right :parseInt(parts[1], 10) || 0,
- bottom:parseInt(parts[2], 10) || 0,
- left :parseInt(parts[3], 10) || 0
- };
- },
- /**
- * Escapes the passed string for use in a regular expression
- * @param {String} str
- * @return {String}
- */
- escapeRegex : function(s) {
- return s.replace(/([\-.*+?\^${}()|\[\]\/\\])/g, "\\$1");
- }
- });
- })();
- /**
- * @class Ext.util.TaskRunner
- * Provides the ability to execute one or more arbitrary tasks in a multithreaded
- * manner. Generally, you can use the singleton {@link Ext.TaskManager} instead, but
- * if needed, you can create separate instances of TaskRunner. Any number of
- * separate tasks can be started at any time and will run independently of each
- * other. Example usage:
- * <pre><code>
- // Start a simple clock task that updates a div once per second
- var updateClock = function(){
- Ext.fly('clock').update(new Date().format('g:i:s A'));
- }
- var task = {
- run: updateClock,
- interval: 1000 //1 second
- }
- var runner = new Ext.util.TaskRunner();
- runner.start(task);
- // equivalent using TaskManager
- Ext.TaskManager.start({
- run: updateClock,
- interval: 1000
- });
- * </code></pre>
- * <p>See the {@link #start} method for details about how to configure a task object.</p>
- * Also see {@link Ext.util.DelayedTask}.
- *
- * @constructor
- * @param {Number} [interval=10] The minimum precision in milliseconds supported by this TaskRunner instance
- */
- Ext.ns('Ext.util');
- Ext.util.TaskRunner = function(interval) {
- interval = interval || 10;
- var tasks = [],
- removeQueue = [],
- id = 0,
- running = false,
- // private
- stopThread = function() {
- running = false;
- clearInterval(id);
- id = 0;
- },
- // private
- startThread = function() {
- if (!running) {
- running = true;
- id = setInterval(runTasks, interval);
- }
- },
- // private
- removeTask = function(t) {
- removeQueue.push(t);
- if (t.onStop) {
- t.onStop.apply(t.scope || t);
- }
- },
- // private
- runTasks = function() {
- var rqLen = removeQueue.length,
- now = new Date().getTime(),
- i;
- if (rqLen > 0) {
- for (i = 0; i < rqLen; i++) {
- Ext.Array.remove(tasks, removeQueue[i]);
- }
- removeQueue = [];
- if (tasks.length < 1) {
- stopThread();
- return;
- }
- }
- i = 0;
- var t,
- itime,
- rt,
- len = tasks.length;
- for (; i < len; ++i) {
- t = tasks[i];
- itime = now - t.taskRunTime;
- if (t.interval <= itime) {
- rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]);
- t.taskRunTime = now;
- if (rt === false || t.taskRunCount === t.repeat) {
- removeTask(t);
- return;
- }
- }
- if (t.duration && t.duration <= (now - t.taskStartTime)) {
- removeTask(t);
- }
- }
- };
- /**
- * Starts a new task.
- * @method start
- * @param {Object} task <p>A config object that supports the following properties:<ul>
- * <li><code>run</code> : Function<div class="sub-desc"><p>The function to execute each time the task is invoked. The
- * function will be called at each interval and passed the <code>args</code> argument if specified, and the
- * current invocation count if not.</p>
- * <p>If a particular scope (<code>this</code> reference) is required, be sure to specify it using the <code>scope</code> argument.</p>
- * <p>Return <code>false</code> from this function to terminate the task.</p></div></li>
- * <li><code>interval</code> : Number<div class="sub-desc">The frequency in milliseconds with which the task
- * should be invoked.</div></li>
- * <li><code>args</code> : Array<div class="sub-desc">(optional) An array of arguments to be passed to the function
- * specified by <code>run</code>. If not specified, the current invocation count is passed.</div></li>
- * <li><code>scope</code> : Object<div class="sub-desc">(optional) The scope (<tt>this</tt> reference) in which to execute the
- * <code>run</code> function. Defaults to the task config object.</div></li>
- * <li><code>duration</code> : Number<div class="sub-desc">(optional) The length of time in milliseconds to invoke
- * the task before stopping automatically (defaults to indefinite).</div></li>
- * <li><code>repeat</code> : Number<div class="sub-desc">(optional) The number of times to invoke the task before
- * stopping automatically (defaults to indefinite).</div></li>
- * </ul></p>
- * <p>Before each invocation, Ext injects the property <code>taskRunCount</code> into the task object so
- * that calculations based on the repeat count can be performed.</p>
- * @return {Object} The task
- */
- this.start = function(task) {
- tasks.push(task);
- task.taskStartTime = new Date().getTime();
- task.taskRunTime = 0;
- task.taskRunCount = 0;
- startThread();
- return task;
- };
- /**
- * Stops an existing running task.
- * @method stop
- * @param {Object} task The task to stop
- * @return {Object} The task
- */
- this.stop = function(task) {
- removeTask(task);
- return task;
- };
- /**
- * Stops all tasks that are currently running.
- * @method stopAll
- */
- this.stopAll = function() {
- stopThread();
- for (var i = 0, len = tasks.length; i < len; i++) {
- if (tasks[i].onStop) {
- tasks[i].onStop();
- }
- }
- tasks = [];
- removeQueue = [];
- };
- };
- /**
- * @class Ext.TaskManager
- * @extends Ext.util.TaskRunner
- * A static {@link Ext.util.TaskRunner} instance that can be used to start and stop arbitrary tasks. See
- * {@link Ext.util.TaskRunner} for supported methods and task config properties.
- * <pre><code>
- // Start a simple clock task that updates a div once per second
- var task = {
- run: function(){
- Ext.fly('clock').update(new Date().format('g:i:s A'));
- },
- interval: 1000 //1 second
- }
- Ext.TaskManager.start(task);
- </code></pre>
- * <p>See the {@link #start} method for details about how to configure a task object.</p>
- * @singleton
- */
- Ext.TaskManager = Ext.create('Ext.util.TaskRunner');
- /**
- * @class Ext.is
- *
- * Determines information about the current platform the application is running on.
- *
- * @singleton
- */
- Ext.is = {
- init : function(navigator) {
- var platforms = this.platforms,
- ln = platforms.length,
- i, platform;
- navigator = navigator || window.navigator;
- for (i = 0; i < ln; i++) {
- platform = platforms[i];
- this[platform.identity] = platform.regex.test(navigator[platform.property]);
- }
- /**
- * @property Desktop True if the browser is running on a desktop machine
- * @type {Boolean}
- */
- this.Desktop = this.Mac || this.Windows || (this.Linux && !this.Android);
- /**
- * @property Tablet True if the browser is running on a tablet (iPad)
- */
- this.Tablet = this.iPad;
- /**
- * @property Phone True if the browser is running on a phone.
- * @type {Boolean}
- */
- this.Phone = !this.Desktop && !this.Tablet;
- /**
- * @property iOS True if the browser is running on iOS
- * @type {Boolean}
- */
- this.iOS = this.iPhone || this.iPad || this.iPod;
-
- /**
- * @property Standalone Detects when application has been saved to homescreen.
- * @type {Boolean}
- */
- this.Standalone = !!window.navigator.standalone;
- },
-
- /**
- * @property iPhone True when the browser is running on a iPhone
- * @type {Boolean}
- */
- platforms: [{
- property: 'platform',
- regex: /iPhone/i,
- identity: 'iPhone'
- },
-
- /**
- * @property iPod True when the browser is running on a iPod
- * @type {Boolean}
- */
- {
- property: 'platform',
- regex: /iPod/i,
- identity: 'iPod'
- },
-
- /**
- * @property iPad True when the browser is running on a iPad
- * @type {Boolean}
- */
- {
- property: 'userAgent',
- regex: /iPad/i,
- identity: 'iPad'
- },
-
- /**
- * @property Blackberry True when the browser is running on a Blackberry
- * @type {Boolean}
- */
- {
- property: 'userAgent',
- regex: /Blackberry/i,
- identity: 'Blackberry'
- },
-
- /**
- * @property Android True when the browser is running on an Android device
- * @type {Boolean}
- */
- {
- property: 'userAgent',
- regex: /Android/i,
- identity: 'Android'
- },
-
- /**
- * @property Mac True when the browser is running on a Mac
- * @type {Boolean}
- */
- {
- property: 'platform',
- regex: /Mac/i,
- identity: 'Mac'
- },
-
- /**
- * @property Windows True when the browser is running on Windows
- * @type {Boolean}
- */
- {
- property: 'platform',
- regex: /Win/i,
- identity: 'Windows'
- },
-
- /**
- * @property Linux True when the browser is running on Linux
- * @type {Boolean}
- */
- {
- property: 'platform',
- regex: /Linux/i,
- identity: 'Linux'
- }]
- };
- Ext.is.init();
- /**
- * @class Ext.supports
- *
- * Determines information about features are supported in the current environment
- *
- * @singleton
- */
- Ext.supports = {
- init : function() {
- var doc = document,
- div = doc.createElement('div'),
- tests = this.tests,
- ln = tests.length,
- i, test;
- div.innerHTML = [
- '<div style="height:30px;width:50px;">',
- '<div style="height:20px;width:20px;"></div>',
- '</div>',
- '<div style="width: 200px; height: 200px; position: relative; padding: 5px;">',
- '<div style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></div>',
- '</div>',
- '<div style="float:left; background-color:transparent;"></div>'
- ].join('');
- doc.body.appendChild(div);
- for (i = 0; i < ln; i++) {
- test = tests[i];
- this[test.identity] = test.fn.call(this, doc, div);
- }
- doc.body.removeChild(div);
- },
- /**
- * @property CSS3BoxShadow True if document environment supports the CSS3 box-shadow style.
- * @type {Boolean}
- */
- CSS3BoxShadow: Ext.isDefined(document.documentElement.style.boxShadow),
- /**
- * @property ClassList True if document environment supports the HTML5 classList API.
- * @type {Boolean}
- */
- ClassList: !!document.documentElement.classList,
- /**
- * @property OrientationChange True if the device supports orientation change
- * @type {Boolean}
- */
- OrientationChange: ((typeof window.orientation != 'undefined') && ('onorientationchange' in window)),
-
- /**
- * @property DeviceMotion True if the device supports device motion (acceleration and rotation rate)
- * @type {Boolean}
- */
- DeviceMotion: ('ondevicemotion' in window),
-
- /**
- * @property Touch True if the device supports touch
- * @type {Boolean}
- */
- // is.Desktop is needed due to the bug in Chrome 5.0.375, Safari 3.1.2
- // and Safari 4.0 (they all have 'ontouchstart' in the window object).
- Touch: ('ontouchstart' in window) && (!Ext.is.Desktop),
- tests: [
- /**
- * @property Transitions True if the device supports CSS3 Transitions
- * @type {Boolean}
- */
- {
- identity: 'Transitions',
- fn: function(doc, div) {
- var prefix = [
- 'webkit',
- 'Moz',
- 'o',
- 'ms',
- 'khtml'
- ],
- TE = 'TransitionEnd',
- transitionEndName = [
- prefix[0] + TE,
- 'transitionend', //Moz bucks the prefixing convention
- prefix[2] + TE,
- prefix[3] + TE,
- prefix[4] + TE
- ],
- ln = prefix.length,
- i = 0,
- out = false;
- div = Ext.get(div);
- for (; i < ln; i++) {
- if (div.getStyle(prefix[i] + "TransitionProperty")) {
- Ext.supports.CSS3Prefix = prefix[i];
- Ext.supports.CSS3TransitionEnd = transitionEndName[i];
- out = true;
- break;
- }
- }
- return out;
- }
- },
-
- /**
- * @property RightMargin True if the device supports right margin.
- * See https://bugs.webkit.org/show_bug.cgi?id=13343 for why this is needed.
- * @type {Boolean}
- */
- {
- identity: 'RightMargin',
- fn: function(doc, div) {
- var view = doc.defaultView;
- return !(view && view.getComputedStyle(div.firstChild.firstChild, null).marginRight != '0px');
- }
- },
- /**
- * @property DisplayChangeInputSelectionBug True if INPUT elements lose their
- * selection when their display style is changed. Essentially, if a text input
- * has focus and its display style is changed, the I-beam disappears.
- *
- * This bug is encountered due to the work around in place for the {@link #RightMargin}
- * bug. This has been observed in Safari 4.0.4 and older, and appears to be fixed
- * in Safari 5. It's not clear if Safari 4.1 has the bug, but it has the same WebKit
- * version number as Safari 5 (according to http://unixpapa.com/js/gecko.html).
- */
- {
- identity: 'DisplayChangeInputSelectionBug',
- fn: function() {
- var webKitVersion = Ext.webKitVersion;
- // WebKit but older than Safari 5 or Chrome 6:
- return 0 < webKitVersion && webKitVersion < 533;
- }
- },
- /**
- * @property DisplayChangeTextAreaSelectionBug True if TEXTAREA elements lose their
- * selection when their display style is changed. Essentially, if a text area has
- * focus and its display style is changed, the I-beam disappears.
- *
- * This bug is encountered due to the work around in place for the {@link #RightMargin}
- * bug. This has been observed in Chrome 10 and Safari 5 and older, and appears to
- * be fixed in Chrome 11.
- */
- {
- identity: 'DisplayChangeTextAreaSelectionBug',
- fn: function() {
- var webKitVersion = Ext.webKitVersion;
- /*
- Has bug w/textarea:
- (Chrome) Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US)
- AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.127
- Safari/534.16
- (Safari) Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us)
- AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5
- Safari/533.21.1
- No bug:
- (Chrome) Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7)
- AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.57
- Safari/534.24
- */
- return 0 < webKitVersion && webKitVersion < 534.24;
- }
- },
- /**
- * @property TransparentColor True if the device supports transparent color
- * @type {Boolean}
- */
- {
- identity: 'TransparentColor',
- fn: function(doc, div, view) {
- view = doc.defaultView;
- return !(view && view.getComputedStyle(div.lastChild, null).backgroundColor != 'transparent');
- }
- },
- /**
- * @property ComputedStyle True if the browser supports document.defaultView.getComputedStyle()
- * @type {Boolean}
- */
- {
- identity: 'ComputedStyle',
- fn: function(doc, div, view) {
- view = doc.defaultView;
- return view && view.getComputedStyle;
- }
- },
-
- /**
- * @property SVG True if the device supports SVG
- * @type {Boolean}
- */
- {
- identity: 'Svg',
- fn: function(doc) {
- return !!doc.createElementNS && !!doc.createElementNS( "http:/" + "/www.w3.org/2000/svg", "svg").createSVGRect;
- }
- },
-
- /**
- * @property Canvas True if the device supports Canvas
- * @type {Boolean}
- */
- {
- identity: 'Canvas',
- fn: function(doc) {
- return !!doc.createElement('canvas').getContext;
- }
- },
-
- /**
- * @property VML True if the device supports VML
- * @type {Boolean}
- */
- {
- identity: 'Vml',
- fn: function(doc) {
- var d = doc.createElement("div");
- d.innerHTML = "<!--[if vml]><br><br><![endif]-->";
- return (d.childNodes.length == 2);
- }
- },
-
- /**
- * @property Float True if the device supports CSS float
- * @type {Boolean}
- */
- {
- identity: 'Float',
- fn: function(doc, div) {
- return !!div.lastChild.style.cssFloat;
- }
- },
-
- /**
- * @property AudioTag True if the device supports the HTML5 audio tag
- * @type {Boolean}
- */
- {
- identity: 'AudioTag',
- fn: function(doc) {
- return !!doc.createElement('audio').canPlayType;
- }
- },
-
- /**
- * @property History True if the device supports HTML5 history
- * @type {Boolean}
- */
- {
- identity: 'History',
- fn: function() {
- return !!(window.history && history.pushState);
- }
- },
-
- /**
- * @property CSS3DTransform True if the device supports CSS3DTransform
- * @type {Boolean}
- */
- {
- identity: 'CSS3DTransform',
- fn: function() {
- return (typeof WebKitCSSMatrix != 'undefined' && new WebKitCSSMatrix().hasOwnProperty('m41'));
- }
- },
- /**
- * @property CSS3LinearGradient True if the device supports CSS3 linear gradients
- * @type {Boolean}
- */
- {
- identity: 'CSS3LinearGradient',
- fn: function(doc, div) {
- var property = 'background-image:',
- webkit = '-webkit-gradient(linear, left top, right bottom, from(black), to(white))',
- w3c = 'linear-gradient(left top, black, white)',
- moz = '-moz-' + w3c,
- options = [property + webkit, property + w3c, property + moz];
-
- div.style.cssText = options.join(';');
-
- return ("" + div.style.backgroundImage).indexOf('gradient') !== -1;
- }
- },
-
- /**
- * @property CSS3BorderRadius True if the device supports CSS3 border radius
- * @type {Boolean}
- */
- {
- identity: 'CSS3BorderRadius',
- fn: function(doc, div) {
- var domPrefixes = ['borderRadius', 'BorderRadius', 'MozBorderRadius', 'WebkitBorderRadius', 'OBorderRadius', 'KhtmlBorderRadius'],
- pass = false,
- i;
- for (i = 0; i < domPrefixes.length; i++) {
- if (document.body.style[domPrefixes[i]] !== undefined) {
- return true;
- }
- }
- return pass;
- }
- },
-
- /**
- * @property GeoLocation True if the device supports GeoLocation
- * @type {Boolean}
- */
- {
- identity: 'GeoLocation',
- fn: function() {
- return (typeof navigator != 'undefined' && typeof navigator.geolocation != 'undefined') || (typeof google != 'undefined' && typeof google.gears != 'undefined');
- }
- },
- /**
- * @property MouseEnterLeave True if the browser supports mouseenter and mouseleave events
- * @type {Boolean}
- */
- {
- identity: 'MouseEnterLeave',
- fn: function(doc, div){
- return ('onmouseenter' in div && 'onmouseleave' in div);
- }
- },
- /**
- * @property MouseWheel True if the browser supports the mousewheel event
- * @type {Boolean}
- */
- {
- identity: 'MouseWheel',
- fn: function(doc, div) {
- return ('onmousewheel' in div);
- }
- },
- /**
- * @property Opacity True if the browser supports normal css opacity
- * @type {Boolean}
- */
- {
- identity: 'Opacity',
- fn: function(doc, div){
- // Not a strict equal comparison in case opacity can be converted to a number.
- if (Ext.isIE6 || Ext.isIE7 || Ext.isIE8) {
- return false;
- }
- div.firstChild.style.cssText = 'opacity:0.73';
- return div.firstChild.style.opacity == '0.73';
- }
- },
- /**
- * @property Placeholder True if the browser supports the HTML5 placeholder attribute on inputs
- * @type {Boolean}
- */
- {
- identity: 'Placeholder',
- fn: function(doc) {
- return 'placeholder' in doc.createElement('input');
- }
- },
-
- /**
- * @property Direct2DBug True if when asking for an element's dimension via offsetWidth or offsetHeight,
- * getBoundingClientRect, etc. the browser returns the subpixel width rounded to the nearest pixel.
- * @type {Boolean}
- */
- {
- identity: 'Direct2DBug',
- fn: function() {
- return Ext.isString(document.body.style.msTransformOrigin);
- }
- },
- /**
- * @property BoundingClientRect True if the browser supports the getBoundingClientRect method on elements
- * @type {Boolean}
- */
- {
- identity: 'BoundingClientRect',
- fn: function(doc, div) {
- return Ext.isFunction(div.getBoundingClientRect);
- }
- },
- {
- identity: 'IncludePaddingInWidthCalculation',
- fn: function(doc, div){
- var el = Ext.get(div.childNodes[1].firstChild);
- return el.getWidth() == 210;
- }
- },
- {
- identity: 'IncludePaddingInHeightCalculation',
- fn: function(doc, div){
- var el = Ext.get(div.childNodes[1].firstChild);
- return el.getHeight() == 210;
- }
- },
-
- /**
- * @property ArraySort True if the Array sort native method isn't bugged.
- * @type {Boolean}
- */
- {
- identity: 'ArraySort',
- fn: function() {
- var a = [1,2,3,4,5].sort(function(){ return 0; });
- return a[0] === 1 && a[1] === 2 && a[2] === 3 && a[3] === 4 && a[4] === 5;
- }
- },
- /**
- * @property Range True if browser support document.createRange native method.
- * @type {Boolean}
- */
- {
- identity: 'Range',
- fn: function() {
- return !!document.createRange;
- }
- },
- /**
- * @property CreateContextualFragment True if browser support CreateContextualFragment range native methods.
- * @type {Boolean}
- */
- {
- identity: 'CreateContextualFragment',
- fn: function() {
- var range = Ext.supports.Range ? document.createRange() : false;
-
- return range && !!range.createContextualFragment;
- }
- },
- /**
- * @property WindowOnError True if browser supports window.onerror.
- * @type {Boolean}
- */
- {
- identity: 'WindowOnError',
- fn: function () {
- // sadly, we cannot feature detect this...
- return Ext.isIE || Ext.isGecko || Ext.webKitVersion >= 534.16; // Chrome 10+
- }
- }
- ]
- };
- /*
- This file is part of Ext JS 4
- Copyright (c) 2011 Sencha Inc
- Contact: http://www.sencha.com/contact
- GNU General Public License Usage
- This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
- If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
- */
- /**
- * @class Ext.DomHelper
- * @alternateClassName Ext.core.DomHelper
- *
- * <p>The DomHelper class provides a layer of abstraction from DOM and transparently supports creating
- * elements via DOM or using HTML fragments. It also has the ability to create HTML fragment templates
- * from your DOM building code.</p>
- *
- * <p><b><u>DomHelper element specification object</u></b></p>
- * <p>A specification object is used when creating elements. Attributes of this object
- * are assumed to be element attributes, except for 4 special attributes:
- * <div class="mdetail-params"><ul>
- * <li><b><tt>tag</tt></b> : <div class="sub-desc">The tag name of the element</div></li>
- * <li><b><tt>children</tt></b> : or <tt>cn</tt><div class="sub-desc">An array of the
- * same kind of element definition objects to be created and appended. These can be nested
- * as deep as you want.</div></li>
- * <li><b><tt>cls</tt></b> : <div class="sub-desc">The class attribute of the element.
- * This will end up being either the "class" attribute on a HTML fragment or className
- * for a DOM node, depending on whether DomHelper is using fragments or DOM.</div></li>
- * <li><b><tt>html</tt></b> : <div class="sub-desc">The innerHTML for the element</div></li>
- * </ul></div></p>
- * <p><b>NOTE:</b> For other arbitrary attributes, the value will currently <b>not</b> be automatically
- * HTML-escaped prior to building the element's HTML string. This means that if your attribute value
- * contains special characters that would not normally be allowed in a double-quoted attribute value,
- * you <b>must</b> manually HTML-encode it beforehand (see {@link Ext.String#htmlEncode}) or risk
- * malformed HTML being created. This behavior may change in a future release.</p>
- *
- * <p><b><u>Insertion methods</u></b></p>
- * <p>Commonly used insertion methods:
- * <div class="mdetail-params"><ul>
- * <li><tt>{@link #append}</tt> : <div class="sub-desc"></div></li>
- * <li><tt>{@link #insertBefore}</tt> : <div class="sub-desc"></div></li>
- * <li><tt>{@link #insertAfter}</tt> : <div class="sub-desc"></div></li>
- * <li><tt>{@link #overwrite}</tt> : <div class="sub-desc"></div></li>
- * <li><tt>{@link #createTemplate}</tt> : <div class="sub-desc"></div></li>
- * <li><tt>{@link #insertHtml}</tt> : <div class="sub-desc"></div></li>
- * </ul></div></p>
- *
- * <p><b><u>Example</u></b></p>
- * <p>This is an example, where an unordered list with 3 children items is appended to an existing
- * element with id <tt>'my-div'</tt>:<br>
- <pre><code>
- var dh = Ext.DomHelper; // create shorthand alias
- // specification object
- var spec = {
- id: 'my-ul',
- tag: 'ul',
- cls: 'my-list',
- // append children after creating
- children: [ // may also specify 'cn' instead of 'children'
- {tag: 'li', id: 'item0', html: 'List Item 0'},
- {tag: 'li', id: 'item1', html: 'List Item 1'},
- {tag: 'li', id: 'item2', html: 'List Item 2'}
- ]
- };
- var list = dh.append(
- 'my-div', // the context element 'my-div' can either be the id or the actual node
- spec // the specification object
- );
- </code></pre></p>
- * <p>Element creation specification parameters in this class may also be passed as an Array of
- * specification objects. This can be used to insert multiple sibling nodes into an existing
- * container very efficiently. For example, to add more list items to the example above:<pre><code>
- dh.append('my-ul', [
- {tag: 'li', id: 'item3', html: 'List Item 3'},
- {tag: 'li', id: 'item4', html: 'List Item 4'}
- ]);
- * </code></pre></p>
- *
- * <p><b><u>Templating</u></b></p>
- * <p>The real power is in the built-in templating. Instead of creating or appending any elements,
- * <tt>{@link #createTemplate}</tt> returns a Template object which can be used over and over to
- * insert new elements. Revisiting the example above, we could utilize templating this time:
- * <pre><code>
- // create the node
- var list = dh.append('my-div', {tag: 'ul', cls: 'my-list'});
- // get template
- var tpl = dh.createTemplate({tag: 'li', id: 'item{0}', html: 'List Item {0}'});
- for(var i = 0; i < 5, i++){
- tpl.append(list, [i]); // use template to append to the actual node
- }
- * </code></pre></p>
- * <p>An example using a template:<pre><code>
- var html = '<a id="{0}" href="{1}" class="nav">{2}</a>';
- var tpl = new Ext.DomHelper.createTemplate(html);
- tpl.append('blog-roll', ['link1', 'http://www.edspencer.net/', "Ed's Site"]);
- tpl.append('blog-roll', ['link2', 'http://www.dustindiaz.com/', "Dustin's Site"]);
- * </code></pre></p>
- *
- * <p>The same example using named parameters:<pre><code>
- var html = '<a id="{id}" href="{url}" class="nav">{text}</a>';
- var tpl = new Ext.DomHelper.createTemplate(html);
- tpl.append('blog-roll', {
- id: 'link1',
- url: 'http://www.edspencer.net/',
- text: "Ed's Site"
- });
- tpl.append('blog-roll', {
- id: 'link2',
- url: 'http://www.dustindiaz.com/',
- text: "Dustin's Site"
- });
- * </code></pre></p>
- *
- * <p><b><u>Compiling Templates</u></b></p>
- * <p>Templates are applied using regular expressions. The performance is great, but if
- * you are adding a bunch of DOM elements using the same template, you can increase
- * performance even further by {@link Ext.Template#compile "compiling"} the template.
- * The way "{@link Ext.Template#compile compile()}" works is the template is parsed and
- * broken up at the different variable points and a dynamic function is created and eval'ed.
- * The generated function performs string concatenation of these parts and the passed
- * variables instead of using regular expressions.
- * <pre><code>
- var html = '<a id="{id}" href="{url}" class="nav">{text}</a>';
- var tpl = new Ext.DomHelper.createTemplate(html);
- tpl.compile();
- //... use template like normal
- * </code></pre></p>
- *
- * <p><b><u>Performance Boost</u></b></p>
- * <p>DomHelper will transparently create HTML fragments when it can. Using HTML fragments instead
- * of DOM can significantly boost performance.</p>
- * <p>Element creation specification parameters may also be strings. If {@link #useDom} is <tt>false</tt>,
- * then the string is used as innerHTML. If {@link #useDom} is <tt>true</tt>, a string specification
- * results in the creation of a text node. Usage:</p>
- * <pre><code>
- Ext.DomHelper.useDom = true; // force it to use DOM; reduces performance
- * </code></pre>
- * @singleton
- */
- Ext.ns('Ext.core');
- Ext.core.DomHelper = Ext.DomHelper = function(){
- var tempTableEl = null,
- emptyTags = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i,
- tableRe = /^table|tbody|tr|td$/i,
- confRe = /tag|children|cn|html$/i,
- tableElRe = /td|tr|tbody/i,
- endRe = /end/i,
- pub,
- // kill repeat to save bytes
- afterbegin = 'afterbegin',
- afterend = 'afterend',
- beforebegin = 'beforebegin',
- beforeend = 'beforeend',
- ts = '<table>',
- te = '</table>',
- tbs = ts+'<tbody>',
- tbe = '</tbody>'+te,
- trs = tbs + '<tr>',
- tre = '</tr>'+tbe;
- // private
- function doInsert(el, o, returnElement, pos, sibling, append){
- el = Ext.getDom(el);
- var newNode;
- if (pub.useDom) {
- newNode = createDom(o, null);
- if (append) {
- el.appendChild(newNode);
- } else {
- (sibling == 'firstChild' ? el : el.parentNode).insertBefore(newNode, el[sibling] || el);
- }
- } else {
- newNode = Ext.DomHelper.insertHtml(pos, el, Ext.DomHelper.createHtml(o));
- }
- return returnElement ? Ext.get(newNode, true) : newNode;
- }
- function createDom(o, parentNode){
- var el,
- doc = document,
- useSet,
- attr,
- val,
- cn;
- if (Ext.isArray(o)) { // Allow Arrays of siblings to be inserted
- el = doc.createDocumentFragment(); // in one shot using a DocumentFragment
- for (var i = 0, l = o.length; i < l; i++) {
- createDom(o[i], el);
- }
- } else if (typeof o == 'string') { // Allow a string as a child spec.
- el = doc.createTextNode(o);
- } else {
- el = doc.createElement( o.tag || 'div' );
- useSet = !!el.setAttribute; // In IE some elements don't have setAttribute
- for (attr in o) {
- if(!confRe.test(attr)){
- val = o[attr];
- if(attr == 'cls'){
- el.className = val;
- }else{
- if(useSet){
- el.setAttribute(attr, val);
- }else{
- el[attr] = val;
- }
- }
- }
- }
- Ext.DomHelper.applyStyles(el, o.style);
- if ((cn = o.children || o.cn)) {
- createDom(cn, el);
- } else if (o.html) {
- el.innerHTML = o.html;
- }
- }
- if(parentNode){
- parentNode.appendChild(el);
- }
- return el;
- }
- // build as innerHTML where available
- function createHtml(o){
- var b = '',
- attr,
- val,
- key,
- cn,
- i;
- if(typeof o == "string"){
- b = o;
- } else if (Ext.isArray(o)) {
- for (i=0; i < o.length; i++) {
- if(o[i]) {
- b += createHtml(o[i]);
- }
- }
- } else {
- b += '<' + (o.tag = o.tag || 'div');
- for (attr in o) {
- val = o[attr];
- if(!confRe.test(attr)){
- if (typeof val == "object") {
- b += ' ' + attr + '="';
- for (key in val) {
- b += key + ':' + val[key] + ';';
- }
- b += '"';
- }else{
- b += ' ' + ({cls : 'class', htmlFor : 'for'}[attr] || attr) + '="' + val + '"';
- }
- }
- }
- // Now either just close the tag or try to add children and close the tag.
- if (emptyTags.test(o.tag)) {
- b += '/>';
- } else {
- b += '>';
- if ((cn = o.children || o.cn)) {
- b += createHtml(cn);
- } else if(o.html){
- b += o.html;
- }
- b += '</' + o.tag + '>';
- }
- }
- return b;
- }
- function ieTable(depth, s, h, e){
- tempTableEl.innerHTML = [s, h, e].join('');
- var i = -1,
- el = tempTableEl,
- ns;
- while(++i < depth){
- el = el.firstChild;
- }
- // If the result is multiple siblings, then encapsulate them into one fragment.
- ns = el.nextSibling;
- if (ns){
- var df = document.createDocumentFragment();
- while(el){
- ns = el.nextSibling;
- df.appendChild(el);
- el = ns;
- }
- el = df;
- }
- return el;
- }
- /**
- * @ignore
- * Nasty code for IE's broken table implementation
- */
- function insertIntoTable(tag, where, el, html) {
- var node,
- before;
- tempTableEl = tempTableEl || document.createElement('div');
- if(tag == 'td' && (where == afterbegin || where == beforeend) ||
- !tableElRe.test(tag) && (where == beforebegin || where == afterend)) {
- return null;
- }
- before = where == beforebegin ? el :
- where == afterend ? el.nextSibling :
- where == afterbegin ? el.firstChild : null;
- if (where == beforebegin || where == afterend) {
- el = el.parentNode;
- }
- if (tag == 'td' || (tag == 'tr' && (where == beforeend || where == afterbegin))) {
- node = ieTable(4, trs, html, tre);
- } else if ((tag == 'tbody' && (where == beforeend || where == afterbegin)) ||
- (tag == 'tr' && (where == beforebegin || where == afterend))) {
- node = ieTable(3, tbs, html, tbe);
- } else {
- node = ieTable(2, ts, html, te);
- }
- el.insertBefore(node, before);
- return node;
- }
- /**
- * @ignore
- * Fix for IE9 createContextualFragment missing method
- */
- function createContextualFragment(html){
- var div = document.createElement("div"),
- fragment = document.createDocumentFragment(),
- i = 0,
- length, childNodes;
- div.innerHTML = html;
- childNodes = div.childNodes;
- length = childNodes.length;
- for (; i < length; i++) {
- fragment.appendChild(childNodes[i].cloneNode(true));
- }
- return fragment;
- }
- pub = {
- /**
- * Returns the markup for the passed Element(s) config.
- * @param {Object} o The DOM object spec (and children)
- * @return {String}
- */
- markup : function(o){
- return createHtml(o);
- },
- /**
- * Applies a style specification to an element.
- * @param {String/HTMLElement} el The element to apply styles to
- * @param {String/Object/Function} styles A style specification string e.g. 'width:100px', or object in the form {width:'100px'}, or
- * a function which returns such a specification.
- */
- applyStyles : function(el, styles){
- if (styles) {
- el = Ext.fly(el);
- if (typeof styles == "function") {
- styles = styles.call();
- }
- if (typeof styles == "string") {
- styles = Ext.Element.parseStyles(styles);
- }
- if (typeof styles == "object") {
- el.setStyle(styles);
- }
- }
- },
- /**
- * Inserts an HTML fragment into the DOM.
- * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.
- *
- * For example take the following HTML: `<div>Contents</div>`
- *
- * Using different `where` values inserts element to the following places:
- *
- * - beforeBegin: `<HERE><div>Contents</div>`
- * - afterBegin: `<div><HERE>Contents</div>`
- * - beforeEnd: `<div>Contents<HERE></div>`
- * - afterEnd: `<div>Contents</div><HERE>`
- *
- * @param {HTMLElement/TextNode} el The context element
- * @param {String} html The HTML fragment
- * @return {HTMLElement} The new node
- */
- insertHtml : function(where, el, html){
- var hash = {},
- hashVal,
- range,
- rangeEl,
- setStart,
- frag,
- rs;
- where = where.toLowerCase();
- // add these here because they are used in both branches of the condition.
- hash[beforebegin] = ['BeforeBegin', 'previousSibling'];
- hash[afterend] = ['AfterEnd', 'nextSibling'];
- // if IE and context element is an HTMLElement
- if (el.insertAdjacentHTML) {
- if(tableRe.test(el.tagName) && (rs = insertIntoTable(el.tagName.toLowerCase(), where, el, html))){
- return rs;
- }
- // add these two to the hash.
- hash[afterbegin] = ['AfterBegin', 'firstChild'];
- hash[beforeend] = ['BeforeEnd', 'lastChild'];
- if ((hashVal = hash[where])) {
- el.insertAdjacentHTML(hashVal[0], html);
- return el[hashVal[1]];
- }
- // if (not IE and context element is an HTMLElement) or TextNode
- } else {
- // we cannot insert anything inside a textnode so...
- if (Ext.isTextNode(el)) {
- where = where === 'afterbegin' ? 'beforebegin' : where;
- where = where === 'beforeend' ? 'afterend' : where;
- }
- range = Ext.supports.CreateContextualFragment ? el.ownerDocument.createRange() : undefined;
- setStart = 'setStart' + (endRe.test(where) ? 'After' : 'Before');
- if (hash[where]) {
- if (range) {
- range[setStart](el);
- frag = range.createContextualFragment(html);
- } else {
- frag = createContextualFragment(html);
- }
- el.parentNode.insertBefore(frag, where == beforebegin ? el : el.nextSibling);
- return el[(where == beforebegin ? 'previous' : 'next') + 'Sibling'];
- } else {
- rangeEl = (where == afterbegin ? 'first' : 'last') + 'Child';
- if (el.firstChild) {
- if (range) {
- range[setStart](el[rangeEl]);
- frag = range.createContextualFragment(html);
- } else {
- frag = createContextualFragment(html);
- }
- if(where == afterbegin){
- el.insertBefore(frag, el.firstChild);
- }else{
- el.appendChild(frag);
- }
- } else {
- el.innerHTML = html;
- }
- return el[rangeEl];
- }
- }
- },
- /**
- * Creates new DOM element(s) and inserts them before el.
- * @param {String/HTMLElement/Ext.Element} el The context element
- * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
- * @param {Boolean} returnElement (optional) true to return a Ext.Element
- * @return {HTMLElement/Ext.Element} The new node
- */
- insertBefore : function(el, o, returnElement){
- return doInsert(el, o, returnElement, beforebegin);
- },
- /**
- * Creates new DOM element(s) and inserts them after el.
- * @param {String/HTMLElement/Ext.Element} el The context element
- * @param {Object} o The DOM object spec (and children)
- * @param {Boolean} returnElement (optional) true to return a Ext.Element
- * @return {HTMLElement/Ext.Element} The new node
- */
- insertAfter : function(el, o, returnElement){
- return doInsert(el, o, returnElement, afterend, 'nextSibling');
- },
- /**
- * Creates new DOM element(s) and inserts them as the first child of el.
- * @param {String/HTMLElement/Ext.Element} el The context element
- * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
- * @param {Boolean} returnElement (optional) true to return a Ext.Element
- * @return {HTMLElement/Ext.Element} The new node
- */
- insertFirst : function(el, o, returnElement){
- return doInsert(el, o, returnElement, afterbegin, 'firstChild');
- },
- /**
- * Creates new DOM element(s) and appends them to el.
- * @param {String/HTMLElement/Ext.Element} el The context element
- * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
- * @param {Boolean} returnElement (optional) true to return a Ext.Element
- * @return {HTMLElement/Ext.Element} The new node
- */
- append : function(el, o, returnElement){
- return doInsert(el, o, returnElement, beforeend, '', true);
- },
- /**
- * Creates new DOM element(s) and overwrites the contents of el with them.
- * @param {String/HTMLElement/Ext.Element} el The context element
- * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
- * @param {Boolean} returnElement (optional) true to return a Ext.Element
- * @return {HTMLElement/Ext.Element} The new node
- */
- overwrite : function(el, o, returnElement){
- el = Ext.getDom(el);
- el.innerHTML = createHtml(o);
- return returnElement ? Ext.get(el.firstChild) : el.firstChild;
- },
- createHtml : createHtml,
- /**
- * Creates new DOM element(s) without inserting them to the document.
- * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
- * @return {HTMLElement} The new uninserted node
- * @method
- */
- createDom: createDom,
- /** True to force the use of DOM instead of html fragments @type Boolean */
- useDom : false,
- /**
- * Creates a new Ext.Template from the DOM object spec.
- * @param {Object} o The DOM object spec (and children)
- * @return {Ext.Template} The new template
- */
- createTemplate : function(o){
- var html = Ext.DomHelper.createHtml(o);
- return Ext.create('Ext.Template', html);
- }
- };
- return pub;
- }();
- /*
- * This is code is also distributed under MIT license for use
- * with jQuery and prototype JavaScript libraries.
- */
- /**
- * @class Ext.DomQuery
- Provides high performance selector/xpath processing by compiling queries into reusable functions. New pseudo classes and matchers can be plugged. It works on HTML and XML documents (if a content node is passed in).
- <p>
- DomQuery supports most of the <a href="http://www.w3.org/TR/2005/WD-css3-selectors-20051215/#selectors">CSS3 selectors spec</a>, along with some custom selectors and basic XPath.</p>
- <p>
- All selectors, attribute filters and pseudos below can be combined infinitely in any order. For example "div.foo:nth-child(odd)[@foo=bar].bar:first" would be a perfectly valid selector. Node filters are processed in the order in which they appear, which allows you to optimize your queries for your document structure.
- </p>
- <h4>Element Selectors:</h4>
- <ul class="list">
- <li> <b>*</b> any element</li>
- <li> <b>E</b> an element with the tag E</li>
- <li> <b>E F</b> All descendent elements of E that have the tag F</li>
- <li> <b>E > F</b> or <b>E/F</b> all direct children elements of E that have the tag F</li>
- <li> <b>E + F</b> all elements with the tag F that are immediately preceded by an element with the tag E</li>
- <li> <b>E ~ F</b> all elements with the tag F that are preceded by a sibling element with the tag E</li>
- </ul>
- <h4>Attribute Selectors:</h4>
- <p>The use of @ and quotes are optional. For example, div[@foo='bar'] is also a valid attribute selector.</p>
- <ul class="list">
- <li> <b>E[foo]</b> has an attribute "foo"</li>
- <li> <b>E[foo=bar]</b> has an attribute "foo" that equals "bar"</li>
- <li> <b>E[foo^=bar]</b> has an attribute "foo" that starts with "bar"</li>
- <li> <b>E[foo$=bar]</b> has an attribute "foo" that ends with "bar"</li>
- <li> <b>E[foo*=bar]</b> has an attribute "foo" that contains the substring "bar"</li>
- <li> <b>E[foo%=2]</b> has an attribute "foo" that is evenly divisible by 2</li>
- <li> <b>E[foo!=bar]</b> attribute "foo" does not equal "bar"</li>
- </ul>
- <h4>Pseudo Classes:</h4>
- <ul class="list">
- <li> <b>E:first-child</b> E is the first child of its parent</li>
- <li> <b>E:last-child</b> E is the last child of its parent</li>
- <li> <b>E:nth-child(<i>n</i>)</b> E is the <i>n</i>th child of its parent (1 based as per the spec)</li>
- <li> <b>E:nth-child(odd)</b> E is an odd child of its parent</li>
- <li> <b>E:nth-child(even)</b> E is an even child of its parent</li>
- <li> <b>E:only-child</b> E is the only child of its parent</li>
- <li> <b>E:checked</b> E is an element that is has a checked attribute that is true (e.g. a radio or checkbox) </li>
- <li> <b>E:first</b> the first E in the resultset</li>
- <li> <b>E:last</b> the last E in the resultset</li>
- <li> <b>E:nth(<i>n</i>)</b> the <i>n</i>th E in the resultset (1 based)</li>
- <li> <b>E:odd</b> shortcut for :nth-child(odd)</li>
- <li> <b>E:even</b> shortcut for :nth-child(even)</li>
- <li> <b>E:contains(foo)</b> E's innerHTML contains the substring "foo"</li>
- <li> <b>E:nodeValue(foo)</b> E contains a textNode with a nodeValue that equals "foo"</li>
- <li> <b>E:not(S)</b> an E element that does not match simple selector S</li>
- <li> <b>E:has(S)</b> an E element that has a descendent that matches simple selector S</li>
- <li> <b>E:next(S)</b> an E element whose next sibling matches simple selector S</li>
- <li> <b>E:prev(S)</b> an E element whose previous sibling matches simple selector S</li>
- <li> <b>E:any(S1|S2|S2)</b> an E element which matches any of the simple selectors S1, S2 or S3//\\</li>
- </ul>
- <h4>CSS Value Selectors:</h4>
- <ul class="list">
- <li> <b>E{display=none}</b> css value "display" that equals "none"</li>
- <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li>
- <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li>
- <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li>
- <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li>
- <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li>
- </ul>
- * @singleton
- */
- Ext.ns('Ext.core');
- Ext.core.DomQuery = Ext.DomQuery = function(){
- var cache = {},
- simpleCache = {},
- valueCache = {},
- nonSpace = /\S/,
- trimRe = /^\s+|\s+$/g,
- tplRe = /\{(\d+)\}/g,
- modeRe = /^(\s?[\/>+~]\s?|\s|$)/,
- tagTokenRe = /^(#)?([\w-\*]+)/,
- nthRe = /(\d*)n\+?(\d*)/,
- nthRe2 = /\D/,
- startIdRe = /^\s*\#/,
- // This is for IE MSXML which does not support expandos.
- // IE runs the same speed using setAttribute, however FF slows way down
- // and Safari completely fails so they need to continue to use expandos.
- isIE = window.ActiveXObject ? true : false,
- key = 30803;
- // this eval is stop the compressor from
- // renaming the variable to something shorter
- eval("var batch = 30803;");
- // Retrieve the child node from a particular
- // parent at the specified index.
- function child(parent, index){
- var i = 0,
- n = parent.firstChild;
- while(n){
- if(n.nodeType == 1){
- if(++i == index){
- return n;
- }
- }
- n = n.nextSibling;
- }
- return null;
- }
- // retrieve the next element node
- function next(n){
- while((n = n.nextSibling) && n.nodeType != 1);
- return n;
- }
- // retrieve the previous element node
- function prev(n){
- while((n = n.previousSibling) && n.nodeType != 1);
- return n;
- }
- // Mark each child node with a nodeIndex skipping and
- // removing empty text nodes.
- function children(parent){
- var n = parent.firstChild,
- nodeIndex = -1,
- nextNode;
- while(n){
- nextNode = n.nextSibling;
- // clean worthless empty nodes.
- if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){
- parent.removeChild(n);
- }else{
- // add an expando nodeIndex
- n.nodeIndex = ++nodeIndex;
- }
- n = nextNode;
- }
- return this;
- }
- // nodeSet - array of nodes
- // cls - CSS Class
- function byClassName(nodeSet, cls){
- if(!cls){
- return nodeSet;
- }
- var result = [], ri = -1;
- for(var i = 0, ci; ci = nodeSet[i]; i++){
- if((' '+ci.className+' ').indexOf(cls) != -1){
- result[++ri] = ci;
- }
- }
- return result;
- };
- function attrValue(n, attr){
- // if its an array, use the first node.
- if(!n.tagName && typeof n.length != "undefined"){
- n = n[0];
- }
- if(!n){
- return null;
- }
- if(attr == "for"){
- return n.htmlFor;
- }
- if(attr == "class" || attr == "className"){
- return n.className;
- }
- return n.getAttribute(attr) || n[attr];
- };
- // ns - nodes
- // mode - false, /, >, +, ~
- // tagName - defaults to "*"
- function getNodes(ns, mode, tagName){
- var result = [], ri = -1, cs;
- if(!ns){
- return result;
- }
- tagName = tagName || "*";
- // convert to array
- if(typeof ns.getElementsByTagName != "undefined"){
- ns = [ns];
- }
- // no mode specified, grab all elements by tagName
- // at any depth
- if(!mode){
- for(var i = 0, ni; ni = ns[i]; i++){
- cs = ni.getElementsByTagName(tagName);
- for(var j = 0, ci; ci = cs[j]; j++){
- result[++ri] = ci;
- }
- }
- // Direct Child mode (/ or >)
- // E > F or E/F all direct children elements of E that have the tag
- } else if(mode == "/" || mode == ">"){
- var utag = tagName.toUpperCase();
- for(var i = 0, ni, cn; ni = ns[i]; i++){
- cn = ni.childNodes;
- for(var j = 0, cj; cj = cn[j]; j++){
- if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){
- result[++ri] = cj;
- }
- }
- }
- // Immediately Preceding mode (+)
- // E + F all elements with the tag F that are immediately preceded by an element with the tag E
- }else if(mode == "+"){
- var utag = tagName.toUpperCase();
- for(var i = 0, n; n = ns[i]; i++){
- while((n = n.nextSibling) && n.nodeType != 1);
- if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
- result[++ri] = n;
- }
- }
- // Sibling mode (~)
- // E ~ F all elements with the tag F that are preceded by a sibling element with the tag E
- }else if(mode == "~"){
- var utag = tagName.toUpperCase();
- for(var i = 0, n; n = ns[i]; i++){
- while((n = n.nextSibling)){
- if (n.nodeName == utag || n.nodeName == tagName || tagName == '*'){
- result[++ri] = n;
- }
- }
- }
- }
- return result;
- }
- function concat(a, b){
- if(b.slice){
- return a.concat(b);
- }
- for(var i = 0, l = b.length; i < l; i++){
- a[a.length] = b[i];
- }
- return a;
- }
- function byTag(cs, tagName){
- if(cs.tagName || cs == document){
- cs = [cs];
- }
- if(!tagName){
- return cs;
- }
- var result = [], ri = -1;
- tagName = tagName.toLowerCase();
- for(var i = 0, ci; ci = cs[i]; i++){
- if(ci.nodeType == 1 && ci.tagName.toLowerCase() == tagName){
- result[++ri] = ci;
- }
- }
- return result;
- }
- function byId(cs, id){
- if(cs.tagName || cs == document){
- cs = [cs];
- }
- if(!id){
- return cs;
- }
- var result = [], ri = -1;
- for(var i = 0, ci; ci = cs[i]; i++){
- if(ci && ci.id == id){
- result[++ri] = ci;
- return result;
- }
- }
- return result;
- }
- // operators are =, !=, ^=, $=, *=, %=, |= and ~=
- // custom can be "{"
- function byAttribute(cs, attr, value, op, custom){
- var result = [],
- ri = -1,
- useGetStyle = custom == "{",
- fn = Ext.DomQuery.operators[op],
- a,
- xml,
- hasXml;
- for(var i = 0, ci; ci = cs[i]; i++){
- // skip non-element nodes.
- if(ci.nodeType != 1){
- continue;
- }
- // only need to do this for the first node
- if(!hasXml){
- xml = Ext.DomQuery.isXml(ci);
- hasXml = true;
- }
- // we only need to change the property names if we're dealing with html nodes, not XML
- if(!xml){
- if(useGetStyle){
- a = Ext.DomQuery.getStyle(ci, attr);
- } else if (attr == "class" || attr == "className"){
- a = ci.className;
- } else if (attr == "for"){
- a = ci.htmlFor;
- } else if (attr == "href"){
- // getAttribute href bug
- // http://www.glennjones.net/Post/809/getAttributehrefbug.htm
- a = ci.getAttribute("href", 2);
- } else{
- a = ci.getAttribute(attr);
- }
- }else{
- a = ci.getAttribute(attr);
- }
- if((fn && fn(a, value)) || (!fn && a)){
- result[++ri] = ci;
- }
- }
- return result;
- }
- function byPseudo(cs, name, value){
- return Ext.DomQuery.pseudos[name](cs, value);
- }
- function nodupIEXml(cs){
- var d = ++key,
- r;
- cs[0].setAttribute("_nodup", d);
- r = [cs[0]];
- for(var i = 1, len = cs.length; i < len; i++){
- var c = cs[i];
- if(!c.getAttribute("_nodup") != d){
- c.setAttribute("_nodup", d);
- r[r.length] = c;
- }
- }
- for(var i = 0, len = cs.length; i < len; i++){
- cs[i].removeAttribute("_nodup");
- }
- return r;
- }
- function nodup(cs){
- if(!cs){
- return [];
- }
- var len = cs.length, c, i, r = cs, cj, ri = -1;
- if(!len || typeof cs.nodeType != "undefined" || len == 1){
- return cs;
- }
- if(isIE && typeof cs[0].selectSingleNode != "undefined"){
- return nodupIEXml(cs);
- }
- var d = ++key;
- cs[0]._nodup = d;
- for(i = 1; c = cs[i]; i++){
- if(c._nodup != d){
- c._nodup = d;
- }else{
- r = [];
- for(var j = 0; j < i; j++){
- r[++ri] = cs[j];
- }
- for(j = i+1; cj = cs[j]; j++){
- if(cj._nodup != d){
- cj._nodup = d;
- r[++ri] = cj;
- }
- }
- return r;
- }
- }
- return r;
- }
- function quickDiffIEXml(c1, c2){
- var d = ++key,
- r = [];
- for(var i = 0, len = c1.length; i < len; i++){
- c1[i].setAttribute("_qdiff", d);
- }
- for(var i = 0, len = c2.length; i < len; i++){
- if(c2[i].getAttribute("_qdiff") != d){
- r[r.length] = c2[i];
- }
- }
- for(var i = 0, len = c1.length; i < len; i++){
- c1[i].removeAttribute("_qdiff");
- }
- return r;
- }
- function quickDiff(c1, c2){
- var len1 = c1.length,
- d = ++key,
- r = [];
- if(!len1){
- return c2;
- }
- if(isIE && typeof c1[0].selectSingleNode != "undefined"){
- return quickDiffIEXml(c1, c2);
- }
- for(var i = 0; i < len1; i++){
- c1[i]._qdiff = d;
- }
- for(var i = 0, len = c2.length; i < len; i++){
- if(c2[i]._qdiff != d){
- r[r.length] = c2[i];
- }
- }
- return r;
- }
- function quickId(ns, mode, root, id){
- if(ns == root){
- var d = root.ownerDocument || root;
- return d.getElementById(id);
- }
- ns = getNodes(ns, mode, "*");
- return byId(ns, id);
- }
- return {
- getStyle : function(el, name){
- return Ext.fly(el).getStyle(name);
- },
- /**
- * Compiles a selector/xpath query into a reusable function. The returned function
- * takes one parameter "root" (optional), which is the context node from where the query should start.
- * @param {String} selector The selector/xpath query
- * @param {String} type (optional) Either "select" (the default) or "simple" for a simple selector match
- * @return {Function}
- */
- compile : function(path, type){
- type = type || "select";
- // setup fn preamble
- var fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"],
- mode,
- lastPath,
- matchers = Ext.DomQuery.matchers,
- matchersLn = matchers.length,
- modeMatch,
- // accept leading mode switch
- lmode = path.match(modeRe);
- if(lmode && lmode[1]){
- fn[fn.length] = 'mode="'+lmode[1].replace(trimRe, "")+'";';
- path = path.replace(lmode[1], "");
- }
- // strip leading slashes
- while(path.substr(0, 1)=="/"){
- path = path.substr(1);
- }
- while(path && lastPath != path){
- lastPath = path;
- var tokenMatch = path.match(tagTokenRe);
- if(type == "select"){
- if(tokenMatch){
- // ID Selector
- if(tokenMatch[1] == "#"){
- fn[fn.length] = 'n = quickId(n, mode, root, "'+tokenMatch[2]+'");';
- }else{
- fn[fn.length] = 'n = getNodes(n, mode, "'+tokenMatch[2]+'");';
- }
- path = path.replace(tokenMatch[0], "");
- }else if(path.substr(0, 1) != '@'){
- fn[fn.length] = 'n = getNodes(n, mode, "*");';
- }
- // type of "simple"
- }else{
- if(tokenMatch){
- if(tokenMatch[1] == "#"){
- fn[fn.length] = 'n = byId(n, "'+tokenMatch[2]+'");';
- }else{
- fn[fn.length] = 'n = byTag(n, "'+tokenMatch[2]+'");';
- }
- path = path.replace(tokenMatch[0], "");
- }
- }
- while(!(modeMatch = path.match(modeRe))){
- var matched = false;
- for(var j = 0; j < matchersLn; j++){
- var t = matchers[j];
- var m = path.match(t.re);
- if(m){
- fn[fn.length] = t.select.replace(tplRe, function(x, i){
- return m[i];
- });
- path = path.replace(m[0], "");
- matched = true;
- break;
- }
- }
- // prevent infinite loop on bad selector
- if(!matched){
- }
- }
- if(modeMatch[1]){
- fn[fn.length] = 'mode="'+modeMatch[1].replace(trimRe, "")+'";';
- path = path.replace(modeMatch[1], "");
- }
- }
- // close fn out
- fn[fn.length] = "return nodup(n);\n}";
- // eval fn and return it
- eval(fn.join(""));
- return f;
- },
- /**
- * Selects an array of DOM nodes using JavaScript-only implementation.
- *
- * Use {@link #select} to take advantage of browsers built-in support for CSS selectors.
- *
- * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
- * @param {HTMLElement/String} root (optional) The start of the query (defaults to document).
- * @return {HTMLElement[]} An Array of DOM elements which match the selector. If there are
- * no matches, and empty Array is returned.
- */
- jsSelect: function(path, root, type){
- // set root to doc if not specified.
- root = root || document;
- if(typeof root == "string"){
- root = document.getElementById(root);
- }
- var paths = path.split(","),
- results = [];
- // loop over each selector
- for(var i = 0, len = paths.length; i < len; i++){
- var subPath = paths[i].replace(trimRe, "");
- // compile and place in cache
- if(!cache[subPath]){
- cache[subPath] = Ext.DomQuery.compile(subPath);
- if(!cache[subPath]){
- }
- }
- var result = cache[subPath](root);
- if(result && result != document){
- results = results.concat(result);
- }
- }
- // if there were multiple selectors, make sure dups
- // are eliminated
- if(paths.length > 1){
- return nodup(results);
- }
- return results;
- },
- isXml: function(el) {
- var docEl = (el ? el.ownerDocument || el : 0).documentElement;
- return docEl ? docEl.nodeName !== "HTML" : false;
- },
- /**
- * Selects an array of DOM nodes by CSS/XPath selector.
- *
- * Uses [document.querySelectorAll][0] if browser supports that, otherwise falls back to
- * {@link Ext.DomQuery#jsSelect} to do the work.
- *
- * Aliased as {@link Ext#query}.
- *
- * [0]: https://developer.mozilla.org/en/DOM/document.querySelectorAll
- *
- * @param {String} path The selector/xpath query
- * @param {HTMLElement} root (optional) The start of the query (defaults to document).
- * @return {HTMLElement[]} An array of DOM elements (not a NodeList as returned by `querySelectorAll`).
- * Empty array when no matches.
- * @method
- */
- select : document.querySelectorAll ? function(path, root, type) {
- root = root || document;
- /*
- * Safari 3.x can't handle uppercase or unicode characters when in quirks mode.
- */
- if (!Ext.DomQuery.isXml(root) && !(Ext.isSafari3 && !Ext.isStrict)) {
- try {
- /*
- * This checking here is to "fix" the behaviour of querySelectorAll
- * for non root document queries. The way qsa works is intentional,
- * however it's definitely not the expected way it should work.
- * More info: http://ejohn.org/blog/thoughts-on-queryselectorall/
- *
- * We only modify the path for single selectors (ie, no multiples),
- * without a full parser it makes it difficult to do this correctly.
- */
- var isDocumentRoot = root.nodeType === 9,
- _path = path,
- _root = root;
- if (!isDocumentRoot && path.indexOf(',') === -1 && !startIdRe.test(path)) {
- _path = '#' + Ext.id(root) + ' ' + path;
- _root = root.parentNode;
- }
- return Ext.Array.toArray(_root.querySelectorAll(_path));
- }
- catch (e) {
- }
- }
- return Ext.DomQuery.jsSelect.call(this, path, root, type);
- } : function(path, root, type) {
- return Ext.DomQuery.jsSelect.call(this, path, root, type);
- },
- /**
- * Selects a single element.
- * @param {String} selector The selector/xpath query
- * @param {HTMLElement} root (optional) The start of the query (defaults to document).
- * @return {HTMLElement} The DOM element which matched the selector.
- */
- selectNode : function(path, root){
- return Ext.DomQuery.select(path, root)[0];
- },
- /**
- * Selects the value of a node, optionally replacing null with the defaultValue.
- * @param {String} selector The selector/xpath query
- * @param {HTMLElement} root (optional) The start of the query (defaults to document).
- * @param {String} defaultValue (optional) When specified, this is return as empty value.
- * @return {String}
- */
- selectValue : function(path, root, defaultValue){
- path = path.replace(trimRe, "");
- if(!valueCache[path]){
- valueCache[path] = Ext.DomQuery.compile(path, "select");
- }
- var n = valueCache[path](root), v;
- n = n[0] ? n[0] : n;
- // overcome a limitation of maximum textnode size
- // Rumored to potentially crash IE6 but has not been confirmed.
- // http://reference.sitepoint.com/javascript/Node/normalize
- // https://developer.mozilla.org/En/DOM/Node.normalize
- if (typeof n.normalize == 'function') n.normalize();
- v = (n && n.firstChild ? n.firstChild.nodeValue : null);
- return ((v === null||v === undefined||v==='') ? defaultValue : v);
- },
- /**
- * Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified.
- * @param {String} selector The selector/xpath query
- * @param {HTMLElement} root (optional) The start of the query (defaults to document).
- * @param {Number} defaultValue (optional) When specified, this is return as empty value.
- * @return {Number}
- */
- selectNumber : function(path, root, defaultValue){
- var v = Ext.DomQuery.selectValue(path, root, defaultValue || 0);
- return parseFloat(v);
- },
- /**
- * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
- * @param {String/HTMLElement/HTMLElement[]} el An element id, element or array of elements
- * @param {String} selector The simple selector to test
- * @return {Boolean}
- */
- is : function(el, ss){
- if(typeof el == "string"){
- el = document.getElementById(el);
- }
- var isArray = Ext.isArray(el),
- result = Ext.DomQuery.filter(isArray ? el : [el], ss);
- return isArray ? (result.length == el.length) : (result.length > 0);
- },
- /**
- * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)
- * @param {HTMLElement[]} el An array of elements to filter
- * @param {String} selector The simple selector to test
- * @param {Boolean} nonMatches If true, it returns the elements that DON'T match
- * the selector instead of the ones that match
- * @return {HTMLElement[]} An Array of DOM elements which match the selector. If there are
- * no matches, and empty Array is returned.
- */
- filter : function(els, ss, nonMatches){
- ss = ss.replace(trimRe, "");
- if(!simpleCache[ss]){
- simpleCache[ss] = Ext.DomQuery.compile(ss, "simple");
- }
- var result = simpleCache[ss](els);
- return nonMatches ? quickDiff(result, els) : result;
- },
- /**
- * Collection of matching regular expressions and code snippets.
- * Each capture group within () will be replace the {} in the select
- * statement as specified by their index.
- */
- matchers : [{
- re: /^\.([\w-]+)/,
- select: 'n = byClassName(n, " {1} ");'
- }, {
- re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
- select: 'n = byPseudo(n, "{1}", "{2}");'
- },{
- re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
- select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
- }, {
- re: /^#([\w-]+)/,
- select: 'n = byId(n, "{1}");'
- },{
- re: /^@([\w-]+)/,
- select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'
- }
- ],
- /**
- * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
- * New operators can be added as long as the match the format <i>c</i>= where <i>c</i> is any character other than space, > <.
- */
- operators : {
- "=" : function(a, v){
- return a == v;
- },
- "!=" : function(a, v){
- return a != v;
- },
- "^=" : function(a, v){
- return a && a.substr(0, v.length) == v;
- },
- "$=" : function(a, v){
- return a && a.substr(a.length-v.length) == v;
- },
- "*=" : function(a, v){
- return a && a.indexOf(v) !== -1;
- },
- "%=" : function(a, v){
- return (a % v) == 0;
- },
- "|=" : function(a, v){
- return a && (a == v || a.substr(0, v.length+1) == v+'-');
- },
- "~=" : function(a, v){
- return a && (' '+a+' ').indexOf(' '+v+' ') != -1;
- }
- },
- /**
- Object hash of "pseudo class" filter functions which are used when filtering selections.
- Each function is passed two parameters:
- - **c** : Array
- An Array of DOM elements to filter.
- - **v** : String
- The argument (if any) supplied in the selector.
- A filter function returns an Array of DOM elements which conform to the pseudo class.
- In addition to the provided pseudo classes listed above such as `first-child` and `nth-child`,
- developers may add additional, custom psuedo class filters to select elements according to application-specific requirements.
- For example, to filter `a` elements to only return links to __external__ resources:
- Ext.DomQuery.pseudos.external = function(c, v){
- var r = [], ri = -1;
- for(var i = 0, ci; ci = c[i]; i++){
- // Include in result set only if it's a link to an external resource
- if(ci.hostname != location.hostname){
- r[++ri] = ci;
- }
- }
- return r;
- };
- Then external links could be gathered with the following statement:
- var externalLinks = Ext.select("a:external");
- * @markdown
- */
- pseudos : {
- "first-child" : function(c){
- var r = [], ri = -1, n;
- for(var i = 0, ci; ci = n = c[i]; i++){
- while((n = n.previousSibling) && n.nodeType != 1);
- if(!n){
- r[++ri] = ci;
- }
- }
- return r;
- },
- "last-child" : function(c){
- var r = [], ri = -1, n;
- for(var i = 0, ci; ci = n = c[i]; i++){
- while((n = n.nextSibling) && n.nodeType != 1);
- if(!n){
- r[++ri] = ci;
- }
- }
- return r;
- },
- "nth-child" : function(c, a) {
- var r = [], ri = -1,
- m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a),
- f = (m[1] || 1) - 0, l = m[2] - 0;
- for(var i = 0, n; n = c[i]; i++){
- var pn = n.parentNode;
- if (batch != pn._batch) {
- var j = 0;
- for(var cn = pn.firstChild; cn; cn = cn.nextSibling){
- if(cn.nodeType == 1){
- cn.nodeIndex = ++j;
- }
- }
- pn._batch = batch;
- }
- if (f == 1) {
- if (l == 0 || n.nodeIndex == l){
- r[++ri] = n;
- }
- } else if ((n.nodeIndex + l) % f == 0){
- r[++ri] = n;
- }
- }
- return r;
- },
- "only-child" : function(c){
- var r = [], ri = -1;;
- for(var i = 0, ci; ci = c[i]; i++){
- if(!prev(ci) && !next(ci)){
- r[++ri] = ci;
- }
- }
- return r;
- },
- "empty" : function(c){
- var r = [], ri = -1;
- for(var i = 0, ci; ci = c[i]; i++){
- var cns = ci.childNodes, j = 0, cn, empty = true;
- while(cn = cns[j]){
- ++j;
- if(cn.nodeType == 1 || cn.nodeType == 3){
- empty = false;
- break;
- }
- }
- if(empty){
- r[++ri] = ci;
- }
- }
- return r;
- },
- "contains" : function(c, v){
- var r = [], ri = -1;
- for(var i = 0, ci; ci = c[i]; i++){
- if((ci.textContent||ci.innerText||'').indexOf(v) != -1){
- r[++ri] = ci;
- }
- }
- return r;
- },
- "nodeValue" : function(c, v){
- var r = [], ri = -1;
- for(var i = 0, ci; ci = c[i]; i++){
- if(ci.firstChild && ci.firstChild.nodeValue == v){
- r[++ri] = ci;
- }
- }
- return r;
- },
- "checked" : function(c){
- var r = [], ri = -1;
- for(var i = 0, ci; ci = c[i]; i++){
- if(ci.checked == true){
- r[++ri] = ci;
- }
- }
- return r;
- },
- "not" : function(c, ss){
- return Ext.DomQuery.filter(c, ss, true);
- },
- "any" : function(c, selectors){
- var ss = selectors.split('|'),
- r = [], ri = -1, s;
- for(var i = 0, ci; ci = c[i]; i++){
- for(var j = 0; s = ss[j]; j++){
- if(Ext.DomQuery.is(ci, s)){
- r[++ri] = ci;
- break;
- }
- }
- }
- return r;
- },
- "odd" : function(c){
- return this["nth-child"](c, "odd");
- },
- "even" : function(c){
- return this["nth-child"](c, "even");
- },
- "nth" : function(c, a){
- return c[a-1] || [];
- },
- "first" : function(c){
- return c[0] || [];
- },
- "last" : function(c){
- return c[c.length-1] || [];
- },
- "has" : function(c, ss){
- var s = Ext.DomQuery.select,
- r = [], ri = -1;
- for(var i = 0, ci; ci = c[i]; i++){
- if(s(ss, ci).length > 0){
- r[++ri] = ci;
- }
- }
- return r;
- },
- "next" : function(c, ss){
- var is = Ext.DomQuery.is,
- r = [], ri = -1;
- for(var i = 0, ci; ci = c[i]; i++){
- var n = next(ci);
- if(n && is(n, ss)){
- r[++ri] = ci;
- }
- }
- return r;
- },
- "prev" : function(c, ss){
- var is = Ext.DomQuery.is,
- r = [], ri = -1;
- for(var i = 0, ci; ci = c[i]; i++){
- var n = prev(ci);
- if(n && is(n, ss)){
- r[++ri] = ci;
- }
- }
- return r;
- }
- }
- };
- }();
- /**
- * Shorthand of {@link Ext.DomQuery#select}
- * @member Ext
- * @method query
- * @alias Ext.DomQuery#select
- */
- Ext.query = Ext.DomQuery.select;
- /**
- * @class Ext.Element
- * @alternateClassName Ext.core.Element
- *
- * Encapsulates a DOM element, adding simple DOM manipulation facilities, normalizing for browser differences.
- *
- * All instances of this class inherit the methods of {@link Ext.fx.Anim} making visual effects easily available to all
- * DOM elements.
- *
- * Note that the events documented in this class are not Ext events, they encapsulate browser events. Some older browsers
- * may not support the full range of events. Which events are supported is beyond the control of Ext JS.
- *
- * Usage:
- *
- * // by id
- * var el = Ext.get("my-div");
- *
- * // by DOM element reference
- * var el = Ext.get(myDivElement);
- *
- * # Animations
- *
- * When an element is manipulated, by default there is no animation.
- *
- * var el = Ext.get("my-div");
- *
- * // no animation
- * el.setWidth(100);
- *
- * Many of the functions for manipulating an element have an optional "animate" parameter. This parameter can be
- * specified as boolean (true) for default animation effects.
- *
- * // default animation
- * el.setWidth(100, true);
- *
- * To configure the effects, an object literal with animation options to use as the Element animation configuration
- * object can also be specified. Note that the supported Element animation configuration options are a subset of the
- * {@link Ext.fx.Anim} animation options specific to Fx effects. The supported Element animation configuration options
- * are:
- *
- * Option Default Description
- * --------- -------- ---------------------------------------------
- * {@link Ext.fx.Anim#duration duration} .35 The duration of the animation in seconds
- * {@link Ext.fx.Anim#easing easing} easeOut The easing method
- * {@link Ext.fx.Anim#callback callback} none A function to execute when the anim completes
- * {@link Ext.fx.Anim#scope scope} this The scope (this) of the callback function
- *
- * Usage:
- *
- * // Element animation options object
- * var opt = {
- * {@link Ext.fx.Anim#duration duration}: 1,
- * {@link Ext.fx.Anim#easing easing}: 'elasticIn',
- * {@link Ext.fx.Anim#callback callback}: this.foo,
- * {@link Ext.fx.Anim#scope scope}: this
- * };
- * // animation with some options set
- * el.setWidth(100, opt);
- *
- * The Element animation object being used for the animation will be set on the options object as "anim", which allows
- * you to stop or manipulate the animation. Here is an example:
- *
- * // using the "anim" property to get the Anim object
- * if(opt.anim.isAnimated()){
- * opt.anim.stop();
- * }
- *
- * # Composite (Collections of) Elements
- *
- * For working with collections of Elements, see {@link Ext.CompositeElement}
- *
- * @constructor
- * Creates new Element directly.
- * @param {String/HTMLElement} element
- * @param {Boolean} forceNew (optional) By default the constructor checks to see if there is already an instance of this
- * element in the cache and if there is it returns the same instance. This will skip that check (useful for extending
- * this class).
- * @return {Object}
- */
- (function() {
- var DOC = document,
- EC = Ext.cache;
- Ext.Element = Ext.core.Element = function(element, forceNew) {
- var dom = typeof element == "string" ? DOC.getElementById(element) : element,
- id;
- if (!dom) {
- return null;
- }
- id = dom.id;
- if (!forceNew && id && EC[id]) {
- // element object already exists
- return EC[id].el;
- }
- /**
- * @property {HTMLElement} dom
- * The DOM element
- */
- this.dom = dom;
- /**
- * @property {String} id
- * The DOM element ID
- */
- this.id = id || Ext.id(dom);
- };
- var DH = Ext.DomHelper,
- El = Ext.Element;
- El.prototype = {
- /**
- * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
- * @param {Object} o The object with the attributes
- * @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos.
- * @return {Ext.Element} this
- */
- set: function(o, useSet) {
- var el = this.dom,
- attr,
- val;
- useSet = (useSet !== false) && !!el.setAttribute;
- for (attr in o) {
- if (o.hasOwnProperty(attr)) {
- val = o[attr];
- if (attr == 'style') {
- DH.applyStyles(el, val);
- } else if (attr == 'cls') {
- el.className = val;
- } else if (useSet) {
- el.setAttribute(attr, val);
- } else {
- el[attr] = val;
- }
- }
- }
- return this;
- },
- // Mouse events
- /**
- * @event click
- * Fires when a mouse click is detected within the element.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event contextmenu
- * Fires when a right click is detected within the element.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event dblclick
- * Fires when a mouse double click is detected within the element.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event mousedown
- * Fires when a mousedown is detected within the element.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event mouseup
- * Fires when a mouseup is detected within the element.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event mouseover
- * Fires when a mouseover is detected within the element.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event mousemove
- * Fires when a mousemove is detected with the element.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event mouseout
- * Fires when a mouseout is detected with the element.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event mouseenter
- * Fires when the mouse enters the element.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event mouseleave
- * Fires when the mouse leaves the element.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- // Keyboard events
- /**
- * @event keypress
- * Fires when a keypress is detected within the element.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event keydown
- * Fires when a keydown is detected within the element.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event keyup
- * Fires when a keyup is detected within the element.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- // HTML frame/object events
- /**
- * @event load
- * Fires when the user agent finishes loading all content within the element. Only supported by window, frames,
- * objects and images.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event unload
- * Fires when the user agent removes all content from a window or frame. For elements, it fires when the target
- * element or any of its content has been removed.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event abort
- * Fires when an object/image is stopped from loading before completely loaded.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event error
- * Fires when an object/image/frame cannot be loaded properly.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event resize
- * Fires when a document view is resized.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event scroll
- * Fires when a document view is scrolled.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- // Form events
- /**
- * @event select
- * Fires when a user selects some text in a text field, including input and textarea.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event change
- * Fires when a control loses the input focus and its value has been modified since gaining focus.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event submit
- * Fires when a form is submitted.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event reset
- * Fires when a form is reset.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event focus
- * Fires when an element receives focus either via the pointing device or by tab navigation.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event blur
- * Fires when an element loses focus either via the pointing device or by tabbing navigation.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- // User Interface events
- /**
- * @event DOMFocusIn
- * Where supported. Similar to HTML focus event, but can be applied to any focusable element.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event DOMFocusOut
- * Where supported. Similar to HTML blur event, but can be applied to any focusable element.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event DOMActivate
- * Where supported. Fires when an element is activated, for instance, through a mouse click or a keypress.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- // DOM Mutation events
- /**
- * @event DOMSubtreeModified
- * Where supported. Fires when the subtree is modified.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event DOMNodeInserted
- * Where supported. Fires when a node has been added as a child of another node.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event DOMNodeRemoved
- * Where supported. Fires when a descendant node of the element is removed.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event DOMNodeRemovedFromDocument
- * Where supported. Fires when a node is being removed from a document.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event DOMNodeInsertedIntoDocument
- * Where supported. Fires when a node is being inserted into a document.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event DOMAttrModified
- * Where supported. Fires when an attribute has been modified.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @event DOMCharacterDataModified
- * Where supported. Fires when the character data has been modified.
- * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
- * @param {HTMLElement} t The target of the event.
- */
- /**
- * @property {String} defaultUnit
- * The default unit to append to CSS values where a unit isn't provided.
- */
- defaultUnit: "px",
- /**
- * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
- * @param {String} selector The simple selector to test
- * @return {Boolean} True if this element matches the selector, else false
- */
- is: function(simpleSelector) {
- return Ext.DomQuery.is(this.dom, simpleSelector);
- },
- /**
- * Tries to focus the element. Any exceptions are caught and ignored.
- * @param {Number} defer (optional) Milliseconds to defer the focus
- * @return {Ext.Element} this
- */
- focus: function(defer,
- /* private */
- dom) {
- var me = this;
- dom = dom || me.dom;
- try {
- if (Number(defer)) {
- Ext.defer(me.focus, defer, null, [null, dom]);
- } else {
- dom.focus();
- }
- } catch(e) {}
- return me;
- },
- /**
- * Tries to blur the element. Any exceptions are caught and ignored.
- * @return {Ext.Element} this
- */
- blur: function() {
- try {
- this.dom.blur();
- } catch(e) {}
- return this;
- },
- /**
- * Returns the value of the "value" attribute
- * @param {Boolean} asNumber true to parse the value as a number
- * @return {String/Number}
- */
- getValue: function(asNumber) {
- var val = this.dom.value;
- return asNumber ? parseInt(val, 10) : val;
- },
- /**
- * Appends an event handler to this element.
- *
- * @param {String} eventName The name of event to handle.
- *
- * @param {Function} fn The handler function the event invokes. This function is passed the following parameters:
- *
- * - **evt** : EventObject
- *
- * The {@link Ext.EventObject EventObject} describing the event.
- *
- * - **el** : HtmlElement
- *
- * The DOM element which was the target of the event. Note that this may be filtered by using the delegate option.
- *
- * - **o** : Object
- *
- * The options object from the addListener call.
- *
- * @param {Object} scope (optional) The scope (**this** reference) in which the handler function is executed. **If
- * omitted, defaults to this Element.**
- *
- * @param {Object} options (optional) An object containing handler configuration properties. This may contain any of
- * the following properties:
- *
- * - **scope** Object :
- *
- * The scope (**this** reference) in which the handler function is executed. **If omitted, defaults to this
- * Element.**
- *
- * - **delegate** String:
- *
- * A simple selector to filter the target or look for a descendant of the target. See below for additional details.
- *
- * - **stopEvent** Boolean:
- *
- * True to stop the event. That is stop propagation, and prevent the default action.
- *
- * - **preventDefault** Boolean:
- *
- * True to prevent the default action
- *
- * - **stopPropagation** Boolean:
- *
- * True to prevent event propagation
- *
- * - **normalized** Boolean:
- *
- * False to pass a browser event to the handler function instead of an Ext.EventObject
- *
- * - **target** Ext.Element:
- *
- * Only call the handler if the event was fired on the target Element, _not_ if the event was bubbled up from a
- * child node.
- *
- * - **delay** Number:
- *
- * The number of milliseconds to delay the invocation of the handler after the event fires.
- *
- * - **single** Boolean:
- *
- * True to add a handler to handle just the next firing of the event, and then remove itself.
- *
- * - **buffer** Number:
- *
- * Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed by the specified number of
- * milliseconds. If the event fires again within that time, the original handler is _not_ invoked, but the new
- * handler is scheduled in its place.
- *
- * **Combining Options**
- *
- * In the following examples, the shorthand form {@link #on} is used rather than the more verbose addListener. The
- * two are equivalent. Using the options argument, it is possible to combine different types of listeners:
- *
- * A delayed, one-time listener that auto stops the event and adds a custom argument (forumId) to the options
- * object. The options object is available as the third parameter in the handler function.
- *
- * Code:
- *
- * el.on('click', this.onClick, this, {
- * single: true,
- * delay: 100,
- * stopEvent : true,
- * forumId: 4
- * });
- *
- * **Attaching multiple handlers in 1 call**
- *
- * The method also allows for a single argument to be passed which is a config object containing properties which
- * specify multiple handlers.
- *
- * Code:
- *
- * el.on({
- * 'click' : {
- * fn: this.onClick,
- * scope: this,
- * delay: 100
- * },
- * 'mouseover' : {
- * fn: this.onMouseOver,
- * scope: this
- * },
- * 'mouseout' : {
- * fn: this.onMouseOut,
- * scope: this
- * }
- * });
- *
- * Or a shorthand syntax:
- *
- * Code:
- *
- * el.on({
- * 'click' : this.onClick,
- * 'mouseover' : this.onMouseOver,
- * 'mouseout' : this.onMouseOut,
- * scope: this
- * });
- *
- * **delegate**
- *
- * This is a configuration option that you can pass along when registering a handler for an event to assist with
- * event delegation. Event delegation is a technique that is used to reduce memory consumption and prevent exposure
- * to memory-leaks. By registering an event for a container element as opposed to each element within a container.
- * By setting this configuration option to a simple selector, the target element will be filtered to look for a
- * descendant of the target. For example:
- *
- * // using this markup:
- * <div id='elId'>
- * <p id='p1'>paragraph one</p>
- * <p id='p2' class='clickable'>paragraph two</p>
- * <p id='p3'>paragraph three</p>
- * </div>
- *
- * // utilize event delegation to registering just one handler on the container element:
- * el = Ext.get('elId');
- * el.on(
- * 'click',
- * function(e,t) {
- * // handle click
- * console.info(t.id); // 'p2'
- * },
- * this,
- * {
- * // filter the target element to be a descendant with the class 'clickable'
- * delegate: '.clickable'
- * }
- * );
- *
- * @return {Ext.Element} this
- */
- addListener: function(eventName, fn, scope, options) {
- Ext.EventManager.on(this.dom, eventName, fn, scope || this, options);
- return this;
- },
- /**
- * Removes an event handler from this element.
- *
- * **Note**: if a *scope* was explicitly specified when {@link #addListener adding} the listener,
- * the same scope must be specified here.
- *
- * Example:
- *
- * el.removeListener('click', this.handlerFn);
- * // or
- * el.un('click', this.handlerFn);
- *
- * @param {String} eventName The name of the event from which to remove the handler.
- * @param {Function} fn The handler function to remove. **This must be a reference to the function passed into the
- * {@link #addListener} call.**
- * @param {Object} scope If a scope (**this** reference) was specified when the listener was added, then this must
- * refer to the same object.
- * @return {Ext.Element} this
- */
- removeListener: function(eventName, fn, scope) {
- Ext.EventManager.un(this.dom, eventName, fn, scope || this);
- return this;
- },
- /**
- * Removes all previous added listeners from this element
- * @return {Ext.Element} this
- */
- removeAllListeners: function() {
- Ext.EventManager.removeAll(this.dom);
- return this;
- },
- /**
- * Recursively removes all previous added listeners from this element and its children
- * @return {Ext.Element} this
- */
- purgeAllListeners: function() {
- Ext.EventManager.purgeElement(this);
- return this;
- },
- /**
- * Test if size has a unit, otherwise appends the passed unit string, or the default for this Element.
- * @param size {Mixed} The size to set
- * @param units {String} The units to append to a numeric size value
- * @private
- */
- addUnits: function(size, units) {
- // Most common case first: Size is set to a number
- if (Ext.isNumber(size)) {
- return size + (units || this.defaultUnit || 'px');
- }
- // Size set to a value which means "auto"
- if (size === "" || size == "auto" || size == null) {
- return size || '';
- }
- // Otherwise, warn if it's not a valid CSS measurement
- if (!unitPattern.test(size)) {
- return size || '';
- }
- return size;
- },
- /**
- * Tests various css rules/browsers to determine if this element uses a border box
- * @return {Boolean}
- */
- isBorderBox: function() {
- return Ext.isBorderBox || noBoxAdjust[(this.dom.tagName || "").toLowerCase()];
- },
- /**
- * Removes this element's dom reference. Note that event and cache removal is handled at {@link Ext#removeNode
- * Ext.removeNode}
- */
- remove: function() {
- var me = this,
- dom = me.dom;
- if (dom) {
- delete me.dom;
- Ext.removeNode(dom);
- }
- },
- /**
- * Sets up event handlers to call the passed functions when the mouse is moved into and out of the Element.
- * @param {Function} overFn The function to call when the mouse enters the Element.
- * @param {Function} outFn The function to call when the mouse leaves the Element.
- * @param {Object} scope (optional) The scope (`this` reference) in which the functions are executed. Defaults
- * to the Element's DOM element.
- * @param {Object} options (optional) Options for the listener. See {@link Ext.util.Observable#addListener the
- * options parameter}.
- * @return {Ext.Element} this
- */
- hover: function(overFn, outFn, scope, options) {
- var me = this;
- me.on('mouseenter', overFn, scope || me.dom, options);
- me.on('mouseleave', outFn, scope || me.dom, options);
- return me;
- },
- /**
- * Returns true if this element is an ancestor of the passed element
- * @param {HTMLElement/String} el The element to check
- * @return {Boolean} True if this element is an ancestor of el, else false
- */
- contains: function(el) {
- return ! el ? false: Ext.Element.isAncestor(this.dom, el.dom ? el.dom: el);
- },
- /**
- * Returns the value of a namespaced attribute from the element's underlying DOM node.
- * @param {String} namespace The namespace in which to look for the attribute
- * @param {String} name The attribute name
- * @return {String} The attribute value
- */
- getAttributeNS: function(ns, name) {
- return this.getAttribute(name, ns);
- },
- /**
- * Returns the value of an attribute from the element's underlying DOM node.
- * @param {String} name The attribute name
- * @param {String} namespace (optional) The namespace in which to look for the attribute
- * @return {String} The attribute value
- * @method
- */
- getAttribute: (Ext.isIE && !(Ext.isIE9 && document.documentMode === 9)) ?
- function(name, ns) {
- var d = this.dom,
- type;
- if(ns) {
- type = typeof d[ns + ":" + name];
- if (type != 'undefined' && type != 'unknown') {
- return d[ns + ":" + name] || null;
- }
- return null;
- }
- if (name === "for") {
- name = "htmlFor";
- }
- return d[name] || null;
- }: function(name, ns) {
- var d = this.dom;
- if (ns) {
- return d.getAttributeNS(ns, name) || d.getAttribute(ns + ":" + name);
- }
- return d.getAttribute(name) || d[name] || null;
- },
- /**
- * Update the innerHTML of this element
- * @param {String} html The new HTML
- * @return {Ext.Element} this
- */
- update: function(html) {
- if (this.dom) {
- this.dom.innerHTML = html;
- }
- return this;
- }
- };
- var ep = El.prototype;
- El.addMethods = function(o) {
- Ext.apply(ep, o);
- };
- /**
- * @method
- * @alias Ext.Element#addListener
- * Shorthand for {@link #addListener}.
- */
- ep.on = ep.addListener;
- /**
- * @method
- * @alias Ext.Element#removeListener
- * Shorthand for {@link #removeListener}.
- */
- ep.un = ep.removeListener;
- /**
- * @method
- * @alias Ext.Element#removeAllListeners
- * Alias for {@link #removeAllListeners}.
- */
- ep.clearListeners = ep.removeAllListeners;
- /**
- * @method destroy
- * @member Ext.Element
- * Removes this element's dom reference. Note that event and cache removal is handled at {@link Ext#removeNode
- * Ext.removeNode}. Alias to {@link #remove}.
- */
- ep.destroy = ep.remove;
- /**
- * @property {Boolean} autoBoxAdjust
- * true to automatically adjust width and height settings for box-model issues (default to true)
- */
- ep.autoBoxAdjust = true;
- // private
- var unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i,
- docEl;
- /**
- * Retrieves Ext.Element objects. {@link Ext#get} is an alias for {@link Ext.Element#get}.
- *
- * **This method does not retrieve {@link Ext.Component Component}s.** This method retrieves Ext.Element
- * objects which encapsulate DOM elements. To retrieve a Component by its ID, use {@link Ext.ComponentManager#get}.
- *
- * Uses simple caching to consistently return the same object. Automatically fixes if an object was recreated with
- * the same id via AJAX or DOM.
- *
- * @param {String/HTMLElement/Ext.Element} el The id of the node, a DOM Node or an existing Element.
- * @return {Ext.Element} The Element object (or null if no matching element was found)
- * @static
- */
- El.get = function(el) {
- var ex,
- elm,
- id;
- if (!el) {
- return null;
- }
- if (typeof el == "string") {
- // element id
- if (! (elm = DOC.getElementById(el))) {
- return null;
- }
- if (EC[el] && EC[el].el) {
- ex = EC[el].el;
- ex.dom = elm;
- } else {
- ex = El.addToCache(new El(elm));
- }
- return ex;
- } else if (el.tagName) {
- // dom element
- if (! (id = el.id)) {
- id = Ext.id(el);
- }
- if (EC[id] && EC[id].el) {
- ex = EC[id].el;
- ex.dom = el;
- } else {
- ex = El.addToCache(new El(el));
- }
- return ex;
- } else if (el instanceof El) {
- if (el != docEl) {
- // refresh dom element in case no longer valid,
- // catch case where it hasn't been appended
- // If an el instance is passed, don't pass to getElementById without some kind of id
- if (Ext.isIE && (el.id == undefined || el.id == '')) {
- el.dom = el.dom;
- } else {
- el.dom = DOC.getElementById(el.id) || el.dom;
- }
- }
- return el;
- } else if (el.isComposite) {
- return el;
- } else if (Ext.isArray(el)) {
- return El.select(el);
- } else if (el == DOC) {
- // create a bogus element object representing the document object
- if (!docEl) {
- var f = function() {};
- f.prototype = El.prototype;
- docEl = new f();
- docEl.dom = DOC;
- }
- return docEl;
- }
- return null;
- };
- /**
- * Retrieves Ext.Element objects like {@link Ext#get} but is optimized for sub-elements.
- * This is helpful for performance, because in IE (prior to IE 9), `getElementById` uses
- * an non-optimized search. In those browsers, starting the search for an element with a
- * matching ID at a parent of that element will greatly speed up the process.
- *
- * Unlike {@link Ext#get}, this method only accepts ID's. If the ID is not a child of
- * this element, it will still be found if it exists in the document, but will be slower
- * than calling {@link Ext#get} directly.
- *
- * @param {String} id The id of the element to get.
- * @return {Ext.Element} The Element object (or null if no matching element was found)
- * @member Ext.Element
- * @method getById
- * @markdown
- */
- ep.getById = (!Ext.isIE6 && !Ext.isIE7 && !Ext.isIE8) ? El.get :
- function (id) {
- var dom = this.dom,
- cached, el, ret;
- if (dom) {
- el = dom.all[id];
- if (el) {
- // calling El.get here is a real hit (2x slower) because it has to
- // redetermine that we are giving it a dom el.
- cached = EC[id];
- if (cached && cached.el) {
- ret = cached.el;
- ret.dom = el;
- } else {
- ret = El.addToCache(new El(el));
- }
- return ret;
- }
- }
- return El.get(id);
- };
- El.addToCache = function(el, id) {
- if (el) {
- id = id || el.id;
- EC[id] = {
- el: el,
- data: {},
- events: {}
- };
- }
- return el;
- };
- // private method for getting and setting element data
- El.data = function(el, key, value) {
- el = El.get(el);
- if (!el) {
- return null;
- }
- var c = EC[el.id].data;
- if (arguments.length == 2) {
- return c[key];
- } else {
- return (c[key] = value);
- }
- };
- // private
- // Garbage collection - uncache elements/purge listeners on orphaned elements
- // so we don't hold a reference and cause the browser to retain them
- function garbageCollect() {
- if (!Ext.enableGarbageCollector) {
- clearInterval(El.collectorThreadId);
- } else {
- var eid,
- el,
- d,
- o;
- for (eid in EC) {
- if (!EC.hasOwnProperty(eid)) {
- continue;
- }
- o = EC[eid];
- if (o.skipGarbageCollection) {
- continue;
- }
- el = o.el;
- d = el.dom;
- // -------------------------------------------------------
- // Determining what is garbage:
- // -------------------------------------------------------
- // !d
- // dom node is null, definitely garbage
- // -------------------------------------------------------
- // !d.parentNode
- // no parentNode == direct orphan, definitely garbage
- // -------------------------------------------------------
- // !d.offsetParent && !document.getElementById(eid)
- // display none elements have no offsetParent so we will
- // also try to look it up by it's id. However, check
- // offsetParent first so we don't do unneeded lookups.
- // This enables collection of elements that are not orphans
- // directly, but somewhere up the line they have an orphan
- // parent.
- // -------------------------------------------------------
- if (!d || !d.parentNode || (!d.offsetParent && !DOC.getElementById(eid))) {
- if (d && Ext.enableListenerCollection) {
- Ext.EventManager.removeAll(d);
- }
- delete EC[eid];
- }
- }
- // Cleanup IE Object leaks
- if (Ext.isIE) {
- var t = {};
- for (eid in EC) {
- if (!EC.hasOwnProperty(eid)) {
- continue;
- }
- t[eid] = EC[eid];
- }
- EC = Ext.cache = t;
- }
- }
- }
- El.collectorThreadId = setInterval(garbageCollect, 30000);
- var flyFn = function() {};
- flyFn.prototype = El.prototype;
- // dom is optional
- El.Flyweight = function(dom) {
- this.dom = dom;
- };
- El.Flyweight.prototype = new flyFn();
- El.Flyweight.prototype.isFlyweight = true;
- El._flyweights = {};
- /**
- * Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference
- * to this element - the dom node can be overwritten by other code. {@link Ext#fly} is alias for
- * {@link Ext.Element#fly}.
- *
- * Use this to make one-time references to DOM elements which are not going to be accessed again either by
- * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link
- * Ext#get Ext.get} will be more appropriate to take advantage of the caching provided by the Ext.Element
- * class.
- *
- * @param {String/HTMLElement} el The dom node or id
- * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts (e.g.
- * internally Ext uses "_global")
- * @return {Ext.Element} The shared Element object (or null if no matching element was found)
- * @static
- */
- El.fly = function(el, named) {
- var ret = null;
- named = named || '_global';
- el = Ext.getDom(el);
- if (el) {
- (El._flyweights[named] = El._flyweights[named] || new El.Flyweight()).dom = el;
- ret = El._flyweights[named];
- }
- return ret;
- };
- /**
- * @member Ext
- * @method get
- * @alias Ext.Element#get
- */
- Ext.get = El.get;
- /**
- * @member Ext
- * @method fly
- * @alias Ext.Element#fly
- */
- Ext.fly = El.fly;
- // speedy lookup for elements never to box adjust
- var noBoxAdjust = Ext.isStrict ? {
- select: 1
- }: {
- input: 1,
- select: 1,
- textarea: 1
- };
- if (Ext.isIE || Ext.isGecko) {
- noBoxAdjust['button'] = 1;
- }
- })();
- /**
- * @class Ext.Element
- */
- Ext.Element.addMethods({
- /**
- * Looks at this node and then at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
- * @param {String} selector The simple selector to test
- * @param {Number/String/HTMLElement/Ext.Element} maxDepth (optional)
- * The max depth to search as a number or element (defaults to 50 || document.body)
- * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
- * @return {HTMLElement} The matching DOM node (or null if no match was found)
- */
- findParent : function(simpleSelector, maxDepth, returnEl) {
- var p = this.dom,
- b = document.body,
- depth = 0,
- stopEl;
- maxDepth = maxDepth || 50;
- if (isNaN(maxDepth)) {
- stopEl = Ext.getDom(maxDepth);
- maxDepth = Number.MAX_VALUE;
- }
- while (p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl) {
- if (Ext.DomQuery.is(p, simpleSelector)) {
- return returnEl ? Ext.get(p) : p;
- }
- depth++;
- p = p.parentNode;
- }
- return null;
- },
- /**
- * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
- * @param {String} selector The simple selector to test
- * @param {Number/String/HTMLElement/Ext.Element} maxDepth (optional)
- * The max depth to search as a number or element (defaults to 10 || document.body)
- * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
- * @return {HTMLElement} The matching DOM node (or null if no match was found)
- */
- findParentNode : function(simpleSelector, maxDepth, returnEl) {
- var p = Ext.fly(this.dom.parentNode, '_internal');
- return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
- },
- /**
- * Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child).
- * This is a shortcut for findParentNode() that always returns an Ext.Element.
- * @param {String} selector The simple selector to test
- * @param {Number/String/HTMLElement/Ext.Element} maxDepth (optional)
- * The max depth to search as a number or element (defaults to 10 || document.body)
- * @return {Ext.Element} The matching DOM node (or null if no match was found)
- */
- up : function(simpleSelector, maxDepth) {
- return this.findParentNode(simpleSelector, maxDepth, true);
- },
- /**
- * Creates a {@link Ext.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
- * @param {String} selector The CSS selector
- * @return {Ext.CompositeElement/Ext.CompositeElement} The composite element
- */
- select : function(selector) {
- return Ext.Element.select(selector, false, this.dom);
- },
- /**
- * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
- * @param {String} selector The CSS selector
- * @return {HTMLElement[]} An array of the matched nodes
- */
- query : function(selector) {
- return Ext.DomQuery.select(selector, this.dom);
- },
- /**
- * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
- * @param {String} selector The CSS selector
- * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
- * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
- */
- down : function(selector, returnDom) {
- var n = Ext.DomQuery.selectNode(selector, this.dom);
- return returnDom ? n : Ext.get(n);
- },
- /**
- * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
- * @param {String} selector The CSS selector
- * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
- * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
- */
- child : function(selector, returnDom) {
- var node,
- me = this,
- id;
- id = Ext.get(me).id;
- // Escape . or :
- id = id.replace(/[\.:]/g, "\\$0");
- node = Ext.DomQuery.selectNode('#' + id + " > " + selector, me.dom);
- return returnDom ? node : Ext.get(node);
- },
- /**
- * Gets the parent node for this element, optionally chaining up trying to match a selector
- * @param {String} selector (optional) Find a parent node that matches the passed simple selector
- * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
- * @return {Ext.Element/HTMLElement} The parent node or null
- */
- parent : function(selector, returnDom) {
- return this.matchNode('parentNode', 'parentNode', selector, returnDom);
- },
- /**
- * Gets the next sibling, skipping text nodes
- * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
- * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
- * @return {Ext.Element/HTMLElement} The next sibling or null
- */
- next : function(selector, returnDom) {
- return this.matchNode('nextSibling', 'nextSibling', selector, returnDom);
- },
- /**
- * Gets the previous sibling, skipping text nodes
- * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
- * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
- * @return {Ext.Element/HTMLElement} The previous sibling or null
- */
- prev : function(selector, returnDom) {
- return this.matchNode('previousSibling', 'previousSibling', selector, returnDom);
- },
- /**
- * Gets the first child, skipping text nodes
- * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
- * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
- * @return {Ext.Element/HTMLElement} The first child or null
- */
- first : function(selector, returnDom) {
- return this.matchNode('nextSibling', 'firstChild', selector, returnDom);
- },
- /**
- * Gets the last child, skipping text nodes
- * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
- * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
- * @return {Ext.Element/HTMLElement} The last child or null
- */
- last : function(selector, returnDom) {
- return this.matchNode('previousSibling', 'lastChild', selector, returnDom);
- },
- matchNode : function(dir, start, selector, returnDom) {
- if (!this.dom) {
- return null;
- }
- var n = this.dom[start];
- while (n) {
- if (n.nodeType == 1 && (!selector || Ext.DomQuery.is(n, selector))) {
- return !returnDom ? Ext.get(n) : n;
- }
- n = n[dir];
- }
- return null;
- }
- });
- /**
- * @class Ext.Element
- */
- Ext.Element.addMethods({
- /**
- * Appends the passed element(s) to this element
- * @param {String/HTMLElement/Ext.Element} el
- * The id of the node, a DOM Node or an existing Element.
- * @return {Ext.Element} this
- */
- appendChild : function(el) {
- return Ext.get(el).appendTo(this);
- },
- /**
- * Appends this element to the passed element
- * @param {String/HTMLElement/Ext.Element} el The new parent element.
- * The id of the node, a DOM Node or an existing Element.
- * @return {Ext.Element} this
- */
- appendTo : function(el) {
- Ext.getDom(el).appendChild(this.dom);
- return this;
- },
- /**
- * Inserts this element before the passed element in the DOM
- * @param {String/HTMLElement/Ext.Element} el The element before which this element will be inserted.
- * The id of the node, a DOM Node or an existing Element.
- * @return {Ext.Element} this
- */
- insertBefore : function(el) {
- el = Ext.getDom(el);
- el.parentNode.insertBefore(this.dom, el);
- return this;
- },
- /**
- * Inserts this element after the passed element in the DOM
- * @param {String/HTMLElement/Ext.Element} el The element to insert after.
- * The id of the node, a DOM Node or an existing Element.
- * @return {Ext.Element} this
- */
- insertAfter : function(el) {
- el = Ext.getDom(el);
- el.parentNode.insertBefore(this.dom, el.nextSibling);
- return this;
- },
- /**
- * Inserts (or creates) an element (or DomHelper config) as the first child of this element
- * @param {String/HTMLElement/Ext.Element/Object} el The id or element to insert or a DomHelper config
- * to create and insert
- * @return {Ext.Element} The new child
- */
- insertFirst : function(el, returnDom) {
- el = el || {};
- if (el.nodeType || el.dom || typeof el == 'string') { // element
- el = Ext.getDom(el);
- this.dom.insertBefore(el, this.dom.firstChild);
- return !returnDom ? Ext.get(el) : el;
- }
- else { // dh config
- return this.createChild(el, this.dom.firstChild, returnDom);
- }
- },
- /**
- * Inserts (or creates) the passed element (or DomHelper config) as a sibling of this element
- * @param {String/HTMLElement/Ext.Element/Object/Array} el The id, element to insert or a DomHelper config
- * to create and insert *or* an array of any of those.
- * @param {String} where (optional) 'before' or 'after' defaults to before
- * @param {Boolean} returnDom (optional) True to return the .;ll;l,raw DOM element instead of Ext.Element
- * @return {Ext.Element} The inserted Element. If an array is passed, the last inserted element is returned.
- */
- insertSibling: function(el, where, returnDom){
- var me = this, rt,
- isAfter = (where || 'before').toLowerCase() == 'after',
- insertEl;
- if(Ext.isArray(el)){
- insertEl = me;
- Ext.each(el, function(e) {
- rt = Ext.fly(insertEl, '_internal').insertSibling(e, where, returnDom);
- if(isAfter){
- insertEl = rt;
- }
- });
- return rt;
- }
- el = el || {};
- if(el.nodeType || el.dom){
- rt = me.dom.parentNode.insertBefore(Ext.getDom(el), isAfter ? me.dom.nextSibling : me.dom);
- if (!returnDom) {
- rt = Ext.get(rt);
- }
- }else{
- if (isAfter && !me.dom.nextSibling) {
- rt = Ext.DomHelper.append(me.dom.parentNode, el, !returnDom);
- } else {
- rt = Ext.DomHelper[isAfter ? 'insertAfter' : 'insertBefore'](me.dom, el, !returnDom);
- }
- }
- return rt;
- },
- /**
- * Replaces the passed element with this element
- * @param {String/HTMLElement/Ext.Element} el The element to replace.
- * The id of the node, a DOM Node or an existing Element.
- * @return {Ext.Element} this
- */
- replace : function(el) {
- el = Ext.get(el);
- this.insertBefore(el);
- el.remove();
- return this;
- },
-
- /**
- * Replaces this element with the passed element
- * @param {String/HTMLElement/Ext.Element/Object} el The new element (id of the node, a DOM Node
- * or an existing Element) or a DomHelper config of an element to create
- * @return {Ext.Element} this
- */
- replaceWith: function(el){
- var me = this;
-
- if(el.nodeType || el.dom || typeof el == 'string'){
- el = Ext.get(el);
- me.dom.parentNode.insertBefore(el, me.dom);
- }else{
- el = Ext.DomHelper.insertBefore(me.dom, el);
- }
-
- delete Ext.cache[me.id];
- Ext.removeNode(me.dom);
- me.id = Ext.id(me.dom = el);
- Ext.Element.addToCache(me.isFlyweight ? new Ext.Element(me.dom) : me);
- return me;
- },
-
- /**
- * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
- * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
- * automatically generated with the specified attributes.
- * @param {HTMLElement} insertBefore (optional) a child element of this element
- * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
- * @return {Ext.Element} The new child element
- */
- createChild : function(config, insertBefore, returnDom) {
- config = config || {tag:'div'};
- if (insertBefore) {
- return Ext.DomHelper.insertBefore(insertBefore, config, returnDom !== true);
- }
- else {
- return Ext.DomHelper[!this.dom.firstChild ? 'insertFirst' : 'append'](this.dom, config, returnDom !== true);
- }
- },
- /**
- * Creates and wraps this element with another element
- * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
- * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element
- * @return {HTMLElement/Ext.Element} The newly created wrapper element
- */
- wrap : function(config, returnDom) {
- var newEl = Ext.DomHelper.insertBefore(this.dom, config || {tag: "div"}, !returnDom),
- d = newEl.dom || newEl;
- d.appendChild(this.dom);
- return newEl;
- },
- /**
- * Inserts an html fragment into this element
- * @param {String} where Where to insert the html in relation to this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
- * See {@link Ext.DomHelper#insertHtml} for details.
- * @param {String} html The HTML fragment
- * @param {Boolean} returnEl (optional) True to return an Ext.Element (defaults to false)
- * @return {HTMLElement/Ext.Element} The inserted node (or nearest related if more than 1 inserted)
- */
- insertHtml : function(where, html, returnEl) {
- var el = Ext.DomHelper.insertHtml(where, this.dom, html);
- return returnEl ? Ext.get(el) : el;
- }
- });
- /**
- * @class Ext.Element
- */
- (function(){
- // local style camelizing for speed
- var ELEMENT = Ext.Element,
- supports = Ext.supports,
- view = document.defaultView,
- opacityRe = /alpha\(opacity=(.*)\)/i,
- trimRe = /^\s+|\s+$/g,
- spacesRe = /\s+/,
- wordsRe = /\w/g,
- adjustDirect2DTableRe = /table-row|table-.*-group/,
- INTERNAL = '_internal',
- PADDING = 'padding',
- MARGIN = 'margin',
- BORDER = 'border',
- LEFT = '-left',
- RIGHT = '-right',
- TOP = '-top',
- BOTTOM = '-bottom',
- WIDTH = '-width',
- MATH = Math,
- HIDDEN = 'hidden',
- ISCLIPPED = 'isClipped',
- OVERFLOW = 'overflow',
- OVERFLOWX = 'overflow-x',
- OVERFLOWY = 'overflow-y',
- ORIGINALCLIP = 'originalClip',
- // special markup used throughout Ext when box wrapping elements
- borders = {l: BORDER + LEFT + WIDTH, r: BORDER + RIGHT + WIDTH, t: BORDER + TOP + WIDTH, b: BORDER + BOTTOM + WIDTH},
- paddings = {l: PADDING + LEFT, r: PADDING + RIGHT, t: PADDING + TOP, b: PADDING + BOTTOM},
- margins = {l: MARGIN + LEFT, r: MARGIN + RIGHT, t: MARGIN + TOP, b: MARGIN + BOTTOM},
- data = ELEMENT.data;
- ELEMENT.boxMarkup = '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div><div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div><div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
- // These property values are read from the parentNode if they cannot be read
- // from the child:
- ELEMENT.inheritedProps = {
- fontSize: 1,
- fontStyle: 1,
- opacity: 1
- };
- Ext.override(ELEMENT, {
- /**
- * TODO: Look at this
- */
- // private ==> used by Fx
- adjustWidth : function(width) {
- var me = this,
- isNum = (typeof width == 'number');
- if(isNum && me.autoBoxAdjust && !me.isBorderBox()){
- width -= (me.getBorderWidth("lr") + me.getPadding("lr"));
- }
- return (isNum && width < 0) ? 0 : width;
- },
- // private ==> used by Fx
- adjustHeight : function(height) {
- var me = this,
- isNum = (typeof height == "number");
- if(isNum && me.autoBoxAdjust && !me.isBorderBox()){
- height -= (me.getBorderWidth("tb") + me.getPadding("tb"));
- }
- return (isNum && height < 0) ? 0 : height;
- },
- /**
- * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
- * @param {String/String[]} className The CSS classes to add separated by space, or an array of classes
- * @return {Ext.Element} this
- */
- addCls : function(className){
- var me = this,
- cls = [],
- space = ((me.dom.className.replace(trimRe, '') == '') ? "" : " "),
- i, len, v;
- if (className === undefined) {
- return me;
- }
- // Separate case is for speed
- if (Object.prototype.toString.call(className) !== '[object Array]') {
- if (typeof className === 'string') {
- className = className.replace(trimRe, '').split(spacesRe);
- if (className.length === 1) {
- className = className[0];
- if (!me.hasCls(className)) {
- me.dom.className += space + className;
- }
- } else {
- this.addCls(className);
- }
- }
- } else {
- for (i = 0, len = className.length; i < len; i++) {
- v = className[i];
- if (typeof v == 'string' && (' ' + me.dom.className + ' ').indexOf(' ' + v + ' ') == -1) {
- cls.push(v);
- }
- }
- if (cls.length) {
- me.dom.className += space + cls.join(" ");
- }
- }
- return me;
- },
- /**
- * Removes one or more CSS classes from the element.
- * @param {String/String[]} className The CSS classes to remove separated by space, or an array of classes
- * @return {Ext.Element} this
- */
- removeCls : function(className){
- var me = this,
- i, idx, len, cls, elClasses;
- if (className === undefined) {
- return me;
- }
- if (Object.prototype.toString.call(className) !== '[object Array]') {
- className = className.replace(trimRe, '').split(spacesRe);
- }
- if (me.dom && me.dom.className) {
- elClasses = me.dom.className.replace(trimRe, '').split(spacesRe);
- for (i = 0, len = className.length; i < len; i++) {
- cls = className[i];
- if (typeof cls == 'string') {
- cls = cls.replace(trimRe, '');
- idx = Ext.Array.indexOf(elClasses, cls);
- if (idx != -1) {
- Ext.Array.erase(elClasses, idx, 1);
- }
- }
- }
- me.dom.className = elClasses.join(" ");
- }
- return me;
- },
- /**
- * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
- * @param {String/String[]} className The CSS class to add, or an array of classes
- * @return {Ext.Element} this
- */
- radioCls : function(className){
- var cn = this.dom.parentNode.childNodes,
- v, i, len;
- className = Ext.isArray(className) ? className : [className];
- for (i = 0, len = cn.length; i < len; i++) {
- v = cn[i];
- if (v && v.nodeType == 1) {
- Ext.fly(v, '_internal').removeCls(className);
- }
- }
- return this.addCls(className);
- },
- /**
- * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
- * @param {String} className The CSS class to toggle
- * @return {Ext.Element} this
- * @method
- */
- toggleCls : Ext.supports.ClassList ?
- function(className) {
- this.dom.classList.toggle(Ext.String.trim(className));
- return this;
- } :
- function(className) {
- return this.hasCls(className) ? this.removeCls(className) : this.addCls(className);
- },
- /**
- * Checks if the specified CSS class exists on this element's DOM node.
- * @param {String} className The CSS class to check for
- * @return {Boolean} True if the class exists, else false
- * @method
- */
- hasCls : Ext.supports.ClassList ?
- function(className) {
- if (!className) {
- return false;
- }
- className = className.split(spacesRe);
- var ln = className.length,
- i = 0;
- for (; i < ln; i++) {
- if (className[i] && this.dom.classList.contains(className[i])) {
- return true;
- }
- }
- return false;
- } :
- function(className){
- return className && (' ' + this.dom.className + ' ').indexOf(' ' + className + ' ') != -1;
- },
- /**
- * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
- * @param {String} oldClassName The CSS class to replace
- * @param {String} newClassName The replacement CSS class
- * @return {Ext.Element} this
- */
- replaceCls : function(oldClassName, newClassName){
- return this.removeCls(oldClassName).addCls(newClassName);
- },
- isStyle : function(style, val) {
- return this.getStyle(style) == val;
- },
- /**
- * Normalizes currentStyle and computedStyle.
- * @param {String} property The style property whose value is returned.
- * @return {String} The current value of the style property for this element.
- * @method
- */
- getStyle : function() {
- return view && view.getComputedStyle ?
- function(prop){
- var el = this.dom,
- v, cs, out, display, cleaner;
- if(el == document){
- return null;
- }
- prop = ELEMENT.normalize(prop);
- out = (v = el.style[prop]) ? v :
- (cs = view.getComputedStyle(el, "")) ? cs[prop] : null;
- // Ignore cases when the margin is correctly reported as 0, the bug only shows
- // numbers larger.
- if(prop == 'marginRight' && out != '0px' && !supports.RightMargin){
- cleaner = ELEMENT.getRightMarginFixCleaner(el);
- display = this.getStyle('display');
- el.style.display = 'inline-block';
- out = view.getComputedStyle(el, '').marginRight;
- el.style.display = display;
- cleaner();
- }
- if(prop == 'backgroundColor' && out == 'rgba(0, 0, 0, 0)' && !supports.TransparentColor){
- out = 'transparent';
- }
- return out;
- } :
- function (prop) {
- var el = this.dom,
- m, cs;
- if (el == document) {
- return null;
- }
- prop = ELEMENT.normalize(prop);
- do {
- if (prop == 'opacity') {
- if (el.style.filter.match) {
- m = el.style.filter.match(opacityRe);
- if(m){
- var fv = parseFloat(m[1]);
- if(!isNaN(fv)){
- return fv ? fv / 100 : 0;
- }
- }
- }
- return 1;
- }
- // the try statement does have a cost, so we avoid it unless we are
- // on IE6
- if (!Ext.isIE6) {
- return el.style[prop] || ((cs = el.currentStyle) ? cs[prop] : null);
- }
- try {
- return el.style[prop] || ((cs = el.currentStyle) ? cs[prop] : null);
- } catch (e) {
- // in some cases, IE6 will throw Invalid Argument for properties
- // like fontSize (see in /examples/tabs/tabs.html).
- }
- if (!ELEMENT.inheritedProps[prop]) {
- break;
- }
- el = el.parentNode;
- // this is _not_ perfect, but we can only hope that the style we
- // need is inherited from a parentNode. If not and since IE won't
- // give us the info we need, we are never going to be 100% right.
- } while (el);
- return null;
- }
- }(),
- /**
- * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
- * are convert to standard 6 digit hex color.
- * @param {String} attr The css attribute
- * @param {String} defaultValue The default value to use when a valid color isn't found
- * @param {String} prefix (optional) defaults to #. Use an empty string when working with
- * color anims.
- */
- getColor : function(attr, defaultValue, prefix){
- var v = this.getStyle(attr),
- color = prefix || prefix === '' ? prefix : '#',
- h;
- if(!v || (/transparent|inherit/.test(v))) {
- return defaultValue;
- }
- if(/^r/.test(v)){
- Ext.each(v.slice(4, v.length -1).split(','), function(s){
- h = parseInt(s, 10);
- color += (h < 16 ? '0' : '') + h.toString(16);
- });
- }else{
- v = v.replace('#', '');
- color += v.length == 3 ? v.replace(/^(\w)(\w)(\w)$/, '$1$1$2$2$3$3') : v;
- }
- return(color.length > 5 ? color.toLowerCase() : defaultValue);
- },
- /**
- * Wrapper for setting style properties, also takes single object parameter of multiple styles.
- * @param {String/Object} property The style property to be set, or an object of multiple styles.
- * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
- * @return {Ext.Element} this
- */
- setStyle : function(prop, value){
- var me = this,
- tmp, style;
- if (!me.dom) {
- return me;
- }
- if (typeof prop === 'string') {
- tmp = {};
- tmp[prop] = value;
- prop = tmp;
- }
- for (style in prop) {
- if (prop.hasOwnProperty(style)) {
- value = Ext.value(prop[style], '');
- if (style == 'opacity') {
- me.setOpacity(value);
- }
- else {
- me.dom.style[ELEMENT.normalize(style)] = value;
- }
- }
- }
- return me;
- },
- /**
- * Set the opacity of the element
- * @param {Number} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
- * @param {Boolean/Object} animate (optional) a standard Element animation config object or <tt>true</tt> for
- * the default animation (<tt>{duration: .35, easing: 'easeIn'}</tt>)
- * @return {Ext.Element} this
- */
- setOpacity: function(opacity, animate) {
- var me = this,
- dom = me.dom,
- val,
- style;
- if (!me.dom) {
- return me;
- }
- style = me.dom.style;
- if (!animate || !me.anim) {
- if (!Ext.supports.Opacity) {
- opacity = opacity < 1 ? 'alpha(opacity=' + opacity * 100 + ')': '';
- val = style.filter.replace(opacityRe, '').replace(trimRe, '');
- style.zoom = 1;
- style.filter = val + (val.length > 0 ? ' ': '') + opacity;
- }
- else {
- style.opacity = opacity;
- }
- }
- else {
- if (!Ext.isObject(animate)) {
- animate = {
- duration: 350,
- easing: 'ease-in'
- };
- }
- me.animate(Ext.applyIf({
- to: {
- opacity: opacity
- }
- },
- animate));
- }
- return me;
- },
- /**
- * Clears any opacity settings from this element. Required in some cases for IE.
- * @return {Ext.Element} this
- */
- clearOpacity : function(){
- var style = this.dom.style;
- if(!Ext.supports.Opacity){
- if(!Ext.isEmpty(style.filter)){
- style.filter = style.filter.replace(opacityRe, '').replace(trimRe, '');
- }
- }else{
- style.opacity = style['-moz-opacity'] = style['-khtml-opacity'] = '';
- }
- return this;
- },
- /**
- * @private
- * Returns 1 if the browser returns the subpixel dimension rounded to the lowest pixel.
- * @return {Number} 0 or 1
- */
- adjustDirect2DDimension: function(dimension) {
- var me = this,
- dom = me.dom,
- display = me.getStyle('display'),
- inlineDisplay = dom.style['display'],
- inlinePosition = dom.style['position'],
- originIndex = dimension === 'width' ? 0 : 1,
- floating;
- if (display === 'inline') {
- dom.style['display'] = 'inline-block';
- }
- dom.style['position'] = display.match(adjustDirect2DTableRe) ? 'absolute' : 'static';
- // floating will contain digits that appears after the decimal point
- // if height or width are set to auto we fallback to msTransformOrigin calculation
- floating = (parseFloat(me.getStyle(dimension)) || parseFloat(dom.currentStyle.msTransformOrigin.split(' ')[originIndex]) * 2) % 1;
- dom.style['position'] = inlinePosition;
- if (display === 'inline') {
- dom.style['display'] = inlineDisplay;
- }
- return floating;
- },
- /**
- * Returns the offset height of the element
- * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
- * @return {Number} The element's height
- */
- getHeight: function(contentHeight, preciseHeight) {
- var me = this,
- dom = me.dom,
- hidden = Ext.isIE && me.isStyle('display', 'none'),
- height, overflow, style, floating;
- // IE Quirks mode acts more like a max-size measurement unless overflow is hidden during measurement.
- // We will put the overflow back to it's original value when we are done measuring.
- if (Ext.isIEQuirks) {
- style = dom.style;
- overflow = style.overflow;
- me.setStyle({ overflow: 'hidden'});
- }
- height = dom.offsetHeight;
- height = MATH.max(height, hidden ? 0 : dom.clientHeight) || 0;
- // IE9 Direct2D dimension rounding bug
- if (!hidden && Ext.supports.Direct2DBug) {
- floating = me.adjustDirect2DDimension('height');
- if (preciseHeight) {
- height += floating;
- }
- else if (floating > 0 && floating < 0.5) {
- height++;
- }
- }
- if (contentHeight) {
- height -= (me.getBorderWidth("tb") + me.getPadding("tb"));
- }
- if (Ext.isIEQuirks) {
- me.setStyle({ overflow: overflow});
- }
- if (height < 0) {
- height = 0;
- }
- return height;
- },
- /**
- * Returns the offset width of the element
- * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
- * @return {Number} The element's width
- */
- getWidth: function(contentWidth, preciseWidth) {
- var me = this,
- dom = me.dom,
- hidden = Ext.isIE && me.isStyle('display', 'none'),
- rect, width, overflow, style, floating, parentPosition;
- // IE Quirks mode acts more like a max-size measurement unless overflow is hidden during measurement.
- // We will put the overflow back to it's original value when we are done measuring.
- if (Ext.isIEQuirks) {
- style = dom.style;
- overflow = style.overflow;
- me.setStyle({overflow: 'hidden'});
- }
- // Fix Opera 10.5x width calculation issues
- if (Ext.isOpera10_5) {
- if (dom.parentNode.currentStyle.position === 'relative') {
- parentPosition = dom.parentNode.style.position;
- dom.parentNode.style.position = 'static';
- width = dom.offsetWidth;
- dom.parentNode.style.position = parentPosition;
- }
- width = Math.max(width || 0, dom.offsetWidth);
- // Gecko will in some cases report an offsetWidth that is actually less than the width of the
- // text contents, because it measures fonts with sub-pixel precision but rounds the calculated
- // value down. Using getBoundingClientRect instead of offsetWidth allows us to get the precise
- // subpixel measurements so we can force them to always be rounded up. See
- // https://bugzilla.mozilla.org/show_bug.cgi?id=458617
- } else if (Ext.supports.BoundingClientRect) {
- rect = dom.getBoundingClientRect();
- width = rect.right - rect.left;
- width = preciseWidth ? width : Math.ceil(width);
- } else {
- width = dom.offsetWidth;
- }
- width = MATH.max(width, hidden ? 0 : dom.clientWidth) || 0;
- // IE9 Direct2D dimension rounding bug
- if (!hidden && Ext.supports.Direct2DBug) {
- floating = me.adjustDirect2DDimension('width');
- if (preciseWidth) {
- width += floating;
- }
- else if (floating > 0 && floating < 0.5) {
- width++;
- }
- }
- if (contentWidth) {
- width -= (me.getBorderWidth("lr") + me.getPadding("lr"));
- }
- if (Ext.isIEQuirks) {
- me.setStyle({ overflow: overflow});
- }
- if (width < 0) {
- width = 0;
- }
- return width;
- },
- /**
- * Set the width of this Element.
- * @param {Number/String} width The new width. This may be one of:<div class="mdetail-params"><ul>
- * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
- * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
- * </ul></div>
- * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
- * @return {Ext.Element} this
- */
- setWidth : function(width, animate){
- var me = this;
- width = me.adjustWidth(width);
- if (!animate || !me.anim) {
- me.dom.style.width = me.addUnits(width);
- }
- else {
- if (!Ext.isObject(animate)) {
- animate = {};
- }
- me.animate(Ext.applyIf({
- to: {
- width: width
- }
- }, animate));
- }
- return me;
- },
- /**
- * Set the height of this Element.
- * <pre><code>
- // change the height to 200px and animate with default configuration
- Ext.fly('elementId').setHeight(200, true);
- // change the height to 150px and animate with a custom configuration
- Ext.fly('elId').setHeight(150, {
- duration : .5, // animation will have a duration of .5 seconds
- // will change the content to "finished"
- callback: function(){ this.{@link #update}("finished"); }
- });
- * </code></pre>
- * @param {Number/String} height The new height. This may be one of:<div class="mdetail-params"><ul>
- * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels.)</li>
- * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
- * </ul></div>
- * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
- * @return {Ext.Element} this
- */
- setHeight : function(height, animate){
- var me = this;
- height = me.adjustHeight(height);
- if (!animate || !me.anim) {
- me.dom.style.height = me.addUnits(height);
- }
- else {
- if (!Ext.isObject(animate)) {
- animate = {};
- }
- me.animate(Ext.applyIf({
- to: {
- height: height
- }
- }, animate));
- }
- return me;
- },
- /**
- * Gets the width of the border(s) for the specified side(s)
- * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
- * passing <tt>'lr'</tt> would get the border <b><u>l</u></b>eft width + the border <b><u>r</u></b>ight width.
- * @return {Number} The width of the sides passed added together
- */
- getBorderWidth : function(side){
- return this.addStyles(side, borders);
- },
- /**
- * Gets the width of the padding(s) for the specified side(s)
- * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
- * passing <tt>'lr'</tt> would get the padding <b><u>l</u></b>eft + the padding <b><u>r</u></b>ight.
- * @return {Number} The padding of the sides passed added together
- */
- getPadding : function(side){
- return this.addStyles(side, paddings);
- },
- /**
- * Store the current overflow setting and clip overflow on the element - use <tt>{@link #unclip}</tt> to remove
- * @return {Ext.Element} this
- */
- clip : function(){
- var me = this,
- dom = me.dom;
- if(!data(dom, ISCLIPPED)){
- data(dom, ISCLIPPED, true);
- data(dom, ORIGINALCLIP, {
- o: me.getStyle(OVERFLOW),
- x: me.getStyle(OVERFLOWX),
- y: me.getStyle(OVERFLOWY)
- });
- me.setStyle(OVERFLOW, HIDDEN);
- me.setStyle(OVERFLOWX, HIDDEN);
- me.setStyle(OVERFLOWY, HIDDEN);
- }
- return me;
- },
- /**
- * Return clipping (overflow) to original clipping before <tt>{@link #clip}</tt> was called
- * @return {Ext.Element} this
- */
- unclip : function(){
- var me = this,
- dom = me.dom,
- clip;
- if(data(dom, ISCLIPPED)){
- data(dom, ISCLIPPED, false);
- clip = data(dom, ORIGINALCLIP);
- if(clip.o){
- me.setStyle(OVERFLOW, clip.o);
- }
- if(clip.x){
- me.setStyle(OVERFLOWX, clip.x);
- }
- if(clip.y){
- me.setStyle(OVERFLOWY, clip.y);
- }
- }
- return me;
- },
- // private
- addStyles : function(sides, styles){
- var totalSize = 0,
- sidesArr = sides.match(wordsRe),
- i = 0,
- len = sidesArr.length,
- side, size;
- for (; i < len; i++) {
- side = sidesArr[i];
- size = side && parseInt(this.getStyle(styles[side]), 10);
- if (size) {
- totalSize += MATH.abs(size);
- }
- }
- return totalSize;
- },
- margins : margins,
- /**
- * More flexible version of {@link #setStyle} for setting style properties.
- * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
- * a function which returns such a specification.
- * @return {Ext.Element} this
- */
- applyStyles : function(style){
- Ext.DomHelper.applyStyles(this.dom, style);
- return this;
- },
- /**
- * Returns an object with properties matching the styles requested.
- * For example, el.getStyles('color', 'font-size', 'width') might return
- * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
- * @param {String} style1 A style name
- * @param {String} style2 A style name
- * @param {String} etc.
- * @return {Object} The style object
- */
- getStyles : function(){
- var styles = {},
- len = arguments.length,
- i = 0, style;
- for(; i < len; ++i) {
- style = arguments[i];
- styles[style] = this.getStyle(style);
- }
- return styles;
- },
- /**
- * <p>Wraps the specified element with a special 9 element markup/CSS block that renders by default as
- * a gray container with a gradient background, rounded corners and a 4-way shadow.</p>
- * <p>This special markup is used throughout Ext when box wrapping elements ({@link Ext.button.Button},
- * {@link Ext.panel.Panel} when <tt>{@link Ext.panel.Panel#frame frame=true}</tt>, {@link Ext.window.Window}). The markup
- * is of this form:</p>
- * <pre><code>
- Ext.Element.boxMarkup =
- '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div>
- <div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div>
- <div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
- * </code></pre>
- * <p>Example usage:</p>
- * <pre><code>
- // Basic box wrap
- Ext.get("foo").boxWrap();
- // You can also add a custom class and use CSS inheritance rules to customize the box look.
- // 'x-box-blue' is a built-in alternative -- look at the related CSS definitions as an example
- // for how to create a custom box wrap style.
- Ext.get("foo").boxWrap().addCls("x-box-blue");
- * </code></pre>
- * @param {String} class (optional) A base CSS class to apply to the containing wrapper element
- * (defaults to <tt>'x-box'</tt>). Note that there are a number of CSS rules that are dependent on
- * this name to make the overall effect work, so if you supply an alternate base class, make sure you
- * also supply all of the necessary rules.
- * @return {Ext.Element} The outermost wrapping element of the created box structure.
- */
- boxWrap : function(cls){
- cls = cls || Ext.baseCSSPrefix + 'box';
- var el = Ext.get(this.insertHtml("beforeBegin", "<div class='" + cls + "'>" + Ext.String.format(ELEMENT.boxMarkup, cls) + "</div>"));
- Ext.DomQuery.selectNode('.' + cls + '-mc', el.dom).appendChild(this.dom);
- return el;
- },
- /**
- * Set the size of this Element. If animation is true, both width and height will be animated concurrently.
- * @param {Number/String} width The new width. This may be one of:<div class="mdetail-params"><ul>
- * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
- * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
- * <li>A size object in the format <code>{width: widthValue, height: heightValue}</code>.</li>
- * </ul></div>
- * @param {Number/String} height The new height. This may be one of:<div class="mdetail-params"><ul>
- * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels).</li>
- * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
- * </ul></div>
- * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
- * @return {Ext.Element} this
- */
- setSize : function(width, height, animate){
- var me = this;
- if (Ext.isObject(width)) { // in case of object from getSize()
- animate = height;
- height = width.height;
- width = width.width;
- }
- width = me.adjustWidth(width);
- height = me.adjustHeight(height);
- if(!animate || !me.anim){
- // Must touch some property before setting style.width/height on non-quirk IE6,7, or the
- // properties will not reflect the changes on the style immediately
- if (!Ext.isIEQuirks && (Ext.isIE6 || Ext.isIE7)) {
- me.dom.offsetTop;
- }
- me.dom.style.width = me.addUnits(width);
- me.dom.style.height = me.addUnits(height);
- }
- else {
- if (animate === true) {
- animate = {};
- }
- me.animate(Ext.applyIf({
- to: {
- width: width,
- height: height
- }
- }, animate));
- }
- return me;
- },
- /**
- * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
- * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
- * if a height has not been set using CSS.
- * @return {Number}
- */
- getComputedHeight : function(){
- var me = this,
- h = Math.max(me.dom.offsetHeight, me.dom.clientHeight);
- if(!h){
- h = parseFloat(me.getStyle('height')) || 0;
- if(!me.isBorderBox()){
- h += me.getFrameWidth('tb');
- }
- }
- return h;
- },
- /**
- * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
- * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
- * if a width has not been set using CSS.
- * @return {Number}
- */
- getComputedWidth : function(){
- var me = this,
- w = Math.max(me.dom.offsetWidth, me.dom.clientWidth);
- if(!w){
- w = parseFloat(me.getStyle('width')) || 0;
- if(!me.isBorderBox()){
- w += me.getFrameWidth('lr');
- }
- }
- return w;
- },
- /**
- * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
- for more information about the sides.
- * @param {String} sides
- * @return {Number}
- */
- getFrameWidth : function(sides, onlyContentBox){
- return onlyContentBox && this.isBorderBox() ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
- },
- /**
- * Sets up event handlers to add and remove a css class when the mouse is over this element
- * @param {String} className
- * @return {Ext.Element} this
- */
- addClsOnOver : function(className){
- var dom = this.dom;
- this.hover(
- function(){
- Ext.fly(dom, INTERNAL).addCls(className);
- },
- function(){
- Ext.fly(dom, INTERNAL).removeCls(className);
- }
- );
- return this;
- },
- /**
- * Sets up event handlers to add and remove a css class when this element has the focus
- * @param {String} className
- * @return {Ext.Element} this
- */
- addClsOnFocus : function(className){
- var me = this,
- dom = me.dom;
- me.on("focus", function(){
- Ext.fly(dom, INTERNAL).addCls(className);
- });
- me.on("blur", function(){
- Ext.fly(dom, INTERNAL).removeCls(className);
- });
- return me;
- },
- /**
- * Sets up event handlers to add and remove a css class when the mouse is down and then up on this element (a click effect)
- * @param {String} className
- * @return {Ext.Element} this
- */
- addClsOnClick : function(className){
- var dom = this.dom;
- this.on("mousedown", function(){
- Ext.fly(dom, INTERNAL).addCls(className);
- var d = Ext.getDoc(),
- fn = function(){
- Ext.fly(dom, INTERNAL).removeCls(className);
- d.removeListener("mouseup", fn);
- };
- d.on("mouseup", fn);
- });
- return this;
- },
- /**
- * <p>Returns the dimensions of the element available to lay content out in.<p>
- * <p>If the element (or any ancestor element) has CSS style <code>display : none</code>, the dimensions will be zero.</p>
- * example:<pre><code>
- var vpSize = Ext.getBody().getViewSize();
- // all Windows created afterwards will have a default value of 90% height and 95% width
- Ext.Window.override({
- width: vpSize.width * 0.9,
- height: vpSize.height * 0.95
- });
- // To handle window resizing you would have to hook onto onWindowResize.
- * </code></pre>
- *
- * getViewSize utilizes clientHeight/clientWidth which excludes sizing of scrollbars.
- * To obtain the size including scrollbars, use getStyleSize
- *
- * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
- */
- getViewSize : function(){
- var me = this,
- dom = me.dom,
- isDoc = (dom == Ext.getDoc().dom || dom == Ext.getBody().dom),
- style, overflow, ret;
- // If the body, use static methods
- if (isDoc) {
- ret = {
- width : ELEMENT.getViewWidth(),
- height : ELEMENT.getViewHeight()
- };
- // Else use clientHeight/clientWidth
- }
- else {
- // IE 6 & IE Quirks mode acts more like a max-size measurement unless overflow is hidden during measurement.
- // We will put the overflow back to it's original value when we are done measuring.
- if (Ext.isIE6 || Ext.isIEQuirks) {
- style = dom.style;
- overflow = style.overflow;
- me.setStyle({ overflow: 'hidden'});
- }
- ret = {
- width : dom.clientWidth,
- height : dom.clientHeight
- };
- if (Ext.isIE6 || Ext.isIEQuirks) {
- me.setStyle({ overflow: overflow });
- }
- }
- return ret;
- },
- /**
- * <p>Returns the dimensions of the element available to lay content out in.<p>
- *
- * getStyleSize utilizes prefers style sizing if present, otherwise it chooses the larger of offsetHeight/clientHeight and offsetWidth/clientWidth.
- * To obtain the size excluding scrollbars, use getViewSize
- *
- * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
- */
- getStyleSize : function(){
- var me = this,
- doc = document,
- d = this.dom,
- isDoc = (d == doc || d == doc.body),
- s = d.style,
- w, h;
- // If the body, use static methods
- if (isDoc) {
- return {
- width : ELEMENT.getViewWidth(),
- height : ELEMENT.getViewHeight()
- };
- }
- // Use Styles if they are set
- if(s.width && s.width != 'auto'){
- w = parseFloat(s.width);
- if(me.isBorderBox()){
- w -= me.getFrameWidth('lr');
- }
- }
- // Use Styles if they are set
- if(s.height && s.height != 'auto'){
- h = parseFloat(s.height);
- if(me.isBorderBox()){
- h -= me.getFrameWidth('tb');
- }
- }
- // Use getWidth/getHeight if style not set.
- return {width: w || me.getWidth(true), height: h || me.getHeight(true)};
- },
- /**
- * Returns the size of the element.
- * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
- * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
- */
- getSize : function(contentSize){
- return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
- },
- /**
- * Forces the browser to repaint this element
- * @return {Ext.Element} this
- */
- repaint : function(){
- var dom = this.dom;
- this.addCls(Ext.baseCSSPrefix + 'repaint');
- setTimeout(function(){
- Ext.fly(dom).removeCls(Ext.baseCSSPrefix + 'repaint');
- }, 1);
- return this;
- },
- /**
- * Enable text selection for this element (normalized across browsers)
- * @return {Ext.Element} this
- */
- selectable : function() {
- var me = this;
- me.dom.unselectable = "off";
- // Prevent it from bubles up and enables it to be selectable
- me.on('selectstart', function (e) {
- e.stopPropagation();
- return true;
- });
- me.applyStyles("-moz-user-select: text; -khtml-user-select: text;");
- me.removeCls(Ext.baseCSSPrefix + 'unselectable');
- return me;
- },
- /**
- * Disables text selection for this element (normalized across browsers)
- * @return {Ext.Element} this
- */
- unselectable : function(){
- var me = this;
- me.dom.unselectable = "on";
- me.swallowEvent("selectstart", true);
- me.applyStyles("-moz-user-select:-moz-none;-khtml-user-select:none;");
- me.addCls(Ext.baseCSSPrefix + 'unselectable');
- return me;
- },
- /**
- * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
- * then it returns the calculated width of the sides (see getPadding)
- * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
- * @return {Object/Number}
- */
- getMargin : function(side){
- var me = this,
- hash = {t:"top", l:"left", r:"right", b: "bottom"},
- o = {},
- key;
- if (!side) {
- for (key in me.margins){
- o[hash[key]] = parseFloat(me.getStyle(me.margins[key])) || 0;
- }
- return o;
- } else {
- return me.addStyles.call(me, side, me.margins);
- }
- }
- });
- })();
- /**
- * @class Ext.Element
- */
- /**
- * Visibility mode constant for use with {@link #setVisibilityMode}. Use visibility to hide element
- * @static
- * @type Number
- */
- Ext.Element.VISIBILITY = 1;
- /**
- * Visibility mode constant for use with {@link #setVisibilityMode}. Use display to hide element
- * @static
- * @type Number
- */
- Ext.Element.DISPLAY = 2;
- /**
- * Visibility mode constant for use with {@link #setVisibilityMode}. Use offsets (x and y positioning offscreen)
- * to hide element.
- * @static
- * @type Number
- */
- Ext.Element.OFFSETS = 3;
- Ext.Element.ASCLASS = 4;
- /**
- * Defaults to 'x-hide-nosize'
- * @static
- * @type String
- */
- Ext.Element.visibilityCls = Ext.baseCSSPrefix + 'hide-nosize';
- Ext.Element.addMethods(function(){
- var El = Ext.Element,
- OPACITY = "opacity",
- VISIBILITY = "visibility",
- DISPLAY = "display",
- HIDDEN = "hidden",
- OFFSETS = "offsets",
- ASCLASS = "asclass",
- NONE = "none",
- NOSIZE = 'nosize',
- ORIGINALDISPLAY = 'originalDisplay',
- VISMODE = 'visibilityMode',
- ISVISIBLE = 'isVisible',
- data = El.data,
- getDisplay = function(dom){
- var d = data(dom, ORIGINALDISPLAY);
- if(d === undefined){
- data(dom, ORIGINALDISPLAY, d = '');
- }
- return d;
- },
- getVisMode = function(dom){
- var m = data(dom, VISMODE);
- if(m === undefined){
- data(dom, VISMODE, m = 1);
- }
- return m;
- };
- return {
- /**
- * @property {String} originalDisplay
- * The element's default display mode
- */
- originalDisplay : "",
- visibilityMode : 1,
- /**
- * Sets the element's visibility mode. When setVisible() is called it
- * will use this to determine whether to set the visibility or the display property.
- * @param {Number} visMode Ext.Element.VISIBILITY or Ext.Element.DISPLAY
- * @return {Ext.Element} this
- */
- setVisibilityMode : function(visMode){
- data(this.dom, VISMODE, visMode);
- return this;
- },
- /**
- * Checks whether the element is currently visible using both visibility and display properties.
- * @return {Boolean} True if the element is currently visible, else false
- */
- isVisible : function() {
- var me = this,
- dom = me.dom,
- visible = data(dom, ISVISIBLE);
- if(typeof visible == 'boolean'){ //return the cached value if registered
- return visible;
- }
- //Determine the current state based on display states
- visible = !me.isStyle(VISIBILITY, HIDDEN) &&
- !me.isStyle(DISPLAY, NONE) &&
- !((getVisMode(dom) == El.ASCLASS) && me.hasCls(me.visibilityCls || El.visibilityCls));
- data(dom, ISVISIBLE, visible);
- return visible;
- },
- /**
- * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
- * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
- * @param {Boolean} visible Whether the element is visible
- * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
- * @return {Ext.Element} this
- */
- setVisible : function(visible, animate){
- var me = this, isDisplay, isVisibility, isOffsets, isNosize,
- dom = me.dom,
- visMode = getVisMode(dom);
- // hideMode string override
- if (typeof animate == 'string'){
- switch (animate) {
- case DISPLAY:
- visMode = El.DISPLAY;
- break;
- case VISIBILITY:
- visMode = El.VISIBILITY;
- break;
- case OFFSETS:
- visMode = El.OFFSETS;
- break;
- case NOSIZE:
- case ASCLASS:
- visMode = El.ASCLASS;
- break;
- }
- me.setVisibilityMode(visMode);
- animate = false;
- }
- if (!animate || !me.anim) {
- if(visMode == El.ASCLASS ){
- me[visible?'removeCls':'addCls'](me.visibilityCls || El.visibilityCls);
- } else if (visMode == El.DISPLAY){
- return me.setDisplayed(visible);
- } else if (visMode == El.OFFSETS){
- if (!visible){
- // Remember position for restoring, if we are not already hidden by offsets.
- if (!me.hideModeStyles) {
- me.hideModeStyles = {
- position: me.getStyle('position'),
- top: me.getStyle('top'),
- left: me.getStyle('left')
- };
- }
- me.applyStyles({position: 'absolute', top: '-10000px', left: '-10000px'});
- }
- // Only "restore" as position if we have actually been hidden using offsets.
- // Calling setVisible(true) on a positioned element should not reposition it.
- else if (me.hideModeStyles) {
- me.applyStyles(me.hideModeStyles || {position: '', top: '', left: ''});
- delete me.hideModeStyles;
- }
- }else{
- me.fixDisplay();
- // Show by clearing visibility style. Explicitly setting to "visible" overrides parent visibility setting.
- dom.style.visibility = visible ? '' : HIDDEN;
- }
- }else{
- // closure for composites
- if(visible){
- me.setOpacity(0.01);
- me.setVisible(true);
- }
- if (!Ext.isObject(animate)) {
- animate = {
- duration: 350,
- easing: 'ease-in'
- };
- }
- me.animate(Ext.applyIf({
- callback: function() {
- visible || me.setVisible(false).setOpacity(1);
- },
- to: {
- opacity: (visible) ? 1 : 0
- }
- }, animate));
- }
- data(dom, ISVISIBLE, visible); //set logical visibility state
- return me;
- },
- /**
- * @private
- * Determine if the Element has a relevant height and width available based
- * upon current logical visibility state
- */
- hasMetrics : function(){
- var dom = this.dom;
- return this.isVisible() || (getVisMode(dom) == El.OFFSETS) || (getVisMode(dom) == El.VISIBILITY);
- },
- /**
- * Toggles the element's visibility or display, depending on visibility mode.
- * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
- * @return {Ext.Element} this
- */
- toggle : function(animate){
- var me = this;
- me.setVisible(!me.isVisible(), me.anim(animate));
- return me;
- },
- /**
- * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
- * @param {Boolean/String} value Boolean value to display the element using its default display, or a string to set the display directly.
- * @return {Ext.Element} this
- */
- setDisplayed : function(value) {
- if(typeof value == "boolean"){
- value = value ? getDisplay(this.dom) : NONE;
- }
- this.setStyle(DISPLAY, value);
- return this;
- },
- // private
- fixDisplay : function(){
- var me = this;
- if (me.isStyle(DISPLAY, NONE)) {
- me.setStyle(VISIBILITY, HIDDEN);
- me.setStyle(DISPLAY, getDisplay(this.dom)); // first try reverting to default
- if (me.isStyle(DISPLAY, NONE)) { // if that fails, default to block
- me.setStyle(DISPLAY, "block");
- }
- }
- },
- /**
- * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
- * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
- * @return {Ext.Element} this
- */
- hide : function(animate){
- // hideMode override
- if (typeof animate == 'string'){
- this.setVisible(false, animate);
- return this;
- }
- this.setVisible(false, this.anim(animate));
- return this;
- },
- /**
- * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
- * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
- * @return {Ext.Element} this
- */
- show : function(animate){
- // hideMode override
- if (typeof animate == 'string'){
- this.setVisible(true, animate);
- return this;
- }
- this.setVisible(true, this.anim(animate));
- return this;
- }
- };
- }());
- /**
- * @class Ext.Element
- */
- Ext.applyIf(Ext.Element.prototype, {
- // @private override base Ext.util.Animate mixin for animate for backwards compatibility
- animate: function(config) {
- var me = this;
- if (!me.id) {
- me = Ext.get(me.dom);
- }
- if (Ext.fx.Manager.hasFxBlock(me.id)) {
- return me;
- }
- Ext.fx.Manager.queueFx(Ext.create('Ext.fx.Anim', me.anim(config)));
- return this;
- },
- // @private override base Ext.util.Animate mixin for animate for backwards compatibility
- anim: function(config) {
- if (!Ext.isObject(config)) {
- return (config) ? {} : false;
- }
- var me = this,
- duration = config.duration || Ext.fx.Anim.prototype.duration,
- easing = config.easing || 'ease',
- animConfig;
- if (config.stopAnimation) {
- me.stopAnimation();
- }
- Ext.applyIf(config, Ext.fx.Manager.getFxDefaults(me.id));
- // Clear any 'paused' defaults.
- Ext.fx.Manager.setFxDefaults(me.id, {
- delay: 0
- });
- animConfig = {
- target: me,
- remove: config.remove,
- alternate: config.alternate || false,
- duration: duration,
- easing: easing,
- callback: config.callback,
- listeners: config.listeners,
- iterations: config.iterations || 1,
- scope: config.scope,
- block: config.block,
- concurrent: config.concurrent,
- delay: config.delay || 0,
- paused: true,
- keyframes: config.keyframes,
- from: config.from || {},
- to: Ext.apply({}, config)
- };
- Ext.apply(animConfig.to, config.to);
- // Anim API properties - backward compat
- delete animConfig.to.to;
- delete animConfig.to.from;
- delete animConfig.to.remove;
- delete animConfig.to.alternate;
- delete animConfig.to.keyframes;
- delete animConfig.to.iterations;
- delete animConfig.to.listeners;
- delete animConfig.to.target;
- delete animConfig.to.paused;
- delete animConfig.to.callback;
- delete animConfig.to.scope;
- delete animConfig.to.duration;
- delete animConfig.to.easing;
- delete animConfig.to.concurrent;
- delete animConfig.to.block;
- delete animConfig.to.stopAnimation;
- delete animConfig.to.delay;
- return animConfig;
- },
- /**
- * Slides the element into view. An anchor point can be optionally passed to set the point of origin for the slide
- * effect. This function automatically handles wrapping the element with a fixed-size container if needed. See the
- * Fx class overview for valid anchor point options. Usage:
- *
- * // default: slide the element in from the top
- * el.slideIn();
- *
- * // custom: slide the element in from the right with a 2-second duration
- * el.slideIn('r', { duration: 2000 });
- *
- * // common config options shown with default values
- * el.slideIn('t', {
- * easing: 'easeOut',
- * duration: 500
- * });
- *
- * @param {String} [anchor='t'] One of the valid Fx anchor positions
- * @param {Object} [options] Object literal with any of the Fx config options
- * @return {Ext.Element} The Element
- */
- slideIn: function(anchor, obj, slideOut) {
- var me = this,
- elStyle = me.dom.style,
- beforeAnim, wrapAnim;
- anchor = anchor || "t";
- obj = obj || {};
- beforeAnim = function() {
- var animScope = this,
- listeners = obj.listeners,
- box, position, restoreSize, wrap, anim;
- if (!slideOut) {
- me.fixDisplay();
- }
- box = me.getBox();
- if ((anchor == 't' || anchor == 'b') && box.height === 0) {
- box.height = me.dom.scrollHeight;
- }
- else if ((anchor == 'l' || anchor == 'r') && box.width === 0) {
- box.width = me.dom.scrollWidth;
- }
- position = me.getPositioning();
- me.setSize(box.width, box.height);
- wrap = me.wrap({
- style: {
- visibility: slideOut ? 'visible' : 'hidden'
- }
- });
- wrap.setPositioning(position);
- if (wrap.isStyle('position', 'static')) {
- wrap.position('relative');
- }
- me.clearPositioning('auto');
- wrap.clip();
- // This element is temporarily positioned absolute within its wrapper.
- // Restore to its default, CSS-inherited visibility setting.
- // We cannot explicitly poke visibility:visible into its style because that overrides the visibility of the wrap.
- me.setStyle({
- visibility: '',
- position: 'absolute'
- });
- if (slideOut) {
- wrap.setSize(box.width, box.height);
- }
- switch (anchor) {
- case 't':
- anim = {
- from: {
- width: box.width + 'px',
- height: '0px'
- },
- to: {
- width: box.width + 'px',
- height: box.height + 'px'
- }
- };
- elStyle.bottom = '0px';
- break;
- case 'l':
- anim = {
- from: {
- width: '0px',
- height: box.height + 'px'
- },
- to: {
- width: box.width + 'px',
- height: box.height + 'px'
- }
- };
- elStyle.right = '0px';
- break;
- case 'r':
- anim = {
- from: {
- x: box.x + box.width,
- width: '0px',
- height: box.height + 'px'
- },
- to: {
- x: box.x,
- width: box.width + 'px',
- height: box.height + 'px'
- }
- };
- break;
- case 'b':
- anim = {
- from: {
- y: box.y + box.height,
- width: box.width + 'px',
- height: '0px'
- },
- to: {
- y: box.y,
- width: box.width + 'px',
- height: box.height + 'px'
- }
- };
- break;
- case 'tl':
- anim = {
- from: {
- x: box.x,
- y: box.y,
- width: '0px',
- height: '0px'
- },
- to: {
- width: box.width + 'px',
- height: box.height + 'px'
- }
- };
- elStyle.bottom = '0px';
- elStyle.right = '0px';
- break;
- case 'bl':
- anim = {
- from: {
- x: box.x + box.width,
- width: '0px',
- height: '0px'
- },
- to: {
- x: box.x,
- width: box.width + 'px',
- height: box.height + 'px'
- }
- };
- elStyle.right = '0px';
- break;
- case 'br':
- anim = {
- from: {
- x: box.x + box.width,
- y: box.y + box.height,
- width: '0px',
- height: '0px'
- },
- to: {
- x: box.x,
- y: box.y,
- width: box.width + 'px',
- height: box.height + 'px'
- }
- };
- break;
- case 'tr':
- anim = {
- from: {
- y: box.y + box.height,
- width: '0px',
- height: '0px'
- },
- to: {
- y: box.y,
- width: box.width + 'px',
- height: box.height + 'px'
- }
- };
- elStyle.bottom = '0px';
- break;
- }
- wrap.show();
- wrapAnim = Ext.apply({}, obj);
- delete wrapAnim.listeners;
- wrapAnim = Ext.create('Ext.fx.Anim', Ext.applyIf(wrapAnim, {
- target: wrap,
- duration: 500,
- easing: 'ease-out',
- from: slideOut ? anim.to : anim.from,
- to: slideOut ? anim.from : anim.to
- }));
- // In the absence of a callback, this listener MUST be added first
- wrapAnim.on('afteranimate', function() {
- if (slideOut) {
- me.setPositioning(position);
- if (obj.useDisplay) {
- me.setDisplayed(false);
- } else {
- me.hide();
- }
- }
- else {
- me.clearPositioning();
- me.setPositioning(position);
- }
- if (wrap.dom) {
- wrap.dom.parentNode.insertBefore(me.dom, wrap.dom);
- wrap.remove();
- }
- me.setSize(box.width, box.height);
- animScope.end();
- });
- // Add configured listeners after
- if (listeners) {
- wrapAnim.on(listeners);
- }
- };
- me.animate({
- duration: obj.duration ? obj.duration * 2 : 1000,
- listeners: {
- beforeanimate: {
- fn: beforeAnim
- },
- afteranimate: {
- fn: function() {
- if (wrapAnim && wrapAnim.running) {
- wrapAnim.end();
- }
- }
- }
- }
- });
- return me;
- },
- /**
- * Slides the element out of view. An anchor point can be optionally passed to set the end point for the slide
- * effect. When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will
- * still take up space in the document. The element must be removed from the DOM using the 'remove' config option if
- * desired. This function automatically handles wrapping the element with a fixed-size container if needed. See the
- * Fx class overview for valid anchor point options. Usage:
- *
- * // default: slide the element out to the top
- * el.slideOut();
- *
- * // custom: slide the element out to the right with a 2-second duration
- * el.slideOut('r', { duration: 2000 });
- *
- * // common config options shown with default values
- * el.slideOut('t', {
- * easing: 'easeOut',
- * duration: 500,
- * remove: false,
- * useDisplay: false
- * });
- *
- * @param {String} [anchor='t'] One of the valid Fx anchor positions
- * @param {Object} [options] Object literal with any of the Fx config options
- * @return {Ext.Element} The Element
- */
- slideOut: function(anchor, o) {
- return this.slideIn(anchor, o, true);
- },
- /**
- * Fades the element out while slowly expanding it in all directions. When the effect is completed, the element will
- * be hidden (visibility = 'hidden') but block elements will still take up space in the document. Usage:
- *
- * // default
- * el.puff();
- *
- * // common config options shown with default values
- * el.puff({
- * easing: 'easeOut',
- * duration: 500,
- * useDisplay: false
- * });
- *
- * @param {Object} options (optional) Object literal with any of the Fx config options
- * @return {Ext.Element} The Element
- */
- puff: function(obj) {
- var me = this,
- beforeAnim;
- obj = Ext.applyIf(obj || {}, {
- easing: 'ease-out',
- duration: 500,
- useDisplay: false
- });
- beforeAnim = function() {
- me.clearOpacity();
- me.show();
- var box = me.getBox(),
- fontSize = me.getStyle('fontSize'),
- position = me.getPositioning();
- this.to = {
- width: box.width * 2,
- height: box.height * 2,
- x: box.x - (box.width / 2),
- y: box.y - (box.height /2),
- opacity: 0,
- fontSize: '200%'
- };
- this.on('afteranimate',function() {
- if (me.dom) {
- if (obj.useDisplay) {
- me.setDisplayed(false);
- } else {
- me.hide();
- }
- me.clearOpacity();
- me.setPositioning(position);
- me.setStyle({fontSize: fontSize});
- }
- });
- };
- me.animate({
- duration: obj.duration,
- easing: obj.easing,
- listeners: {
- beforeanimate: {
- fn: beforeAnim
- }
- }
- });
- return me;
- },
- /**
- * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television).
- * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still
- * take up space in the document. The element must be removed from the DOM using the 'remove' config option if
- * desired. Usage:
- *
- * // default
- * el.switchOff();
- *
- * // all config options shown with default values
- * el.switchOff({
- * easing: 'easeIn',
- * duration: .3,
- * remove: false,
- * useDisplay: false
- * });
- *
- * @param {Object} options (optional) Object literal with any of the Fx config options
- * @return {Ext.Element} The Element
- */
- switchOff: function(obj) {
- var me = this,
- beforeAnim;
- obj = Ext.applyIf(obj || {}, {
- easing: 'ease-in',
- duration: 500,
- remove: false,
- useDisplay: false
- });
- beforeAnim = function() {
- var animScope = this,
- size = me.getSize(),
- xy = me.getXY(),
- keyframe, position;
- me.clearOpacity();
- me.clip();
- position = me.getPositioning();
- keyframe = Ext.create('Ext.fx.Animator', {
- target: me,
- duration: obj.duration,
- easing: obj.easing,
- keyframes: {
- 33: {
- opacity: 0.3
- },
- 66: {
- height: 1,
- y: xy[1] + size.height / 2
- },
- 100: {
- width: 1,
- x: xy[0] + size.width / 2
- }
- }
- });
- keyframe.on('afteranimate', function() {
- if (obj.useDisplay) {
- me.setDisplayed(false);
- } else {
- me.hide();
- }
- me.clearOpacity();
- me.setPositioning(position);
- me.setSize(size);
- animScope.end();
- });
- };
- me.animate({
- duration: (obj.duration * 2),
- listeners: {
- beforeanimate: {
- fn: beforeAnim
- }
- }
- });
- return me;
- },
- /**
- * Shows a ripple of exploding, attenuating borders to draw attention to an Element. Usage:
- *
- * // default: a single light blue ripple
- * el.frame();
- *
- * // custom: 3 red ripples lasting 3 seconds total
- * el.frame("#ff0000", 3, { duration: 3 });
- *
- * // common config options shown with default values
- * el.frame("#C3DAF9", 1, {
- * duration: 1 //duration of each individual ripple.
- * // Note: Easing is not configurable and will be ignored if included
- * });
- *
- * @param {String} [color='C3DAF9'] The color of the border. Should be a 6 char hex color without the leading #
- * (defaults to light blue).
- * @param {Number} [count=1] The number of ripples to display
- * @param {Object} [options] Object literal with any of the Fx config options
- * @return {Ext.Element} The Element
- */
- frame : function(color, count, obj){
- var me = this,
- beforeAnim;
- color = color || '#C3DAF9';
- count = count || 1;
- obj = obj || {};
- beforeAnim = function() {
- me.show();
- var animScope = this,
- box = me.getBox(),
- proxy = Ext.getBody().createChild({
- style: {
- position : 'absolute',
- 'pointer-events': 'none',
- 'z-index': 35000,
- border : '0px solid ' + color
- }
- }),
- proxyAnim;
- proxyAnim = Ext.create('Ext.fx.Anim', {
- target: proxy,
- duration: obj.duration || 1000,
- iterations: count,
- from: {
- top: box.y,
- left: box.x,
- borderWidth: 0,
- opacity: 1,
- height: box.height,
- width: box.width
- },
- to: {
- top: box.y - 20,
- left: box.x - 20,
- borderWidth: 10,
- opacity: 0,
- height: box.height + 40,
- width: box.width + 40
- }
- });
- proxyAnim.on('afteranimate', function() {
- proxy.remove();
- animScope.end();
- });
- };
- me.animate({
- duration: (obj.duration * 2) || 2000,
- listeners: {
- beforeanimate: {
- fn: beforeAnim
- }
- }
- });
- return me;
- },
- /**
- * Slides the element while fading it out of view. An anchor point can be optionally passed to set the ending point
- * of the effect. Usage:
- *
- * // default: slide the element downward while fading out
- * el.ghost();
- *
- * // custom: slide the element out to the right with a 2-second duration
- * el.ghost('r', { duration: 2000 });
- *
- * // common config options shown with default values
- * el.ghost('b', {
- * easing: 'easeOut',
- * duration: 500
- * });
- *
- * @param {String} [anchor='b'] One of the valid Fx anchor positions
- * @param {Object} [options] Object literal with any of the Fx config options
- * @return {Ext.Element} The Element
- */
- ghost: function(anchor, obj) {
- var me = this,
- beforeAnim;
- anchor = anchor || "b";
- beforeAnim = function() {
- var width = me.getWidth(),
- height = me.getHeight(),
- xy = me.getXY(),
- position = me.getPositioning(),
- to = {
- opacity: 0
- };
- switch (anchor) {
- case 't':
- to.y = xy[1] - height;
- break;
- case 'l':
- to.x = xy[0] - width;
- break;
- case 'r':
- to.x = xy[0] + width;
- break;
- case 'b':
- to.y = xy[1] + height;
- break;
- case 'tl':
- to.x = xy[0] - width;
- to.y = xy[1] - height;
- break;
- case 'bl':
- to.x = xy[0] - width;
- to.y = xy[1] + height;
- break;
- case 'br':
- to.x = xy[0] + width;
- to.y = xy[1] + height;
- break;
- case 'tr':
- to.x = xy[0] + width;
- to.y = xy[1] - height;
- break;
- }
- this.to = to;
- this.on('afteranimate', function () {
- if (me.dom) {
- me.hide();
- me.clearOpacity();
- me.setPositioning(position);
- }
- });
- };
- me.animate(Ext.applyIf(obj || {}, {
- duration: 500,
- easing: 'ease-out',
- listeners: {
- beforeanimate: {
- fn: beforeAnim
- }
- }
- }));
- return me;
- },
- /**
- * Highlights the Element by setting a color (applies to the background-color by default, but can be changed using
- * the "attr" config option) and then fading back to the original color. If no original color is available, you
- * should provide the "endColor" config option which will be cleared after the animation. Usage:
- *
- * // default: highlight background to yellow
- * el.highlight();
- *
- * // custom: highlight foreground text to blue for 2 seconds
- * el.highlight("0000ff", { attr: 'color', duration: 2000 });
- *
- * // common config options shown with default values
- * el.highlight("ffff9c", {
- * attr: "backgroundColor", //can be any valid CSS property (attribute) that supports a color value
- * endColor: (current color) or "ffffff",
- * easing: 'easeIn',
- * duration: 1000
- * });
- *
- * @param {String} [color='ffff9c'] The highlight color. Should be a 6 char hex color without the leading #
- * @param {Object} [options] Object literal with any of the Fx config options
- * @return {Ext.Element} The Element
- */
- highlight: function(color, o) {
- var me = this,
- dom = me.dom,
- from = {},
- restore, to, attr, lns, event, fn;
- o = o || {};
- lns = o.listeners || {};
- attr = o.attr || 'backgroundColor';
- from[attr] = color || 'ffff9c';
- if (!o.to) {
- to = {};
- to[attr] = o.endColor || me.getColor(attr, 'ffffff', '');
- }
- else {
- to = o.to;
- }
- // Don't apply directly on lns, since we reference it in our own callbacks below
- o.listeners = Ext.apply(Ext.apply({}, lns), {
- beforeanimate: function() {
- restore = dom.style[attr];
- me.clearOpacity();
- me.show();
- event = lns.beforeanimate;
- if (event) {
- fn = event.fn || event;
- return fn.apply(event.scope || lns.scope || window, arguments);
- }
- },
- afteranimate: function() {
- if (dom) {
- dom.style[attr] = restore;
- }
- event = lns.afteranimate;
- if (event) {
- fn = event.fn || event;
- fn.apply(event.scope || lns.scope || window, arguments);
- }
- }
- });
- me.animate(Ext.apply({}, o, {
- duration: 1000,
- easing: 'ease-in',
- from: from,
- to: to
- }));
- return me;
- },
- /**
- * @deprecated 4.0
- * Creates a pause before any subsequent queued effects begin. If there are no effects queued after the pause it will
- * have no effect. Usage:
- *
- * el.pause(1);
- *
- * @param {Number} seconds The length of time to pause (in seconds)
- * @return {Ext.Element} The Element
- */
- pause: function(ms) {
- var me = this;
- Ext.fx.Manager.setFxDefaults(me.id, {
- delay: ms
- });
- return me;
- },
- /**
- * Fade an element in (from transparent to opaque). The ending opacity can be specified using the `opacity`
- * config option. Usage:
- *
- * // default: fade in from opacity 0 to 100%
- * el.fadeIn();
- *
- * // custom: fade in from opacity 0 to 75% over 2 seconds
- * el.fadeIn({ opacity: .75, duration: 2000});
- *
- * // common config options shown with default values
- * el.fadeIn({
- * opacity: 1, //can be any value between 0 and 1 (e.g. .5)
- * easing: 'easeOut',
- * duration: 500
- * });
- *
- * @param {Object} options (optional) Object literal with any of the Fx config options
- * @return {Ext.Element} The Element
- */
- fadeIn: function(o) {
- this.animate(Ext.apply({}, o, {
- opacity: 1
- }));
- return this;
- },
- /**
- * Fade an element out (from opaque to transparent). The ending opacity can be specified using the `opacity`
- * config option. Note that IE may require `useDisplay:true` in order to redisplay correctly.
- * Usage:
- *
- * // default: fade out from the element's current opacity to 0
- * el.fadeOut();
- *
- * // custom: fade out from the element's current opacity to 25% over 2 seconds
- * el.fadeOut({ opacity: .25, duration: 2000});
- *
- * // common config options shown with default values
- * el.fadeOut({
- * opacity: 0, //can be any value between 0 and 1 (e.g. .5)
- * easing: 'easeOut',
- * duration: 500,
- * remove: false,
- * useDisplay: false
- * });
- *
- * @param {Object} options (optional) Object literal with any of the Fx config options
- * @return {Ext.Element} The Element
- */
- fadeOut: function(o) {
- this.animate(Ext.apply({}, o, {
- opacity: 0
- }));
- return this;
- },
- /**
- * @deprecated 4.0
- * Animates the transition of an element's dimensions from a starting height/width to an ending height/width. This
- * method is a convenience implementation of {@link #shift}. Usage:
- *
- * // change height and width to 100x100 pixels
- * el.scale(100, 100);
- *
- * // common config options shown with default values. The height and width will default to
- * // the element's existing values if passed as null.
- * el.scale(
- * [element's width],
- * [element's height], {
- * easing: 'easeOut',
- * duration: .35
- * }
- * );
- *
- * @param {Number} width The new width (pass undefined to keep the original width)
- * @param {Number} height The new height (pass undefined to keep the original height)
- * @param {Object} options (optional) Object literal with any of the Fx config options
- * @return {Ext.Element} The Element
- */
- scale: function(w, h, o) {
- this.animate(Ext.apply({}, o, {
- width: w,
- height: h
- }));
- return this;
- },
- /**
- * @deprecated 4.0
- * Animates the transition of any combination of an element's dimensions, xy position and/or opacity. Any of these
- * properties not specified in the config object will not be changed. This effect requires that at least one new
- * dimension, position or opacity setting must be passed in on the config object in order for the function to have
- * any effect. Usage:
- *
- * // slide the element horizontally to x position 200 while changing the height and opacity
- * el.shift({ x: 200, height: 50, opacity: .8 });
- *
- * // common config options shown with default values.
- * el.shift({
- * width: [element's width],
- * height: [element's height],
- * x: [element's x position],
- * y: [element's y position],
- * opacity: [element's opacity],
- * easing: 'easeOut',
- * duration: .35
- * });
- *
- * @param {Object} options Object literal with any of the Fx config options
- * @return {Ext.Element} The Element
- */
- shift: function(config) {
- this.animate(config);
- return this;
- }
- });
- /**
- * @class Ext.Element
- */
- Ext.applyIf(Ext.Element, {
- unitRe: /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i,
- camelRe: /(-[a-z])/gi,
- opacityRe: /alpha\(opacity=(.*)\)/i,
- cssRe: /([a-z0-9-]+)\s*:\s*([^;\s]+(?:\s*[^;\s]+)*);?/gi,
- propertyCache: {},
- defaultUnit : "px",
- borders: {l: 'border-left-width', r: 'border-right-width', t: 'border-top-width', b: 'border-bottom-width'},
- paddings: {l: 'padding-left', r: 'padding-right', t: 'padding-top', b: 'padding-bottom'},
- margins: {l: 'margin-left', r: 'margin-right', t: 'margin-top', b: 'margin-bottom'},
- // Reference the prototype's version of the method. Signatures are identical.
- addUnits : Ext.Element.prototype.addUnits,
- /**
- * Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations
- * (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result)
- * @static
- * @param {Number/String} box The encoded margins
- * @return {Object} An object with margin sizes for top, right, bottom and left
- */
- parseBox : function(box) {
- if (Ext.isObject(box)) {
- return {
- top: box.top || 0,
- right: box.right || 0,
- bottom: box.bottom || 0,
- left: box.left || 0
- };
- } else {
- if (typeof box != 'string') {
- box = box.toString();
- }
- var parts = box.split(' '),
- ln = parts.length;
-
- if (ln == 1) {
- parts[1] = parts[2] = parts[3] = parts[0];
- }
- else if (ln == 2) {
- parts[2] = parts[0];
- parts[3] = parts[1];
- }
- else if (ln == 3) {
- parts[3] = parts[1];
- }
-
- return {
- top :parseFloat(parts[0]) || 0,
- right :parseFloat(parts[1]) || 0,
- bottom:parseFloat(parts[2]) || 0,
- left :parseFloat(parts[3]) || 0
- };
- }
-
- },
-
- /**
- * Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations
- * (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result)
- * @static
- * @param {Number/String} box The encoded margins
- * @param {String} units The type of units to add
- * @return {String} An string with unitized (px if units is not specified) metrics for top, right, bottom and left
- */
- unitizeBox : function(box, units) {
- var A = this.addUnits,
- B = this.parseBox(box);
-
- return A(B.top, units) + ' ' +
- A(B.right, units) + ' ' +
- A(B.bottom, units) + ' ' +
- A(B.left, units);
-
- },
- // private
- camelReplaceFn : function(m, a) {
- return a.charAt(1).toUpperCase();
- },
- /**
- * Normalizes CSS property keys from dash delimited to camel case JavaScript Syntax.
- * For example:
- * <ul>
- * <li>border-width -> borderWidth</li>
- * <li>padding-top -> paddingTop</li>
- * </ul>
- * @static
- * @param {String} prop The property to normalize
- * @return {String} The normalized string
- */
- normalize : function(prop) {
- if (prop == 'float') {
- prop = Ext.supports.Float ? 'cssFloat' : 'styleFloat';
- }
- return this.propertyCache[prop] || (this.propertyCache[prop] = prop.replace(this.camelRe, this.camelReplaceFn));
- },
- /**
- * Retrieves the document height
- * @static
- * @return {Number} documentHeight
- */
- getDocumentHeight: function() {
- return Math.max(!Ext.isStrict ? document.body.scrollHeight : document.documentElement.scrollHeight, this.getViewportHeight());
- },
- /**
- * Retrieves the document width
- * @static
- * @return {Number} documentWidth
- */
- getDocumentWidth: function() {
- return Math.max(!Ext.isStrict ? document.body.scrollWidth : document.documentElement.scrollWidth, this.getViewportWidth());
- },
- /**
- * Retrieves the viewport height of the window.
- * @static
- * @return {Number} viewportHeight
- */
- getViewportHeight: function(){
- return window.innerHeight;
- },
- /**
- * Retrieves the viewport width of the window.
- * @static
- * @return {Number} viewportWidth
- */
- getViewportWidth : function() {
- return window.innerWidth;
- },
- /**
- * Retrieves the viewport size of the window.
- * @static
- * @return {Object} object containing width and height properties
- */
- getViewSize : function() {
- return {
- width: window.innerWidth,
- height: window.innerHeight
- };
- },
- /**
- * Retrieves the current orientation of the window. This is calculated by
- * determing if the height is greater than the width.
- * @static
- * @return {String} Orientation of window: 'portrait' or 'landscape'
- */
- getOrientation : function() {
- if (Ext.supports.OrientationChange) {
- return (window.orientation == 0) ? 'portrait' : 'landscape';
- }
-
- return (window.innerHeight > window.innerWidth) ? 'portrait' : 'landscape';
- },
- /**
- * Returns the top Element that is located at the passed coordinates
- * @static
- * @param {Number} x The x coordinate
- * @param {Number} y The y coordinate
- * @return {String} The found Element
- */
- fromPoint: function(x, y) {
- return Ext.get(document.elementFromPoint(x, y));
- },
-
- /**
- * Converts a CSS string into an object with a property for each style.
- * <p>
- * The sample code below would return an object with 2 properties, one
- * for background-color and one for color.</p>
- * <pre><code>
- var css = 'background-color: red;color: blue; ';
- console.log(Ext.Element.parseStyles(css));
- * </code></pre>
- * @static
- * @param {String} styles A CSS string
- * @return {Object} styles
- */
- parseStyles: function(styles){
- var out = {},
- cssRe = this.cssRe,
- matches;
-
- if (styles) {
- // Since we're using the g flag on the regex, we need to set the lastIndex.
- // This automatically happens on some implementations, but not others, see:
- // http://stackoverflow.com/questions/2645273/javascript-regular-expression-literal-persists-between-function-calls
- // http://blog.stevenlevithan.com/archives/fixing-javascript-regexp
- cssRe.lastIndex = 0;
- while ((matches = cssRe.exec(styles))) {
- out[matches[1]] = matches[2];
- }
- }
- return out;
- }
- });
- /**
- * @class Ext.CompositeElementLite
- * <p>This class encapsulates a <i>collection</i> of DOM elements, providing methods to filter
- * members, or to perform collective actions upon the whole set.</p>
- * <p>Although they are not listed, this class supports all of the methods of {@link Ext.Element} and
- * {@link Ext.fx.Anim}. The methods from these classes will be performed on all the elements in this collection.</p>
- * Example:<pre><code>
- var els = Ext.select("#some-el div.some-class");
- // or select directly from an existing element
- var el = Ext.get('some-el');
- el.select('div.some-class');
- els.setWidth(100); // all elements become 100 width
- els.hide(true); // all elements fade out and hide
- // or
- els.setWidth(100).hide(true);
- </code></pre>
- */
- Ext.CompositeElementLite = function(els, root){
- /**
- * <p>The Array of DOM elements which this CompositeElement encapsulates. Read-only.</p>
- * <p>This will not <i>usually</i> be accessed in developers' code, but developers wishing
- * to augment the capabilities of the CompositeElementLite class may use it when adding
- * methods to the class.</p>
- * <p>For example to add the <code>nextAll</code> method to the class to <b>add</b> all
- * following siblings of selected elements, the code would be</p><code><pre>
- Ext.override(Ext.CompositeElementLite, {
- nextAll: function() {
- var els = this.elements, i, l = els.length, n, r = [], ri = -1;
- // Loop through all elements in this Composite, accumulating
- // an Array of all siblings.
- for (i = 0; i < l; i++) {
- for (n = els[i].nextSibling; n; n = n.nextSibling) {
- r[++ri] = n;
- }
- }
- // Add all found siblings to this Composite
- return this.add(r);
- }
- });</pre></code>
- * @property {HTMLElement} elements
- */
- this.elements = [];
- this.add(els, root);
- this.el = new Ext.Element.Flyweight();
- };
- Ext.CompositeElementLite.prototype = {
- isComposite: true,
- // private
- getElement : function(el){
- // Set the shared flyweight dom property to the current element
- var e = this.el;
- e.dom = el;
- e.id = el.id;
- return e;
- },
- // private
- transformElement : function(el){
- return Ext.getDom(el);
- },
- /**
- * Returns the number of elements in this Composite.
- * @return Number
- */
- getCount : function(){
- return this.elements.length;
- },
- /**
- * Adds elements to this Composite object.
- * @param {HTMLElement[]/Ext.CompositeElement} els Either an Array of DOM elements to add, or another Composite object who's elements should be added.
- * @return {Ext.CompositeElement} This Composite object.
- */
- add : function(els, root){
- var me = this,
- elements = me.elements;
- if(!els){
- return this;
- }
- if(typeof els == "string"){
- els = Ext.Element.selectorFunction(els, root);
- }else if(els.isComposite){
- els = els.elements;
- }else if(!Ext.isIterable(els)){
- els = [els];
- }
- for(var i = 0, len = els.length; i < len; ++i){
- elements.push(me.transformElement(els[i]));
- }
- return me;
- },
- invoke : function(fn, args){
- var me = this,
- els = me.elements,
- len = els.length,
- e,
- i;
- for(i = 0; i < len; i++) {
- e = els[i];
- if(e){
- Ext.Element.prototype[fn].apply(me.getElement(e), args);
- }
- }
- return me;
- },
- /**
- * Returns a flyweight Element of the dom element object at the specified index
- * @param {Number} index
- * @return {Ext.Element}
- */
- item : function(index){
- var me = this,
- el = me.elements[index],
- out = null;
- if(el){
- out = me.getElement(el);
- }
- return out;
- },
- // fixes scope with flyweight
- addListener : function(eventName, handler, scope, opt){
- var els = this.elements,
- len = els.length,
- i, e;
- for(i = 0; i<len; i++) {
- e = els[i];
- if(e) {
- Ext.EventManager.on(e, eventName, handler, scope || e, opt);
- }
- }
- return this;
- },
- /**
- * <p>Calls the passed function for each element in this composite.</p>
- * @param {Function} fn The function to call. The function is passed the following parameters:<ul>
- * <li><b>el</b> : Element<div class="sub-desc">The current Element in the iteration.
- * <b>This is the flyweight (shared) Ext.Element instance, so if you require a
- * a reference to the dom node, use el.dom.</b></div></li>
- * <li><b>c</b> : Composite<div class="sub-desc">This Composite object.</div></li>
- * <li><b>idx</b> : Number<div class="sub-desc">The zero-based index in the iteration.</div></li>
- * </ul>
- * @param {Object} [scope] The scope (<i>this</i> reference) in which the function is executed. (defaults to the Element)
- * @return {Ext.CompositeElement} this
- */
- each : function(fn, scope){
- var me = this,
- els = me.elements,
- len = els.length,
- i, e;
- for(i = 0; i<len; i++) {
- e = els[i];
- if(e){
- e = this.getElement(e);
- if(fn.call(scope || e, e, me, i) === false){
- break;
- }
- }
- }
- return me;
- },
- /**
- * Clears this Composite and adds the elements passed.
- * @param {HTMLElement[]/Ext.CompositeElement} els Either an array of DOM elements, or another Composite from which to fill this Composite.
- * @return {Ext.CompositeElement} this
- */
- fill : function(els){
- var me = this;
- me.elements = [];
- me.add(els);
- return me;
- },
- /**
- * Filters this composite to only elements that match the passed selector.
- * @param {String/Function} selector A string CSS selector or a comparison function.
- * The comparison function will be called with the following arguments:<ul>
- * <li><code>el</code> : Ext.Element<div class="sub-desc">The current DOM element.</div></li>
- * <li><code>index</code> : Number<div class="sub-desc">The current index within the collection.</div></li>
- * </ul>
- * @return {Ext.CompositeElement} this
- */
- filter : function(selector){
- var els = [],
- me = this,
- fn = Ext.isFunction(selector) ? selector
- : function(el){
- return el.is(selector);
- };
- me.each(function(el, self, i) {
- if (fn(el, i) !== false) {
- els[els.length] = me.transformElement(el);
- }
- });
- me.elements = els;
- return me;
- },
- /**
- * Find the index of the passed element within the composite collection.
- * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.
- * @return Number The index of the passed Ext.Element in the composite collection, or -1 if not found.
- */
- indexOf : function(el){
- return Ext.Array.indexOf(this.elements, this.transformElement(el));
- },
- /**
- * Replaces the specified element with the passed element.
- * @param {String/HTMLElement/Ext.Element/Number} el The id of an element, the Element itself, the index of the element in this composite
- * to replace.
- * @param {String/Ext.Element} replacement The id of an element or the Element itself.
- * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
- * @return {Ext.CompositeElement} this
- */
- replaceElement : function(el, replacement, domReplace){
- var index = !isNaN(el) ? el : this.indexOf(el),
- d;
- if(index > -1){
- replacement = Ext.getDom(replacement);
- if(domReplace){
- d = this.elements[index];
- d.parentNode.insertBefore(replacement, d);
- Ext.removeNode(d);
- }
- Ext.Array.splice(this.elements, index, 1, replacement);
- }
- return this;
- },
- /**
- * Removes all elements.
- */
- clear : function(){
- this.elements = [];
- }
- };
- Ext.CompositeElementLite.prototype.on = Ext.CompositeElementLite.prototype.addListener;
- /**
- * @private
- * Copies all of the functions from Ext.Element's prototype onto CompositeElementLite's prototype.
- * This is called twice - once immediately below, and once again after additional Ext.Element
- * are added in Ext JS
- */
- Ext.CompositeElementLite.importElementMethods = function() {
- var fnName,
- ElProto = Ext.Element.prototype,
- CelProto = Ext.CompositeElementLite.prototype;
- for (fnName in ElProto) {
- if (typeof ElProto[fnName] == 'function'){
- (function(fnName) {
- CelProto[fnName] = CelProto[fnName] || function() {
- return this.invoke(fnName, arguments);
- };
- }).call(CelProto, fnName);
- }
- }
- };
- Ext.CompositeElementLite.importElementMethods();
- if(Ext.DomQuery){
- Ext.Element.selectorFunction = Ext.DomQuery.select;
- }
- /**
- * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
- * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
- * {@link Ext.CompositeElementLite CompositeElementLite} object.
- * @param {String/HTMLElement[]} selector The CSS selector or an array of elements
- * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
- * @return {Ext.CompositeElementLite/Ext.CompositeElement}
- * @member Ext.Element
- * @method select
- */
- Ext.Element.select = function(selector, root){
- var els;
- if(typeof selector == "string"){
- els = Ext.Element.selectorFunction(selector, root);
- }else if(selector.length !== undefined){
- els = selector;
- }else{
- }
- return new Ext.CompositeElementLite(els);
- };
- /**
- * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
- * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
- * {@link Ext.CompositeElementLite CompositeElementLite} object.
- * @param {String/HTMLElement[]} selector The CSS selector or an array of elements
- * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
- * @return {Ext.CompositeElementLite/Ext.CompositeElement}
- * @member Ext
- * @method select
- */
- Ext.select = Ext.Element.select;
- /**
- * @class Ext.util.DelayedTask
- *
- * The DelayedTask class provides a convenient way to "buffer" the execution of a method,
- * performing setTimeout where a new timeout cancels the old timeout. When called, the
- * task will wait the specified time period before executing. If durng that time period,
- * the task is called again, the original call will be cancelled. This continues so that
- * the function is only called a single time for each iteration.
- *
- * This method is especially useful for things like detecting whether a user has finished
- * typing in a text field. An example would be performing validation on a keypress. You can
- * use this class to buffer the keypress events for a certain number of milliseconds, and
- * perform only if they stop for that amount of time.
- *
- * ## Usage
- *
- * var task = new Ext.util.DelayedTask(function(){
- * alert(Ext.getDom('myInputField').value.length);
- * });
- *
- * // Wait 500ms before calling our function. If the user presses another key
- * // during that 500ms, it will be cancelled and we'll wait another 500ms.
- * Ext.get('myInputField').on('keypress', function(){
- * task.{@link #delay}(500);
- * });
- *
- * Note that we are using a DelayedTask here to illustrate a point. The configuration
- * option `buffer` for {@link Ext.util.Observable#addListener addListener/on} will
- * also setup a delayed task for you to buffer events.
- *
- * @constructor The parameters to this constructor serve as defaults and are not required.
- * @param {Function} fn (optional) The default function to call. If not specified here, it must be specified during the {@link #delay} call.
- * @param {Object} scope (optional) The default scope (The <code><b>this</b></code> reference) in which the
- * function is called. If not specified, <code>this</code> will refer to the browser window.
- * @param {Array} args (optional) The default Array of arguments.
- */
- Ext.util.DelayedTask = function(fn, scope, args) {
- var me = this,
- id,
- call = function() {
- clearInterval(id);
- id = null;
- fn.apply(scope, args || []);
- };
- /**
- * Cancels any pending timeout and queues a new one
- * @param {Number} delay The milliseconds to delay
- * @param {Function} newFn (optional) Overrides function passed to constructor
- * @param {Object} newScope (optional) Overrides scope passed to constructor. Remember that if no scope
- * is specified, <code>this</code> will refer to the browser window.
- * @param {Array} newArgs (optional) Overrides args passed to constructor
- */
- this.delay = function(delay, newFn, newScope, newArgs) {
- me.cancel();
- fn = newFn || fn;
- scope = newScope || scope;
- args = newArgs || args;
- id = setInterval(call, delay);
- };
- /**
- * Cancel the last queued timeout
- */
- this.cancel = function(){
- if (id) {
- clearInterval(id);
- id = null;
- }
- };
- };
- Ext.require('Ext.util.DelayedTask', function() {
- Ext.util.Event = Ext.extend(Object, (function() {
- function createBuffered(handler, listener, o, scope) {
- listener.task = new Ext.util.DelayedTask();
- return function() {
- listener.task.delay(o.buffer, handler, scope, Ext.Array.toArray(arguments));
- };
- }
- function createDelayed(handler, listener, o, scope) {
- return function() {
- var task = new Ext.util.DelayedTask();
- if (!listener.tasks) {
- listener.tasks = [];
- }
- listener.tasks.push(task);
- task.delay(o.delay || 10, handler, scope, Ext.Array.toArray(arguments));
- };
- }
- function createSingle(handler, listener, o, scope) {
- return function() {
- listener.ev.removeListener(listener.fn, scope);
- return handler.apply(scope, arguments);
- };
- }
- return {
- isEvent: true,
- constructor: function(observable, name) {
- this.name = name;
- this.observable = observable;
- this.listeners = [];
- },
- addListener: function(fn, scope, options) {
- var me = this,
- listener;
- scope = scope || me.observable;
- if (!me.isListening(fn, scope)) {
- listener = me.createListener(fn, scope, options);
- if (me.firing) {
- // if we are currently firing this event, don't disturb the listener loop
- me.listeners = me.listeners.slice(0);
- }
- me.listeners.push(listener);
- }
- },
- createListener: function(fn, scope, o) {
- o = o || {};
- scope = scope || this.observable;
- var listener = {
- fn: fn,
- scope: scope,
- o: o,
- ev: this
- },
- handler = fn;
- // The order is important. The 'single' wrapper must be wrapped by the 'buffer' and 'delayed' wrapper
- // because the event removal that the single listener does destroys the listener's DelayedTask(s)
- if (o.single) {
- handler = createSingle(handler, listener, o, scope);
- }
- if (o.delay) {
- handler = createDelayed(handler, listener, o, scope);
- }
- if (o.buffer) {
- handler = createBuffered(handler, listener, o, scope);
- }
- listener.fireFn = handler;
- return listener;
- },
- findListener: function(fn, scope) {
- var listeners = this.listeners,
- i = listeners.length,
- listener,
- s;
- while (i--) {
- listener = listeners[i];
- if (listener) {
- s = listener.scope;
- if (listener.fn == fn && (s == scope || s == this.observable)) {
- return i;
- }
- }
- }
- return - 1;
- },
- isListening: function(fn, scope) {
- return this.findListener(fn, scope) !== -1;
- },
- removeListener: function(fn, scope) {
- var me = this,
- index,
- listener,
- k;
- index = me.findListener(fn, scope);
- if (index != -1) {
- listener = me.listeners[index];
- if (me.firing) {
- me.listeners = me.listeners.slice(0);
- }
- // cancel and remove a buffered handler that hasn't fired yet
- if (listener.task) {
- listener.task.cancel();
- delete listener.task;
- }
- // cancel and remove all delayed handlers that haven't fired yet
- k = listener.tasks && listener.tasks.length;
- if (k) {
- while (k--) {
- listener.tasks[k].cancel();
- }
- delete listener.tasks;
- }
- // remove this listener from the listeners array
- Ext.Array.erase(me.listeners, index, 1);
- return true;
- }
- return false;
- },
- // Iterate to stop any buffered/delayed events
- clearListeners: function() {
- var listeners = this.listeners,
- i = listeners.length;
- while (i--) {
- this.removeListener(listeners[i].fn, listeners[i].scope);
- }
- },
- fire: function() {
- var me = this,
- listeners = me.listeners,
- count = listeners.length,
- i,
- args,
- listener;
- if (count > 0) {
- me.firing = true;
- for (i = 0; i < count; i++) {
- listener = listeners[i];
- args = arguments.length ? Array.prototype.slice.call(arguments, 0) : [];
- if (listener.o) {
- args.push(listener.o);
- }
- if (listener && listener.fireFn.apply(listener.scope || me.observable, args) === false) {
- return (me.firing = false);
- }
- }
- }
- me.firing = false;
- return true;
- }
- };
- })());
- });
- /**
- * @class Ext.EventManager
- * Registers event handlers that want to receive a normalized EventObject instead of the standard browser event and provides
- * several useful events directly.
- * See {@link Ext.EventObject} for more details on normalized event objects.
- * @singleton
- */
- Ext.EventManager = {
- // --------------------- onReady ---------------------
- /**
- * Check if we have bound our global onReady listener
- * @private
- */
- hasBoundOnReady: false,
- /**
- * Check if fireDocReady has been called
- * @private
- */
- hasFiredReady: false,
- /**
- * Timer for the document ready event in old IE versions
- * @private
- */
- readyTimeout: null,
- /**
- * Checks if we have bound an onreadystatechange event
- * @private
- */
- hasOnReadyStateChange: false,
- /**
- * Holds references to any onReady functions
- * @private
- */
- readyEvent: new Ext.util.Event(),
- /**
- * Check the ready state for old IE versions
- * @private
- * @return {Boolean} True if the document is ready
- */
- checkReadyState: function(){
- var me = Ext.EventManager;
- if(window.attachEvent){
- // See here for reference: http://javascript.nwbox.com/IEContentLoaded/
- // licensed courtesy of http://developer.yahoo.com/yui/license.html
- if (window != top) {
- return false;
- }
- try{
- document.documentElement.doScroll('left');
- }catch(e){
- return false;
- }
- me.fireDocReady();
- return true;
- }
- if (document.readyState == 'complete') {
- me.fireDocReady();
- return true;
- }
- me.readyTimeout = setTimeout(arguments.callee, 2);
- return false;
- },
- /**
- * Binds the appropriate browser event for checking if the DOM has loaded.
- * @private
- */
- bindReadyEvent: function(){
- var me = Ext.EventManager;
- if (me.hasBoundOnReady) {
- return;
- }
- if (document.addEventListener) {
- document.addEventListener('DOMContentLoaded', me.fireDocReady, false);
- // fallback, load will ~always~ fire
- window.addEventListener('load', me.fireDocReady, false);
- } else {
- // check if the document is ready, this will also kick off the scroll checking timer
- if (!me.checkReadyState()) {
- document.attachEvent('onreadystatechange', me.checkReadyState);
- me.hasOnReadyStateChange = true;
- }
- // fallback, onload will ~always~ fire
- window.attachEvent('onload', me.fireDocReady, false);
- }
- me.hasBoundOnReady = true;
- },
- /**
- * We know the document is loaded, so trigger any onReady events.
- * @private
- */
- fireDocReady: function(){
- var me = Ext.EventManager;
- // only unbind these events once
- if (!me.hasFiredReady) {
- me.hasFiredReady = true;
- if (document.addEventListener) {
- document.removeEventListener('DOMContentLoaded', me.fireDocReady, false);
- window.removeEventListener('load', me.fireDocReady, false);
- } else {
- if (me.readyTimeout !== null) {
- clearTimeout(me.readyTimeout);
- }
- if (me.hasOnReadyStateChange) {
- document.detachEvent('onreadystatechange', me.checkReadyState);
- }
- window.detachEvent('onload', me.fireDocReady);
- }
- Ext.supports.init();
- }
- if (!Ext.isReady) {
- Ext.isReady = true;
- me.onWindowUnload();
- me.readyEvent.fire();
- }
- },
- /**
- * Adds a listener to be notified when the document is ready (before onload and before images are loaded). Can be
- * accessed shorthanded as Ext.onReady().
- * @param {Function} fn The method the event invokes.
- * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
- * @param {Boolean} options (optional) Options object as passed to {@link Ext.Element#addListener}.
- */
- onDocumentReady: function(fn, scope, options){
- options = options || {};
- var me = Ext.EventManager,
- readyEvent = me.readyEvent;
- // force single to be true so our event is only ever fired once.
- options.single = true;
- // Document already loaded, let's just fire it
- if (Ext.isReady) {
- readyEvent.addListener(fn, scope, options);
- readyEvent.fire();
- } else {
- options.delay = options.delay || 1;
- readyEvent.addListener(fn, scope, options);
- me.bindReadyEvent();
- }
- },
- // --------------------- event binding ---------------------
- /**
- * Contains a list of all document mouse downs, so we can ensure they fire even when stopEvent is called.
- * @private
- */
- stoppedMouseDownEvent: new Ext.util.Event(),
- /**
- * Options to parse for the 4th argument to addListener.
- * @private
- */
- propRe: /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate|freezeEvent)$/,
- /**
- * Get the id of the element. If one has not been assigned, automatically assign it.
- * @param {HTMLElement/Ext.Element} element The element to get the id for.
- * @return {String} id
- */
- getId : function(element) {
- var skipGarbageCollection = false,
- id;
- element = Ext.getDom(element);
- if (element === document || element === window) {
- id = element === document ? Ext.documentId : Ext.windowId;
- }
- else {
- id = Ext.id(element);
- }
- // skip garbage collection for special elements (window, document, iframes)
- if (element && (element.getElementById || element.navigator)) {
- skipGarbageCollection = true;
- }
- if (!Ext.cache[id]){
- Ext.Element.addToCache(new Ext.Element(element), id);
- if (skipGarbageCollection) {
- Ext.cache[id].skipGarbageCollection = true;
- }
- }
- return id;
- },
- /**
- * Convert a "config style" listener into a set of flat arguments so they can be passed to addListener
- * @private
- * @param {Object} element The element the event is for
- * @param {Object} event The event configuration
- * @param {Object} isRemove True if a removal should be performed, otherwise an add will be done.
- */
- prepareListenerConfig: function(element, config, isRemove){
- var me = this,
- propRe = me.propRe,
- key, value, args;
- // loop over all the keys in the object
- for (key in config) {
- if (config.hasOwnProperty(key)) {
- // if the key is something else then an event option
- if (!propRe.test(key)) {
- value = config[key];
- // if the value is a function it must be something like click: function(){}, scope: this
- // which means that there might be multiple event listeners with shared options
- if (Ext.isFunction(value)) {
- // shared options
- args = [element, key, value, config.scope, config];
- } else {
- // if its not a function, it must be an object like click: {fn: function(){}, scope: this}
- args = [element, key, value.fn, value.scope, value];
- }
- if (isRemove === true) {
- me.removeListener.apply(this, args);
- } else {
- me.addListener.apply(me, args);
- }
- }
- }
- }
- },
- /**
- * Normalize cross browser event differences
- * @private
- * @param {Object} eventName The event name
- * @param {Object} fn The function to execute
- * @return {Object} The new event name/function
- */
- normalizeEvent: function(eventName, fn){
- if (/mouseenter|mouseleave/.test(eventName) && !Ext.supports.MouseEnterLeave) {
- if (fn) {
- fn = Ext.Function.createInterceptor(fn, this.contains, this);
- }
- eventName = eventName == 'mouseenter' ? 'mouseover' : 'mouseout';
- } else if (eventName == 'mousewheel' && !Ext.supports.MouseWheel && !Ext.isOpera){
- eventName = 'DOMMouseScroll';
- }
- return {
- eventName: eventName,
- fn: fn
- };
- },
- /**
- * Checks whether the event's relatedTarget is contained inside (or <b>is</b>) the element.
- * @private
- * @param {Object} event
- */
- contains: function(event){
- var parent = event.browserEvent.currentTarget,
- child = this.getRelatedTarget(event);
- if (parent && parent.firstChild) {
- while (child) {
- if (child === parent) {
- return false;
- }
- child = child.parentNode;
- if (child && (child.nodeType != 1)) {
- child = null;
- }
- }
- }
- return true;
- },
- /**
- * Appends an event handler to an element. The shorthand version {@link #on} is equivalent. Typically you will
- * use {@link Ext.Element#addListener} directly on an Element in favor of calling this version.
- * @param {String/HTMLElement} el The html element or id to assign the event handler to.
- * @param {String} eventName The name of the event to listen for.
- * @param {Function} handler The handler function the event invokes. This function is passed
- * the following parameters:<ul>
- * <li>evt : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li>
- * <li>t : Element<div class="sub-desc">The {@link Ext.Element Element} which was the target of the event.
- * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li>
- * <li>o : Object<div class="sub-desc">The options object from the addListener call.</div></li>
- * </ul>
- * @param {Object} scope (optional) The scope (<b><code>this</code></b> reference) in which the handler function is executed. <b>Defaults to the Element</b>.
- * @param {Object} options (optional) An object containing handler configuration properties.
- * This may contain any of the following properties:<ul>
- * <li>scope : Object<div class="sub-desc">The scope (<b><code>this</code></b> reference) in which the handler function is executed. <b>Defaults to the Element</b>.</div></li>
- * <li>delegate : String<div class="sub-desc">A simple selector to filter the target or look for a descendant of the target</div></li>
- * <li>stopEvent : Boolean<div class="sub-desc">True to stop the event. That is stop propagation, and prevent the default action.</div></li>
- * <li>preventDefault : Boolean<div class="sub-desc">True to prevent the default action</div></li>
- * <li>stopPropagation : Boolean<div class="sub-desc">True to prevent event propagation</div></li>
- * <li>normalized : Boolean<div class="sub-desc">False to pass a browser event to the handler function instead of an Ext.EventObject</div></li>
- * <li>delay : Number<div class="sub-desc">The number of milliseconds to delay the invocation of the handler after te event fires.</div></li>
- * <li>single : Boolean<div class="sub-desc">True to add a handler to handle just the next firing of the event, and then remove itself.</div></li>
- * <li>buffer : Number<div class="sub-desc">Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed
- * by the specified number of milliseconds. If the event fires again within that time, the original
- * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</div></li>
- * <li>target : Element<div class="sub-desc">Only call the handler if the event was fired on the target Element, <i>not</i> if the event was bubbled up from a child node.</div></li>
- * </ul><br>
- * <p>See {@link Ext.Element#addListener} for examples of how to use these options.</p>
- */
- addListener: function(element, eventName, fn, scope, options){
- // Check if we've been passed a "config style" event.
- if (typeof eventName !== 'string') {
- this.prepareListenerConfig(element, eventName);
- return;
- }
- var dom = Ext.getDom(element),
- bind,
- wrap;
- // create the wrapper function
- options = options || {};
- bind = this.normalizeEvent(eventName, fn);
- wrap = this.createListenerWrap(dom, eventName, bind.fn, scope, options);
- if (dom.attachEvent) {
- dom.attachEvent('on' + bind.eventName, wrap);
- } else {
- dom.addEventListener(bind.eventName, wrap, options.capture || false);
- }
- if (dom == document && eventName == 'mousedown') {
- this.stoppedMouseDownEvent.addListener(wrap);
- }
- // add all required data into the event cache
- this.getEventListenerCache(dom, eventName).push({
- fn: fn,
- wrap: wrap,
- scope: scope
- });
- },
- /**
- * Removes an event handler from an element. The shorthand version {@link #un} is equivalent. Typically
- * you will use {@link Ext.Element#removeListener} directly on an Element in favor of calling this version.
- * @param {String/HTMLElement} el The id or html element from which to remove the listener.
- * @param {String} eventName The name of the event.
- * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
- * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
- * then this must refer to the same object.
- */
- removeListener : function(element, eventName, fn, scope) {
- // handle our listener config object syntax
- if (typeof eventName !== 'string') {
- this.prepareListenerConfig(element, eventName, true);
- return;
- }
- var dom = Ext.getDom(element),
- cache = this.getEventListenerCache(dom, eventName),
- bindName = this.normalizeEvent(eventName).eventName,
- i = cache.length, j,
- listener, wrap, tasks;
- while (i--) {
- listener = cache[i];
- if (listener && (!fn || listener.fn == fn) && (!scope || listener.scope === scope)) {
- wrap = listener.wrap;
- // clear buffered calls
- if (wrap.task) {
- clearTimeout(wrap.task);
- delete wrap.task;
- }
- // clear delayed calls
- j = wrap.tasks && wrap.tasks.length;
- if (j) {
- while (j--) {
- clearTimeout(wrap.tasks[j]);
- }
- delete wrap.tasks;
- }
- if (dom.detachEvent) {
- dom.detachEvent('on' + bindName, wrap);
- } else {
- dom.removeEventListener(bindName, wrap, false);
- }
- if (wrap && dom == document && eventName == 'mousedown') {
- this.stoppedMouseDownEvent.removeListener(wrap);
- }
- // remove listener from cache
- Ext.Array.erase(cache, i, 1);
- }
- }
- },
- /**
- * Removes all event handers from an element. Typically you will use {@link Ext.Element#removeAllListeners}
- * directly on an Element in favor of calling this version.
- * @param {String/HTMLElement} el The id or html element from which to remove all event handlers.
- */
- removeAll : function(element){
- var dom = Ext.getDom(element),
- cache, ev;
- if (!dom) {
- return;
- }
- cache = this.getElementEventCache(dom);
- for (ev in cache) {
- if (cache.hasOwnProperty(ev)) {
- this.removeListener(dom, ev);
- }
- }
- Ext.cache[dom.id].events = {};
- },
- /**
- * Recursively removes all previous added listeners from an element and its children. Typically you will use {@link Ext.Element#purgeAllListeners}
- * directly on an Element in favor of calling this version.
- * @param {String/HTMLElement} el The id or html element from which to remove all event handlers.
- * @param {String} eventName (optional) The name of the event.
- */
- purgeElement : function(element, eventName) {
- var dom = Ext.getDom(element),
- i = 0, len;
- if(eventName) {
- this.removeListener(dom, eventName);
- }
- else {
- this.removeAll(dom);
- }
- if(dom && dom.childNodes) {
- for(len = element.childNodes.length; i < len; i++) {
- this.purgeElement(element.childNodes[i], eventName);
- }
- }
- },
- /**
- * Create the wrapper function for the event
- * @private
- * @param {HTMLElement} dom The dom element
- * @param {String} ename The event name
- * @param {Function} fn The function to execute
- * @param {Object} scope The scope to execute callback in
- * @param {Object} options The options
- * @return {Function} the wrapper function
- */
- createListenerWrap : function(dom, ename, fn, scope, options) {
- options = options || {};
- var f, gen;
- return function wrap(e, args) {
- // Compile the implementation upon first firing
- if (!gen) {
- f = ['if(!Ext) {return;}'];
- if(options.buffer || options.delay || options.freezeEvent) {
- f.push('e = new Ext.EventObjectImpl(e, ' + (options.freezeEvent ? 'true' : 'false' ) + ');');
- } else {
- f.push('e = Ext.EventObject.setEvent(e);');
- }
- if (options.delegate) {
- f.push('var t = e.getTarget("' + options.delegate + '", this);');
- f.push('if(!t) {return;}');
- } else {
- f.push('var t = e.target;');
- }
- if (options.target) {
- f.push('if(e.target !== options.target) {return;}');
- }
- if(options.stopEvent) {
- f.push('e.stopEvent();');
- } else {
- if(options.preventDefault) {
- f.push('e.preventDefault();');
- }
- if(options.stopPropagation) {
- f.push('e.stopPropagation();');
- }
- }
- if(options.normalized === false) {
- f.push('e = e.browserEvent;');
- }
- if(options.buffer) {
- f.push('(wrap.task && clearTimeout(wrap.task));');
- f.push('wrap.task = setTimeout(function(){');
- }
- if(options.delay) {
- f.push('wrap.tasks = wrap.tasks || [];');
- f.push('wrap.tasks.push(setTimeout(function(){');
- }
- // finally call the actual handler fn
- f.push('fn.call(scope || dom, e, t, options);');
- if(options.single) {
- f.push('Ext.EventManager.removeListener(dom, ename, fn, scope);');
- }
- if(options.delay) {
- f.push('}, ' + options.delay + '));');
- }
- if(options.buffer) {
- f.push('}, ' + options.buffer + ');');
- }
- gen = Ext.functionFactory('e', 'options', 'fn', 'scope', 'ename', 'dom', 'wrap', 'args', f.join('\n'));
- }
- gen.call(dom, e, options, fn, scope, ename, dom, wrap, args);
- };
- },
- /**
- * Get the event cache for a particular element for a particular event
- * @private
- * @param {HTMLElement} element The element
- * @param {Object} eventName The event name
- * @return {Array} The events for the element
- */
- getEventListenerCache : function(element, eventName) {
- if (!element) {
- return [];
- }
- var eventCache = this.getElementEventCache(element);
- return eventCache[eventName] || (eventCache[eventName] = []);
- },
- /**
- * Gets the event cache for the object
- * @private
- * @param {HTMLElement} element The element
- * @return {Object} The event cache for the object
- */
- getElementEventCache : function(element) {
- if (!element) {
- return {};
- }
- var elementCache = Ext.cache[this.getId(element)];
- return elementCache.events || (elementCache.events = {});
- },
- // --------------------- utility methods ---------------------
- mouseLeaveRe: /(mouseout|mouseleave)/,
- mouseEnterRe: /(mouseover|mouseenter)/,
- /**
- * Stop the event (preventDefault and stopPropagation)
- * @param {Event} The event to stop
- */
- stopEvent: function(event) {
- this.stopPropagation(event);
- this.preventDefault(event);
- },
- /**
- * Cancels bubbling of the event.
- * @param {Event} The event to stop bubbling.
- */
- stopPropagation: function(event) {
- event = event.browserEvent || event;
- if (event.stopPropagation) {
- event.stopPropagation();
- } else {
- event.cancelBubble = true;
- }
- },
- /**
- * Prevents the browsers default handling of the event.
- * @param {Event} The event to prevent the default
- */
- preventDefault: function(event) {
- event = event.browserEvent || event;
- if (event.preventDefault) {
- event.preventDefault();
- } else {
- event.returnValue = false;
- // Some keys events require setting the keyCode to -1 to be prevented
- try {
- // all ctrl + X and F1 -> F12
- if (event.ctrlKey || event.keyCode > 111 && event.keyCode < 124) {
- event.keyCode = -1;
- }
- } catch (e) {
- // see this outdated document http://support.microsoft.com/kb/934364/en-us for more info
- }
- }
- },
- /**
- * Gets the related target from the event.
- * @param {Object} event The event
- * @return {HTMLElement} The related target.
- */
- getRelatedTarget: function(event) {
- event = event.browserEvent || event;
- var target = event.relatedTarget;
- if (!target) {
- if (this.mouseLeaveRe.test(event.type)) {
- target = event.toElement;
- } else if (this.mouseEnterRe.test(event.type)) {
- target = event.fromElement;
- }
- }
- return this.resolveTextNode(target);
- },
- /**
- * Gets the x coordinate from the event
- * @param {Object} event The event
- * @return {Number} The x coordinate
- */
- getPageX: function(event) {
- return this.getXY(event)[0];
- },
- /**
- * Gets the y coordinate from the event
- * @param {Object} event The event
- * @return {Number} The y coordinate
- */
- getPageY: function(event) {
- return this.getXY(event)[1];
- },
- /**
- * Gets the x & y coordinate from the event
- * @param {Object} event The event
- * @return {Number[]} The x/y coordinate
- */
- getPageXY: function(event) {
- event = event.browserEvent || event;
- var x = event.pageX,
- y = event.pageY,
- doc = document.documentElement,
- body = document.body;
- // pageX/pageY not available (undefined, not null), use clientX/clientY instead
- if (!x && x !== 0) {
- x = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);
- y = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);
- }
- return [x, y];
- },
- /**
- * Gets the target of the event.
- * @param {Object} event The event
- * @return {HTMLElement} target
- */
- getTarget: function(event) {
- event = event.browserEvent || event;
- return this.resolveTextNode(event.target || event.srcElement);
- },
- /**
- * Resolve any text nodes accounting for browser differences.
- * @private
- * @param {HTMLElement} node The node
- * @return {HTMLElement} The resolved node
- */
- // technically no need to browser sniff this, however it makes no sense to check this every time, for every event, whether the string is equal.
- resolveTextNode: Ext.isGecko ?
- function(node) {
- if (!node) {
- return;
- }
- // work around firefox bug, https://bugzilla.mozilla.org/show_bug.cgi?id=101197
- var s = HTMLElement.prototype.toString.call(node);
- if (s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]') {
- return;
- }
- return node.nodeType == 3 ? node.parentNode: node;
- }: function(node) {
- return node && node.nodeType == 3 ? node.parentNode: node;
- },
- // --------------------- custom event binding ---------------------
- // Keep track of the current width/height
- curWidth: 0,
- curHeight: 0,
- /**
- * Adds a listener to be notified when the browser window is resized and provides resize event buffering (100 milliseconds),
- * passes new viewport width and height to handlers.
- * @param {Function} fn The handler function the window resize event invokes.
- * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
- * @param {Boolean} options Options object as passed to {@link Ext.Element#addListener}
- */
- onWindowResize: function(fn, scope, options){
- var resize = this.resizeEvent;
- if(!resize){
- this.resizeEvent = resize = new Ext.util.Event();
- this.on(window, 'resize', this.fireResize, this, {buffer: 100});
- }
- resize.addListener(fn, scope, options);
- },
- /**
- * Fire the resize event.
- * @private
- */
- fireResize: function(){
- var me = this,
- w = Ext.Element.getViewWidth(),
- h = Ext.Element.getViewHeight();
- //whacky problem in IE where the resize event will sometimes fire even though the w/h are the same.
- if(me.curHeight != h || me.curWidth != w){
- me.curHeight = h;
- me.curWidth = w;
- me.resizeEvent.fire(w, h);
- }
- },
- /**
- * Removes the passed window resize listener.
- * @param {Function} fn The method the event invokes
- * @param {Object} scope The scope of handler
- */
- removeResizeListener: function(fn, scope){
- if (this.resizeEvent) {
- this.resizeEvent.removeListener(fn, scope);
- }
- },
- onWindowUnload: function() {
- var unload = this.unloadEvent;
- if (!unload) {
- this.unloadEvent = unload = new Ext.util.Event();
- this.addListener(window, 'unload', this.fireUnload, this);
- }
- },
- /**
- * Fires the unload event for items bound with onWindowUnload
- * @private
- */
- fireUnload: function() {
- // wrap in a try catch, could have some problems during unload
- try {
- this.removeUnloadListener();
- // Work around FF3 remembering the last scroll position when refreshing the grid and then losing grid view
- if (Ext.isGecko3) {
- var gridviews = Ext.ComponentQuery.query('gridview'),
- i = 0,
- ln = gridviews.length;
- for (; i < ln; i++) {
- gridviews[i].scrollToTop();
- }
- }
- // Purge all elements in the cache
- var el,
- cache = Ext.cache;
- for (el in cache) {
- if (cache.hasOwnProperty(el)) {
- Ext.EventManager.removeAll(el);
- }
- }
- } catch(e) {
- }
- },
- /**
- * Removes the passed window unload listener.
- * @param {Function} fn The method the event invokes
- * @param {Object} scope The scope of handler
- */
- removeUnloadListener: function(){
- if (this.unloadEvent) {
- this.removeListener(window, 'unload', this.fireUnload);
- }
- },
- /**
- * note 1: IE fires ONLY the keydown event on specialkey autorepeat
- * note 2: Safari < 3.1, Gecko (Mac/Linux) & Opera fire only the keypress event on specialkey autorepeat
- * (research done by Jan Wolter at http://unixpapa.com/js/key.html)
- * @private
- */
- useKeyDown: Ext.isWebKit ?
- parseInt(navigator.userAgent.match(/AppleWebKit\/(\d+)/)[1], 10) >= 525 :
- !((Ext.isGecko && !Ext.isWindows) || Ext.isOpera),
- /**
- * Indicates which event to use for getting key presses.
- * @return {String} The appropriate event name.
- */
- getKeyEvent: function(){
- return this.useKeyDown ? 'keydown' : 'keypress';
- }
- };
- /**
- * Alias for {@link Ext.Loader#onReady Ext.Loader.onReady} with withDomReady set to true
- * @member Ext
- * @method onReady
- */
- Ext.onReady = function(fn, scope, options) {
- Ext.Loader.onReady(fn, scope, true, options);
- };
- /**
- * Alias for {@link Ext.EventManager#onDocumentReady Ext.EventManager.onDocumentReady}
- * @member Ext
- * @method onDocumentReady
- */
- Ext.onDocumentReady = Ext.EventManager.onDocumentReady;
- /**
- * Alias for {@link Ext.EventManager#addListener Ext.EventManager.addListener}
- * @member Ext.EventManager
- * @method on
- */
- Ext.EventManager.on = Ext.EventManager.addListener;
- /**
- * Alias for {@link Ext.EventManager#removeListener Ext.EventManager.removeListener}
- * @member Ext.EventManager
- * @method un
- */
- Ext.EventManager.un = Ext.EventManager.removeListener;
- (function(){
- var initExtCss = function() {
- // find the body element
- var bd = document.body || document.getElementsByTagName('body')[0],
- baseCSSPrefix = Ext.baseCSSPrefix,
- cls = [baseCSSPrefix + 'body'],
- htmlCls = [],
- html;
- if (!bd) {
- return false;
- }
- html = bd.parentNode;
- function add (c) {
- cls.push(baseCSSPrefix + c);
- }
- //Let's keep this human readable!
- if (Ext.isIE) {
- add('ie');
- // very often CSS needs to do checks like "IE7+" or "IE6 or 7". To help
- // reduce the clutter (since CSS/SCSS cannot do these tests), we add some
- // additional classes:
- //
- // x-ie7p : IE7+ : 7 <= ieVer
- // x-ie7m : IE7- : ieVer <= 7
- // x-ie8p : IE8+ : 8 <= ieVer
- // x-ie8m : IE8- : ieVer <= 8
- // x-ie9p : IE9+ : 9 <= ieVer
- // x-ie78 : IE7 or 8 : 7 <= ieVer <= 8
- //
- if (Ext.isIE6) {
- add('ie6');
- } else { // ignore pre-IE6 :)
- add('ie7p');
- if (Ext.isIE7) {
- add('ie7');
- } else {
- add('ie8p');
- if (Ext.isIE8) {
- add('ie8');
- } else {
- add('ie9p');
- if (Ext.isIE9) {
- add('ie9');
- }
- }
- }
- }
- if (Ext.isIE6 || Ext.isIE7) {
- add('ie7m');
- }
- if (Ext.isIE6 || Ext.isIE7 || Ext.isIE8) {
- add('ie8m');
- }
- if (Ext.isIE7 || Ext.isIE8) {
- add('ie78');
- }
- }
- if (Ext.isGecko) {
- add('gecko');
- if (Ext.isGecko3) {
- add('gecko3');
- }
- if (Ext.isGecko4) {
- add('gecko4');
- }
- if (Ext.isGecko5) {
- add('gecko5');
- }
- }
- if (Ext.isOpera) {
- add('opera');
- }
- if (Ext.isWebKit) {
- add('webkit');
- }
- if (Ext.isSafari) {
- add('safari');
- if (Ext.isSafari2) {
- add('safari2');
- }
- if (Ext.isSafari3) {
- add('safari3');
- }
- if (Ext.isSafari4) {
- add('safari4');
- }
- if (Ext.isSafari5) {
- add('safari5');
- }
- }
- if (Ext.isChrome) {
- add('chrome');
- }
- if (Ext.isMac) {
- add('mac');
- }
- if (Ext.isLinux) {
- add('linux');
- }
- if (!Ext.supports.CSS3BorderRadius) {
- add('nbr');
- }
- if (!Ext.supports.CSS3LinearGradient) {
- add('nlg');
- }
- if (!Ext.scopeResetCSS) {
- add('reset');
- }
- // add to the parent to allow for selectors x-strict x-border-box, also set the isBorderBox property correctly
- if (html) {
- if (Ext.isStrict && (Ext.isIE6 || Ext.isIE7)) {
- Ext.isBorderBox = false;
- }
- else {
- Ext.isBorderBox = true;
- }
- htmlCls.push(baseCSSPrefix + (Ext.isBorderBox ? 'border-box' : 'strict'));
- if (!Ext.isStrict) {
- htmlCls.push(baseCSSPrefix + 'quirks');
- }
- Ext.fly(html, '_internal').addCls(htmlCls);
- }
- Ext.fly(bd, '_internal').addCls(cls);
- return true;
- };
- Ext.onReady(initExtCss);
- })();
- /**
- * @class Ext.EventObject
- Just as {@link Ext.Element} wraps around a native DOM node, Ext.EventObject
- wraps the browser's native event-object normalizing cross-browser differences,
- such as which mouse button is clicked, keys pressed, mechanisms to stop
- event-propagation along with a method to prevent default actions from taking place.
- For example:
- function handleClick(e, t){ // e is not a standard event object, it is a Ext.EventObject
- e.preventDefault();
- var target = e.getTarget(); // same as t (the target HTMLElement)
- ...
- }
- var myDiv = {@link Ext#get Ext.get}("myDiv"); // get reference to an {@link Ext.Element}
- myDiv.on( // 'on' is shorthand for addListener
- "click", // perform an action on click of myDiv
- handleClick // reference to the action handler
- );
- // other methods to do the same:
- Ext.EventManager.on("myDiv", 'click', handleClick);
- Ext.EventManager.addListener("myDiv", 'click', handleClick);
- * @singleton
- * @markdown
- */
- Ext.define('Ext.EventObjectImpl', {
- uses: ['Ext.util.Point'],
- /** Key constant @type Number */
- BACKSPACE: 8,
- /** Key constant @type Number */
- TAB: 9,
- /** Key constant @type Number */
- NUM_CENTER: 12,
- /** Key constant @type Number */
- ENTER: 13,
- /** Key constant @type Number */
- RETURN: 13,
- /** Key constant @type Number */
- SHIFT: 16,
- /** Key constant @type Number */
- CTRL: 17,
- /** Key constant @type Number */
- ALT: 18,
- /** Key constant @type Number */
- PAUSE: 19,
- /** Key constant @type Number */
- CAPS_LOCK: 20,
- /** Key constant @type Number */
- ESC: 27,
- /** Key constant @type Number */
- SPACE: 32,
- /** Key constant @type Number */
- PAGE_UP: 33,
- /** Key constant @type Number */
- PAGE_DOWN: 34,
- /** Key constant @type Number */
- END: 35,
- /** Key constant @type Number */
- HOME: 36,
- /** Key constant @type Number */
- LEFT: 37,
- /** Key constant @type Number */
- UP: 38,
- /** Key constant @type Number */
- RIGHT: 39,
- /** Key constant @type Number */
- DOWN: 40,
- /** Key constant @type Number */
- PRINT_SCREEN: 44,
- /** Key constant @type Number */
- INSERT: 45,
- /** Key constant @type Number */
- DELETE: 46,
- /** Key constant @type Number */
- ZERO: 48,
- /** Key constant @type Number */
- ONE: 49,
- /** Key constant @type Number */
- TWO: 50,
- /** Key constant @type Number */
- THREE: 51,
- /** Key constant @type Number */
- FOUR: 52,
- /** Key constant @type Number */
- FIVE: 53,
- /** Key constant @type Number */
- SIX: 54,
- /** Key constant @type Number */
- SEVEN: 55,
- /** Key constant @type Number */
- EIGHT: 56,
- /** Key constant @type Number */
- NINE: 57,
- /** Key constant @type Number */
- A: 65,
- /** Key constant @type Number */
- B: 66,
- /** Key constant @type Number */
- C: 67,
- /** Key constant @type Number */
- D: 68,
- /** Key constant @type Number */
- E: 69,
- /** Key constant @type Number */
- F: 70,
- /** Key constant @type Number */
- G: 71,
- /** Key constant @type Number */
- H: 72,
- /** Key constant @type Number */
- I: 73,
- /** Key constant @type Number */
- J: 74,
- /** Key constant @type Number */
- K: 75,
- /** Key constant @type Number */
- L: 76,
- /** Key constant @type Number */
- M: 77,
- /** Key constant @type Number */
- N: 78,
- /** Key constant @type Number */
- O: 79,
- /** Key constant @type Number */
- P: 80,
- /** Key constant @type Number */
- Q: 81,
- /** Key constant @type Number */
- R: 82,
- /** Key constant @type Number */
- S: 83,
- /** Key constant @type Number */
- T: 84,
- /** Key constant @type Number */
- U: 85,
- /** Key constant @type Number */
- V: 86,
- /** Key constant @type Number */
- W: 87,
- /** Key constant @type Number */
- X: 88,
- /** Key constant @type Number */
- Y: 89,
- /** Key constant @type Number */
- Z: 90,
- /** Key constant @type Number */
- CONTEXT_MENU: 93,
- /** Key constant @type Number */
- NUM_ZERO: 96,
- /** Key constant @type Number */
- NUM_ONE: 97,
- /** Key constant @type Number */
- NUM_TWO: 98,
- /** Key constant @type Number */
- NUM_THREE: 99,
- /** Key constant @type Number */
- NUM_FOUR: 100,
- /** Key constant @type Number */
- NUM_FIVE: 101,
- /** Key constant @type Number */
- NUM_SIX: 102,
- /** Key constant @type Number */
- NUM_SEVEN: 103,
- /** Key constant @type Number */
- NUM_EIGHT: 104,
- /** Key constant @type Number */
- NUM_NINE: 105,
- /** Key constant @type Number */
- NUM_MULTIPLY: 106,
- /** Key constant @type Number */
- NUM_PLUS: 107,
- /** Key constant @type Number */
- NUM_MINUS: 109,
- /** Key constant @type Number */
- NUM_PERIOD: 110,
- /** Key constant @type Number */
- NUM_DIVISION: 111,
- /** Key constant @type Number */
- F1: 112,
- /** Key constant @type Number */
- F2: 113,
- /** Key constant @type Number */
- F3: 114,
- /** Key constant @type Number */
- F4: 115,
- /** Key constant @type Number */
- F5: 116,
- /** Key constant @type Number */
- F6: 117,
- /** Key constant @type Number */
- F7: 118,
- /** Key constant @type Number */
- F8: 119,
- /** Key constant @type Number */
- F9: 120,
- /** Key constant @type Number */
- F10: 121,
- /** Key constant @type Number */
- F11: 122,
- /** Key constant @type Number */
- F12: 123,
- /**
- * The mouse wheel delta scaling factor. This value depends on browser version and OS and
- * attempts to produce a similar scrolling experience across all platforms and browsers.
- *
- * To change this value:
- *
- * Ext.EventObjectImpl.prototype.WHEEL_SCALE = 72;
- *
- * @type Number
- * @markdown
- */
- WHEEL_SCALE: (function () {
- var scale;
- if (Ext.isGecko) {
- // Firefox uses 3 on all platforms
- scale = 3;
- } else if (Ext.isMac) {
- // Continuous scrolling devices have momentum and produce much more scroll than
- // discrete devices on the same OS and browser. To make things exciting, Safari
- // (and not Chrome) changed from small values to 120 (like IE).
- if (Ext.isSafari && Ext.webKitVersion >= 532.0) {
- // Safari changed the scrolling factor to match IE (for details see
- // https://bugs.webkit.org/show_bug.cgi?id=24368). The WebKit version where this
- // change was introduced was 532.0
- // Detailed discussion:
- // https://bugs.webkit.org/show_bug.cgi?id=29601
- // http://trac.webkit.org/browser/trunk/WebKit/chromium/src/mac/WebInputEventFactory.mm#L1063
- scale = 120;
- } else {
- // MS optical wheel mouse produces multiples of 12 which is close enough
- // to help tame the speed of the continuous mice...
- scale = 12;
- }
- // Momentum scrolling produces very fast scrolling, so increase the scale factor
- // to help produce similar results cross platform. This could be even larger and
- // it would help those mice, but other mice would become almost unusable as a
- // result (since we cannot tell which device type is in use).
- scale *= 3;
- } else {
- // IE, Opera and other Windows browsers use 120.
- scale = 120;
- }
- return scale;
- })(),
- /**
- * Simple click regex
- * @private
- */
- clickRe: /(dbl)?click/,
- // safari keypress events for special keys return bad keycodes
- safariKeys: {
- 3: 13, // enter
- 63234: 37, // left
- 63235: 39, // right
- 63232: 38, // up
- 63233: 40, // down
- 63276: 33, // page up
- 63277: 34, // page down
- 63272: 46, // delete
- 63273: 36, // home
- 63275: 35 // end
- },
- // normalize button clicks, don't see any way to feature detect this.
- btnMap: Ext.isIE ? {
- 1: 0,
- 4: 1,
- 2: 2
- } : {
- 0: 0,
- 1: 1,
- 2: 2
- },
- constructor: function(event, freezeEvent){
- if (event) {
- this.setEvent(event.browserEvent || event, freezeEvent);
- }
- },
- setEvent: function(event, freezeEvent){
- var me = this, button, options;
- if (event == me || (event && event.browserEvent)) { // already wrapped
- return event;
- }
- me.browserEvent = event;
- if (event) {
- // normalize buttons
- button = event.button ? me.btnMap[event.button] : (event.which ? event.which - 1 : -1);
- if (me.clickRe.test(event.type) && button == -1) {
- button = 0;
- }
- options = {
- type: event.type,
- button: button,
- shiftKey: event.shiftKey,
- // mac metaKey behaves like ctrlKey
- ctrlKey: event.ctrlKey || event.metaKey || false,
- altKey: event.altKey,
- // in getKey these will be normalized for the mac
- keyCode: event.keyCode,
- charCode: event.charCode,
- // cache the targets for the delayed and or buffered events
- target: Ext.EventManager.getTarget(event),
- relatedTarget: Ext.EventManager.getRelatedTarget(event),
- currentTarget: event.currentTarget,
- xy: (freezeEvent ? me.getXY() : null)
- };
- } else {
- options = {
- button: -1,
- shiftKey: false,
- ctrlKey: false,
- altKey: false,
- keyCode: 0,
- charCode: 0,
- target: null,
- xy: [0, 0]
- };
- }
- Ext.apply(me, options);
- return me;
- },
- /**
- * Stop the event (preventDefault and stopPropagation)
- */
- stopEvent: function(){
- this.stopPropagation();
- this.preventDefault();
- },
- /**
- * Prevents the browsers default handling of the event.
- */
- preventDefault: function(){
- if (this.browserEvent) {
- Ext.EventManager.preventDefault(this.browserEvent);
- }
- },
- /**
- * Cancels bubbling of the event.
- */
- stopPropagation: function(){
- var browserEvent = this.browserEvent;
- if (browserEvent) {
- if (browserEvent.type == 'mousedown') {
- Ext.EventManager.stoppedMouseDownEvent.fire(this);
- }
- Ext.EventManager.stopPropagation(browserEvent);
- }
- },
- /**
- * Gets the character code for the event.
- * @return {Number}
- */
- getCharCode: function(){
- return this.charCode || this.keyCode;
- },
- /**
- * Returns a normalized keyCode for the event.
- * @return {Number} The key code
- */
- getKey: function(){
- return this.normalizeKey(this.keyCode || this.charCode);
- },
- /**
- * Normalize key codes across browsers
- * @private
- * @param {Number} key The key code
- * @return {Number} The normalized code
- */
- normalizeKey: function(key){
- // can't feature detect this
- return Ext.isWebKit ? (this.safariKeys[key] || key) : key;
- },
- /**
- * Gets the x coordinate of the event.
- * @return {Number}
- * @deprecated 4.0 Replaced by {@link #getX}
- */
- getPageX: function(){
- return this.getX();
- },
- /**
- * Gets the y coordinate of the event.
- * @return {Number}
- * @deprecated 4.0 Replaced by {@link #getY}
- */
- getPageY: function(){
- return this.getY();
- },
- /**
- * Gets the x coordinate of the event.
- * @return {Number}
- */
- getX: function() {
- return this.getXY()[0];
- },
- /**
- * Gets the y coordinate of the event.
- * @return {Number}
- */
- getY: function() {
- return this.getXY()[1];
- },
- /**
- * Gets the page coordinates of the event.
- * @return {Number[]} The xy values like [x, y]
- */
- getXY: function() {
- if (!this.xy) {
- // same for XY
- this.xy = Ext.EventManager.getPageXY(this.browserEvent);
- }
- return this.xy;
- },
- /**
- * Gets the target for the event.
- * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
- * @param {Number/HTMLElement} maxDepth (optional) The max depth to search as a number or element (defaults to 10 || document.body)
- * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
- * @return {HTMLElement}
- */
- getTarget : function(selector, maxDepth, returnEl){
- if (selector) {
- return Ext.fly(this.target).findParent(selector, maxDepth, returnEl);
- }
- return returnEl ? Ext.get(this.target) : this.target;
- },
- /**
- * Gets the related target.
- * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
- * @param {Number/HTMLElement} maxDepth (optional) The max depth to search as a number or element (defaults to 10 || document.body)
- * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
- * @return {HTMLElement}
- */
- getRelatedTarget : function(selector, maxDepth, returnEl){
- if (selector) {
- return Ext.fly(this.relatedTarget).findParent(selector, maxDepth, returnEl);
- }
- return returnEl ? Ext.get(this.relatedTarget) : this.relatedTarget;
- },
- /**
- * Correctly scales a given wheel delta.
- * @param {Number} delta The delta value.
- */
- correctWheelDelta : function (delta) {
- var scale = this.WHEEL_SCALE,
- ret = Math.round(delta / scale);
- if (!ret && delta) {
- ret = (delta < 0) ? -1 : 1; // don't allow non-zero deltas to go to zero!
- }
- return ret;
- },
- /**
- * Returns the mouse wheel deltas for this event.
- * @return {Object} An object with "x" and "y" properties holding the mouse wheel deltas.
- */
- getWheelDeltas : function () {
- var me = this,
- event = me.browserEvent,
- dx = 0, dy = 0; // the deltas
- if (Ext.isDefined(event.wheelDeltaX)) { // WebKit has both dimensions
- dx = event.wheelDeltaX;
- dy = event.wheelDeltaY;
- } else if (event.wheelDelta) { // old WebKit and IE
- dy = event.wheelDelta;
- } else if (event.detail) { // Gecko
- dy = -event.detail; // gecko is backwards
- // Gecko sometimes returns really big values if the user changes settings to
- // scroll a whole page per scroll
- if (dy > 100) {
- dy = 3;
- } else if (dy < -100) {
- dy = -3;
- }
- // Firefox 3.1 adds an axis field to the event to indicate direction of
- // scroll. See https://developer.mozilla.org/en/Gecko-Specific_DOM_Events
- if (Ext.isDefined(event.axis) && event.axis === event.HORIZONTAL_AXIS) {
- dx = dy;
- dy = 0;
- }
- }
- return {
- x: me.correctWheelDelta(dx),
- y: me.correctWheelDelta(dy)
- };
- },
- /**
- * Normalizes mouse wheel y-delta across browsers. To get x-delta information, use
- * {@link #getWheelDeltas} instead.
- * @return {Number} The mouse wheel y-delta
- */
- getWheelDelta : function(){
- var deltas = this.getWheelDeltas();
- return deltas.y;
- },
- /**
- * Returns true if the target of this event is a child of el. Unless the allowEl parameter is set, it will return false if if the target is el.
- * Example usage:<pre><code>
- // Handle click on any child of an element
- Ext.getBody().on('click', function(e){
- if(e.within('some-el')){
- alert('Clicked on a child of some-el!');
- }
- });
- // Handle click directly on an element, ignoring clicks on child nodes
- Ext.getBody().on('click', function(e,t){
- if((t.id == 'some-el') && !e.within(t, true)){
- alert('Clicked directly on some-el!');
- }
- });
- </code></pre>
- * @param {String/HTMLElement/Ext.Element} el The id, DOM element or Ext.Element to check
- * @param {Boolean} related (optional) true to test if the related target is within el instead of the target
- * @param {Boolean} allowEl (optional) true to also check if the passed element is the target or related target
- * @return {Boolean}
- */
- within : function(el, related, allowEl){
- if(el){
- var t = related ? this.getRelatedTarget() : this.getTarget(),
- result;
- if (t) {
- result = Ext.fly(el).contains(t);
- if (!result && allowEl) {
- result = t == Ext.getDom(el);
- }
- return result;
- }
- }
- return false;
- },
- /**
- * Checks if the key pressed was a "navigation" key
- * @return {Boolean} True if the press is a navigation keypress
- */
- isNavKeyPress : function(){
- var me = this,
- k = this.normalizeKey(me.keyCode);
- return (k >= 33 && k <= 40) || // Page Up/Down, End, Home, Left, Up, Right, Down
- k == me.RETURN ||
- k == me.TAB ||
- k == me.ESC;
- },
- /**
- * Checks if the key pressed was a "special" key
- * @return {Boolean} True if the press is a special keypress
- */
- isSpecialKey : function(){
- var k = this.normalizeKey(this.keyCode);
- return (this.type == 'keypress' && this.ctrlKey) ||
- this.isNavKeyPress() ||
- (k == this.BACKSPACE) || // Backspace
- (k >= 16 && k <= 20) || // Shift, Ctrl, Alt, Pause, Caps Lock
- (k >= 44 && k <= 46); // Print Screen, Insert, Delete
- },
- /**
- * Returns a point object that consists of the object coordinates.
- * @return {Ext.util.Point} point
- */
- getPoint : function(){
- var xy = this.getXY();
- return Ext.create('Ext.util.Point', xy[0], xy[1]);
- },
- /**
- * Returns true if the control, meta, shift or alt key was pressed during this event.
- * @return {Boolean}
- */
- hasModifier : function(){
- return this.ctrlKey || this.altKey || this.shiftKey || this.metaKey;
- },
- /**
- * Injects a DOM event using the data in this object and (optionally) a new target.
- * This is a low-level technique and not likely to be used by application code. The
- * currently supported event types are:
- * <p><b>HTMLEvents</b></p>
- * <ul>
- * <li>load</li>
- * <li>unload</li>
- * <li>select</li>
- * <li>change</li>
- * <li>submit</li>
- * <li>reset</li>
- * <li>resize</li>
- * <li>scroll</li>
- * </ul>
- * <p><b>MouseEvents</b></p>
- * <ul>
- * <li>click</li>
- * <li>dblclick</li>
- * <li>mousedown</li>
- * <li>mouseup</li>
- * <li>mouseover</li>
- * <li>mousemove</li>
- * <li>mouseout</li>
- * </ul>
- * <p><b>UIEvents</b></p>
- * <ul>
- * <li>focusin</li>
- * <li>focusout</li>
- * <li>activate</li>
- * <li>focus</li>
- * <li>blur</li>
- * </ul>
- * @param {Ext.Element/HTMLElement} target (optional) If specified, the target for the event. This
- * is likely to be used when relaying a DOM event. If not specified, {@link #getTarget}
- * is used to determine the target.
- */
- injectEvent: function () {
- var API,
- dispatchers = {}; // keyed by event type (e.g., 'mousedown')
- // Good reference: http://developer.yahoo.com/yui/docs/UserAction.js.html
- // IE9 has createEvent, but this code causes major problems with htmleditor (it
- // blocks all mouse events and maybe more). TODO
- if (!Ext.isIE && document.createEvent) { // if (DOM compliant)
- API = {
- createHtmlEvent: function (doc, type, bubbles, cancelable) {
- var event = doc.createEvent('HTMLEvents');
- event.initEvent(type, bubbles, cancelable);
- return event;
- },
- createMouseEvent: function (doc, type, bubbles, cancelable, detail,
- clientX, clientY, ctrlKey, altKey, shiftKey, metaKey,
- button, relatedTarget) {
- var event = doc.createEvent('MouseEvents'),
- view = doc.defaultView || window;
- if (event.initMouseEvent) {
- event.initMouseEvent(type, bubbles, cancelable, view, detail,
- clientX, clientY, clientX, clientY, ctrlKey, altKey,
- shiftKey, metaKey, button, relatedTarget);
- } else { // old Safari
- event = doc.createEvent('UIEvents');
- event.initEvent(type, bubbles, cancelable);
- event.view = view;
- event.detail = detail;
- event.screenX = clientX;
- event.screenY = clientY;
- event.clientX = clientX;
- event.clientY = clientY;
- event.ctrlKey = ctrlKey;
- event.altKey = altKey;
- event.metaKey = metaKey;
- event.shiftKey = shiftKey;
- event.button = button;
- event.relatedTarget = relatedTarget;
- }
- return event;
- },
- createUIEvent: function (doc, type, bubbles, cancelable, detail) {
- var event = doc.createEvent('UIEvents'),
- view = doc.defaultView || window;
- event.initUIEvent(type, bubbles, cancelable, view, detail);
- return event;
- },
- fireEvent: function (target, type, event) {
- target.dispatchEvent(event);
- },
- fixTarget: function (target) {
- // Safari3 doesn't have window.dispatchEvent()
- if (target == window && !target.dispatchEvent) {
- return document;
- }
- return target;
- }
- };
- } else if (document.createEventObject) { // else if (IE)
- var crazyIEButtons = { 0: 1, 1: 4, 2: 2 };
- API = {
- createHtmlEvent: function (doc, type, bubbles, cancelable) {
- var event = doc.createEventObject();
- event.bubbles = bubbles;
- event.cancelable = cancelable;
- return event;
- },
- createMouseEvent: function (doc, type, bubbles, cancelable, detail,
- clientX, clientY, ctrlKey, altKey, shiftKey, metaKey,
- button, relatedTarget) {
- var event = doc.createEventObject();
- event.bubbles = bubbles;
- event.cancelable = cancelable;
- event.detail = detail;
- event.screenX = clientX;
- event.screenY = clientY;
- event.clientX = clientX;
- event.clientY = clientY;
- event.ctrlKey = ctrlKey;
- event.altKey = altKey;
- event.shiftKey = shiftKey;
- event.metaKey = metaKey;
- event.button = crazyIEButtons[button] || button;
- event.relatedTarget = relatedTarget; // cannot assign to/fromElement
- return event;
- },
- createUIEvent: function (doc, type, bubbles, cancelable, detail) {
- var event = doc.createEventObject();
- event.bubbles = bubbles;
- event.cancelable = cancelable;
- return event;
- },
- fireEvent: function (target, type, event) {
- target.fireEvent('on' + type, event);
- },
- fixTarget: function (target) {
- if (target == document) {
- // IE6,IE7 thinks window==document and doesn't have window.fireEvent()
- // IE6,IE7 cannot properly call document.fireEvent()
- return document.documentElement;
- }
- return target;
- }
- };
- }
- //----------------
- // HTMLEvents
- Ext.Object.each({
- load: [false, false],
- unload: [false, false],
- select: [true, false],
- change: [true, false],
- submit: [true, true],
- reset: [true, false],
- resize: [true, false],
- scroll: [true, false]
- },
- function (name, value) {
- var bubbles = value[0], cancelable = value[1];
- dispatchers[name] = function (targetEl, srcEvent) {
- var e = API.createHtmlEvent(name, bubbles, cancelable);
- API.fireEvent(targetEl, name, e);
- };
- });
- //----------------
- // MouseEvents
- function createMouseEventDispatcher (type, detail) {
- var cancelable = (type != 'mousemove');
- return function (targetEl, srcEvent) {
- var xy = srcEvent.getXY(),
- e = API.createMouseEvent(targetEl.ownerDocument, type, true, cancelable,
- detail, xy[0], xy[1], srcEvent.ctrlKey, srcEvent.altKey,
- srcEvent.shiftKey, srcEvent.metaKey, srcEvent.button,
- srcEvent.relatedTarget);
- API.fireEvent(targetEl, type, e);
- };
- }
- Ext.each(['click', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 'mousemove', 'mouseout'],
- function (eventName) {
- dispatchers[eventName] = createMouseEventDispatcher(eventName, 1);
- });
- //----------------
- // UIEvents
- Ext.Object.each({
- focusin: [true, false],
- focusout: [true, false],
- activate: [true, true],
- focus: [false, false],
- blur: [false, false]
- },
- function (name, value) {
- var bubbles = value[0], cancelable = value[1];
- dispatchers[name] = function (targetEl, srcEvent) {
- var e = API.createUIEvent(targetEl.ownerDocument, name, bubbles, cancelable, 1);
- API.fireEvent(targetEl, name, e);
- };
- });
- //---------
- if (!API) {
- // not even sure what ancient browsers fall into this category...
- dispatchers = {}; // never mind all those we just built :P
- API = {
- fixTarget: function (t) {
- return t;
- }
- };
- }
- function cannotInject (target, srcEvent) {
- }
- return function (target) {
- var me = this,
- dispatcher = dispatchers[me.type] || cannotInject,
- t = target ? (target.dom || target) : me.getTarget();
- t = API.fixTarget(t);
- dispatcher(t, me);
- };
- }() // call to produce method
- }, function() {
- Ext.EventObject = new Ext.EventObjectImpl();
- });
- /**
- * @class Ext.Element
- */
- (function(){
- var doc = document,
- activeElement = null,
- isCSS1 = doc.compatMode == "CSS1Compat",
- ELEMENT = Ext.Element,
- fly = function(el){
- if (!_fly) {
- _fly = new Ext.Element.Flyweight();
- }
- _fly.dom = el;
- return _fly;
- }, _fly;
- // If the browser does not support document.activeElement we need some assistance.
- // This covers old Safari 3.2 (4.0 added activeElement along with just about all
- // other browsers). We need this support to handle issues with old Safari.
- if (!('activeElement' in doc) && doc.addEventListener) {
- doc.addEventListener('focus',
- function (ev) {
- if (ev && ev.target) {
- activeElement = (ev.target == doc) ? null : ev.target;
- }
- }, true);
- }
- /*
- * Helper function to create the function that will restore the selection.
- */
- function makeSelectionRestoreFn (activeEl, start, end) {
- return function () {
- activeEl.selectionStart = start;
- activeEl.selectionEnd = end;
- };
- }
- Ext.apply(ELEMENT, {
- isAncestor : function(p, c) {
- var ret = false;
- p = Ext.getDom(p);
- c = Ext.getDom(c);
- if (p && c) {
- if (p.contains) {
- return p.contains(c);
- } else if (p.compareDocumentPosition) {
- return !!(p.compareDocumentPosition(c) & 16);
- } else {
- while ((c = c.parentNode)) {
- ret = c == p || ret;
- }
- }
- }
- return ret;
- },
- /**
- * Returns the active element in the DOM. If the browser supports activeElement
- * on the document, this is returned. If not, the focus is tracked and the active
- * element is maintained internally.
- * @return {HTMLElement} The active (focused) element in the document.
- */
- getActiveElement: function () {
- return doc.activeElement || activeElement;
- },
- /**
- * Creates a function to call to clean up problems with the work-around for the
- * WebKit RightMargin bug. The work-around is to add "display: 'inline-block'" to
- * the element before calling getComputedStyle and then to restore its original
- * display value. The problem with this is that it corrupts the selection of an
- * INPUT or TEXTAREA element (as in the "I-beam" goes away but ths focus remains).
- * To cleanup after this, we need to capture the selection of any such element and
- * then restore it after we have restored the display style.
- *
- * @param target {Element} The top-most element being adjusted.
- * @private
- */
- getRightMarginFixCleaner: function (target) {
- var supports = Ext.supports,
- hasInputBug = supports.DisplayChangeInputSelectionBug,
- hasTextAreaBug = supports.DisplayChangeTextAreaSelectionBug;
- if (hasInputBug || hasTextAreaBug) {
- var activeEl = doc.activeElement || activeElement, // save a call
- tag = activeEl && activeEl.tagName,
- start,
- end;
- if ((hasTextAreaBug && tag == 'TEXTAREA') ||
- (hasInputBug && tag == 'INPUT' && activeEl.type == 'text')) {
- if (ELEMENT.isAncestor(target, activeEl)) {
- start = activeEl.selectionStart;
- end = activeEl.selectionEnd;
- if (Ext.isNumber(start) && Ext.isNumber(end)) { // to be safe...
- // We don't create the raw closure here inline because that
- // will be costly even if we don't want to return it (nested
- // function decls and exprs are often instantiated on entry
- // regardless of whether execution ever reaches them):
- return makeSelectionRestoreFn(activeEl, start, end);
- }
- }
- }
- }
- return Ext.emptyFn; // avoid special cases, just return a nop
- },
- getViewWidth : function(full) {
- return full ? ELEMENT.getDocumentWidth() : ELEMENT.getViewportWidth();
- },
- getViewHeight : function(full) {
- return full ? ELEMENT.getDocumentHeight() : ELEMENT.getViewportHeight();
- },
- getDocumentHeight: function() {
- return Math.max(!isCSS1 ? doc.body.scrollHeight : doc.documentElement.scrollHeight, ELEMENT.getViewportHeight());
- },
- getDocumentWidth: function() {
- return Math.max(!isCSS1 ? doc.body.scrollWidth : doc.documentElement.scrollWidth, ELEMENT.getViewportWidth());
- },
- getViewportHeight: function(){
- return Ext.isIE ?
- (Ext.isStrict ? doc.documentElement.clientHeight : doc.body.clientHeight) :
- self.innerHeight;
- },
- getViewportWidth : function() {
- return (!Ext.isStrict && !Ext.isOpera) ? doc.body.clientWidth :
- Ext.isIE ? doc.documentElement.clientWidth : self.innerWidth;
- },
- getY : function(el) {
- return ELEMENT.getXY(el)[1];
- },
- getX : function(el) {
- return ELEMENT.getXY(el)[0];
- },
- getOffsetParent: function (el) {
- el = Ext.getDom(el);
- try {
- // accessing offsetParent can throw "Unspecified Error" in IE6-8 (not 9)
- return el.offsetParent;
- } catch (e) {
- var body = document.body; // safe bet, unless...
- return (el == body) ? null : body;
- }
- },
- getXY : function(el) {
- var p,
- pe,
- b,
- bt,
- bl,
- dbd,
- x = 0,
- y = 0,
- scroll,
- hasAbsolute,
- bd = (doc.body || doc.documentElement),
- ret;
- el = Ext.getDom(el);
- if(el != bd){
- hasAbsolute = fly(el).isStyle("position", "absolute");
- if (el.getBoundingClientRect) {
- try {
- b = el.getBoundingClientRect();
- scroll = fly(document).getScroll();
- ret = [ Math.round(b.left + scroll.left), Math.round(b.top + scroll.top) ];
- } catch (e) {
- // IE6-8 can also throw from getBoundingClientRect...
- }
- }
- if (!ret) {
- for (p = el; p; p = ELEMENT.getOffsetParent(p)) {
- pe = fly(p);
- x += p.offsetLeft;
- y += p.offsetTop;
- hasAbsolute = hasAbsolute || pe.isStyle("position", "absolute");
- if (Ext.isGecko) {
- y += bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
- x += bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
- if (p != el && !pe.isStyle('overflow','visible')) {
- x += bl;
- y += bt;
- }
- }
- }
- if (Ext.isSafari && hasAbsolute) {
- x -= bd.offsetLeft;
- y -= bd.offsetTop;
- }
- if (Ext.isGecko && !hasAbsolute) {
- dbd = fly(bd);
- x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
- y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
- }
- p = el.parentNode;
- while (p && p != bd) {
- if (!Ext.isOpera || (p.tagName != 'TR' && !fly(p).isStyle("display", "inline"))) {
- x -= p.scrollLeft;
- y -= p.scrollTop;
- }
- p = p.parentNode;
- }
- ret = [x,y];
- }
- }
- return ret || [0,0];
- },
- setXY : function(el, xy) {
- (el = Ext.fly(el, '_setXY')).position();
- var pts = el.translatePoints(xy),
- style = el.dom.style,
- pos;
- for (pos in pts) {
- if (!isNaN(pts[pos])) {
- style[pos] = pts[pos] + "px";
- }
- }
- },
- setX : function(el, x) {
- ELEMENT.setXY(el, [x, false]);
- },
- setY : function(el, y) {
- ELEMENT.setXY(el, [false, y]);
- },
- /**
- * Serializes a DOM form into a url encoded string
- * @param {Object} form The form
- * @return {String} The url encoded form
- */
- serializeForm: function(form) {
- var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements,
- hasSubmit = false,
- encoder = encodeURIComponent,
- name,
- data = '',
- type,
- hasValue;
- Ext.each(fElements, function(element){
- name = element.name;
- type = element.type;
- if (!element.disabled && name) {
- if (/select-(one|multiple)/i.test(type)) {
- Ext.each(element.options, function(opt){
- if (opt.selected) {
- hasValue = opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttributeNode('value').specified;
- data += Ext.String.format("{0}={1}&", encoder(name), encoder(hasValue ? opt.value : opt.text));
- }
- });
- } else if (!(/file|undefined|reset|button/i.test(type))) {
- if (!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit)) {
- data += encoder(name) + '=' + encoder(element.value) + '&';
- hasSubmit = /submit/i.test(type);
- }
- }
- }
- });
- return data.substr(0, data.length - 1);
- }
- });
- })();
- /**
- * @class Ext.Element
- */
- Ext.Element.addMethods((function(){
- var focusRe = /button|input|textarea|select|object/;
- return {
- /**
- * Monitors this Element for the mouse leaving. Calls the function after the specified delay only if
- * the mouse was not moved back into the Element within the delay. If the mouse <i>was</i> moved
- * back in, the function is not called.
- * @param {Number} delay The delay <b>in milliseconds</b> to wait for possible mouse re-entry before calling the handler function.
- * @param {Function} handler The function to call if the mouse remains outside of this Element for the specified time.
- * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to this Element.
- * @return {Object} The listeners object which was added to this element so that monitoring can be stopped. Example usage:<pre><code>
- // Hide the menu if the mouse moves out for 250ms or more
- this.mouseLeaveMonitor = this.menuEl.monitorMouseLeave(250, this.hideMenu, this);
- ...
- // Remove mouseleave monitor on menu destroy
- this.menuEl.un(this.mouseLeaveMonitor);
- </code></pre>
- */
- monitorMouseLeave: function(delay, handler, scope) {
- var me = this,
- timer,
- listeners = {
- mouseleave: function(e) {
- timer = setTimeout(Ext.Function.bind(handler, scope||me, [e]), delay);
- },
- mouseenter: function() {
- clearTimeout(timer);
- },
- freezeEvent: true
- };
- me.on(listeners);
- return listeners;
- },
- /**
- * Stops the specified event(s) from bubbling and optionally prevents the default action
- * @param {String/String[]} eventName an event / array of events to stop from bubbling
- * @param {Boolean} preventDefault (optional) true to prevent the default action too
- * @return {Ext.Element} this
- */
- swallowEvent : function(eventName, preventDefault) {
- var me = this;
- function fn(e) {
- e.stopPropagation();
- if (preventDefault) {
- e.preventDefault();
- }
- }
- if (Ext.isArray(eventName)) {
- Ext.each(eventName, function(e) {
- me.on(e, fn);
- });
- return me;
- }
- me.on(eventName, fn);
- return me;
- },
- /**
- * Create an event handler on this element such that when the event fires and is handled by this element,
- * it will be relayed to another object (i.e., fired again as if it originated from that object instead).
- * @param {String} eventName The type of event to relay
- * @param {Object} object Any object that extends {@link Ext.util.Observable} that will provide the context
- * for firing the relayed event
- */
- relayEvent : function(eventName, observable) {
- this.on(eventName, function(e) {
- observable.fireEvent(eventName, e);
- });
- },
- /**
- * Removes Empty, or whitespace filled text nodes. Combines adjacent text nodes.
- * @param {Boolean} forceReclean (optional) By default the element
- * keeps track if it has been cleaned already so
- * you can call this over and over. However, if you update the element and
- * need to force a reclean, you can pass true.
- */
- clean : function(forceReclean) {
- var me = this,
- dom = me.dom,
- n = dom.firstChild,
- nx,
- ni = -1;
-
- if (Ext.Element.data(dom, 'isCleaned') && forceReclean !== true) {
- return me;
- }
- while (n) {
- nx = n.nextSibling;
- if (n.nodeType == 3) {
- // Remove empty/whitespace text nodes
- if (!(/\S/.test(n.nodeValue))) {
- dom.removeChild(n);
- // Combine adjacent text nodes
- } else if (nx && nx.nodeType == 3) {
- n.appendData(Ext.String.trim(nx.data));
- dom.removeChild(nx);
- nx = n.nextSibling;
- n.nodeIndex = ++ni;
- }
- } else {
- // Recursively clean
- Ext.fly(n).clean();
- n.nodeIndex = ++ni;
- }
- n = nx;
- }
- Ext.Element.data(dom, 'isCleaned', true);
- return me;
- },
- /**
- * Direct access to the Ext.ElementLoader {@link Ext.ElementLoader#load} method. The method takes the same object
- * parameter as {@link Ext.ElementLoader#load}
- * @return {Ext.Element} this
- */
- load : function(options) {
- this.getLoader().load(options);
- return this;
- },
- /**
- * Gets this element's {@link Ext.ElementLoader ElementLoader}
- * @return {Ext.ElementLoader} The loader
- */
- getLoader : function() {
- var dom = this.dom,
- data = Ext.Element.data,
- loader = data(dom, 'loader');
-
- if (!loader) {
- loader = Ext.create('Ext.ElementLoader', {
- target: this
- });
- data(dom, 'loader', loader);
- }
- return loader;
- },
- /**
- * Update the innerHTML of this element, optionally searching for and processing scripts
- * @param {String} html The new HTML
- * @param {Boolean} [loadScripts=false] True to look for and process scripts
- * @param {Function} [callback] For async script loading you can be notified when the update completes
- * @return {Ext.Element} this
- */
- update : function(html, loadScripts, callback) {
- var me = this,
- id,
- dom,
- interval;
- if (!me.dom) {
- return me;
- }
- html = html || '';
- dom = me.dom;
- if (loadScripts !== true) {
- dom.innerHTML = html;
- Ext.callback(callback, me);
- return me;
- }
- id = Ext.id();
- html += '<span id="' + id + '"></span>';
- interval = setInterval(function(){
- if (!document.getElementById(id)) {
- return false;
- }
- clearInterval(interval);
- var DOC = document,
- hd = DOC.getElementsByTagName("head")[0],
- re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig,
- srcRe = /\ssrc=([\'\"])(.*?)\1/i,
- typeRe = /\stype=([\'\"])(.*?)\1/i,
- match,
- attrs,
- srcMatch,
- typeMatch,
- el,
- s;
- while ((match = re.exec(html))) {
- attrs = match[1];
- srcMatch = attrs ? attrs.match(srcRe) : false;
- if (srcMatch && srcMatch[2]) {
- s = DOC.createElement("script");
- s.src = srcMatch[2];
- typeMatch = attrs.match(typeRe);
- if (typeMatch && typeMatch[2]) {
- s.type = typeMatch[2];
- }
- hd.appendChild(s);
- } else if (match[2] && match[2].length > 0) {
- if (window.execScript) {
- window.execScript(match[2]);
- } else {
- window.eval(match[2]);
- }
- }
- }
- el = DOC.getElementById(id);
- if (el) {
- Ext.removeNode(el);
- }
- Ext.callback(callback, me);
- }, 20);
- dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, '');
- return me;
- },
- // inherit docs, overridden so we can add removeAnchor
- removeAllListeners : function() {
- this.removeAnchor();
- Ext.EventManager.removeAll(this.dom);
- return this;
- },
-
- /**
- * Gets the parent node of the current element taking into account Ext.scopeResetCSS
- * @protected
- * @return {HTMLElement} The parent element
- */
- getScopeParent: function(){
- var parent = this.dom.parentNode;
- return Ext.scopeResetCSS ? parent.parentNode : parent;
- },
- /**
- * Creates a proxy element of this element
- * @param {String/Object} config The class name of the proxy element or a DomHelper config object
- * @param {String/HTMLElement} [renderTo] The element or element id to render the proxy to (defaults to document.body)
- * @param {Boolean} [matchBox=false] True to align and size the proxy to this element now.
- * @return {Ext.Element} The new proxy element
- */
- createProxy : function(config, renderTo, matchBox) {
- config = (typeof config == 'object') ? config : {tag : "div", cls: config};
- var me = this,
- proxy = renderTo ? Ext.DomHelper.append(renderTo, config, true) :
- Ext.DomHelper.insertBefore(me.dom, config, true);
- proxy.setVisibilityMode(Ext.Element.DISPLAY);
- proxy.hide();
- if (matchBox && me.setBox && me.getBox) { // check to make sure Element.position.js is loaded
- proxy.setBox(me.getBox());
- }
- return proxy;
- },
-
- /**
- * Checks whether this element can be focused.
- * @return {Boolean} True if the element is focusable
- */
- focusable: function(){
- var dom = this.dom,
- nodeName = dom.nodeName.toLowerCase(),
- canFocus = false,
- hasTabIndex = !isNaN(dom.tabIndex);
-
- if (!dom.disabled) {
- if (focusRe.test(nodeName)) {
- canFocus = true;
- } else {
- canFocus = nodeName == 'a' ? dom.href || hasTabIndex : hasTabIndex;
- }
- }
- return canFocus && this.isVisible(true);
- }
- };
- })());
- Ext.Element.prototype.clearListeners = Ext.Element.prototype.removeAllListeners;
- /**
- * @class Ext.Element
- */
- Ext.Element.addMethods({
- /**
- * Gets the x,y coordinates specified by the anchor position on the element.
- * @param {String} [anchor='c'] The specified anchor position. See {@link #alignTo}
- * for details on supported anchor positions.
- * @param {Boolean} [local] True to get the local (element top/left-relative) anchor position instead
- * of page coordinates
- * @param {Object} [size] An object containing the size to use for calculating anchor position
- * {width: (target width), height: (target height)} (defaults to the element's current size)
- * @return {Number[]} [x, y] An array containing the element's x and y coordinates
- */
- getAnchorXY : function(anchor, local, s){
- //Passing a different size is useful for pre-calculating anchors,
- //especially for anchored animations that change the el size.
- anchor = (anchor || "tl").toLowerCase();
- s = s || {};
- var me = this,
- vp = me.dom == document.body || me.dom == document,
- w = s.width || vp ? Ext.Element.getViewWidth() : me.getWidth(),
- h = s.height || vp ? Ext.Element.getViewHeight() : me.getHeight(),
- xy,
- r = Math.round,
- o = me.getXY(),
- scroll = me.getScroll(),
- extraX = vp ? scroll.left : !local ? o[0] : 0,
- extraY = vp ? scroll.top : !local ? o[1] : 0,
- hash = {
- c : [r(w * 0.5), r(h * 0.5)],
- t : [r(w * 0.5), 0],
- l : [0, r(h * 0.5)],
- r : [w, r(h * 0.5)],
- b : [r(w * 0.5), h],
- tl : [0, 0],
- bl : [0, h],
- br : [w, h],
- tr : [w, 0]
- };
- xy = hash[anchor];
- return [xy[0] + extraX, xy[1] + extraY];
- },
- /**
- * Anchors an element to another element and realigns it when the window is resized.
- * @param {String/HTMLElement/Ext.Element} element The element to align to.
- * @param {String} position The position to align to.
- * @param {Number[]} [offsets] Offset the positioning by [x, y]
- * @param {Boolean/Object} [animate] True for the default animation or a standard Element animation config object
- * @param {Boolean/Number} [monitorScroll] True to monitor body scroll and reposition. If this parameter
- * is a number, it is used as the buffer delay (defaults to 50ms).
- * @param {Function} [callback] The function to call after the animation finishes
- * @return {Ext.Element} this
- */
- anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback){
- var me = this,
- dom = me.dom,
- scroll = !Ext.isEmpty(monitorScroll),
- action = function(){
- Ext.fly(dom).alignTo(el, alignment, offsets, animate);
- Ext.callback(callback, Ext.fly(dom));
- },
- anchor = this.getAnchor();
- // previous listener anchor, remove it
- this.removeAnchor();
- Ext.apply(anchor, {
- fn: action,
- scroll: scroll
- });
- Ext.EventManager.onWindowResize(action, null);
- if(scroll){
- Ext.EventManager.on(window, 'scroll', action, null,
- {buffer: !isNaN(monitorScroll) ? monitorScroll : 50});
- }
- action.call(me); // align immediately
- return me;
- },
- /**
- * Remove any anchor to this element. See {@link #anchorTo}.
- * @return {Ext.Element} this
- */
- removeAnchor : function(){
- var me = this,
- anchor = this.getAnchor();
- if(anchor && anchor.fn){
- Ext.EventManager.removeResizeListener(anchor.fn);
- if(anchor.scroll){
- Ext.EventManager.un(window, 'scroll', anchor.fn);
- }
- delete anchor.fn;
- }
- return me;
- },
- // private
- getAnchor : function(){
- var data = Ext.Element.data,
- dom = this.dom;
- if (!dom) {
- return;
- }
- var anchor = data(dom, '_anchor');
- if(!anchor){
- anchor = data(dom, '_anchor', {});
- }
- return anchor;
- },
- getAlignVector: function(el, spec, offset) {
- var me = this,
- side = {t:"top", l:"left", r:"right", b: "bottom"},
- thisRegion = me.getRegion(),
- elRegion;
- el = Ext.get(el);
- if(!el || !el.dom){
- }
- elRegion = el.getRegion();
- },
- /**
- * Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the
- * supported position values.
- * @param {String/HTMLElement/Ext.Element} element The element to align to.
- * @param {String} [position="tl-bl?"] The position to align to (defaults to )
- * @param {Number[]} [offsets] Offset the positioning by [x, y]
- * @return {Number[]} [x, y]
- */
- getAlignToXY : function(el, p, o){
- el = Ext.get(el);
- if(!el || !el.dom){
- }
- o = o || [0,0];
- p = (!p || p == "?" ? "tl-bl?" : (!(/-/).test(p) && p !== "" ? "tl-" + p : p || "tl-bl")).toLowerCase();
- var me = this,
- d = me.dom,
- a1,
- a2,
- x,
- y,
- //constrain the aligned el to viewport if necessary
- w,
- h,
- r,
- dw = Ext.Element.getViewWidth() -10, // 10px of margin for ie
- dh = Ext.Element.getViewHeight()-10, // 10px of margin for ie
- p1y,
- p1x,
- p2y,
- p2x,
- swapY,
- swapX,
- doc = document,
- docElement = doc.documentElement,
- docBody = doc.body,
- scrollX = (docElement.scrollLeft || docBody.scrollLeft || 0)+5,
- scrollY = (docElement.scrollTop || docBody.scrollTop || 0)+5,
- c = false, //constrain to viewport
- p1 = "",
- p2 = "",
- m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/);
- if(!m){
- }
- p1 = m[1];
- p2 = m[2];
- c = !!m[3];
- //Subtract the aligned el's internal xy from the target's offset xy
- //plus custom offset to get the aligned el's new offset xy
- a1 = me.getAnchorXY(p1, true);
- a2 = el.getAnchorXY(p2, false);
- x = a2[0] - a1[0] + o[0];
- y = a2[1] - a1[1] + o[1];
- if(c){
- w = me.getWidth();
- h = me.getHeight();
- r = el.getRegion();
- //If we are at a viewport boundary and the aligned el is anchored on a target border that is
- //perpendicular to the vp border, allow the aligned el to slide on that border,
- //otherwise swap the aligned el to the opposite border of the target.
- p1y = p1.charAt(0);
- p1x = p1.charAt(p1.length-1);
- p2y = p2.charAt(0);
- p2x = p2.charAt(p2.length-1);
- swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t"));
- swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r"));
- if (x + w > dw + scrollX) {
- x = swapX ? r.left-w : dw+scrollX-w;
- }
- if (x < scrollX) {
- x = swapX ? r.right : scrollX;
- }
- if (y + h > dh + scrollY) {
- y = swapY ? r.top-h : dh+scrollY-h;
- }
- if (y < scrollY){
- y = swapY ? r.bottom : scrollY;
- }
- }
- return [x,y];
- },
- /**
- * Aligns this element with another element relative to the specified anchor points. If the other element is the
- * document it aligns it to the viewport.
- * The position parameter is optional, and can be specified in any one of the following formats:
- * <ul>
- * <li><b>Blank</b>: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").</li>
- * <li><b>One anchor (deprecated)</b>: The passed anchor position is used as the target element's anchor point.
- * The element being aligned will position its top-left corner (tl) to that point. <i>This method has been
- * deprecated in favor of the newer two anchor syntax below</i>.</li>
- * <li><b>Two anchors</b>: If two values from the table below are passed separated by a dash, the first value is used as the
- * element's anchor point, and the second value is used as the target's anchor point.</li>
- * </ul>
- * In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of
- * the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to
- * the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than
- * that specified in order to enforce the viewport constraints.
- * Following are all of the supported anchor positions:
- <pre>
- Value Description
- ----- -----------------------------
- tl The top left corner (default)
- t The center of the top edge
- tr The top right corner
- l The center of the left edge
- c In the center of the element
- r The center of the right edge
- bl The bottom left corner
- b The center of the bottom edge
- br The bottom right corner
- </pre>
- Example Usage:
- <pre><code>
- // align el to other-el using the default positioning ("tl-bl", non-constrained)
- el.alignTo("other-el");
- // align the top left corner of el with the top right corner of other-el (constrained to viewport)
- el.alignTo("other-el", "tr?");
- // align the bottom right corner of el with the center left edge of other-el
- el.alignTo("other-el", "br-l?");
- // align the center of el with the bottom left corner of other-el and
- // adjust the x position by -6 pixels (and the y position by 0)
- el.alignTo("other-el", "c-bl", [-6, 0]);
- </code></pre>
- * @param {String/HTMLElement/Ext.Element} element The element to align to.
- * @param {String} [position="tl-bl?"] The position to align to
- * @param {Number[]} [offsets] Offset the positioning by [x, y]
- * @param {Boolean/Object} [animate] true for the default animation or a standard Element animation config object
- * @return {Ext.Element} this
- */
- alignTo : function(element, position, offsets, animate){
- var me = this;
- return me.setXY(me.getAlignToXY(element, position, offsets),
- me.anim && !!animate ? me.anim(animate) : false);
- },
- // private ==> used outside of core
- adjustForConstraints : function(xy, parent) {
- var vector = this.getConstrainVector(parent, xy);
- if (vector) {
- xy[0] += vector[0];
- xy[1] += vector[1];
- }
- return xy;
- },
- /**
- * <p>Returns the <code>[X, Y]</code> vector by which this element must be translated to make a best attempt
- * to constrain within the passed constraint. Returns <code>false</code> is this element does not need to be moved.</p>
- * <p>Priority is given to constraining the top and left within the constraint.</p>
- * <p>The constraint may either be an existing element into which this element is to be constrained, or
- * an {@link Ext.util.Region Region} into which this element is to be constrained.</p>
- * @param constrainTo {Mixed} The Element or {@link Ext.util.Region Region} into which this element is to be constrained.
- * @param proposedPosition {Array} A proposed <code>[X, Y]</code> position to test for validity and to produce a vector for instead
- * of using this Element's current position;
- * @returns {Number[]/Boolean} <b>If</b> this element <i>needs</i> to be translated, an <code>[X, Y]</code>
- * vector by which this element must be translated. Otherwise, <code>false</code>.
- */
- getConstrainVector: function(constrainTo, proposedPosition) {
- if (!(constrainTo instanceof Ext.util.Region)) {
- constrainTo = Ext.get(constrainTo).getViewRegion();
- }
- var thisRegion = this.getRegion(),
- vector = [0, 0],
- shadowSize = this.shadow && this.shadow.offset,
- overflowed = false;
- // Shift this region to occupy the proposed position
- if (proposedPosition) {
- thisRegion.translateBy(proposedPosition[0] - thisRegion.x, proposedPosition[1] - thisRegion.y);
- }
- // Reduce the constrain region to allow for shadow
- // TODO: Rewrite the Shadow class. When that's done, get the extra for each side from the Shadow.
- if (shadowSize) {
- constrainTo.adjust(0, -shadowSize, -shadowSize, shadowSize);
- }
- // Constrain the X coordinate by however much this Element overflows
- if (thisRegion.right > constrainTo.right) {
- overflowed = true;
- vector[0] = (constrainTo.right - thisRegion.right); // overflowed the right
- }
- if (thisRegion.left + vector[0] < constrainTo.left) {
- overflowed = true;
- vector[0] = (constrainTo.left - thisRegion.left); // overflowed the left
- }
- // Constrain the Y coordinate by however much this Element overflows
- if (thisRegion.bottom > constrainTo.bottom) {
- overflowed = true;
- vector[1] = (constrainTo.bottom - thisRegion.bottom); // overflowed the bottom
- }
- if (thisRegion.top + vector[1] < constrainTo.top) {
- overflowed = true;
- vector[1] = (constrainTo.top - thisRegion.top); // overflowed the top
- }
- return overflowed ? vector : false;
- },
- /**
- * Calculates the x, y to center this element on the screen
- * @return {Number[]} The x, y values [x, y]
- */
- getCenterXY : function(){
- return this.getAlignToXY(document, 'c-c');
- },
- /**
- * Centers the Element in either the viewport, or another Element.
- * @param {String/HTMLElement/Ext.Element} centerIn (optional) The element in which to center the element.
- */
- center : function(centerIn){
- return this.alignTo(centerIn || document, 'c-c');
- }
- });
- /**
- * @class Ext.Element
- */
- (function(){
- var ELEMENT = Ext.Element,
- LEFT = "left",
- RIGHT = "right",
- TOP = "top",
- BOTTOM = "bottom",
- POSITION = "position",
- STATIC = "static",
- RELATIVE = "relative",
- AUTO = "auto",
- ZINDEX = "z-index";
- Ext.override(Ext.Element, {
- /**
- * Gets the current X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
- * @return {Number} The X position of the element
- */
- getX : function(){
- return ELEMENT.getX(this.dom);
- },
- /**
- * Gets the current Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
- * @return {Number} The Y position of the element
- */
- getY : function(){
- return ELEMENT.getY(this.dom);
- },
- /**
- * Gets the current position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
- * @return {Number[]} The XY position of the element
- */
- getXY : function(){
- return ELEMENT.getXY(this.dom);
- },
- /**
- * Returns the offsets of this element from the passed element. Both element must be part of the DOM tree and not have display:none to have page coordinates.
- * @param {String/HTMLElement/Ext.Element} element The element to get the offsets from.
- * @return {Number[]} The XY page offsets (e.g. [100, -200])
- */
- getOffsetsTo : function(el){
- var o = this.getXY(),
- e = Ext.fly(el, '_internal').getXY();
- return [o[0]-e[0],o[1]-e[1]];
- },
- /**
- * Sets the X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
- * @param {Number} The X position of the element
- * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
- * @return {Ext.Element} this
- */
- setX : function(x, animate){
- return this.setXY([x, this.getY()], animate);
- },
- /**
- * Sets the Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
- * @param {Number} The Y position of the element
- * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
- * @return {Ext.Element} this
- */
- setY : function(y, animate){
- return this.setXY([this.getX(), y], animate);
- },
- /**
- * Sets the element's left position directly using CSS style (instead of {@link #setX}).
- * @param {String} left The left CSS property value
- * @return {Ext.Element} this
- */
- setLeft : function(left){
- this.setStyle(LEFT, this.addUnits(left));
- return this;
- },
- /**
- * Sets the element's top position directly using CSS style (instead of {@link #setY}).
- * @param {String} top The top CSS property value
- * @return {Ext.Element} this
- */
- setTop : function(top){
- this.setStyle(TOP, this.addUnits(top));
- return this;
- },
- /**
- * Sets the element's CSS right style.
- * @param {String} right The right CSS property value
- * @return {Ext.Element} this
- */
- setRight : function(right){
- this.setStyle(RIGHT, this.addUnits(right));
- return this;
- },
- /**
- * Sets the element's CSS bottom style.
- * @param {String} bottom The bottom CSS property value
- * @return {Ext.Element} this
- */
- setBottom : function(bottom){
- this.setStyle(BOTTOM, this.addUnits(bottom));
- return this;
- },
- /**
- * Sets the position of the element in page coordinates, regardless of how the element is positioned.
- * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
- * @param {Number[]} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
- * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
- * @return {Ext.Element} this
- */
- setXY: function(pos, animate) {
- var me = this;
- if (!animate || !me.anim) {
- ELEMENT.setXY(me.dom, pos);
- }
- else {
- if (!Ext.isObject(animate)) {
- animate = {};
- }
- me.animate(Ext.applyIf({ to: { x: pos[0], y: pos[1] } }, animate));
- }
- return me;
- },
- /**
- * Sets the position of the element in page coordinates, regardless of how the element is positioned.
- * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
- * @param {Number} x X value for new position (coordinates are page-based)
- * @param {Number} y Y value for new position (coordinates are page-based)
- * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
- * @return {Ext.Element} this
- */
- setLocation : function(x, y, animate){
- return this.setXY([x, y], animate);
- },
- /**
- * Sets the position of the element in page coordinates, regardless of how the element is positioned.
- * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
- * @param {Number} x X value for new position (coordinates are page-based)
- * @param {Number} y Y value for new position (coordinates are page-based)
- * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
- * @return {Ext.Element} this
- */
- moveTo : function(x, y, animate){
- return this.setXY([x, y], animate);
- },
- /**
- * Gets the left X coordinate
- * @param {Boolean} local True to get the local css position instead of page coordinate
- * @return {Number}
- */
- getLeft : function(local){
- return !local ? this.getX() : parseInt(this.getStyle(LEFT), 10) || 0;
- },
- /**
- * Gets the right X coordinate of the element (element X position + element width)
- * @param {Boolean} local True to get the local css position instead of page coordinate
- * @return {Number}
- */
- getRight : function(local){
- var me = this;
- return !local ? me.getX() + me.getWidth() : (me.getLeft(true) + me.getWidth()) || 0;
- },
- /**
- * Gets the top Y coordinate
- * @param {Boolean} local True to get the local css position instead of page coordinate
- * @return {Number}
- */
- getTop : function(local) {
- return !local ? this.getY() : parseInt(this.getStyle(TOP), 10) || 0;
- },
- /**
- * Gets the bottom Y coordinate of the element (element Y position + element height)
- * @param {Boolean} local True to get the local css position instead of page coordinate
- * @return {Number}
- */
- getBottom : function(local){
- var me = this;
- return !local ? me.getY() + me.getHeight() : (me.getTop(true) + me.getHeight()) || 0;
- },
- /**
- * Initializes positioning on this element. If a desired position is not passed, it will make the
- * the element positioned relative IF it is not already positioned.
- * @param {String} pos (optional) Positioning to use "relative", "absolute" or "fixed"
- * @param {Number} zIndex (optional) The zIndex to apply
- * @param {Number} x (optional) Set the page X position
- * @param {Number} y (optional) Set the page Y position
- */
- position : function(pos, zIndex, x, y) {
- var me = this;
- if (!pos && me.isStyle(POSITION, STATIC)){
- me.setStyle(POSITION, RELATIVE);
- } else if(pos) {
- me.setStyle(POSITION, pos);
- }
- if (zIndex){
- me.setStyle(ZINDEX, zIndex);
- }
- if (x || y) {
- me.setXY([x || false, y || false]);
- }
- },
- /**
- * Clear positioning back to the default when the document was loaded
- * @param {String} value (optional) The value to use for the left,right,top,bottom, defaults to '' (empty string). You could use 'auto'.
- * @return {Ext.Element} this
- */
- clearPositioning : function(value){
- value = value || '';
- this.setStyle({
- left : value,
- right : value,
- top : value,
- bottom : value,
- "z-index" : "",
- position : STATIC
- });
- return this;
- },
- /**
- * Gets an object with all CSS positioning properties. Useful along with setPostioning to get
- * snapshot before performing an update and then restoring the element.
- * @return {Object}
- */
- getPositioning : function(){
- var l = this.getStyle(LEFT);
- var t = this.getStyle(TOP);
- return {
- "position" : this.getStyle(POSITION),
- "left" : l,
- "right" : l ? "" : this.getStyle(RIGHT),
- "top" : t,
- "bottom" : t ? "" : this.getStyle(BOTTOM),
- "z-index" : this.getStyle(ZINDEX)
- };
- },
- /**
- * Set positioning with an object returned by getPositioning().
- * @param {Object} posCfg
- * @return {Ext.Element} this
- */
- setPositioning : function(pc){
- var me = this,
- style = me.dom.style;
- me.setStyle(pc);
- if(pc.right == AUTO){
- style.right = "";
- }
- if(pc.bottom == AUTO){
- style.bottom = "";
- }
- return me;
- },
- /**
- * Translates the passed page coordinates into left/top css values for this element
- * @param {Number/Number[]} x The page x or an array containing [x, y]
- * @param {Number} y (optional) The page y, required if x is not an array
- * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
- */
- translatePoints: function(x, y) {
- if (Ext.isArray(x)) {
- y = x[1];
- x = x[0];
- }
- var me = this,
- relative = me.isStyle(POSITION, RELATIVE),
- o = me.getXY(),
- left = parseInt(me.getStyle(LEFT), 10),
- top = parseInt(me.getStyle(TOP), 10);
- if (!Ext.isNumber(left)) {
- left = relative ? 0 : me.dom.offsetLeft;
- }
- if (!Ext.isNumber(top)) {
- top = relative ? 0 : me.dom.offsetTop;
- }
- left = (Ext.isNumber(x)) ? x - o[0] + left : undefined;
- top = (Ext.isNumber(y)) ? y - o[1] + top : undefined;
- return {
- left: left,
- top: top
- };
- },
- /**
- * Sets the element's box. Use getBox() on another element to get a box obj. If animate is true then width, height, x and y will be animated concurrently.
- * @param {Object} box The box to fill {x, y, width, height}
- * @param {Boolean} adjust (optional) Whether to adjust for box-model issues automatically
- * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
- * @return {Ext.Element} this
- */
- setBox: function(box, adjust, animate) {
- var me = this,
- w = box.width,
- h = box.height;
- if ((adjust && !me.autoBoxAdjust) && !me.isBorderBox()) {
- w -= (me.getBorderWidth("lr") + me.getPadding("lr"));
- h -= (me.getBorderWidth("tb") + me.getPadding("tb"));
- }
- me.setBounds(box.x, box.y, w, h, animate);
- return me;
- },
- /**
- * Return an object defining the area of this Element which can be passed to {@link #setBox} to
- * set another Element's size/location to match this element.
- * @param {Boolean} contentBox (optional) If true a box for the content of the element is returned.
- * @param {Boolean} local (optional) If true the element's left and top are returned instead of page x/y.
- * @return {Object} box An object in the format<pre><code>
- {
- x: <Element's X position>,
- y: <Element's Y position>,
- width: <Element's width>,
- height: <Element's height>,
- bottom: <Element's lower bound>,
- right: <Element's rightmost bound>
- }
- </code></pre>
- * The returned object may also be addressed as an Array where index 0 contains the X position
- * and index 1 contains the Y position. So the result may also be used for {@link #setXY}
- */
- getBox: function(contentBox, local) {
- var me = this,
- xy,
- left,
- top,
- getBorderWidth = me.getBorderWidth,
- getPadding = me.getPadding,
- l, r, t, b, w, h, bx;
- if (!local) {
- xy = me.getXY();
- } else {
- left = parseInt(me.getStyle("left"), 10) || 0;
- top = parseInt(me.getStyle("top"), 10) || 0;
- xy = [left, top];
- }
- w = me.getWidth();
- h = me.getHeight();
- if (!contentBox) {
- bx = {
- x: xy[0],
- y: xy[1],
- 0: xy[0],
- 1: xy[1],
- width: w,
- height: h
- };
- } else {
- l = getBorderWidth.call(me, "l") + getPadding.call(me, "l");
- r = getBorderWidth.call(me, "r") + getPadding.call(me, "r");
- t = getBorderWidth.call(me, "t") + getPadding.call(me, "t");
- b = getBorderWidth.call(me, "b") + getPadding.call(me, "b");
- bx = {
- x: xy[0] + l,
- y: xy[1] + t,
- 0: xy[0] + l,
- 1: xy[1] + t,
- width: w - (l + r),
- height: h - (t + b)
- };
- }
- bx.right = bx.x + bx.width;
- bx.bottom = bx.y + bx.height;
- return bx;
- },
- /**
- * Move this element relative to its current position.
- * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down").
- * @param {Number} distance How far to move the element in pixels
- * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
- */
- move: function(direction, distance, animate) {
- var me = this,
- xy = me.getXY(),
- x = xy[0],
- y = xy[1],
- left = [x - distance, y],
- right = [x + distance, y],
- top = [x, y - distance],
- bottom = [x, y + distance],
- hash = {
- l: left,
- left: left,
- r: right,
- right: right,
- t: top,
- top: top,
- up: top,
- b: bottom,
- bottom: bottom,
- down: bottom
- };
- direction = direction.toLowerCase();
- me.moveTo(hash[direction][0], hash[direction][1], animate);
- },
- /**
- * Quick set left and top adding default units
- * @param {String} left The left CSS property value
- * @param {String} top The top CSS property value
- * @return {Ext.Element} this
- */
- setLeftTop: function(left, top) {
- var me = this,
- style = me.dom.style;
- style.left = me.addUnits(left);
- style.top = me.addUnits(top);
- return me;
- },
- /**
- * Returns the region of this element.
- * The element must be part of the DOM tree to have a region (display:none or elements not appended return false).
- * @return {Ext.util.Region} A Region containing "top, left, bottom, right" member data.
- */
- getRegion: function() {
- return this.getPageBox(true);
- },
- /**
- * Returns the <b>content</b> region of this element. That is the region within the borders and padding.
- * @return {Ext.util.Region} A Region containing "top, left, bottom, right" member data.
- */
- getViewRegion: function() {
- var me = this,
- isBody = me.dom === document.body,
- scroll, pos, top, left, width, height;
- // For the body we want to do some special logic
- if (isBody) {
- scroll = me.getScroll();
- left = scroll.left;
- top = scroll.top;
- width = Ext.Element.getViewportWidth();
- height = Ext.Element.getViewportHeight();
- }
- else {
- pos = me.getXY();
- left = pos[0] + me.getBorderWidth('l') + me.getPadding('l');
- top = pos[1] + me.getBorderWidth('t') + me.getPadding('t');
- width = me.getWidth(true);
- height = me.getHeight(true);
- }
- return Ext.create('Ext.util.Region', top, left + width, top + height, left);
- },
- /**
- * Return an object defining the area of this Element which can be passed to {@link #setBox} to
- * set another Element's size/location to match this element.
- * @param {Boolean} asRegion(optional) If true an Ext.util.Region will be returned
- * @return {Object} box An object in the format<pre><code>
- {
- x: <Element's X position>,
- y: <Element's Y position>,
- width: <Element's width>,
- height: <Element's height>,
- bottom: <Element's lower bound>,
- right: <Element's rightmost bound>
- }
- </code></pre>
- * The returned object may also be addressed as an Array where index 0 contains the X position
- * and index 1 contains the Y position. So the result may also be used for {@link #setXY}
- */
- getPageBox : function(getRegion) {
- var me = this,
- el = me.dom,
- isDoc = el === document.body,
- w = isDoc ? Ext.Element.getViewWidth() : el.offsetWidth,
- h = isDoc ? Ext.Element.getViewHeight() : el.offsetHeight,
- xy = me.getXY(),
- t = xy[1],
- r = xy[0] + w,
- b = xy[1] + h,
- l = xy[0];
- if (getRegion) {
- return Ext.create('Ext.util.Region', t, r, b, l);
- }
- else {
- return {
- left: l,
- top: t,
- width: w,
- height: h,
- right: r,
- bottom: b
- };
- }
- },
- /**
- * Sets the element's position and size in one shot. If animation is true then width, height, x and y will be animated concurrently.
- * @param {Number} x X value for new position (coordinates are page-based)
- * @param {Number} y Y value for new position (coordinates are page-based)
- * @param {Number/String} width The new width. This may be one of:<div class="mdetail-params"><ul>
- * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels)</li>
- * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
- * </ul></div>
- * @param {Number/String} height The new height. This may be one of:<div class="mdetail-params"><ul>
- * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels)</li>
- * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
- * </ul></div>
- * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
- * @return {Ext.Element} this
- */
- setBounds: function(x, y, width, height, animate) {
- var me = this;
- if (!animate || !me.anim) {
- me.setSize(width, height);
- me.setLocation(x, y);
- } else {
- if (!Ext.isObject(animate)) {
- animate = {};
- }
- me.animate(Ext.applyIf({
- to: {
- x: x,
- y: y,
- width: me.adjustWidth(width),
- height: me.adjustHeight(height)
- }
- }, animate));
- }
- return me;
- },
- /**
- * Sets the element's position and size the specified region. If animation is true then width, height, x and y will be animated concurrently.
- * @param {Ext.util.Region} region The region to fill
- * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
- * @return {Ext.Element} this
- */
- setRegion: function(region, animate) {
- return this.setBounds(region.left, region.top, region.right - region.left, region.bottom - region.top, animate);
- }
- });
- })();
- /**
- * @class Ext.Element
- */
- Ext.override(Ext.Element, {
- /**
- * Returns true if this element is scrollable.
- * @return {Boolean}
- */
- isScrollable : function(){
- var dom = this.dom;
- return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth;
- },
- /**
- * Returns the current scroll position of the element.
- * @return {Object} An object containing the scroll position in the format {left: (scrollLeft), top: (scrollTop)}
- */
- getScroll : function() {
- var d = this.dom,
- doc = document,
- body = doc.body,
- docElement = doc.documentElement,
- l,
- t,
- ret;
- if (d == doc || d == body) {
- if (Ext.isIE && Ext.isStrict) {
- l = docElement.scrollLeft;
- t = docElement.scrollTop;
- } else {
- l = window.pageXOffset;
- t = window.pageYOffset;
- }
- ret = {
- left: l || (body ? body.scrollLeft : 0),
- top : t || (body ? body.scrollTop : 0)
- };
- } else {
- ret = {
- left: d.scrollLeft,
- top : d.scrollTop
- };
- }
-
- return ret;
- },
-
- /**
- * Scrolls this element the specified scroll point. It does NOT do bounds checking so if you scroll to a weird value it will try to do it. For auto bounds checking, use scroll().
- * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
- * @param {Number} value The new scroll value
- * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
- * @return {Ext.Element} this
- */
- scrollTo : function(side, value, animate) {
- //check if we're scrolling top or left
- var top = /top/i.test(side),
- me = this,
- dom = me.dom,
- obj = {},
- prop;
- if (!animate || !me.anim) {
- // just setting the value, so grab the direction
- prop = 'scroll' + (top ? 'Top' : 'Left');
- dom[prop] = value;
- }
- else {
- if (!Ext.isObject(animate)) {
- animate = {};
- }
- obj['scroll' + (top ? 'Top' : 'Left')] = value;
- me.animate(Ext.applyIf({
- to: obj
- }, animate));
- }
- return me;
- },
- /**
- * Scrolls this element into view within the passed container.
- * @param {String/HTMLElement/Ext.Element} container (optional) The container element to scroll (defaults to document.body). Should be a
- * string (id), dom node, or Ext.Element.
- * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
- * @return {Ext.Element} this
- */
- scrollIntoView : function(container, hscroll) {
- container = Ext.getDom(container) || Ext.getBody().dom;
- var el = this.dom,
- offsets = this.getOffsetsTo(container),
- // el's box
- left = offsets[0] + container.scrollLeft,
- top = offsets[1] + container.scrollTop,
- bottom = top + el.offsetHeight,
- right = left + el.offsetWidth,
- // ct's box
- ctClientHeight = container.clientHeight,
- ctScrollTop = parseInt(container.scrollTop, 10),
- ctScrollLeft = parseInt(container.scrollLeft, 10),
- ctBottom = ctScrollTop + ctClientHeight,
- ctRight = ctScrollLeft + container.clientWidth;
- if (el.offsetHeight > ctClientHeight || top < ctScrollTop) {
- container.scrollTop = top;
- } else if (bottom > ctBottom) {
- container.scrollTop = bottom - ctClientHeight;
- }
- // corrects IE, other browsers will ignore
- container.scrollTop = container.scrollTop;
- if (hscroll !== false) {
- if (el.offsetWidth > container.clientWidth || left < ctScrollLeft) {
- container.scrollLeft = left;
- }
- else if (right > ctRight) {
- container.scrollLeft = right - container.clientWidth;
- }
- container.scrollLeft = container.scrollLeft;
- }
- return this;
- },
- // private
- scrollChildIntoView : function(child, hscroll) {
- Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
- },
- /**
- * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
- * within this element's scrollable range.
- * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down").
- * @param {Number} distance How far to scroll the element in pixels
- * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
- * @return {Boolean} Returns true if a scroll was triggered or false if the element
- * was scrolled as far as it could go.
- */
- scroll : function(direction, distance, animate) {
- if (!this.isScrollable()) {
- return false;
- }
- var el = this.dom,
- l = el.scrollLeft, t = el.scrollTop,
- w = el.scrollWidth, h = el.scrollHeight,
- cw = el.clientWidth, ch = el.clientHeight,
- scrolled = false, v,
- hash = {
- l: Math.min(l + distance, w-cw),
- r: v = Math.max(l - distance, 0),
- t: Math.max(t - distance, 0),
- b: Math.min(t + distance, h-ch)
- };
- hash.d = hash.b;
- hash.u = hash.t;
- direction = direction.substr(0, 1);
- if ((v = hash[direction]) > -1) {
- scrolled = true;
- this.scrollTo(direction == 'l' || direction == 'r' ? 'left' : 'top', v, this.anim(animate));
- }
- return scrolled;
- }
- });
- /**
- * @class Ext.Element
- */
- Ext.Element.addMethods(
- function() {
- var VISIBILITY = "visibility",
- DISPLAY = "display",
- HIDDEN = "hidden",
- NONE = "none",
- XMASKED = Ext.baseCSSPrefix + "masked",
- XMASKEDRELATIVE = Ext.baseCSSPrefix + "masked-relative",
- data = Ext.Element.data;
- return {
- /**
- * Checks whether the element is currently visible using both visibility and display properties.
- * @param {Boolean} [deep=false] True to walk the dom and see if parent elements are hidden
- * @return {Boolean} True if the element is currently visible, else false
- */
- isVisible : function(deep) {
- var vis = !this.isStyle(VISIBILITY, HIDDEN) && !this.isStyle(DISPLAY, NONE),
- p = this.dom.parentNode;
- if (deep !== true || !vis) {
- return vis;
- }
- while (p && !(/^body/i.test(p.tagName))) {
- if (!Ext.fly(p, '_isVisible').isVisible()) {
- return false;
- }
- p = p.parentNode;
- }
- return true;
- },
- /**
- * Returns true if display is not "none"
- * @return {Boolean}
- */
- isDisplayed : function() {
- return !this.isStyle(DISPLAY, NONE);
- },
- /**
- * Convenience method for setVisibilityMode(Element.DISPLAY)
- * @param {String} display (optional) What to set display to when visible
- * @return {Ext.Element} this
- */
- enableDisplayMode : function(display) {
- this.setVisibilityMode(Ext.Element.DISPLAY);
- if (!Ext.isEmpty(display)) {
- data(this.dom, 'originalDisplay', display);
- }
- return this;
- },
- /**
- * Puts a mask over this element to disable user interaction. Requires core.css.
- * This method can only be applied to elements which accept child nodes.
- * @param {String} msg (optional) A message to display in the mask
- * @param {String} msgCls (optional) A css class to apply to the msg element
- * @return {Ext.Element} The mask element
- */
- mask : function(msg, msgCls) {
- var me = this,
- dom = me.dom,
- setExpression = dom.style.setExpression,
- dh = Ext.DomHelper,
- EXTELMASKMSG = Ext.baseCSSPrefix + "mask-msg",
- el,
- mask;
- if (!(/^body/i.test(dom.tagName) && me.getStyle('position') == 'static')) {
- me.addCls(XMASKEDRELATIVE);
- }
- el = data(dom, 'maskMsg');
- if (el) {
- el.remove();
- }
- el = data(dom, 'mask');
- if (el) {
- el.remove();
- }
- mask = dh.append(dom, {cls : Ext.baseCSSPrefix + "mask"}, true);
- data(dom, 'mask', mask);
- me.addCls(XMASKED);
- mask.setDisplayed(true);
- if (typeof msg == 'string') {
- var mm = dh.append(dom, {cls : EXTELMASKMSG, cn:{tag:'div'}}, true);
- data(dom, 'maskMsg', mm);
- mm.dom.className = msgCls ? EXTELMASKMSG + " " + msgCls : EXTELMASKMSG;
- mm.dom.firstChild.innerHTML = msg;
- mm.setDisplayed(true);
- mm.center(me);
- }
- // NOTE: CSS expressions are resource intensive and to be used only as a last resort
- // These expressions are removed as soon as they are no longer necessary - in the unmask method.
- // In normal use cases an element will be masked for a limited period of time.
- // Fix for https://sencha.jira.com/browse/EXTJSIV-19.
- // IE6 strict mode and IE6-9 quirks mode takes off left+right padding when calculating width!
- if (!Ext.supports.IncludePaddingInWidthCalculation && setExpression) {
- mask.dom.style.setExpression('width', 'this.parentNode.offsetWidth + "px"');
- }
- // Some versions and modes of IE subtract top+bottom padding when calculating height.
- // Different versions from those which make the same error for width!
- if (!Ext.supports.IncludePaddingInHeightCalculation && setExpression) {
- mask.dom.style.setExpression('height', 'this.parentNode.offsetHeight + "px"');
- }
- // ie will not expand full height automatically
- else if (Ext.isIE && !(Ext.isIE7 && Ext.isStrict) && me.getStyle('height') == 'auto') {
- mask.setSize(undefined, me.getHeight());
- }
- return mask;
- },
- /**
- * Removes a previously applied mask.
- */
- unmask : function() {
- var me = this,
- dom = me.dom,
- mask = data(dom, 'mask'),
- maskMsg = data(dom, 'maskMsg');
- if (mask) {
- // Remove resource-intensive CSS expressions as soon as they are not required.
- if (mask.dom.style.clearExpression) {
- mask.dom.style.clearExpression('width');
- mask.dom.style.clearExpression('height');
- }
- if (maskMsg) {
- maskMsg.remove();
- data(dom, 'maskMsg', undefined);
- }
- mask.remove();
- data(dom, 'mask', undefined);
- me.removeCls([XMASKED, XMASKEDRELATIVE]);
- }
- },
- /**
- * Returns true if this element is masked. Also re-centers any displayed message within the mask.
- * @return {Boolean}
- */
- isMasked : function() {
- var me = this,
- mask = data(me.dom, 'mask'),
- maskMsg = data(me.dom, 'maskMsg');
- if (mask && mask.isVisible()) {
- if (maskMsg) {
- maskMsg.center(me);
- }
- return true;
- }
- return false;
- },
- /**
- * Creates an iframe shim for this element to keep selects and other windowed objects from
- * showing through.
- * @return {Ext.Element} The new shim element
- */
- createShim : function() {
- var el = document.createElement('iframe'),
- shim;
- el.frameBorder = '0';
- el.className = Ext.baseCSSPrefix + 'shim';
- el.src = Ext.SSL_SECURE_URL;
- shim = Ext.get(this.dom.parentNode.insertBefore(el, this.dom));
- shim.autoBoxAdjust = false;
- return shim;
- }
- };
- }()
- );
- /**
- * @class Ext.Element
- */
- Ext.Element.addMethods({
- /**
- * Convenience method for constructing a KeyMap
- * @param {String/Number/Number[]/Object} key Either a string with the keys to listen for, the numeric key code, array of key codes or an object with the following options:
- * <code>{key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}</code>
- * @param {Function} fn The function to call
- * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the specified function is executed. Defaults to this Element.
- * @return {Ext.util.KeyMap} The KeyMap created
- */
- addKeyListener : function(key, fn, scope){
- var config;
- if(typeof key != 'object' || Ext.isArray(key)){
- config = {
- key: key,
- fn: fn,
- scope: scope
- };
- }else{
- config = {
- key : key.key,
- shift : key.shift,
- ctrl : key.ctrl,
- alt : key.alt,
- fn: fn,
- scope: scope
- };
- }
- return Ext.create('Ext.util.KeyMap', this, config);
- },
- /**
- * Creates a KeyMap for this element
- * @param {Object} config The KeyMap config. See {@link Ext.util.KeyMap} for more details
- * @return {Ext.util.KeyMap} The KeyMap created
- */
- addKeyMap : function(config){
- return Ext.create('Ext.util.KeyMap', this, config);
- }
- });
- //Import the newly-added Ext.Element functions into CompositeElementLite. We call this here because
- //Element.keys.js is the last extra Ext.Element include in the ext-all.js build
- Ext.CompositeElementLite.importElementMethods();
- /**
- * @class Ext.CompositeElementLite
- */
- Ext.apply(Ext.CompositeElementLite.prototype, {
- addElements : function(els, root){
- if(!els){
- return this;
- }
- if(typeof els == "string"){
- els = Ext.Element.selectorFunction(els, root);
- }
- var yels = this.elements;
- Ext.each(els, function(e) {
- yels.push(Ext.get(e));
- });
- return this;
- },
- /**
- * Returns the first Element
- * @return {Ext.Element}
- */
- first : function(){
- return this.item(0);
- },
- /**
- * Returns the last Element
- * @return {Ext.Element}
- */
- last : function(){
- return this.item(this.getCount()-1);
- },
- /**
- * Returns true if this composite contains the passed element
- * @param el {String/HTMLElement/Ext.Element/Number} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.
- * @return Boolean
- */
- contains : function(el){
- return this.indexOf(el) != -1;
- },
- /**
- * Removes the specified element(s).
- * @param {String/HTMLElement/Ext.Element/Number} el The id of an element, the Element itself, the index of the element in this composite
- * or an array of any of those.
- * @param {Boolean} removeDom (optional) True to also remove the element from the document
- * @return {Ext.CompositeElement} this
- */
- removeElement : function(keys, removeDom){
- var me = this,
- els = this.elements,
- el;
- Ext.each(keys, function(val){
- if ((el = (els[val] || els[val = me.indexOf(val)]))) {
- if(removeDom){
- if(el.dom){
- el.remove();
- }else{
- Ext.removeNode(el);
- }
- }
- Ext.Array.erase(els, val, 1);
- }
- });
- return this;
- }
- });
- /**
- * @class Ext.CompositeElement
- * @extends Ext.CompositeElementLite
- * <p>This class encapsulates a <i>collection</i> of DOM elements, providing methods to filter
- * members, or to perform collective actions upon the whole set.</p>
- * <p>Although they are not listed, this class supports all of the methods of {@link Ext.Element} and
- * {@link Ext.fx.Anim}. The methods from these classes will be performed on all the elements in this collection.</p>
- * <p>All methods return <i>this</i> and can be chained.</p>
- * Usage:
- <pre><code>
- var els = Ext.select("#some-el div.some-class", true);
- // or select directly from an existing element
- var el = Ext.get('some-el');
- el.select('div.some-class', true);
- els.setWidth(100); // all elements become 100 width
- els.hide(true); // all elements fade out and hide
- // or
- els.setWidth(100).hide(true);
- </code></pre>
- */
- Ext.CompositeElement = Ext.extend(Ext.CompositeElementLite, {
- constructor : function(els, root){
- this.elements = [];
- this.add(els, root);
- },
- // private
- getElement : function(el){
- // In this case just return it, since we already have a reference to it
- return el;
- },
- // private
- transformElement : function(el){
- return Ext.get(el);
- }
- });
- /**
- * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
- * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
- * {@link Ext.CompositeElementLite CompositeElementLite} object.
- * @param {String/HTMLElement[]} selector The CSS selector or an array of elements
- * @param {Boolean} [unique] true to create a unique Ext.Element for each element (defaults to a shared flyweight object)
- * @param {HTMLElement/String} [root] The root element of the query or id of the root
- * @return {Ext.CompositeElementLite/Ext.CompositeElement}
- * @member Ext.Element
- * @method select
- */
- Ext.Element.select = function(selector, unique, root){
- var els;
- if(typeof selector == "string"){
- els = Ext.Element.selectorFunction(selector, root);
- }else if(selector.length !== undefined){
- els = selector;
- }else{
- }
- return (unique === true) ? new Ext.CompositeElement(els) : new Ext.CompositeElementLite(els);
- };
- /**
- * Shorthand of {@link Ext.Element#select}.
- * @member Ext
- * @method select
- * @alias Ext.Element#select
- */
- Ext.select = Ext.Element.select;
- /*
- This file is part of Ext JS 4
- Copyright (c) 2011 Sencha Inc
- Contact: http://www.sencha.com/contact
- GNU General Public License Usage
- This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
- If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
- */
- /**
- * Base class that provides a common interface for publishing events. Subclasses are expected to to have a property
- * "events" with all the events defined, and, optionally, a property "listeners" with configured listeners defined.
- *
- * For example:
- *
- * Ext.define('Employee', {
- * extend: 'Ext.util.Observable',
- * constructor: function(config){
- * this.name = config.name;
- * this.addEvents({
- * "fired" : true,
- * "quit" : true
- * });
- *
- * // Copy configured listeners into *this* object so that the base class's
- * // constructor will add them.
- * this.listeners = config.listeners;
- *
- * // Call our superclass constructor to complete construction process.
- * this.callParent(arguments)
- * }
- * });
- *
- * This could then be used like this:
- *
- * var newEmployee = new Employee({
- * name: employeeName,
- * listeners: {
- * quit: function() {
- * // By default, "this" will be the object that fired the event.
- * alert(this.name + " has quit!");
- * }
- * }
- * });
- */
- Ext.define('Ext.util.Observable', {
- /* Begin Definitions */
- requires: ['Ext.util.Event'],
- statics: {
- /**
- * Removes **all** added captures from the Observable.
- *
- * @param {Ext.util.Observable} o The Observable to release
- * @static
- */
- releaseCapture: function(o) {
- o.fireEvent = this.prototype.fireEvent;
- },
- /**
- * Starts capture on the specified Observable. All events will be passed to the supplied function with the event
- * name + standard signature of the event **before** the event is fired. If the supplied function returns false,
- * the event will not fire.
- *
- * @param {Ext.util.Observable} o The Observable to capture events from.
- * @param {Function} fn The function to call when an event is fired.
- * @param {Object} scope (optional) The scope (`this` reference) in which the function is executed. Defaults to
- * the Observable firing the event.
- * @static
- */
- capture: function(o, fn, scope) {
- o.fireEvent = Ext.Function.createInterceptor(o.fireEvent, fn, scope);
- },
- /**
- * Sets observability on the passed class constructor.
- *
- * This makes any event fired on any instance of the passed class also fire a single event through
- * the **class** allowing for central handling of events on many instances at once.
- *
- * Usage:
- *
- * Ext.util.Observable.observe(Ext.data.Connection);
- * Ext.data.Connection.on('beforerequest', function(con, options) {
- * console.log('Ajax request made to ' + options.url);
- * });
- *
- * @param {Function} c The class constructor to make observable.
- * @param {Object} listeners An object containing a series of listeners to add. See {@link #addListener}.
- * @static
- */
- observe: function(cls, listeners) {
- if (cls) {
- if (!cls.isObservable) {
- Ext.applyIf(cls, new this());
- this.capture(cls.prototype, cls.fireEvent, cls);
- }
- if (Ext.isObject(listeners)) {
- cls.on(listeners);
- }
- return cls;
- }
- }
- },
- /* End Definitions */
- /**
- * @cfg {Object} listeners
- *
- * A config object containing one or more event handlers to be added to this object during initialization. This
- * should be a valid listeners config object as specified in the {@link #addListener} example for attaching multiple
- * handlers at once.
- *
- * **DOM events from Ext JS {@link Ext.Component Components}**
- *
- * While _some_ Ext JS Component classes export selected DOM events (e.g. "click", "mouseover" etc), this is usually
- * only done when extra value can be added. For example the {@link Ext.view.View DataView}'s **`{@link
- * Ext.view.View#itemclick itemclick}`** event passing the node clicked on. To access DOM events directly from a
- * child element of a Component, we need to specify the `element` option to identify the Component property to add a
- * DOM listener to:
- *
- * new Ext.panel.Panel({
- * width: 400,
- * height: 200,
- * dockedItems: [{
- * xtype: 'toolbar'
- * }],
- * listeners: {
- * click: {
- * element: 'el', //bind to the underlying el property on the panel
- * fn: function(){ console.log('click el'); }
- * },
- * dblclick: {
- * element: 'body', //bind to the underlying body property on the panel
- * fn: function(){ console.log('dblclick body'); }
- * }
- * }
- * });
- */
- // @private
- isObservable: true,
- constructor: function(config) {
- var me = this;
- Ext.apply(me, config);
- if (me.listeners) {
- me.on(me.listeners);
- delete me.listeners;
- }
- me.events = me.events || {};
- if (me.bubbleEvents) {
- me.enableBubble(me.bubbleEvents);
- }
- },
- // @private
- eventOptionsRe : /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate|element|vertical|horizontal|freezeEvent)$/,
- /**
- * Adds listeners to any Observable object (or Ext.Element) which are automatically removed when this Component is
- * destroyed.
- *
- * @param {Ext.util.Observable/Ext.Element} item The item to which to add a listener/listeners.
- * @param {Object/String} ename The event name, or an object containing event name properties.
- * @param {Function} fn (optional) If the `ename` parameter was an event name, this is the handler function.
- * @param {Object} scope (optional) If the `ename` parameter was an event name, this is the scope (`this` reference)
- * in which the handler function is executed.
- * @param {Object} opt (optional) If the `ename` parameter was an event name, this is the
- * {@link Ext.util.Observable#addListener addListener} options.
- */
- addManagedListener : function(item, ename, fn, scope, options) {
- var me = this,
- managedListeners = me.managedListeners = me.managedListeners || [],
- config;
- if (typeof ename !== 'string') {
- options = ename;
- for (ename in options) {
- if (options.hasOwnProperty(ename)) {
- config = options[ename];
- if (!me.eventOptionsRe.test(ename)) {
- me.addManagedListener(item, ename, config.fn || config, config.scope || options.scope, config.fn ? config : options);
- }
- }
- }
- }
- else {
- managedListeners.push({
- item: item,
- ename: ename,
- fn: fn,
- scope: scope,
- options: options
- });
- item.on(ename, fn, scope, options);
- }
- },
- /**
- * Removes listeners that were added by the {@link #mon} method.
- *
- * @param {Ext.util.Observable/Ext.Element} item The item from which to remove a listener/listeners.
- * @param {Object/String} ename The event name, or an object containing event name properties.
- * @param {Function} fn (optional) If the `ename` parameter was an event name, this is the handler function.
- * @param {Object} scope (optional) If the `ename` parameter was an event name, this is the scope (`this` reference)
- * in which the handler function is executed.
- */
- removeManagedListener : function(item, ename, fn, scope) {
- var me = this,
- options,
- config,
- managedListeners,
- length,
- i;
- if (typeof ename !== 'string') {
- options = ename;
- for (ename in options) {
- if (options.hasOwnProperty(ename)) {
- config = options[ename];
- if (!me.eventOptionsRe.test(ename)) {
- me.removeManagedListener(item, ename, config.fn || config, config.scope || options.scope);
- }
- }
- }
- }
- managedListeners = me.managedListeners ? me.managedListeners.slice() : [];
- for (i = 0, length = managedListeners.length; i < length; i++) {
- me.removeManagedListenerItem(false, managedListeners[i], item, ename, fn, scope);
- }
- },
- /**
- * Fires the specified event with the passed parameters (minus the event name, plus the `options` object passed
- * to {@link #addListener}).
- *
- * An event may be set to bubble up an Observable parent hierarchy (See {@link Ext.Component#getBubbleTarget}) by
- * calling {@link #enableBubble}.
- *
- * @param {String} eventName The name of the event to fire.
- * @param {Object...} args Variable number of parameters are passed to handlers.
- * @return {Boolean} returns false if any of the handlers return false otherwise it returns true.
- */
- fireEvent: function(eventName) {
- var name = eventName.toLowerCase(),
- events = this.events,
- event = events && events[name],
- bubbles = event && event.bubble;
- return this.continueFireEvent(name, Ext.Array.slice(arguments, 1), bubbles);
- },
- /**
- * Continue to fire event.
- * @private
- *
- * @param {String} eventName
- * @param {Array} args
- * @param {Boolean} bubbles
- */
- continueFireEvent: function(eventName, args, bubbles) {
- var target = this,
- queue, event,
- ret = true;
- do {
- if (target.eventsSuspended === true) {
- if ((queue = target.eventQueue)) {
- queue.push([eventName, args, bubbles]);
- }
- return ret;
- } else {
- event = target.events[eventName];
- // Continue bubbling if event exists and it is `true` or the handler didn't returns false and it
- // configure to bubble.
- if (event && event != true) {
- if ((ret = event.fire.apply(event, args)) === false) {
- break;
- }
- }
- }
- } while (bubbles && (target = target.getBubbleParent()));
- return ret;
- },
- /**
- * Gets the bubbling parent for an Observable
- * @private
- * @return {Ext.util.Observable} The bubble parent. null is returned if no bubble target exists
- */
- getBubbleParent: function(){
- var me = this, parent = me.getBubbleTarget && me.getBubbleTarget();
- if (parent && parent.isObservable) {
- return parent;
- }
- return null;
- },
- /**
- * Appends an event handler to this object.
- *
- * @param {String} eventName The name of the event to listen for. May also be an object who's property names are
- * event names.
- * @param {Function} fn The method the event invokes. Will be called with arguments given to
- * {@link #fireEvent} plus the `options` parameter described below.
- * @param {Object} [scope] The scope (`this` reference) in which the handler function is executed. **If
- * omitted, defaults to the object which fired the event.**
- * @param {Object} [options] An object containing handler configuration.
- *
- * **Note:** Unlike in ExtJS 3.x, the options object will also be passed as the last argument to every event handler.
- *
- * This object may contain any of the following properties:
- *
- * - **scope** : Object
- *
- * The scope (`this` reference) in which the handler function is executed. **If omitted, defaults to the object
- * which fired the event.**
- *
- * - **delay** : Number
- *
- * The number of milliseconds to delay the invocation of the handler after the event fires.
- *
- * - **single** : Boolean
- *
- * True to add a handler to handle just the next firing of the event, and then remove itself.
- *
- * - **buffer** : Number
- *
- * Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed by the specified number of
- * milliseconds. If the event fires again within that time, the original handler is _not_ invoked, but the new
- * handler is scheduled in its place.
- *
- * - **target** : Observable
- *
- * Only call the handler if the event was fired on the target Observable, _not_ if the event was bubbled up from a
- * child Observable.
- *
- * - **element** : String
- *
- * **This option is only valid for listeners bound to {@link Ext.Component Components}.** The name of a Component
- * property which references an element to add a listener to.
- *
- * This option is useful during Component construction to add DOM event listeners to elements of
- * {@link Ext.Component Components} which will exist only after the Component is rendered.
- * For example, to add a click listener to a Panel's body:
- *
- * new Ext.panel.Panel({
- * title: 'The title',
- * listeners: {
- * click: this.handlePanelClick,
- * element: 'body'
- * }
- * });
- *
- * **Combining Options**
- *
- * Using the options argument, it is possible to combine different types of listeners:
- *
- * A delayed, one-time listener.
- *
- * myPanel.on('hide', this.handleClick, this, {
- * single: true,
- * delay: 100
- * });
- *
- * **Attaching multiple handlers in 1 call**
- *
- * The method also allows for a single argument to be passed which is a config object containing properties which
- * specify multiple events. For example:
- *
- * myGridPanel.on({
- * cellClick: this.onCellClick,
- * mouseover: this.onMouseOver,
- * mouseout: this.onMouseOut,
- * scope: this // Important. Ensure "this" is correct during handler execution
- * });
- *
- * One can also specify options for each event handler separately:
- *
- * myGridPanel.on({
- * cellClick: {fn: this.onCellClick, scope: this, single: true},
- * mouseover: {fn: panel.onMouseOver, scope: panel}
- * });
- *
- */
- addListener: function(ename, fn, scope, options) {
- var me = this,
- config,
- event;
- if (typeof ename !== 'string') {
- options = ename;
- for (ename in options) {
- if (options.hasOwnProperty(ename)) {
- config = options[ename];
- if (!me.eventOptionsRe.test(ename)) {
- me.addListener(ename, config.fn || config, config.scope || options.scope, config.fn ? config : options);
- }
- }
- }
- }
- else {
- ename = ename.toLowerCase();
- me.events[ename] = me.events[ename] || true;
- event = me.events[ename] || true;
- if (Ext.isBoolean(event)) {
- me.events[ename] = event = new Ext.util.Event(me, ename);
- }
- event.addListener(fn, scope, Ext.isObject(options) ? options : {});
- }
- },
- /**
- * Removes an event handler.
- *
- * @param {String} eventName The type of event the handler was associated with.
- * @param {Function} fn The handler to remove. **This must be a reference to the function passed into the
- * {@link #addListener} call.**
- * @param {Object} scope (optional) The scope originally specified for the handler. It must be the same as the
- * scope argument specified in the original call to {@link #addListener} or the listener will not be removed.
- */
- removeListener: function(ename, fn, scope) {
- var me = this,
- config,
- event,
- options;
- if (typeof ename !== 'string') {
- options = ename;
- for (ename in options) {
- if (options.hasOwnProperty(ename)) {
- config = options[ename];
- if (!me.eventOptionsRe.test(ename)) {
- me.removeListener(ename, config.fn || config, config.scope || options.scope);
- }
- }
- }
- } else {
- ename = ename.toLowerCase();
- event = me.events[ename];
- if (event && event.isEvent) {
- event.removeListener(fn, scope);
- }
- }
- },
- /**
- * Removes all listeners for this object including the managed listeners
- */
- clearListeners: function() {
- var events = this.events,
- event,
- key;
- for (key in events) {
- if (events.hasOwnProperty(key)) {
- event = events[key];
- if (event.isEvent) {
- event.clearListeners();
- }
- }
- }
- this.clearManagedListeners();
- },
- /**
- * Removes all managed listeners for this object.
- */
- clearManagedListeners : function() {
- var managedListeners = this.managedListeners || [],
- i = 0,
- len = managedListeners.length;
- for (; i < len; i++) {
- this.removeManagedListenerItem(true, managedListeners[i]);
- }
- this.managedListeners = [];
- },
- /**
- * Remove a single managed listener item
- * @private
- * @param {Boolean} isClear True if this is being called during a clear
- * @param {Object} managedListener The managed listener item
- * See removeManagedListener for other args
- */
- removeManagedListenerItem: function(isClear, managedListener, item, ename, fn, scope){
- if (isClear || (managedListener.item === item && managedListener.ename === ename && (!fn || managedListener.fn === fn) && (!scope || managedListener.scope === scope))) {
- managedListener.item.un(managedListener.ename, managedListener.fn, managedListener.scope);
- if (!isClear) {
- Ext.Array.remove(this.managedListeners, managedListener);
- }
- }
- },
- /**
- * Adds the specified events to the list of events which this Observable may fire.
- *
- * @param {Object/String} o Either an object with event names as properties with a value of `true` or the first
- * event name string if multiple event names are being passed as separate parameters. Usage:
- *
- * this.addEvents({
- * storeloaded: true,
- * storecleared: true
- * });
- *
- * @param {String...} more (optional) Additional event names if multiple event names are being passed as separate
- * parameters. Usage:
- *
- * this.addEvents('storeloaded', 'storecleared');
- *
- */
- addEvents: function(o) {
- var me = this,
- args,
- len,
- i;
- me.events = me.events || {};
- if (Ext.isString(o)) {
- args = arguments;
- i = args.length;
- while (i--) {
- me.events[args[i]] = me.events[args[i]] || true;
- }
- } else {
- Ext.applyIf(me.events, o);
- }
- },
- /**
- * Checks to see if this object has any listeners for a specified event
- *
- * @param {String} eventName The name of the event to check for
- * @return {Boolean} True if the event is being listened for, else false
- */
- hasListener: function(ename) {
- var event = this.events[ename.toLowerCase()];
- return event && event.isEvent === true && event.listeners.length > 0;
- },
- /**
- * Suspends the firing of all events. (see {@link #resumeEvents})
- *
- * @param {Boolean} queueSuspended Pass as true to queue up suspended events to be fired
- * after the {@link #resumeEvents} call instead of discarding all suspended events.
- */
- suspendEvents: function(queueSuspended) {
- this.eventsSuspended = true;
- if (queueSuspended && !this.eventQueue) {
- this.eventQueue = [];
- }
- },
- /**
- * Resumes firing events (see {@link #suspendEvents}).
- *
- * If events were suspended using the `queueSuspended` parameter, then all events fired
- * during event suspension will be sent to any listeners now.
- */
- resumeEvents: function() {
- var me = this,
- queued = me.eventQueue;
- me.eventsSuspended = false;
- delete me.eventQueue;
- if (queued) {
- Ext.each(queued, function(e) {
- me.continueFireEvent.apply(me, e);
- });
- }
- },
- /**
- * Relays selected events from the specified Observable as if the events were fired by `this`.
- *
- * @param {Object} origin The Observable whose events this object is to relay.
- * @param {String[]} events Array of event names to relay.
- * @param {String} prefix
- */
- relayEvents : function(origin, events, prefix) {
- prefix = prefix || '';
- var me = this,
- len = events.length,
- i = 0,
- oldName,
- newName;
- for (; i < len; i++) {
- oldName = events[i].substr(prefix.length);
- newName = prefix + oldName;
- me.events[newName] = me.events[newName] || true;
- origin.on(oldName, me.createRelayer(newName));
- }
- },
- /**
- * @private
- * Creates an event handling function which refires the event from this object as the passed event name.
- * @param newName
- * @returns {Function}
- */
- createRelayer: function(newName){
- var me = this;
- return function(){
- return me.fireEvent.apply(me, [newName].concat(Array.prototype.slice.call(arguments, 0, -1)));
- };
- },
- /**
- * Enables events fired by this Observable to bubble up an owner hierarchy by calling `this.getBubbleTarget()` if
- * present. There is no implementation in the Observable base class.
- *
- * This is commonly used by Ext.Components to bubble events to owner Containers.
- * See {@link Ext.Component#getBubbleTarget}. The default implementation in Ext.Component returns the
- * Component's immediate owner. But if a known target is required, this can be overridden to access the
- * required target more quickly.
- *
- * Example:
- *
- * Ext.override(Ext.form.field.Base, {
- * // Add functionality to Field's initComponent to enable the change event to bubble
- * initComponent : Ext.Function.createSequence(Ext.form.field.Base.prototype.initComponent, function() {
- * this.enableBubble('change');
- * }),
- *
- * // We know that we want Field's events to bubble directly to the FormPanel.
- * getBubbleTarget : function() {
- * if (!this.formPanel) {
- * this.formPanel = this.findParentByType('form');
- * }
- * return this.formPanel;
- * }
- * });
- *
- * var myForm = new Ext.formPanel({
- * title: 'User Details',
- * items: [{
- * ...
- * }],
- * listeners: {
- * change: function() {
- * // Title goes red if form has been modified.
- * myForm.header.setStyle('color', 'red');
- * }
- * }
- * });
- *
- * @param {String/String[]} events The event name to bubble, or an Array of event names.
- */
- enableBubble: function(events) {
- var me = this;
- if (!Ext.isEmpty(events)) {
- events = Ext.isArray(events) ? events: Ext.Array.toArray(arguments);
- Ext.each(events,
- function(ename) {
- ename = ename.toLowerCase();
- var ce = me.events[ename] || true;
- if (Ext.isBoolean(ce)) {
- ce = new Ext.util.Event(me, ename);
- me.events[ename] = ce;
- }
- ce.bubble = true;
- });
- }
- }
- }, function() {
- this.createAlias({
- /**
- * @method
- * Shorthand for {@link #addListener}.
- * @alias Ext.util.Observable#addListener
- */
- on: 'addListener',
- /**
- * @method
- * Shorthand for {@link #removeListener}.
- * @alias Ext.util.Observable#removeListener
- */
- un: 'removeListener',
- /**
- * @method
- * Shorthand for {@link #addManagedListener}.
- * @alias Ext.util.Observable#addManagedListener
- */
- mon: 'addManagedListener',
- /**
- * @method
- * Shorthand for {@link #removeManagedListener}.
- * @alias Ext.util.Observable#removeManagedListener
- */
- mun: 'removeManagedListener'
- });
- //deprecated, will be removed in 5.0
- this.observeClass = this.observe;
- Ext.apply(Ext.util.Observable.prototype, function(){
- // this is considered experimental (along with beforeMethod, afterMethod, removeMethodListener?)
- // allows for easier interceptor and sequences, including cancelling and overwriting the return value of the call
- // private
- function getMethodEvent(method){
- var e = (this.methodEvents = this.methodEvents || {})[method],
- returnValue,
- v,
- cancel,
- obj = this;
- if (!e) {
- this.methodEvents[method] = e = {};
- e.originalFn = this[method];
- e.methodName = method;
- e.before = [];
- e.after = [];
- var makeCall = function(fn, scope, args){
- if((v = fn.apply(scope || obj, args)) !== undefined){
- if (typeof v == 'object') {
- if(v.returnValue !== undefined){
- returnValue = v.returnValue;
- }else{
- returnValue = v;
- }
- cancel = !!v.cancel;
- }
- else
- if (v === false) {
- cancel = true;
- }
- else {
- returnValue = v;
- }
- }
- };
- this[method] = function(){
- var args = Array.prototype.slice.call(arguments, 0),
- b, i, len;
- returnValue = v = undefined;
- cancel = false;
- for(i = 0, len = e.before.length; i < len; i++){
- b = e.before[i];
- makeCall(b.fn, b.scope, args);
- if (cancel) {
- return returnValue;
- }
- }
- if((v = e.originalFn.apply(obj, args)) !== undefined){
- returnValue = v;
- }
- for(i = 0, len = e.after.length; i < len; i++){
- b = e.after[i];
- makeCall(b.fn, b.scope, args);
- if (cancel) {
- return returnValue;
- }
- }
- return returnValue;
- };
- }
- return e;
- }
- return {
- // these are considered experimental
- // allows for easier interceptor and sequences, including cancelling and overwriting the return value of the call
- // adds an 'interceptor' called before the original method
- beforeMethod : function(method, fn, scope){
- getMethodEvent.call(this, method).before.push({
- fn: fn,
- scope: scope
- });
- },
- // adds a 'sequence' called after the original method
- afterMethod : function(method, fn, scope){
- getMethodEvent.call(this, method).after.push({
- fn: fn,
- scope: scope
- });
- },
- removeMethodListener: function(method, fn, scope){
- var e = this.getMethodEvent(method),
- i, len;
- for(i = 0, len = e.before.length; i < len; i++){
- if(e.before[i].fn == fn && e.before[i].scope == scope){
- Ext.Array.erase(e.before, i, 1);
- return;
- }
- }
- for(i = 0, len = e.after.length; i < len; i++){
- if(e.after[i].fn == fn && e.after[i].scope == scope){
- Ext.Array.erase(e.after, i, 1);
- return;
- }
- }
- },
- toggleEventLogging: function(toggle) {
- Ext.util.Observable[toggle ? 'capture' : 'releaseCapture'](this, function(en) {
- if (Ext.isDefined(Ext.global.console)) {
- Ext.global.console.log(en, arguments);
- }
- });
- }
- };
- }());
- });
- /**
- * @class Ext.util.Animate
- * This animation class is a mixin.
- *
- * Ext.util.Animate provides an API for the creation of animated transitions of properties and styles.
- * This class is used as a mixin and currently applied to {@link Ext.Element}, {@link Ext.CompositeElement},
- * {@link Ext.draw.Sprite}, {@link Ext.draw.CompositeSprite}, and {@link Ext.Component}. Note that Components
- * have a limited subset of what attributes can be animated such as top, left, x, y, height, width, and
- * opacity (color, paddings, and margins can not be animated).
- *
- * ## Animation Basics
- *
- * All animations require three things - `easing`, `duration`, and `to` (the final end value for each property)
- * you wish to animate. Easing and duration are defaulted values specified below.
- * Easing describes how the intermediate values used during a transition will be calculated.
- * {@link Ext.fx.Anim#easing Easing} allows for a transition to change speed over its duration.
- * You may use the defaults for easing and duration, but you must always set a
- * {@link Ext.fx.Anim#to to} property which is the end value for all animations.
- *
- * Popular element 'to' configurations are:
- *
- * - opacity
- * - x
- * - y
- * - color
- * - height
- * - width
- *
- * Popular sprite 'to' configurations are:
- *
- * - translation
- * - path
- * - scale
- * - stroke
- * - rotation
- *
- * The default duration for animations is 250 (which is a 1/4 of a second). Duration is denoted in
- * milliseconds. Therefore 1 second is 1000, 1 minute would be 60000, and so on. The default easing curve
- * used for all animations is 'ease'. Popular easing functions are included and can be found in {@link Ext.fx.Anim#easing Easing}.
- *
- * For example, a simple animation to fade out an element with a default easing and duration:
- *
- * var p1 = Ext.get('myElementId');
- *
- * p1.animate({
- * to: {
- * opacity: 0
- * }
- * });
- *
- * To make this animation fade out in a tenth of a second:
- *
- * var p1 = Ext.get('myElementId');
- *
- * p1.animate({
- * duration: 100,
- * to: {
- * opacity: 0
- * }
- * });
- *
- * ## Animation Queues
- *
- * By default all animations are added to a queue which allows for animation via a chain-style API.
- * For example, the following code will queue 4 animations which occur sequentially (one right after the other):
- *
- * p1.animate({
- * to: {
- * x: 500
- * }
- * }).animate({
- * to: {
- * y: 150
- * }
- * }).animate({
- * to: {
- * backgroundColor: '#f00' //red
- * }
- * }).animate({
- * to: {
- * opacity: 0
- * }
- * });
- *
- * You can change this behavior by calling the {@link Ext.util.Animate#syncFx syncFx} method and all
- * subsequent animations for the specified target will be run concurrently (at the same time).
- *
- * p1.syncFx(); //this will make all animations run at the same time
- *
- * p1.animate({
- * to: {
- * x: 500
- * }
- * }).animate({
- * to: {
- * y: 150
- * }
- * }).animate({
- * to: {
- * backgroundColor: '#f00' //red
- * }
- * }).animate({
- * to: {
- * opacity: 0
- * }
- * });
- *
- * This works the same as:
- *
- * p1.animate({
- * to: {
- * x: 500,
- * y: 150,
- * backgroundColor: '#f00' //red
- * opacity: 0
- * }
- * });
- *
- * The {@link Ext.util.Animate#stopAnimation stopAnimation} method can be used to stop any
- * currently running animations and clear any queued animations.
- *
- * ## Animation Keyframes
- *
- * You can also set up complex animations with {@link Ext.fx.Anim#keyframes keyframes} which follow the
- * CSS3 Animation configuration pattern. Note rotation, translation, and scaling can only be done for sprites.
- * The previous example can be written with the following syntax:
- *
- * p1.animate({
- * duration: 1000, //one second total
- * keyframes: {
- * 25: { //from 0 to 250ms (25%)
- * x: 0
- * },
- * 50: { //from 250ms to 500ms (50%)
- * y: 0
- * },
- * 75: { //from 500ms to 750ms (75%)
- * backgroundColor: '#f00' //red
- * },
- * 100: { //from 750ms to 1sec
- * opacity: 0
- * }
- * }
- * });
- *
- * ## Animation Events
- *
- * Each animation you create has events for {@link Ext.fx.Anim#beforeanimate beforeanimate},
- * {@link Ext.fx.Anim#afteranimate afteranimate}, and {@link Ext.fx.Anim#lastframe lastframe}.
- * Keyframed animations adds an additional {@link Ext.fx.Animator#keyframe keyframe} event which
- * fires for each keyframe in your animation.
- *
- * All animations support the {@link Ext.util.Observable#listeners listeners} configuration to attact functions to these events.
- *
- * startAnimate: function() {
- * var p1 = Ext.get('myElementId');
- * p1.animate({
- * duration: 100,
- * to: {
- * opacity: 0
- * },
- * listeners: {
- * beforeanimate: function() {
- * // Execute my custom method before the animation
- * this.myBeforeAnimateFn();
- * },
- * afteranimate: function() {
- * // Execute my custom method after the animation
- * this.myAfterAnimateFn();
- * },
- * scope: this
- * });
- * },
- * myBeforeAnimateFn: function() {
- * // My custom logic
- * },
- * myAfterAnimateFn: function() {
- * // My custom logic
- * }
- *
- * Due to the fact that animations run asynchronously, you can determine if an animation is currently
- * running on any target by using the {@link Ext.util.Animate#getActiveAnimation getActiveAnimation}
- * method. This method will return false if there are no active animations or return the currently
- * running {@link Ext.fx.Anim} instance.
- *
- * In this example, we're going to wait for the current animation to finish, then stop any other
- * queued animations before we fade our element's opacity to 0:
- *
- * var curAnim = p1.getActiveAnimation();
- * if (curAnim) {
- * curAnim.on('afteranimate', function() {
- * p1.stopAnimation();
- * p1.animate({
- * to: {
- * opacity: 0
- * }
- * });
- * });
- * }
- *
- * @docauthor Jamie Avins <jamie@sencha.com>
- */
- Ext.define('Ext.util.Animate', {
- uses: ['Ext.fx.Manager', 'Ext.fx.Anim'],
- /**
- * <p>Perform custom animation on this object.<p>
- * <p>This method is applicable to both the {@link Ext.Component Component} class and the {@link Ext.Element Element} class.
- * It performs animated transitions of certain properties of this object over a specified timeline.</p>
- * <p>The sole parameter is an object which specifies start property values, end property values, and properties which
- * describe the timeline. Of the properties listed below, only <b><code>to</code></b> is mandatory.</p>
- * <p>Properties include<ul>
- * <li><code>from</code> <div class="sub-desc">An object which specifies start values for the properties being animated.
- * If not supplied, properties are animated from current settings. The actual properties which may be animated depend upon
- * ths object being animated. See the sections below on Element and Component animation.<div></li>
- * <li><code>to</code> <div class="sub-desc">An object which specifies end values for the properties being animated.</div></li>
- * <li><code>duration</code><div class="sub-desc">The duration <b>in milliseconds</b> for which the animation will run.</div></li>
- * <li><code>easing</code> <div class="sub-desc">A string value describing an easing type to modify the rate of change from the default linear to non-linear. Values may be one of:<code><ul>
- * <li>ease</li>
- * <li>easeIn</li>
- * <li>easeOut</li>
- * <li>easeInOut</li>
- * <li>backIn</li>
- * <li>backOut</li>
- * <li>elasticIn</li>
- * <li>elasticOut</li>
- * <li>bounceIn</li>
- * <li>bounceOut</li>
- * </ul></code></div></li>
- * <li><code>keyframes</code> <div class="sub-desc">This is an object which describes the state of animated properties at certain points along the timeline.
- * it is an object containing properties who's names are the percentage along the timeline being described and who's values specify the animation state at that point.</div></li>
- * <li><code>listeners</code> <div class="sub-desc">This is a standard {@link Ext.util.Observable#listeners listeners} configuration object which may be used
- * to inject behaviour at either the <code>beforeanimate</code> event or the <code>afteranimate</code> event.</div></li>
- * </ul></p>
- * <h3>Animating an {@link Ext.Element Element}</h3>
- * When animating an Element, the following properties may be specified in <code>from</code>, <code>to</code>, and <code>keyframe</code> objects:<ul>
- * <li><code>x</code> <div class="sub-desc">The page X position in pixels.</div></li>
- * <li><code>y</code> <div class="sub-desc">The page Y position in pixels</div></li>
- * <li><code>left</code> <div class="sub-desc">The element's CSS <code>left</code> value. Units must be supplied.</div></li>
- * <li><code>top</code> <div class="sub-desc">The element's CSS <code>top</code> value. Units must be supplied.</div></li>
- * <li><code>width</code> <div class="sub-desc">The element's CSS <code>width</code> value. Units must be supplied.</div></li>
- * <li><code>height</code> <div class="sub-desc">The element's CSS <code>height</code> value. Units must be supplied.</div></li>
- * <li><code>scrollLeft</code> <div class="sub-desc">The element's <code>scrollLeft</code> value.</div></li>
- * <li><code>scrollTop</code> <div class="sub-desc">The element's <code>scrollLeft</code> value.</div></li>
- * <li><code>opacity</code> <div class="sub-desc">The element's <code>opacity</code> value. This must be a value between <code>0</code> and <code>1</code>.</div></li>
- * </ul>
- * <p><b>Be aware than animating an Element which is being used by an Ext Component without in some way informing the Component about the changed element state
- * will result in incorrect Component behaviour. This is because the Component will be using the old state of the element. To avoid this problem, it is now possible to
- * directly animate certain properties of Components.</b></p>
- * <h3>Animating a {@link Ext.Component Component}</h3>
- * When animating an Element, the following properties may be specified in <code>from</code>, <code>to</code>, and <code>keyframe</code> objects:<ul>
- * <li><code>x</code> <div class="sub-desc">The Component's page X position in pixels.</div></li>
- * <li><code>y</code> <div class="sub-desc">The Component's page Y position in pixels</div></li>
- * <li><code>left</code> <div class="sub-desc">The Component's <code>left</code> value in pixels.</div></li>
- * <li><code>top</code> <div class="sub-desc">The Component's <code>top</code> value in pixels.</div></li>
- * <li><code>width</code> <div class="sub-desc">The Component's <code>width</code> value in pixels.</div></li>
- * <li><code>width</code> <div class="sub-desc">The Component's <code>width</code> value in pixels.</div></li>
- * <li><code>dynamic</code> <div class="sub-desc">Specify as true to update the Component's layout (if it is a Container) at every frame
- * of the animation. <i>Use sparingly as laying out on every intermediate size change is an expensive operation</i>.</div></li>
- * </ul>
- * <p>For example, to animate a Window to a new size, ensuring that its internal layout, and any shadow is correct:</p>
- * <pre><code>
- myWindow = Ext.create('Ext.window.Window', {
- title: 'Test Component animation',
- width: 500,
- height: 300,
- layout: {
- type: 'hbox',
- align: 'stretch'
- },
- items: [{
- title: 'Left: 33%',
- margins: '5 0 5 5',
- flex: 1
- }, {
- title: 'Left: 66%',
- margins: '5 5 5 5',
- flex: 2
- }]
- });
- myWindow.show();
- myWindow.header.el.on('click', function() {
- myWindow.animate({
- to: {
- width: (myWindow.getWidth() == 500) ? 700 : 500,
- height: (myWindow.getHeight() == 300) ? 400 : 300,
- }
- });
- });
- </code></pre>
- * <p>For performance reasons, by default, the internal layout is only updated when the Window reaches its final <code>"to"</code> size. If dynamic updating of the Window's child
- * Components is required, then configure the animation with <code>dynamic: true</code> and the two child items will maintain their proportions during the animation.</p>
- * @param {Object} config An object containing properties which describe the animation's start and end states, and the timeline of the animation.
- * @return {Object} this
- */
- animate: function(animObj) {
- var me = this;
- if (Ext.fx.Manager.hasFxBlock(me.id)) {
- return me;
- }
- Ext.fx.Manager.queueFx(Ext.create('Ext.fx.Anim', me.anim(animObj)));
- return this;
- },
- // @private - process the passed fx configuration.
- anim: function(config) {
- if (!Ext.isObject(config)) {
- return (config) ? {} : false;
- }
- var me = this;
- if (config.stopAnimation) {
- me.stopAnimation();
- }
- Ext.applyIf(config, Ext.fx.Manager.getFxDefaults(me.id));
- return Ext.apply({
- target: me,
- paused: true
- }, config);
- },
- /**
- * @deprecated 4.0 Replaced by {@link #stopAnimation}
- * Stops any running effects and clears this object's internal effects queue if it contains
- * any additional effects that haven't started yet.
- * @return {Ext.Element} The Element
- * @method
- */
- stopFx: Ext.Function.alias(Ext.util.Animate, 'stopAnimation'),
- /**
- * Stops any running effects and clears this object's internal effects queue if it contains
- * any additional effects that haven't started yet.
- * @return {Ext.Element} The Element
- */
- stopAnimation: function() {
- Ext.fx.Manager.stopAnimation(this.id);
- return this;
- },
- /**
- * Ensures that all effects queued after syncFx is called on this object are
- * run concurrently. This is the opposite of {@link #sequenceFx}.
- * @return {Object} this
- */
- syncFx: function() {
- Ext.fx.Manager.setFxDefaults(this.id, {
- concurrent: true
- });
- return this;
- },
- /**
- * Ensures that all effects queued after sequenceFx is called on this object are
- * run in sequence. This is the opposite of {@link #syncFx}.
- * @return {Object} this
- */
- sequenceFx: function() {
- Ext.fx.Manager.setFxDefaults(this.id, {
- concurrent: false
- });
- return this;
- },
- /**
- * @deprecated 4.0 Replaced by {@link #getActiveAnimation}
- * @alias Ext.util.Animate#getActiveAnimation
- * @method
- */
- hasActiveFx: Ext.Function.alias(Ext.util.Animate, 'getActiveAnimation'),
- /**
- * Returns the current animation if this object has any effects actively running or queued, else returns false.
- * @return {Ext.fx.Anim/Boolean} Anim if element has active effects, else false
- */
- getActiveAnimation: function() {
- return Ext.fx.Manager.getActiveAnimation(this.id);
- }
- }, function(){
- // Apply Animate mixin manually until Element is defined in the proper 4.x way
- Ext.applyIf(Ext.Element.prototype, this.prototype);
- // We need to call this again so the animation methods get copied over to CE
- Ext.CompositeElementLite.importElementMethods();
- });
- /**
- * @class Ext.state.Provider
- * <p>Abstract base class for state provider implementations. The provider is responsible
- * for setting values and extracting values to/from the underlying storage source. The
- * storage source can vary and the details should be implemented in a subclass. For example
- * a provider could use a server side database or the browser localstorage where supported.</p>
- *
- * <p>This class provides methods for encoding and decoding <b>typed</b> variables including
- * dates and defines the Provider interface. By default these methods put the value and the
- * type information into a delimited string that can be stored. These should be overridden in
- * a subclass if you want to change the format of the encoded value and subsequent decoding.</p>
- */
- Ext.define('Ext.state.Provider', {
- mixins: {
- observable: 'Ext.util.Observable'
- },
-
- /**
- * @cfg {String} prefix A string to prefix to items stored in the underlying state store.
- * Defaults to <tt>'ext-'</tt>
- */
- prefix: 'ext-',
-
- constructor : function(config){
- config = config || {};
- var me = this;
- Ext.apply(me, config);
- /**
- * @event statechange
- * Fires when a state change occurs.
- * @param {Ext.state.Provider} this This state provider
- * @param {String} key The state key which was changed
- * @param {String} value The encoded value for the state
- */
- me.addEvents("statechange");
- me.state = {};
- me.mixins.observable.constructor.call(me);
- },
-
- /**
- * Returns the current value for a key
- * @param {String} name The key name
- * @param {Object} defaultValue A default value to return if the key's value is not found
- * @return {Object} The state data
- */
- get : function(name, defaultValue){
- return typeof this.state[name] == "undefined" ?
- defaultValue : this.state[name];
- },
- /**
- * Clears a value from the state
- * @param {String} name The key name
- */
- clear : function(name){
- var me = this;
- delete me.state[name];
- me.fireEvent("statechange", me, name, null);
- },
- /**
- * Sets the value for a key
- * @param {String} name The key name
- * @param {Object} value The value to set
- */
- set : function(name, value){
- var me = this;
- me.state[name] = value;
- me.fireEvent("statechange", me, name, value);
- },
- /**
- * Decodes a string previously encoded with {@link #encodeValue}.
- * @param {String} value The value to decode
- * @return {Object} The decoded value
- */
- decodeValue : function(value){
- // a -> Array
- // n -> Number
- // d -> Date
- // b -> Boolean
- // s -> String
- // o -> Object
- // -> Empty (null)
- var me = this,
- re = /^(a|n|d|b|s|o|e)\:(.*)$/,
- matches = re.exec(unescape(value)),
- all,
- type,
- value,
- keyValue;
-
- if(!matches || !matches[1]){
- return; // non state
- }
-
- type = matches[1];
- value = matches[2];
- switch (type) {
- case 'e':
- return null;
- case 'n':
- return parseFloat(value);
- case 'd':
- return new Date(Date.parse(value));
- case 'b':
- return (value == '1');
- case 'a':
- all = [];
- if(value != ''){
- Ext.each(value.split('^'), function(val){
- all.push(me.decodeValue(val));
- }, me);
- }
- return all;
- case 'o':
- all = {};
- if(value != ''){
- Ext.each(value.split('^'), function(val){
- keyValue = val.split('=');
- all[keyValue[0]] = me.decodeValue(keyValue[1]);
- }, me);
- }
- return all;
- default:
- return value;
- }
- },
- /**
- * Encodes a value including type information. Decode with {@link #decodeValue}.
- * @param {Object} value The value to encode
- * @return {String} The encoded value
- */
- encodeValue : function(value){
- var flat = '',
- i = 0,
- enc,
- len,
- key;
-
- if (value == null) {
- return 'e:1';
- } else if(typeof value == 'number') {
- enc = 'n:' + value;
- } else if(typeof value == 'boolean') {
- enc = 'b:' + (value ? '1' : '0');
- } else if(Ext.isDate(value)) {
- enc = 'd:' + value.toGMTString();
- } else if(Ext.isArray(value)) {
- for (len = value.length; i < len; i++) {
- flat += this.encodeValue(value[i]);
- if (i != len - 1) {
- flat += '^';
- }
- }
- enc = 'a:' + flat;
- } else if (typeof value == 'object') {
- for (key in value) {
- if (typeof value[key] != 'function' && value[key] !== undefined) {
- flat += key + '=' + this.encodeValue(value[key]) + '^';
- }
- }
- enc = 'o:' + flat.substring(0, flat.length-1);
- } else {
- enc = 's:' + value;
- }
- return escape(enc);
- }
- });
- /**
- * Provides searching of Components within Ext.ComponentManager (globally) or a specific
- * Ext.container.Container on the document with a similar syntax to a CSS selector.
- *
- * Components can be retrieved by using their {@link Ext.Component xtype} with an optional . prefix
- *
- * - `component` or `.component`
- * - `gridpanel` or `.gridpanel`
- *
- * An itemId or id must be prefixed with a #
- *
- * - `#myContainer`
- *
- * Attributes must be wrapped in brackets
- *
- * - `component[autoScroll]`
- * - `panel[title="Test"]`
- *
- * Member expressions from candidate Components may be tested. If the expression returns a *truthy* value,
- * the candidate Component will be included in the query:
- *
- * var disabledFields = myFormPanel.query("{isDisabled()}");
- *
- * Pseudo classes may be used to filter results in the same way as in {@link Ext.DomQuery DomQuery}:
- *
- * // Function receives array and returns a filtered array.
- * Ext.ComponentQuery.pseudos.invalid = function(items) {
- * var i = 0, l = items.length, c, result = [];
- * for (; i < l; i++) {
- * if (!(c = items[i]).isValid()) {
- * result.push(c);
- * }
- * }
- * return result;
- * };
- *
- * var invalidFields = myFormPanel.query('field:invalid');
- * if (invalidFields.length) {
- * invalidFields[0].getEl().scrollIntoView(myFormPanel.body);
- * for (var i = 0, l = invalidFields.length; i < l; i++) {
- * invalidFields[i].getEl().frame("red");
- * }
- * }
- *
- * Default pseudos include:
- *
- * - not
- * - last
- *
- * Queries return an array of components.
- * Here are some example queries.
- *
- * // retrieve all Ext.Panels in the document by xtype
- * var panelsArray = Ext.ComponentQuery.query('panel');
- *
- * // retrieve all Ext.Panels within the container with an id myCt
- * var panelsWithinmyCt = Ext.ComponentQuery.query('#myCt panel');
- *
- * // retrieve all direct children which are Ext.Panels within myCt
- * var directChildPanel = Ext.ComponentQuery.query('#myCt > panel');
- *
- * // retrieve all grids and trees
- * var gridsAndTrees = Ext.ComponentQuery.query('gridpanel, treepanel');
- *
- * For easy access to queries based from a particular Container see the {@link Ext.container.Container#query},
- * {@link Ext.container.Container#down} and {@link Ext.container.Container#child} methods. Also see
- * {@link Ext.Component#up}.
- */
- Ext.define('Ext.ComponentQuery', {
- singleton: true,
- uses: ['Ext.ComponentManager']
- }, function() {
- var cq = this,
- // A function source code pattern with a placeholder which accepts an expression which yields a truth value when applied
- // as a member on each item in the passed array.
- filterFnPattern = [
- 'var r = [],',
- 'i = 0,',
- 'it = items,',
- 'l = it.length,',
- 'c;',
- 'for (; i < l; i++) {',
- 'c = it[i];',
- 'if (c.{0}) {',
- 'r.push(c);',
- '}',
- '}',
- 'return r;'
- ].join(''),
- filterItems = function(items, operation) {
- // Argument list for the operation is [ itemsArray, operationArg1, operationArg2...]
- // The operation's method loops over each item in the candidate array and
- // returns an array of items which match its criteria
- return operation.method.apply(this, [ items ].concat(operation.args));
- },
- getItems = function(items, mode) {
- var result = [],
- i = 0,
- length = items.length,
- candidate,
- deep = mode !== '>';
-
- for (; i < length; i++) {
- candidate = items[i];
- if (candidate.getRefItems) {
- result = result.concat(candidate.getRefItems(deep));
- }
- }
- return result;
- },
- getAncestors = function(items) {
- var result = [],
- i = 0,
- length = items.length,
- candidate;
- for (; i < length; i++) {
- candidate = items[i];
- while (!!(candidate = (candidate.ownerCt || candidate.floatParent))) {
- result.push(candidate);
- }
- }
- return result;
- },
- // Filters the passed candidate array and returns only items which match the passed xtype
- filterByXType = function(items, xtype, shallow) {
- if (xtype === '*') {
- return items.slice();
- }
- else {
- var result = [],
- i = 0,
- length = items.length,
- candidate;
- for (; i < length; i++) {
- candidate = items[i];
- if (candidate.isXType(xtype, shallow)) {
- result.push(candidate);
- }
- }
- return result;
- }
- },
- // Filters the passed candidate array and returns only items which have the passed className
- filterByClassName = function(items, className) {
- var EA = Ext.Array,
- result = [],
- i = 0,
- length = items.length,
- candidate;
- for (; i < length; i++) {
- candidate = items[i];
- if (candidate.el ? candidate.el.hasCls(className) : EA.contains(candidate.initCls(), className)) {
- result.push(candidate);
- }
- }
- return result;
- },
- // Filters the passed candidate array and returns only items which have the specified property match
- filterByAttribute = function(items, property, operator, value) {
- var result = [],
- i = 0,
- length = items.length,
- candidate;
- for (; i < length; i++) {
- candidate = items[i];
- if (!value ? !!candidate[property] : (String(candidate[property]) === value)) {
- result.push(candidate);
- }
- }
- return result;
- },
- // Filters the passed candidate array and returns only items which have the specified itemId or id
- filterById = function(items, id) {
- var result = [],
- i = 0,
- length = items.length,
- candidate;
- for (; i < length; i++) {
- candidate = items[i];
- if (candidate.getItemId() === id) {
- result.push(candidate);
- }
- }
- return result;
- },
- // Filters the passed candidate array and returns only items which the named pseudo class matcher filters in
- filterByPseudo = function(items, name, value) {
- return cq.pseudos[name](items, value);
- },
- // Determines leading mode
- // > for direct child, and ^ to switch to ownerCt axis
- modeRe = /^(\s?([>\^])\s?|\s|$)/,
- // Matches a token with possibly (true|false) appended for the "shallow" parameter
- tokenRe = /^(#)?([\w\-]+|\*)(?:\((true|false)\))?/,
- matchers = [{
- // Checks for .xtype with possibly (true|false) appended for the "shallow" parameter
- re: /^\.([\w\-]+)(?:\((true|false)\))?/,
- method: filterByXType
- },{
- // checks for [attribute=value]
- re: /^(?:[\[](?:@)?([\w\-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]])/,
- method: filterByAttribute
- }, {
- // checks for #cmpItemId
- re: /^#([\w\-]+)/,
- method: filterById
- }, {
- // checks for :<pseudo_class>(<selector>)
- re: /^\:([\w\-]+)(?:\(((?:\{[^\}]+\})|(?:(?!\{)[^\s>\/]*?(?!\})))\))?/,
- method: filterByPseudo
- }, {
- // checks for {<member_expression>}
- re: /^(?:\{([^\}]+)\})/,
- method: filterFnPattern
- }];
- // @class Ext.ComponentQuery.Query
- // This internal class is completely hidden in documentation.
- cq.Query = Ext.extend(Object, {
- constructor: function(cfg) {
- cfg = cfg || {};
- Ext.apply(this, cfg);
- },
- // Executes this Query upon the selected root.
- // The root provides the initial source of candidate Component matches which are progressively
- // filtered by iterating through this Query's operations cache.
- // If no root is provided, all registered Components are searched via the ComponentManager.
- // root may be a Container who's descendant Components are filtered
- // root may be a Component with an implementation of getRefItems which provides some nested Components such as the
- // docked items within a Panel.
- // root may be an array of candidate Components to filter using this Query.
- execute : function(root) {
- var operations = this.operations,
- i = 0,
- length = operations.length,
- operation,
- workingItems;
- // no root, use all Components in the document
- if (!root) {
- workingItems = Ext.ComponentManager.all.getArray();
- }
- // Root is a candidate Array
- else if (Ext.isArray(root)) {
- workingItems = root;
- }
- // We are going to loop over our operations and take care of them
- // one by one.
- for (; i < length; i++) {
- operation = operations[i];
- // The mode operation requires some custom handling.
- // All other operations essentially filter down our current
- // working items, while mode replaces our current working
- // items by getting children from each one of our current
- // working items. The type of mode determines the type of
- // children we get. (e.g. > only gets direct children)
- if (operation.mode === '^') {
- workingItems = getAncestors(workingItems || [root]);
- }
- else if (operation.mode) {
- workingItems = getItems(workingItems || [root], operation.mode);
- }
- else {
- workingItems = filterItems(workingItems || getItems([root]), operation);
- }
- // If this is the last operation, it means our current working
- // items are the final matched items. Thus return them!
- if (i === length -1) {
- return workingItems;
- }
- }
- return [];
- },
- is: function(component) {
- var operations = this.operations,
- components = Ext.isArray(component) ? component : [component],
- originalLength = components.length,
- lastOperation = operations[operations.length-1],
- ln, i;
- components = filterItems(components, lastOperation);
- if (components.length === originalLength) {
- if (operations.length > 1) {
- for (i = 0, ln = components.length; i < ln; i++) {
- if (Ext.Array.indexOf(this.execute(), components[i]) === -1) {
- return false;
- }
- }
- }
- return true;
- }
- return false;
- }
- });
- Ext.apply(this, {
- // private cache of selectors and matching ComponentQuery.Query objects
- cache: {},
- // private cache of pseudo class filter functions
- pseudos: {
- not: function(components, selector){
- var CQ = Ext.ComponentQuery,
- i = 0,
- length = components.length,
- results = [],
- index = -1,
- component;
-
- for(; i < length; ++i) {
- component = components[i];
- if (!CQ.is(component, selector)) {
- results[++index] = component;
- }
- }
- return results;
- },
- last: function(components) {
- return components[components.length - 1];
- }
- },
- /**
- * Returns an array of matched Components from within the passed root object.
- *
- * This method filters returned Components in a similar way to how CSS selector based DOM
- * queries work using a textual selector string.
- *
- * See class summary for details.
- *
- * @param {String} selector The selector string to filter returned Components
- * @param {Ext.container.Container} root The Container within which to perform the query.
- * If omitted, all Components within the document are included in the search.
- *
- * This parameter may also be an array of Components to filter according to the selector.</p>
- * @returns {Ext.Component[]} The matched Components.
- *
- * @member Ext.ComponentQuery
- */
- query: function(selector, root) {
- var selectors = selector.split(','),
- length = selectors.length,
- i = 0,
- results = [],
- noDupResults = [],
- dupMatcher = {},
- query, resultsLn, cmp;
- for (; i < length; i++) {
- selector = Ext.String.trim(selectors[i]);
- query = this.cache[selector];
- if (!query) {
- this.cache[selector] = query = this.parse(selector);
- }
- results = results.concat(query.execute(root));
- }
- // multiple selectors, potential to find duplicates
- // lets filter them out.
- if (length > 1) {
- resultsLn = results.length;
- for (i = 0; i < resultsLn; i++) {
- cmp = results[i];
- if (!dupMatcher[cmp.id]) {
- noDupResults.push(cmp);
- dupMatcher[cmp.id] = true;
- }
- }
- results = noDupResults;
- }
- return results;
- },
- /**
- * Tests whether the passed Component matches the selector string.
- * @param {Ext.Component} component The Component to test
- * @param {String} selector The selector string to test against.
- * @return {Boolean} True if the Component matches the selector.
- * @member Ext.ComponentQuery
- */
- is: function(component, selector) {
- if (!selector) {
- return true;
- }
- var query = this.cache[selector];
- if (!query) {
- this.cache[selector] = query = this.parse(selector);
- }
- return query.is(component);
- },
- parse: function(selector) {
- var operations = [],
- length = matchers.length,
- lastSelector,
- tokenMatch,
- matchedChar,
- modeMatch,
- selectorMatch,
- i, matcher, method;
- // We are going to parse the beginning of the selector over and
- // over again, slicing off the selector any portions we converted into an
- // operation, until it is an empty string.
- while (selector && lastSelector !== selector) {
- lastSelector = selector;
- // First we check if we are dealing with a token like #, * or an xtype
- tokenMatch = selector.match(tokenRe);
- if (tokenMatch) {
- matchedChar = tokenMatch[1];
- // If the token is prefixed with a # we push a filterById operation to our stack
- if (matchedChar === '#') {
- operations.push({
- method: filterById,
- args: [Ext.String.trim(tokenMatch[2])]
- });
- }
- // If the token is prefixed with a . we push a filterByClassName operation to our stack
- // FIXME: Not enabled yet. just needs \. adding to the tokenRe prefix
- else if (matchedChar === '.') {
- operations.push({
- method: filterByClassName,
- args: [Ext.String.trim(tokenMatch[2])]
- });
- }
- // If the token is a * or an xtype string, we push a filterByXType
- // operation to the stack.
- else {
- operations.push({
- method: filterByXType,
- args: [Ext.String.trim(tokenMatch[2]), Boolean(tokenMatch[3])]
- });
- }
- // Now we slice of the part we just converted into an operation
- selector = selector.replace(tokenMatch[0], '');
- }
- // If the next part of the query is not a space or > or ^, it means we
- // are going to check for more things that our current selection
- // has to comply to.
- while (!(modeMatch = selector.match(modeRe))) {
- // Lets loop over each type of matcher and execute it
- // on our current selector.
- for (i = 0; selector && i < length; i++) {
- matcher = matchers[i];
- selectorMatch = selector.match(matcher.re);
- method = matcher.method;
- // If we have a match, add an operation with the method
- // associated with this matcher, and pass the regular
- // expression matches are arguments to the operation.
- if (selectorMatch) {
- operations.push({
- method: Ext.isString(matcher.method)
- // Turn a string method into a function by formatting the string with our selector matche expression
- // A new method is created for different match expressions, eg {id=='textfield-1024'}
- // Every expression may be different in different selectors.
- ? Ext.functionFactory('items', Ext.String.format.apply(Ext.String, [method].concat(selectorMatch.slice(1))))
- : matcher.method,
- args: selectorMatch.slice(1)
- });
- selector = selector.replace(selectorMatch[0], '');
- break; // Break on match
- }
- }
- }
- // Now we are going to check for a mode change. This means a space
- // or a > to determine if we are going to select all the children
- // of the currently matched items, or a ^ if we are going to use the
- // ownerCt axis as the candidate source.
- if (modeMatch[1]) { // Assignment, and test for truthiness!
- operations.push({
- mode: modeMatch[2]||modeMatch[1]
- });
- selector = selector.replace(modeMatch[0], '');
- }
- }
- // Now that we have all our operations in an array, we are going
- // to create a new Query using these operations.
- return new cq.Query({
- operations: operations
- });
- }
- });
- });
- /**
- * @class Ext.util.HashMap
- * <p>
- * Represents a collection of a set of key and value pairs. Each key in the HashMap
- * must be unique, the same key cannot exist twice. Access to items is provided via
- * the key only. Sample usage:
- * <pre><code>
- var map = new Ext.util.HashMap();
- map.add('key1', 1);
- map.add('key2', 2);
- map.add('key3', 3);
- map.each(function(key, value, length){
- console.log(key, value, length);
- });
- * </code></pre>
- * </p>
- *
- * <p>The HashMap is an unordered class,
- * there is no guarantee when iterating over the items that they will be in any particular
- * order. If this is required, then use a {@link Ext.util.MixedCollection}.
- * </p>
- */
- Ext.define('Ext.util.HashMap', {
- mixins: {
- observable: 'Ext.util.Observable'
- },
- /**
- * @cfg {Function} keyFn A function that is used to retrieve a default key for a passed object.
- * A default is provided that returns the <b>id</b> property on the object. This function is only used
- * if the add method is called with a single argument.
- */
- /**
- * Creates new HashMap.
- * @param {Object} config (optional) Config object.
- */
- constructor: function(config) {
- config = config || {};
-
- var me = this,
- keyFn = config.keyFn;
- me.addEvents(
- /**
- * @event add
- * Fires when a new item is added to the hash
- * @param {Ext.util.HashMap} this.
- * @param {String} key The key of the added item.
- * @param {Object} value The value of the added item.
- */
- 'add',
- /**
- * @event clear
- * Fires when the hash is cleared.
- * @param {Ext.util.HashMap} this.
- */
- 'clear',
- /**
- * @event remove
- * Fires when an item is removed from the hash.
- * @param {Ext.util.HashMap} this.
- * @param {String} key The key of the removed item.
- * @param {Object} value The value of the removed item.
- */
- 'remove',
- /**
- * @event replace
- * Fires when an item is replaced in the hash.
- * @param {Ext.util.HashMap} this.
- * @param {String} key The key of the replaced item.
- * @param {Object} value The new value for the item.
- * @param {Object} old The old value for the item.
- */
- 'replace'
- );
- me.mixins.observable.constructor.call(me, config);
- me.clear(true);
-
- if (keyFn) {
- me.getKey = keyFn;
- }
- },
- /**
- * Gets the number of items in the hash.
- * @return {Number} The number of items in the hash.
- */
- getCount: function() {
- return this.length;
- },
- /**
- * Implementation for being able to extract the key from an object if only
- * a single argument is passed.
- * @private
- * @param {String} key The key
- * @param {Object} value The value
- * @return {Array} [key, value]
- */
- getData: function(key, value) {
- // if we have no value, it means we need to get the key from the object
- if (value === undefined) {
- value = key;
- key = this.getKey(value);
- }
- return [key, value];
- },
- /**
- * Extracts the key from an object. This is a default implementation, it may be overridden
- * @param {Object} o The object to get the key from
- * @return {String} The key to use.
- */
- getKey: function(o) {
- return o.id;
- },
- /**
- * Adds an item to the collection. Fires the {@link #add} event when complete.
- * @param {String} key <p>The key to associate with the item, or the new item.</p>
- * <p>If a {@link #getKey} implementation was specified for this HashMap,
- * or if the key of the stored items is in a property called <tt><b>id</b></tt>,
- * the HashMap will be able to <i>derive</i> the key for the new item.
- * In this case just pass the new item in this parameter.</p>
- * @param {Object} o The item to add.
- * @return {Object} The item added.
- */
- add: function(key, value) {
- var me = this,
- data;
- if (arguments.length === 1) {
- value = key;
- key = me.getKey(value);
- }
- if (me.containsKey(key)) {
- return me.replace(key, value);
- }
- data = me.getData(key, value);
- key = data[0];
- value = data[1];
- me.map[key] = value;
- ++me.length;
- me.fireEvent('add', me, key, value);
- return value;
- },
- /**
- * Replaces an item in the hash. If the key doesn't exist, the
- * {@link #add} method will be used.
- * @param {String} key The key of the item.
- * @param {Object} value The new value for the item.
- * @return {Object} The new value of the item.
- */
- replace: function(key, value) {
- var me = this,
- map = me.map,
- old;
- if (!me.containsKey(key)) {
- me.add(key, value);
- }
- old = map[key];
- map[key] = value;
- me.fireEvent('replace', me, key, value, old);
- return value;
- },
- /**
- * Remove an item from the hash.
- * @param {Object} o The value of the item to remove.
- * @return {Boolean} True if the item was successfully removed.
- */
- remove: function(o) {
- var key = this.findKey(o);
- if (key !== undefined) {
- return this.removeAtKey(key);
- }
- return false;
- },
- /**
- * Remove an item from the hash.
- * @param {String} key The key to remove.
- * @return {Boolean} True if the item was successfully removed.
- */
- removeAtKey: function(key) {
- var me = this,
- value;
- if (me.containsKey(key)) {
- value = me.map[key];
- delete me.map[key];
- --me.length;
- me.fireEvent('remove', me, key, value);
- return true;
- }
- return false;
- },
- /**
- * Retrieves an item with a particular key.
- * @param {String} key The key to lookup.
- * @return {Object} The value at that key. If it doesn't exist, <tt>undefined</tt> is returned.
- */
- get: function(key) {
- return this.map[key];
- },
- /**
- * Removes all items from the hash.
- * @return {Ext.util.HashMap} this
- */
- clear: function(/* private */ initial) {
- var me = this;
- me.map = {};
- me.length = 0;
- if (initial !== true) {
- me.fireEvent('clear', me);
- }
- return me;
- },
- /**
- * Checks whether a key exists in the hash.
- * @param {String} key The key to check for.
- * @return {Boolean} True if they key exists in the hash.
- */
- containsKey: function(key) {
- return this.map[key] !== undefined;
- },
- /**
- * Checks whether a value exists in the hash.
- * @param {Object} value The value to check for.
- * @return {Boolean} True if the value exists in the dictionary.
- */
- contains: function(value) {
- return this.containsKey(this.findKey(value));
- },
- /**
- * Return all of the keys in the hash.
- * @return {Array} An array of keys.
- */
- getKeys: function() {
- return this.getArray(true);
- },
- /**
- * Return all of the values in the hash.
- * @return {Array} An array of values.
- */
- getValues: function() {
- return this.getArray(false);
- },
- /**
- * Gets either the keys/values in an array from the hash.
- * @private
- * @param {Boolean} isKey True to extract the keys, otherwise, the value
- * @return {Array} An array of either keys/values from the hash.
- */
- getArray: function(isKey) {
- var arr = [],
- key,
- map = this.map;
- for (key in map) {
- if (map.hasOwnProperty(key)) {
- arr.push(isKey ? key: map[key]);
- }
- }
- return arr;
- },
- /**
- * Executes the specified function once for each item in the hash.
- * Returning false from the function will cease iteration.
- *
- * The paramaters passed to the function are:
- * <div class="mdetail-params"><ul>
- * <li><b>key</b> : String<p class="sub-desc">The key of the item</p></li>
- * <li><b>value</b> : Number<p class="sub-desc">The value of the item</p></li>
- * <li><b>length</b> : Number<p class="sub-desc">The total number of items in the hash</p></li>
- * </ul></div>
- * @param {Function} fn The function to execute.
- * @param {Object} scope The scope to execute in. Defaults to <tt>this</tt>.
- * @return {Ext.util.HashMap} this
- */
- each: function(fn, scope) {
- // copy items so they may be removed during iteration.
- var items = Ext.apply({}, this.map),
- key,
- length = this.length;
- scope = scope || this;
- for (key in items) {
- if (items.hasOwnProperty(key)) {
- if (fn.call(scope, key, items[key], length) === false) {
- break;
- }
- }
- }
- return this;
- },
- /**
- * Performs a shallow copy on this hash.
- * @return {Ext.util.HashMap} The new hash object.
- */
- clone: function() {
- var hash = new this.self(),
- map = this.map,
- key;
- hash.suspendEvents();
- for (key in map) {
- if (map.hasOwnProperty(key)) {
- hash.add(key, map[key]);
- }
- }
- hash.resumeEvents();
- return hash;
- },
- /**
- * @private
- * Find the key for a value.
- * @param {Object} value The value to find.
- * @return {Object} The value of the item. Returns <tt>undefined</tt> if not found.
- */
- findKey: function(value) {
- var key,
- map = this.map;
- for (key in map) {
- if (map.hasOwnProperty(key) && map[key] === value) {
- return key;
- }
- }
- return undefined;
- }
- });
- /**
- * @class Ext.state.Manager
- * This is the global state manager. By default all components that are "state aware" check this class
- * for state information if you don't pass them a custom state provider. In order for this class
- * to be useful, it must be initialized with a provider when your application initializes. Example usage:
- <pre><code>
- // in your initialization function
- init : function(){
- Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
- var win = new Window(...);
- win.restoreState();
- }
- </code></pre>
- * This class passes on calls from components to the underlying {@link Ext.state.Provider} so that
- * there is a common interface that can be used without needing to refer to a specific provider instance
- * in every component.
- * @singleton
- * @docauthor Evan Trimboli <evan@sencha.com>
- */
- Ext.define('Ext.state.Manager', {
- singleton: true,
- requires: ['Ext.state.Provider'],
- constructor: function() {
- this.provider = Ext.create('Ext.state.Provider');
- },
-
-
- /**
- * Configures the default state provider for your application
- * @param {Ext.state.Provider} stateProvider The state provider to set
- */
- setProvider : function(stateProvider){
- this.provider = stateProvider;
- },
- /**
- * Returns the current value for a key
- * @param {String} name The key name
- * @param {Object} defaultValue The default value to return if the key lookup does not match
- * @return {Object} The state data
- */
- get : function(key, defaultValue){
- return this.provider.get(key, defaultValue);
- },
- /**
- * Sets the value for a key
- * @param {String} name The key name
- * @param {Object} value The state data
- */
- set : function(key, value){
- this.provider.set(key, value);
- },
- /**
- * Clears a value from the state
- * @param {String} name The key name
- */
- clear : function(key){
- this.provider.clear(key);
- },
- /**
- * Gets the currently configured state provider
- * @return {Ext.state.Provider} The state provider
- */
- getProvider : function(){
- return this.provider;
- }
- });
- /**
- * @class Ext.state.Stateful
- * A mixin for being able to save the state of an object to an underlying
- * {@link Ext.state.Provider}.
- */
- Ext.define('Ext.state.Stateful', {
- /* Begin Definitions */
- mixins: {
- observable: 'Ext.util.Observable'
- },
- requires: ['Ext.state.Manager'],
- /* End Definitions */
- /**
- * @cfg {Boolean} stateful
- * <p>A flag which causes the object to attempt to restore the state of
- * internal properties from a saved state on startup. The object must have
- * a <code>{@link #stateId}</code> for state to be managed.
- * Auto-generated ids are not guaranteed to be stable across page loads and
- * cannot be relied upon to save and restore the same state for a object.<p>
- * <p>For state saving to work, the state manager's provider must have been
- * set to an implementation of {@link Ext.state.Provider} which overrides the
- * {@link Ext.state.Provider#set set} and {@link Ext.state.Provider#get get}
- * methods to save and recall name/value pairs. A built-in implementation,
- * {@link Ext.state.CookieProvider} is available.</p>
- * <p>To set the state provider for the current page:</p>
- * <pre><code>
- Ext.state.Manager.setProvider(new Ext.state.CookieProvider({
- expires: new Date(new Date().getTime()+(1000*60*60*24*7)), //7 days from now
- }));
- * </code></pre>
- * <p>A stateful object attempts to save state when one of the events
- * listed in the <code>{@link #stateEvents}</code> configuration fires.</p>
- * <p>To save state, a stateful object first serializes its state by
- * calling <b><code>{@link #getState}</code></b>. By default, this function does
- * nothing. The developer must provide an implementation which returns an
- * object hash which represents the restorable state of the object.</p>
- * <p>The value yielded by getState is passed to {@link Ext.state.Manager#set}
- * which uses the configured {@link Ext.state.Provider} to save the object
- * keyed by the <code>{@link #stateId}</code>.</p>
- * <p>During construction, a stateful object attempts to <i>restore</i>
- * its state by calling {@link Ext.state.Manager#get} passing the
- * <code>{@link #stateId}</code></p>
- * <p>The resulting object is passed to <b><code>{@link #applyState}</code></b>.
- * The default implementation of <code>{@link #applyState}</code> simply copies
- * properties into the object, but a developer may override this to support
- * more behaviour.</p>
- * <p>You can perform extra processing on state save and restore by attaching
- * handlers to the {@link #beforestaterestore}, {@link #staterestore},
- * {@link #beforestatesave} and {@link #statesave} events.</p>
- */
- stateful: true,
- /**
- * @cfg {String} stateId
- * The unique id for this object to use for state management purposes.
- * <p>See {@link #stateful} for an explanation of saving and restoring state.</p>
- */
- /**
- * @cfg {String[]} stateEvents
- * <p>An array of events that, when fired, should trigger this object to
- * save its state. Defaults to none. <code>stateEvents</code> may be any type
- * of event supported by this object, including browser or custom events
- * (e.g., <tt>['click', 'customerchange']</tt>).</p>
- * <p>See <code>{@link #stateful}</code> for an explanation of saving and
- * restoring object state.</p>
- */
- /**
- * @cfg {Number} saveDelay
- * A buffer to be applied if many state events are fired within a short period.
- */
- saveDelay: 100,
- autoGenIdRe: /^((\w+-)|(ext-comp-))\d{4,}$/i,
- constructor: function(config) {
- var me = this;
- config = config || {};
- if (Ext.isDefined(config.stateful)) {
- me.stateful = config.stateful;
- }
- if (Ext.isDefined(config.saveDelay)) {
- me.saveDelay = config.saveDelay;
- }
- me.stateId = me.stateId || config.stateId;
- if (!me.stateEvents) {
- me.stateEvents = [];
- }
- if (config.stateEvents) {
- me.stateEvents.concat(config.stateEvents);
- }
- this.addEvents(
- /**
- * @event beforestaterestore
- * Fires before the state of the object is restored. Return false from an event handler to stop the restore.
- * @param {Ext.state.Stateful} this
- * @param {Object} state The hash of state values returned from the StateProvider. If this
- * event is not vetoed, then the state object is passed to <b><tt>applyState</tt></b>. By default,
- * that simply copies property values into this object. The method maybe overriden to
- * provide custom state restoration.
- */
- 'beforestaterestore',
- /**
- * @event staterestore
- * Fires after the state of the object is restored.
- * @param {Ext.state.Stateful} this
- * @param {Object} state The hash of state values returned from the StateProvider. This is passed
- * to <b><tt>applyState</tt></b>. By default, that simply copies property values into this
- * object. The method maybe overriden to provide custom state restoration.
- */
- 'staterestore',
- /**
- * @event beforestatesave
- * Fires before the state of the object is saved to the configured state provider. Return false to stop the save.
- * @param {Ext.state.Stateful} this
- * @param {Object} state The hash of state values. This is determined by calling
- * <b><tt>getState()</tt></b> on the object. This method must be provided by the
- * developer to return whetever representation of state is required, by default, Ext.state.Stateful
- * has a null implementation.
- */
- 'beforestatesave',
- /**
- * @event statesave
- * Fires after the state of the object is saved to the configured state provider.
- * @param {Ext.state.Stateful} this
- * @param {Object} state The hash of state values. This is determined by calling
- * <b><tt>getState()</tt></b> on the object. This method must be provided by the
- * developer to return whetever representation of state is required, by default, Ext.state.Stateful
- * has a null implementation.
- */
- 'statesave'
- );
- me.mixins.observable.constructor.call(me);
- if (me.stateful !== false) {
- me.initStateEvents();
- me.initState();
- }
- },
- /**
- * Initializes any state events for this object.
- * @private
- */
- initStateEvents: function() {
- this.addStateEvents(this.stateEvents);
- },
- /**
- * Add events that will trigger the state to be saved.
- * @param {String/String[]} events The event name or an array of event names.
- */
- addStateEvents: function(events){
- if (!Ext.isArray(events)) {
- events = [events];
- }
- var me = this,
- i = 0,
- len = events.length;
- for (; i < len; ++i) {
- me.on(events[i], me.onStateChange, me);
- }
- },
- /**
- * This method is called when any of the {@link #stateEvents} are fired.
- * @private
- */
- onStateChange: function(){
- var me = this,
- delay = me.saveDelay;
- if (delay > 0) {
- if (!me.stateTask) {
- me.stateTask = Ext.create('Ext.util.DelayedTask', me.saveState, me);
- }
- me.stateTask.delay(me.saveDelay);
- } else {
- me.saveState();
- }
- },
- /**
- * Saves the state of the object to the persistence store.
- * @private
- */
- saveState: function() {
- var me = this,
- id,
- state;
- if (me.stateful !== false) {
- id = me.getStateId();
- if (id) {
- state = me.getState();
- if (me.fireEvent('beforestatesave', me, state) !== false) {
- Ext.state.Manager.set(id, state);
- me.fireEvent('statesave', me, state);
- }
- }
- }
- },
- /**
- * Gets the current state of the object. By default this function returns null,
- * it should be overridden in subclasses to implement methods for getting the state.
- * @return {Object} The current state
- */
- getState: function(){
- return null;
- },
- /**
- * Applies the state to the object. This should be overridden in subclasses to do
- * more complex state operations. By default it applies the state properties onto
- * the current object.
- * @param {Object} state The state
- */
- applyState: function(state) {
- if (state) {
- Ext.apply(this, state);
- }
- },
- /**
- * Gets the state id for this object.
- * @return {String} The state id, null if not found.
- */
- getStateId: function() {
- var me = this,
- id = me.stateId;
- if (!id) {
- id = me.autoGenIdRe.test(String(me.id)) ? null : me.id;
- }
- return id;
- },
- /**
- * Initializes the state of the object upon construction.
- * @private
- */
- initState: function(){
- var me = this,
- id = me.getStateId(),
- state;
- if (me.stateful !== false) {
- if (id) {
- state = Ext.state.Manager.get(id);
- if (state) {
- state = Ext.apply({}, state);
- if (me.fireEvent('beforestaterestore', me, state) !== false) {
- me.applyState(state);
- me.fireEvent('staterestore', me, state);
- }
- }
- }
- }
- },
- /**
- * Conditionally saves a single property from this object to the given state object.
- * The idea is to only save state which has changed from the initial state so that
- * current software settings do not override future software settings. Only those
- * values that are user-changed state should be saved.
- *
- * @param {String} propName The name of the property to save.
- * @param {Object} state The state object in to which to save the property.
- * @param {String} stateName (optional) The name to use for the property in state.
- * @return {Boolean} True if the property was saved, false if not.
- */
- savePropToState: function (propName, state, stateName) {
- var me = this,
- value = me[propName],
- config = me.initialConfig;
- if (me.hasOwnProperty(propName)) {
- if (!config || config[propName] !== value) {
- if (state) {
- state[stateName || propName] = value;
- }
- return true;
- }
- }
- return false;
- },
- savePropsToState: function (propNames, state) {
- var me = this;
- Ext.each(propNames, function (propName) {
- me.savePropToState(propName, state);
- });
- return state;
- },
- /**
- * Destroys this stateful object.
- */
- destroy: function(){
- var task = this.stateTask;
- if (task) {
- task.cancel();
- }
- this.clearListeners();
- }
- });
- /**
- * Base Manager class
- */
- Ext.define('Ext.AbstractManager', {
- /* Begin Definitions */
- requires: ['Ext.util.HashMap'],
- /* End Definitions */
- typeName: 'type',
- constructor: function(config) {
- Ext.apply(this, config || {});
- /**
- * @property {Ext.util.HashMap} all
- * Contains all of the items currently managed
- */
- this.all = Ext.create('Ext.util.HashMap');
- this.types = {};
- },
- /**
- * Returns an item by id.
- * For additional details see {@link Ext.util.HashMap#get}.
- * @param {String} id The id of the item
- * @return {Object} The item, undefined if not found.
- */
- get : function(id) {
- return this.all.get(id);
- },
- /**
- * Registers an item to be managed
- * @param {Object} item The item to register
- */
- register: function(item) {
- this.all.add(item);
- },
- /**
- * Unregisters an item by removing it from this manager
- * @param {Object} item The item to unregister
- */
- unregister: function(item) {
- this.all.remove(item);
- },
- /**
- * Registers a new item constructor, keyed by a type key.
- * @param {String} type The mnemonic string by which the class may be looked up.
- * @param {Function} cls The new instance class.
- */
- registerType : function(type, cls) {
- this.types[type] = cls;
- cls[this.typeName] = type;
- },
- /**
- * Checks if an item type is registered.
- * @param {String} type The mnemonic string by which the class may be looked up
- * @return {Boolean} Whether the type is registered.
- */
- isRegistered : function(type){
- return this.types[type] !== undefined;
- },
- /**
- * Creates and returns an instance of whatever this manager manages, based on the supplied type and
- * config object.
- * @param {Object} config The config object
- * @param {String} defaultType If no type is discovered in the config object, we fall back to this type
- * @return {Object} The instance of whatever this manager is managing
- */
- create: function(config, defaultType) {
- var type = config[this.typeName] || config.type || defaultType,
- Constructor = this.types[type];
- return new Constructor(config);
- },
- /**
- * Registers a function that will be called when an item with the specified id is added to the manager.
- * This will happen on instantiation.
- * @param {String} id The item id
- * @param {Function} fn The callback function. Called with a single parameter, the item.
- * @param {Object} scope The scope (this reference) in which the callback is executed.
- * Defaults to the item.
- */
- onAvailable : function(id, fn, scope){
- var all = this.all,
- item;
-
- if (all.containsKey(id)) {
- item = all.get(id);
- fn.call(scope || item, item);
- } else {
- all.on('add', function(map, key, item){
- if (key == id) {
- fn.call(scope || item, item);
- all.un('add', fn, scope);
- }
- });
- }
- },
-
- /**
- * Executes the specified function once for each item in the collection.
- * @param {Function} fn The function to execute.
- * @param {String} fn.key The key of the item
- * @param {Number} fn.value The value of the item
- * @param {Number} fn.length The total number of items in the collection
- * @param {Boolean} fn.return False to cease iteration.
- * @param {Object} scope The scope to execute in. Defaults to `this`.
- */
- each: function(fn, scope){
- this.all.each(fn, scope || this);
- },
-
- /**
- * Gets the number of items in the collection.
- * @return {Number} The number of items in the collection.
- */
- getCount: function(){
- return this.all.getCount();
- }
- });
- /**
- * @class Ext.ComponentManager
- * @extends Ext.AbstractManager
- * <p>Provides a registry of all Components (instances of {@link Ext.Component} or any subclass
- * thereof) on a page so that they can be easily accessed by {@link Ext.Component component}
- * {@link Ext.Component#id id} (see {@link #get}, or the convenience method {@link Ext#getCmp Ext.getCmp}).</p>
- * <p>This object also provides a registry of available Component <i>classes</i>
- * indexed by a mnemonic code known as the Component's {@link Ext.Component#xtype xtype}.
- * The <code>xtype</code> provides a way to avoid instantiating child Components
- * when creating a full, nested config object for a complete Ext page.</p>
- * <p>A child Component may be specified simply as a <i>config object</i>
- * as long as the correct <code>{@link Ext.Component#xtype xtype}</code> is specified so that if and when the Component
- * needs rendering, the correct type can be looked up for lazy instantiation.</p>
- * <p>For a list of all available <code>{@link Ext.Component#xtype xtypes}</code>, see {@link Ext.Component}.</p>
- * @singleton
- */
- Ext.define('Ext.ComponentManager', {
- extend: 'Ext.AbstractManager',
- alternateClassName: 'Ext.ComponentMgr',
-
- singleton: true,
-
- typeName: 'xtype',
-
- /**
- * Creates a new Component from the specified config object using the
- * config object's xtype to determine the class to instantiate.
- * @param {Object} config A configuration object for the Component you wish to create.
- * @param {Function} defaultType (optional) The constructor to provide the default Component type if
- * the config object does not contain a <code>xtype</code>. (Optional if the config contains a <code>xtype</code>).
- * @return {Ext.Component} The newly instantiated Component.
- */
- create: function(component, defaultType){
- if (component instanceof Ext.AbstractComponent) {
- return component;
- }
- else if (Ext.isString(component)) {
- return Ext.createByAlias('widget.' + component);
- }
- else {
- var type = component.xtype || defaultType,
- config = component;
-
- return Ext.createByAlias('widget.' + type, config);
- }
- },
- registerType: function(type, cls) {
- this.types[type] = cls;
- cls[this.typeName] = type;
- cls.prototype[this.typeName] = type;
- }
- });
- /**
- * An abstract base class which provides shared methods for Components across the Sencha product line.
- *
- * Please refer to sub class's documentation
- * @private
- */
- Ext.define('Ext.AbstractComponent', {
- /* Begin Definitions */
- requires: [
- 'Ext.ComponentQuery',
- 'Ext.ComponentManager'
- ],
- mixins: {
- observable: 'Ext.util.Observable',
- animate: 'Ext.util.Animate',
- state: 'Ext.state.Stateful'
- },
- // The "uses" property specifies class which are used in an instantiated AbstractComponent.
- // They do *not* have to be loaded before this class may be defined - that is what "requires" is for.
- uses: [
- 'Ext.PluginManager',
- 'Ext.ComponentManager',
- 'Ext.Element',
- 'Ext.DomHelper',
- 'Ext.XTemplate',
- 'Ext.ComponentQuery',
- 'Ext.ComponentLoader',
- 'Ext.EventManager',
- 'Ext.layout.Layout',
- 'Ext.layout.component.Auto',
- 'Ext.LoadMask',
- 'Ext.ZIndexManager'
- ],
- statics: {
- AUTO_ID: 1000
- },
- /* End Definitions */
- isComponent: true,
- getAutoId: function() {
- return ++Ext.AbstractComponent.AUTO_ID;
- },
- /**
- * @cfg {String} id
- * The **unique id of this component instance.**
- *
- * It should not be necessary to use this configuration except for singleton objects in your application. Components
- * created with an id may be accessed globally using {@link Ext#getCmp Ext.getCmp}.
- *
- * Instead of using assigned ids, use the {@link #itemId} config, and {@link Ext.ComponentQuery ComponentQuery}
- * which provides selector-based searching for Sencha Components analogous to DOM querying. The {@link
- * Ext.container.Container Container} class contains {@link Ext.container.Container#down shortcut methods} to query
- * its descendant Components by selector.
- *
- * Note that this id will also be used as the element id for the containing HTML element that is rendered to the
- * page for this component. This allows you to write id-based CSS rules to style the specific instance of this
- * component uniquely, and also to select sub-elements using this component's id as the parent.
- *
- * **Note**: to avoid complications imposed by a unique id also see `{@link #itemId}`.
- *
- * **Note**: to access the container of a Component see `{@link #ownerCt}`.
- *
- * Defaults to an {@link #getId auto-assigned id}.
- */
- /**
- * @cfg {String} itemId
- * An itemId can be used as an alternative way to get a reference to a component when no object reference is
- * available. Instead of using an `{@link #id}` with {@link Ext}.{@link Ext#getCmp getCmp}, use `itemId` with
- * {@link Ext.container.Container}.{@link Ext.container.Container#getComponent getComponent} which will retrieve
- * `itemId`'s or {@link #id}'s. Since `itemId`'s are an index to the container's internal MixedCollection, the
- * `itemId` is scoped locally to the container -- avoiding potential conflicts with {@link Ext.ComponentManager}
- * which requires a **unique** `{@link #id}`.
- *
- * var c = new Ext.panel.Panel({ //
- * {@link Ext.Component#height height}: 300,
- * {@link #renderTo}: document.body,
- * {@link Ext.container.Container#layout layout}: 'auto',
- * {@link Ext.container.Container#items items}: [
- * {
- * itemId: 'p1',
- * {@link Ext.panel.Panel#title title}: 'Panel 1',
- * {@link Ext.Component#height height}: 150
- * },
- * {
- * itemId: 'p2',
- * {@link Ext.panel.Panel#title title}: 'Panel 2',
- * {@link Ext.Component#height height}: 150
- * }
- * ]
- * })
- * p1 = c.{@link Ext.container.Container#getComponent getComponent}('p1'); // not the same as {@link Ext#getCmp Ext.getCmp()}
- * p2 = p1.{@link #ownerCt}.{@link Ext.container.Container#getComponent getComponent}('p2'); // reference via a sibling
- *
- * Also see {@link #id}, `{@link Ext.container.Container#query}`, `{@link Ext.container.Container#down}` and
- * `{@link Ext.container.Container#child}`.
- *
- * **Note**: to access the container of an item see {@link #ownerCt}.
- */
- /**
- * @property {Ext.Container} ownerCt
- * This Component's owner {@link Ext.container.Container Container} (is set automatically
- * when this Component is added to a Container). Read-only.
- *
- * **Note**: to access items within the Container see {@link #itemId}.
- */
- /**
- * @property {Boolean} layoutManagedWidth
- * @private
- * Flag set by the container layout to which this Component is added.
- * If the layout manages this Component's width, it sets the value to 1.
- * If it does NOT manage the width, it sets it to 2.
- * If the layout MAY affect the width, but only if the owning Container has a fixed width, this is set to 0.
- */
- /**
- * @property {Boolean} layoutManagedHeight
- * @private
- * Flag set by the container layout to which this Component is added.
- * If the layout manages this Component's height, it sets the value to 1.
- * If it does NOT manage the height, it sets it to 2.
- * If the layout MAY affect the height, but only if the owning Container has a fixed height, this is set to 0.
- */
- /**
- * @cfg {String/Object} autoEl
- * A tag name or {@link Ext.DomHelper DomHelper} spec used to create the {@link #getEl Element} which will
- * encapsulate this Component.
- *
- * You do not normally need to specify this. For the base classes {@link Ext.Component} and
- * {@link Ext.container.Container}, this defaults to **'div'**. The more complex Sencha classes use a more
- * complex DOM structure specified by their own {@link #renderTpl}s.
- *
- * This is intended to allow the developer to create application-specific utility Components encapsulated by
- * different DOM elements. Example usage:
- *
- * {
- * xtype: 'component',
- * autoEl: {
- * tag: 'img',
- * src: 'http://www.example.com/example.jpg'
- * }
- * }, {
- * xtype: 'component',
- * autoEl: {
- * tag: 'blockquote',
- * html: 'autoEl is cool!'
- * }
- * }, {
- * xtype: 'container',
- * autoEl: 'ul',
- * cls: 'ux-unordered-list',
- * items: {
- * xtype: 'component',
- * autoEl: 'li',
- * html: 'First list item'
- * }
- * }
- */
- /**
- * @cfg {Ext.XTemplate/String/String[]} renderTpl
- * An {@link Ext.XTemplate XTemplate} used to create the internal structure inside this Component's encapsulating
- * {@link #getEl Element}.
- *
- * You do not normally need to specify this. For the base classes {@link Ext.Component} and
- * {@link Ext.container.Container}, this defaults to **`null`** which means that they will be initially rendered
- * with no internal structure; they render their {@link #getEl Element} empty. The more specialized ExtJS and Touch
- * classes which use a more complex DOM structure, provide their own template definitions.
- *
- * This is intended to allow the developer to create application-specific utility Components with customized
- * internal structure.
- *
- * Upon rendering, any created child elements may be automatically imported into object properties using the
- * {@link #renderSelectors} and {@link #childEls} options.
- */
- renderTpl: null,
- /**
- * @cfg {Object} renderData
- *
- * The data used by {@link #renderTpl} in addition to the following property values of the component:
- *
- * - id
- * - ui
- * - uiCls
- * - baseCls
- * - componentCls
- * - frame
- *
- * See {@link #renderSelectors} and {@link #childEls} for usage examples.
- */
- /**
- * @cfg {Object} renderSelectors
- * An object containing properties specifying {@link Ext.DomQuery DomQuery} selectors which identify child elements
- * created by the render process.
- *
- * After the Component's internal structure is rendered according to the {@link #renderTpl}, this object is iterated through,
- * and the found Elements are added as properties to the Component using the `renderSelector` property name.
- *
- * For example, a Component which renderes a title and description into its element:
- *
- * Ext.create('Ext.Component', {
- * renderTo: Ext.getBody(),
- * renderTpl: [
- * '<h1 class="title">{title}</h1>',
- * '<p>{desc}</p>'
- * ],
- * renderData: {
- * title: "Error",
- * desc: "Something went wrong"
- * },
- * renderSelectors: {
- * titleEl: 'h1.title',
- * descEl: 'p'
- * },
- * listeners: {
- * afterrender: function(cmp){
- * // After rendering the component will have a titleEl and descEl properties
- * cmp.titleEl.setStyle({color: "red"});
- * }
- * }
- * });
- *
- * For a faster, but less flexible, alternative that achieves the same end result (properties for child elements on the
- * Component after render), see {@link #childEls} and {@link #addChildEls}.
- */
- /**
- * @cfg {Object[]} childEls
- * An array describing the child elements of the Component. Each member of the array
- * is an object with these properties:
- *
- * - `name` - The property name on the Component for the child element.
- * - `itemId` - The id to combine with the Component's id that is the id of the child element.
- * - `id` - The id of the child element.
- *
- * If the array member is a string, it is equivalent to `{ name: m, itemId: m }`.
- *
- * For example, a Component which renders a title and body text:
- *
- * Ext.create('Ext.Component', {
- * renderTo: Ext.getBody(),
- * renderTpl: [
- * '<h1 id="{id}-title">{title}</h1>',
- * '<p>{msg}</p>',
- * ],
- * renderData: {
- * title: "Error",
- * msg: "Something went wrong"
- * },
- * childEls: ["title"],
- * listeners: {
- * afterrender: function(cmp){
- * // After rendering the component will have a title property
- * cmp.title.setStyle({color: "red"});
- * }
- * }
- * });
- *
- * A more flexible, but somewhat slower, approach is {@link #renderSelectors}.
- */
- /**
- * @cfg {String/HTMLElement/Ext.Element} renderTo
- * Specify the id of the element, a DOM element or an existing Element that this component will be rendered into.
- *
- * **Notes:**
- *
- * Do *not* use this option if the Component is to be a child item of a {@link Ext.container.Container Container}.
- * It is the responsibility of the {@link Ext.container.Container Container}'s
- * {@link Ext.container.Container#layout layout manager} to render and manage its child items.
- *
- * When using this config, a call to render() is not required.
- *
- * See `{@link #render}` also.
- */
- /**
- * @cfg {Boolean} frame
- * Specify as `true` to have the Component inject framing elements within the Component at render time to provide a
- * graphical rounded frame around the Component content.
- *
- * This is only necessary when running on outdated, or non standard-compliant browsers such as Microsoft's Internet
- * Explorer prior to version 9 which do not support rounded corners natively.
- *
- * The extra space taken up by this framing is available from the read only property {@link #frameSize}.
- */
- /**
- * @property {Object} frameSize
- * Read-only property indicating the width of any framing elements which were added within the encapsulating element
- * to provide graphical, rounded borders. See the {@link #frame} config.
- *
- * This is an object containing the frame width in pixels for all four sides of the Component containing the
- * following properties:
- *
- * @property {Number} frameSize.top The width of the top framing element in pixels.
- * @property {Number} frameSize.right The width of the right framing element in pixels.
- * @property {Number} frameSize.bottom The width of the bottom framing element in pixels.
- * @property {Number} frameSize.left The width of the left framing element in pixels.
- */
- /**
- * @cfg {String/Object} componentLayout
- * The sizing and positioning of a Component's internal Elements is the responsibility of the Component's layout
- * manager which sizes a Component's internal structure in response to the Component being sized.
- *
- * Generally, developers will not use this configuration as all provided Components which need their internal
- * elements sizing (Such as {@link Ext.form.field.Base input fields}) come with their own componentLayout managers.
- *
- * The {@link Ext.layout.container.Auto default layout manager} will be used on instances of the base Ext.Component
- * class which simply sizes the Component's encapsulating element to the height and width specified in the
- * {@link #setSize} method.
- */
- /**
- * @cfg {Ext.XTemplate/Ext.Template/String/String[]} tpl
- * An {@link Ext.Template}, {@link Ext.XTemplate} or an array of strings to form an Ext.XTemplate. Used in
- * conjunction with the `{@link #data}` and `{@link #tplWriteMode}` configurations.
- */
- /**
- * @cfg {Object} data
- * The initial set of data to apply to the `{@link #tpl}` to update the content area of the Component.
- */
- /**
- * @cfg {String} xtype
- * The `xtype` configuration option can be used to optimize Component creation and rendering. It serves as a
- * shortcut to the full componet name. For example, the component `Ext.button.Button` has an xtype of `button`.
- *
- * You can define your own xtype on a custom {@link Ext.Component component} by specifying the
- * {@link Ext.Class#alias alias} config option with a prefix of `widget`. For example:
- *
- * Ext.define('PressMeButton', {
- * extend: 'Ext.button.Button',
- * alias: 'widget.pressmebutton',
- * text: 'Press Me'
- * })
- *
- * Any Component can be created implicitly as an object config with an xtype specified, allowing it to be
- * declared and passed into the rendering pipeline without actually being instantiated as an object. Not only is
- * rendering deferred, but the actual creation of the object itself is also deferred, saving memory and resources
- * until they are actually needed. In complex, nested layouts containing many Components, this can make a
- * noticeable improvement in performance.
- *
- * // Explicit creation of contained Components:
- * var panel = new Ext.Panel({
- * ...
- * items: [
- * Ext.create('Ext.button.Button', {
- * text: 'OK'
- * })
- * ]
- * };
- *
- * // Implicit creation using xtype:
- * var panel = new Ext.Panel({
- * ...
- * items: [{
- * xtype: 'button',
- * text: 'OK'
- * }]
- * };
- *
- * In the first example, the button will always be created immediately during the panel's initialization. With
- * many added Components, this approach could potentially slow the rendering of the page. In the second example,
- * the button will not be created or rendered until the panel is actually displayed in the browser. If the panel
- * is never displayed (for example, if it is a tab that remains hidden) then the button will never be created and
- * will never consume any resources whatsoever.
- */
- /**
- * @cfg {String} tplWriteMode
- * The Ext.(X)Template method to use when updating the content area of the Component.
- * See `{@link Ext.XTemplate#overwrite}` for information on default mode.
- */
- tplWriteMode: 'overwrite',
- /**
- * @cfg {String} [baseCls='x-component']
- * The base CSS class to apply to this components's element. This will also be prepended to elements within this
- * component like Panel's body will get a class x-panel-body. This means that if you create a subclass of Panel, and
- * you want it to get all the Panels styling for the element and the body, you leave the baseCls x-panel and use
- * componentCls to add specific styling for this component.
- */
- baseCls: Ext.baseCSSPrefix + 'component',
- /**
- * @cfg {String} componentCls
- * CSS Class to be added to a components root level element to give distinction to it via styling.
- */
- /**
- * @cfg {String} [cls='']
- * An optional extra CSS class that will be added to this component's Element. This can be useful
- * for adding customized styles to the component or any of its children using standard CSS rules.
- */
- /**
- * @cfg {String} [overCls='']
- * An optional extra CSS class that will be added to this component's Element when the mouse moves over the Element,
- * and removed when the mouse moves out. This can be useful for adding customized 'active' or 'hover' styles to the
- * component or any of its children using standard CSS rules.
- */
- /**
- * @cfg {String} [disabledCls='x-item-disabled']
- * CSS class to add when the Component is disabled. Defaults to 'x-item-disabled'.
- */
- disabledCls: Ext.baseCSSPrefix + 'item-disabled',
- /**
- * @cfg {String/String[]} ui
- * A set style for a component. Can be a string or an Array of multiple strings (UIs)
- */
- ui: 'default',
- /**
- * @cfg {String[]} uiCls
- * An array of of classNames which are currently applied to this component
- * @private
- */
- uiCls: [],
- /**
- * @cfg {String} style
- * A custom style specification to be applied to this component's Element. Should be a valid argument to
- * {@link Ext.Element#applyStyles}.
- *
- * new Ext.panel.Panel({
- * title: 'Some Title',
- * renderTo: Ext.getBody(),
- * width: 400, height: 300,
- * layout: 'form',
- * items: [{
- * xtype: 'textarea',
- * style: {
- * width: '95%',
- * marginBottom: '10px'
- * }
- * },
- * new Ext.button.Button({
- * text: 'Send',
- * minWidth: '100',
- * style: {
- * marginBottom: '10px'
- * }
- * })
- * ]
- * });
- */
- /**
- * @cfg {Number} width
- * The width of this component in pixels.
- */
- /**
- * @cfg {Number} height
- * The height of this component in pixels.
- */
- /**
- * @cfg {Number/String} border
- * Specifies the border for this component. The border can be a single numeric value to apply to all sides or it can
- * be a CSS style specification for each style, for example: '10 5 3 10'.
- */
- /**
- * @cfg {Number/String} padding
- * Specifies the padding for this component. The padding can be a single numeric value to apply to all sides or it
- * can be a CSS style specification for each style, for example: '10 5 3 10'.
- */
- /**
- * @cfg {Number/String} margin
- * Specifies the margin for this component. The margin can be a single numeric value to apply to all sides or it can
- * be a CSS style specification for each style, for example: '10 5 3 10'.
- */
- /**
- * @cfg {Boolean} hidden
- * True to hide the component.
- */
- hidden: false,
- /**
- * @cfg {Boolean} disabled
- * True to disable the component.
- */
- disabled: false,
- /**
- * @cfg {Boolean} [draggable=false]
- * Allows the component to be dragged.
- */
- /**
- * @property {Boolean} draggable
- * Read-only property indicating whether or not the component can be dragged
- */
- draggable: false,
- /**
- * @cfg {Boolean} floating
- * Create the Component as a floating and use absolute positioning.
- *
- * The z-index of floating Components is handled by a ZIndexManager. If you simply render a floating Component into the DOM, it will be managed
- * by the global {@link Ext.WindowManager WindowManager}.
- *
- * If you include a floating Component as a child item of a Container, then upon render, ExtJS will seek an ancestor floating Component to house a new
- * ZIndexManager instance to manage its descendant floaters. If no floating ancestor can be found, the global WindowManager will be used.
- *
- * When a floating Component which has a ZindexManager managing descendant floaters is destroyed, those descendant floaters will also be destroyed.
- */
- floating: false,
- /**
- * @cfg {String} hideMode
- * A String which specifies how this Component's encapsulating DOM element will be hidden. Values may be:
- *
- * - `'display'` : The Component will be hidden using the `display: none` style.
- * - `'visibility'` : The Component will be hidden using the `visibility: hidden` style.
- * - `'offsets'` : The Component will be hidden by absolutely positioning it out of the visible area of the document.
- * This is useful when a hidden Component must maintain measurable dimensions. Hiding using `display` results in a
- * Component having zero dimensions.
- */
- hideMode: 'display',
- /**
- * @cfg {String} contentEl
- * Specify an existing HTML element, or the `id` of an existing HTML element to use as the content for this component.
- *
- * This config option is used to take an existing HTML element and place it in the layout element of a new component
- * (it simply moves the specified DOM element _after the Component is rendered_ to use as the content.
- *
- * **Notes:**
- *
- * The specified HTML element is appended to the layout element of the component _after any configured
- * {@link #html HTML} has been inserted_, and so the document will not contain this element at the time
- * the {@link #render} event is fired.
- *
- * The specified HTML element used will not participate in any **`{@link Ext.container.Container#layout layout}`**
- * scheme that the Component may use. It is just HTML. Layouts operate on child
- * **`{@link Ext.container.Container#items items}`**.
- *
- * Add either the `x-hidden` or the `x-hide-display` CSS class to prevent a brief flicker of the content before it
- * is rendered to the panel.
- */
- /**
- * @cfg {String/Object} [html='']
- * An HTML fragment, or a {@link Ext.DomHelper DomHelper} specification to use as the layout element content.
- * The HTML content is added after the component is rendered, so the document will not contain this HTML at the time
- * the {@link #render} event is fired. This content is inserted into the body _before_ any configured {@link #contentEl}
- * is appended.
- */
- /**
- * @cfg {Boolean} styleHtmlContent
- * True to automatically style the html inside the content target of this component (body for panels).
- */
- styleHtmlContent: false,
- /**
- * @cfg {String} [styleHtmlCls='x-html']
- * The class that is added to the content target when you set styleHtmlContent to true.
- */
- styleHtmlCls: Ext.baseCSSPrefix + 'html',
- /**
- * @cfg {Number} minHeight
- * The minimum value in pixels which this Component will set its height to.
- *
- * **Warning:** This will override any size management applied by layout managers.
- */
- /**
- * @cfg {Number} minWidth
- * The minimum value in pixels which this Component will set its width to.
- *
- * **Warning:** This will override any size management applied by layout managers.
- */
- /**
- * @cfg {Number} maxHeight
- * The maximum value in pixels which this Component will set its height to.
- *
- * **Warning:** This will override any size management applied by layout managers.
- */
- /**
- * @cfg {Number} maxWidth
- * The maximum value in pixels which this Component will set its width to.
- *
- * **Warning:** This will override any size management applied by layout managers.
- */
- /**
- * @cfg {Ext.ComponentLoader/Object} loader
- * A configuration object or an instance of a {@link Ext.ComponentLoader} to load remote content for this Component.
- */
- /**
- * @cfg {Boolean} autoShow
- * True to automatically show the component upon creation. This config option may only be used for
- * {@link #floating} components or components that use {@link #autoRender}. Defaults to false.
- */
- autoShow: false,
- /**
- * @cfg {Boolean/String/HTMLElement/Ext.Element} autoRender
- * This config is intended mainly for non-{@link #floating} Components which may or may not be shown. Instead of using
- * {@link #renderTo} in the configuration, and rendering upon construction, this allows a Component to render itself
- * upon first _{@link #show}_. If {@link #floating} is true, the value of this config is omited as if it is `true`.
- *
- * Specify as `true` to have this Component render to the document body upon first show.
- *
- * Specify as an element, or the ID of an element to have this Component render to a specific element upon first
- * show.
- *
- * **This defaults to `true` for the {@link Ext.window.Window Window} class.**
- */
- autoRender: false,
- needsLayout: false,
- // @private
- allowDomMove: true,
- /**
- * @cfg {Object/Object[]} plugins
- * An object or array of objects that will provide custom functionality for this component. The only requirement for
- * a valid plugin is that it contain an init method that accepts a reference of type Ext.Component. When a component
- * is created, if any plugins are available, the component will call the init method on each plugin, passing a
- * reference to itself. Each plugin can then call methods or respond to events on the component as needed to provide
- * its functionality.
- */
- /**
- * @property {Boolean} rendered
- * Read-only property indicating whether or not the component has been rendered.
- */
- rendered: false,
- /**
- * @property {Number} componentLayoutCounter
- * @private
- * The number of component layout calls made on this object.
- */
- componentLayoutCounter: 0,
- weight: 0,
- trimRe: /^\s+|\s+$/g,
- spacesRe: /\s+/,
- /**
- * @property {Boolean} maskOnDisable
- * This is an internal flag that you use when creating custom components. By default this is set to true which means
- * that every component gets a mask when its disabled. Components like FieldContainer, FieldSet, Field, Button, Tab
- * override this property to false since they want to implement custom disable logic.
- */
- maskOnDisable: true,
- /**
- * Creates new Component.
- * @param {Object} config (optional) Config object.
- */
- constructor : function(config) {
- var me = this,
- i, len;
- config = config || {};
- me.initialConfig = config;
- Ext.apply(me, config);
- me.addEvents(
- /**
- * @event beforeactivate
- * Fires before a Component has been visually activated. Returning false from an event listener can prevent
- * the activate from occurring.
- * @param {Ext.Component} this
- */
- 'beforeactivate',
- /**
- * @event activate
- * Fires after a Component has been visually activated.
- * @param {Ext.Component} this
- */
- 'activate',
- /**
- * @event beforedeactivate
- * Fires before a Component has been visually deactivated. Returning false from an event listener can
- * prevent the deactivate from occurring.
- * @param {Ext.Component} this
- */
- 'beforedeactivate',
- /**
- * @event deactivate
- * Fires after a Component has been visually deactivated.
- * @param {Ext.Component} this
- */
- 'deactivate',
- /**
- * @event added
- * Fires after a Component had been added to a Container.
- * @param {Ext.Component} this
- * @param {Ext.container.Container} container Parent Container
- * @param {Number} pos position of Component
- */
- 'added',
- /**
- * @event disable
- * Fires after the component is disabled.
- * @param {Ext.Component} this
- */
- 'disable',
- /**
- * @event enable
- * Fires after the component is enabled.
- * @param {Ext.Component} this
- */
- 'enable',
- /**
- * @event beforeshow
- * Fires before the component is shown when calling the {@link #show} method. Return false from an event
- * handler to stop the show.
- * @param {Ext.Component} this
- */
- 'beforeshow',
- /**
- * @event show
- * Fires after the component is shown when calling the {@link #show} method.
- * @param {Ext.Component} this
- */
- 'show',
- /**
- * @event beforehide
- * Fires before the component is hidden when calling the {@link #hide} method. Return false from an event
- * handler to stop the hide.
- * @param {Ext.Component} this
- */
- 'beforehide',
- /**
- * @event hide
- * Fires after the component is hidden. Fires after the component is hidden when calling the {@link #hide}
- * method.
- * @param {Ext.Component} this
- */
- 'hide',
- /**
- * @event removed
- * Fires when a component is removed from an Ext.container.Container
- * @param {Ext.Component} this
- * @param {Ext.container.Container} ownerCt Container which holds the component
- */
- 'removed',
- /**
- * @event beforerender
- * Fires before the component is {@link #rendered}. Return false from an event handler to stop the
- * {@link #render}.
- * @param {Ext.Component} this
- */
- 'beforerender',
- /**
- * @event render
- * Fires after the component markup is {@link #rendered}.
- * @param {Ext.Component} this
- */
- 'render',
- /**
- * @event afterrender
- * Fires after the component rendering is finished.
- *
- * The afterrender event is fired after this Component has been {@link #rendered}, been postprocesed by any
- * afterRender method defined for the Component.
- * @param {Ext.Component} this
- */
- 'afterrender',
- /**
- * @event beforedestroy
- * Fires before the component is {@link #destroy}ed. Return false from an event handler to stop the
- * {@link #destroy}.
- * @param {Ext.Component} this
- */
- 'beforedestroy',
- /**
- * @event destroy
- * Fires after the component is {@link #destroy}ed.
- * @param {Ext.Component} this
- */
- 'destroy',
- /**
- * @event resize
- * Fires after the component is resized.
- * @param {Ext.Component} this
- * @param {Number} adjWidth The box-adjusted width that was set
- * @param {Number} adjHeight The box-adjusted height that was set
- */
- 'resize',
- /**
- * @event move
- * Fires after the component is moved.
- * @param {Ext.Component} this
- * @param {Number} x The new x position
- * @param {Number} y The new y position
- */
- 'move'
- );
- me.getId();
- me.mons = [];
- me.additionalCls = [];
- me.renderData = me.renderData || {};
- me.renderSelectors = me.renderSelectors || {};
- if (me.plugins) {
- me.plugins = [].concat(me.plugins);
- me.constructPlugins();
- }
- me.initComponent();
- // ititComponent gets a chance to change the id property before registering
- Ext.ComponentManager.register(me);
- // Dont pass the config so that it is not applied to 'this' again
- me.mixins.observable.constructor.call(me);
- me.mixins.state.constructor.call(me, config);
- // Save state on resize.
- this.addStateEvents('resize');
- // Move this into Observable?
- if (me.plugins) {
- me.plugins = [].concat(me.plugins);
- for (i = 0, len = me.plugins.length; i < len; i++) {
- me.plugins[i] = me.initPlugin(me.plugins[i]);
- }
- }
- me.loader = me.getLoader();
- if (me.renderTo) {
- me.render(me.renderTo);
- // EXTJSIV-1935 - should be a way to do afterShow or something, but that
- // won't work. Likewise, rendering hidden and then showing (w/autoShow) has
- // implications to afterRender so we cannot do that.
- }
- if (me.autoShow) {
- me.show();
- }
- },
- initComponent: function () {
- // This is called again here to allow derived classes to add plugin configs to the
- // plugins array before calling down to this, the base initComponent.
- this.constructPlugins();
- },
- /**
- * The supplied default state gathering method for the AbstractComponent class.
- *
- * This method returns dimension settings such as `flex`, `anchor`, `width` and `height` along with `collapsed`
- * state.
- *
- * Subclasses which implement more complex state should call the superclass's implementation, and apply their state
- * to the result if this basic state is to be saved.
- *
- * Note that Component state will only be saved if the Component has a {@link #stateId} and there as a StateProvider
- * configured for the document.
- *
- * @return {Object}
- */
- getState: function() {
- var me = this,
- layout = me.ownerCt ? (me.shadowOwnerCt || me.ownerCt).getLayout() : null,
- state = {
- collapsed: me.collapsed
- },
- width = me.width,
- height = me.height,
- cm = me.collapseMemento,
- anchors;
- // If a Panel-local collapse has taken place, use remembered values as the dimensions.
- // TODO: remove this coupling with Panel's privates! All collapse/expand logic should be refactored into one place.
- if (me.collapsed && cm) {
- if (Ext.isDefined(cm.data.width)) {
- width = cm.width;
- }
- if (Ext.isDefined(cm.data.height)) {
- height = cm.height;
- }
- }
- // If we have flex, only store the perpendicular dimension.
- if (layout && me.flex) {
- state.flex = me.flex;
- if (layout.perpendicularPrefix) {
- state[layout.perpendicularPrefix] = me['get' + layout.perpendicularPrefixCap]();
- } else {
- }
- }
- // If we have anchor, only store dimensions which are *not* being anchored
- else if (layout && me.anchor) {
- state.anchor = me.anchor;
- anchors = me.anchor.split(' ').concat(null);
- if (!anchors[0]) {
- if (me.width) {
- state.width = width;
- }
- }
- if (!anchors[1]) {
- if (me.height) {
- state.height = height;
- }
- }
- }
- // Store dimensions.
- else {
- if (me.width) {
- state.width = width;
- }
- if (me.height) {
- state.height = height;
- }
- }
- // Don't save dimensions if they are unchanged from the original configuration.
- if (state.width == me.initialConfig.width) {
- delete state.width;
- }
- if (state.height == me.initialConfig.height) {
- delete state.height;
- }
- // If a Box layout was managing the perpendicular dimension, don't save that dimension
- if (layout && layout.align && (layout.align.indexOf('stretch') !== -1)) {
- delete state[layout.perpendicularPrefix];
- }
- return state;
- },
- show: Ext.emptyFn,
- animate: function(animObj) {
- var me = this,
- to;
- animObj = animObj || {};
- to = animObj.to || {};
- if (Ext.fx.Manager.hasFxBlock(me.id)) {
- return me;
- }
- // Special processing for animating Component dimensions.
- if (!animObj.dynamic && (to.height || to.width)) {
- var curWidth = me.getWidth(),
- w = curWidth,
- curHeight = me.getHeight(),
- h = curHeight,
- needsResize = false;
- if (to.height && to.height > curHeight) {
- h = to.height;
- needsResize = true;
- }
- if (to.width && to.width > curWidth) {
- w = to.width;
- needsResize = true;
- }
- // If any dimensions are being increased, we must resize the internal structure
- // of the Component, but then clip it by sizing its encapsulating element back to original dimensions.
- // The animation will then progressively reveal the larger content.
- if (needsResize) {
- var clearWidth = !Ext.isNumber(me.width),
- clearHeight = !Ext.isNumber(me.height);
- me.componentLayout.childrenChanged = true;
- me.setSize(w, h, me.ownerCt);
- me.el.setSize(curWidth, curHeight);
- if (clearWidth) {
- delete me.width;
- }
- if (clearHeight) {
- delete me.height;
- }
- }
- }
- return me.mixins.animate.animate.apply(me, arguments);
- },
- /**
- * This method finds the topmost active layout who's processing will eventually determine the size and position of
- * this Component.
- *
- * This method is useful when dynamically adding Components into Containers, and some processing must take place
- * after the final sizing and positioning of the Component has been performed.
- *
- * @return {Ext.Component}
- */
- findLayoutController: function() {
- return this.findParentBy(function(c) {
- // Return true if we are at the root of the Container tree
- // or this Container's layout is busy but the next one up is not.
- return !c.ownerCt || (c.layout.layoutBusy && !c.ownerCt.layout.layoutBusy);
- });
- },
- onShow : function() {
- // Layout if needed
- var needsLayout = this.needsLayout;
- if (Ext.isObject(needsLayout)) {
- this.doComponentLayout(needsLayout.width, needsLayout.height, needsLayout.isSetSize, needsLayout.ownerCt);
- }
- },
- constructPlugin: function(plugin) {
- if (plugin.ptype && typeof plugin.init != 'function') {
- plugin.cmp = this;
- plugin = Ext.PluginManager.create(plugin);
- }
- else if (typeof plugin == 'string') {
- plugin = Ext.PluginManager.create({
- ptype: plugin,
- cmp: this
- });
- }
- return plugin;
- },
- /**
- * Ensures that the plugins array contains fully constructed plugin instances. This converts any configs into their
- * appropriate instances.
- */
- constructPlugins: function() {
- var me = this,
- plugins = me.plugins,
- i, len;
- if (plugins) {
- for (i = 0, len = plugins.length; i < len; i++) {
- // this just returns already-constructed plugin instances...
- plugins[i] = me.constructPlugin(plugins[i]);
- }
- }
- },
- // @private
- initPlugin : function(plugin) {
- plugin.init(this);
- return plugin;
- },
- /**
- * Handles autoRender. Floating Components may have an ownerCt. If they are asking to be constrained, constrain them
- * within that ownerCt, and have their z-index managed locally. Floating Components are always rendered to
- * document.body
- */
- doAutoRender: function() {
- var me = this;
- if (me.floating) {
- me.render(document.body);
- } else {
- me.render(Ext.isBoolean(me.autoRender) ? Ext.getBody() : me.autoRender);
- }
- },
- // @private
- render : function(container, position) {
- var me = this;
- if (!me.rendered && me.fireEvent('beforerender', me) !== false) {
- // Flag set during the render process.
- // It can be used to inhibit event-driven layout calls during the render phase
- me.rendering = true;
- // If this.el is defined, we want to make sure we are dealing with
- // an Ext Element.
- if (me.el) {
- me.el = Ext.get(me.el);
- }
- // Perform render-time processing for floating Components
- if (me.floating) {
- me.onFloatRender();
- }
- container = me.initContainer(container);
- me.onRender(container, position);
- // Tell the encapsulating element to hide itself in the way the Component is configured to hide
- // This means DISPLAY, VISIBILITY or OFFSETS.
- me.el.setVisibilityMode(Ext.Element[me.hideMode.toUpperCase()]);
- if (me.overCls) {
- me.el.hover(me.addOverCls, me.removeOverCls, me);
- }
- me.fireEvent('render', me);
- me.initContent();
- me.afterRender(container);
- me.fireEvent('afterrender', me);
- me.initEvents();
- if (me.hidden) {
- // Hiding during the render process should not perform any ancillary
- // actions that the full hide process does; It is not hiding, it begins in a hidden state.'
- // So just make the element hidden according to the configured hideMode
- me.el.hide();
- }
- if (me.disabled) {
- // pass silent so the event doesn't fire the first time.
- me.disable(true);
- }
- // Delete the flag once the rendering is done.
- delete me.rendering;
- }
- return me;
- },
- // @private
- onRender : function(container, position) {
- var me = this,
- el = me.el,
- styles = me.initStyles(),
- renderTpl, renderData, i;
- position = me.getInsertPosition(position);
- if (!el) {
- if (position) {
- el = Ext.DomHelper.insertBefore(position, me.getElConfig(), true);
- }
- else {
- el = Ext.DomHelper.append(container, me.getElConfig(), true);
- }
- }
- else if (me.allowDomMove !== false) {
- if (position) {
- container.dom.insertBefore(el.dom, position);
- } else {
- container.dom.appendChild(el.dom);
- }
- }
- if (Ext.scopeResetCSS && !me.ownerCt) {
- // If this component's el is the body element, we add the reset class to the html tag
- if (el.dom == Ext.getBody().dom) {
- el.parent().addCls(Ext.baseCSSPrefix + 'reset');
- }
- else {
- // Else we wrap this element in an element that adds the reset class.
- me.resetEl = el.wrap({
- cls: Ext.baseCSSPrefix + 'reset'
- });
- }
- }
- me.setUI(me.ui);
- el.addCls(me.initCls());
- el.setStyle(styles);
- // Here we check if the component has a height set through style or css.
- // If it does then we set the this.height to that value and it won't be
- // considered an auto height component
- // if (this.height === undefined) {
- // var height = el.getHeight();
- // // This hopefully means that the panel has an explicit height set in style or css
- // if (height - el.getPadding('tb') - el.getBorderWidth('tb') > 0) {
- // this.height = height;
- // }
- // }
- me.el = el;
- me.initFrame();
- renderTpl = me.initRenderTpl();
- if (renderTpl) {
- renderData = me.initRenderData();
- renderTpl.append(me.getTargetEl(), renderData);
- }
- me.applyRenderSelectors();
- me.rendered = true;
- },
- // @private
- afterRender : function() {
- var me = this,
- pos,
- xy;
- me.getComponentLayout();
- // Set the size if a size is configured, or if this is the outermost Container.
- // Also, if this is a collapsed Panel, it needs an initial component layout
- // to lay out its header so that it can have a height determined.
- if (me.collapsed || (!me.ownerCt || (me.height || me.width))) {
- me.setSize(me.width, me.height);
- } else {
- // It is expected that child items be rendered before this method returns and
- // the afterrender event fires. Since we aren't going to do the layout now, we
- // must render the child items. This is handled implicitly above in the layout
- // caused by setSize.
- me.renderChildren();
- }
- // For floaters, calculate x and y if they aren't defined by aligning
- // the sized element to the center of either the container or the ownerCt
- if (me.floating && (me.x === undefined || me.y === undefined)) {
- if (me.floatParent) {
- xy = me.el.getAlignToXY(me.floatParent.getTargetEl(), 'c-c');
- pos = me.floatParent.getTargetEl().translatePoints(xy[0], xy[1]);
- } else {
- xy = me.el.getAlignToXY(me.container, 'c-c');
- pos = me.container.translatePoints(xy[0], xy[1]);
- }
- me.x = me.x === undefined ? pos.left: me.x;
- me.y = me.y === undefined ? pos.top: me.y;
- }
- if (Ext.isDefined(me.x) || Ext.isDefined(me.y)) {
- me.setPosition(me.x, me.y);
- }
- if (me.styleHtmlContent) {
- me.getTargetEl().addCls(me.styleHtmlCls);
- }
- },
- /**
- * @private
- * Called by Component#doAutoRender
- *
- * Register a Container configured `floating: true` with this Component's {@link Ext.ZIndexManager ZIndexManager}.
- *
- * Components added in ths way will not participate in any layout, but will be rendered
- * upon first show in the way that {@link Ext.window.Window Window}s are.
- */
- registerFloatingItem: function(cmp) {
- var me = this;
- if (!me.floatingItems) {
- me.floatingItems = Ext.create('Ext.ZIndexManager', me);
- }
- me.floatingItems.register(cmp);
- },
- renderChildren: function () {
- var me = this,
- layout = me.getComponentLayout();
- me.suspendLayout = true;
- layout.renderChildren();
- delete me.suspendLayout;
- },
- frameCls: Ext.baseCSSPrefix + 'frame',
- frameIdRegex: /[-]frame\d+[TMB][LCR]$/,
- frameElementCls: {
- tl: [],
- tc: [],
- tr: [],
- ml: [],
- mc: [],
- mr: [],
- bl: [],
- bc: [],
- br: []
- },
- frameTpl: [
- '<tpl if="top">',
- '<tpl if="left"><div id="{fgid}TL" class="{frameCls}-tl {baseCls}-tl {baseCls}-{ui}-tl<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-tl</tpl></tpl>" style="background-position: {tl}; padding-left: {frameWidth}px" role="presentation"></tpl>',
- '<tpl if="right"><div id="{fgid}TR" class="{frameCls}-tr {baseCls}-tr {baseCls}-{ui}-tr<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-tr</tpl></tpl>" style="background-position: {tr}; padding-right: {frameWidth}px" role="presentation"></tpl>',
- '<div id="{fgid}TC" class="{frameCls}-tc {baseCls}-tc {baseCls}-{ui}-tc<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-tc</tpl></tpl>" style="background-position: {tc}; height: {frameWidth}px" role="presentation"></div>',
- '<tpl if="right"></div></tpl>',
- '<tpl if="left"></div></tpl>',
- '</tpl>',
- '<tpl if="left"><div id="{fgid}ML" class="{frameCls}-ml {baseCls}-ml {baseCls}-{ui}-ml<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-ml</tpl></tpl>" style="background-position: {ml}; padding-left: {frameWidth}px" role="presentation"></tpl>',
- '<tpl if="right"><div id="{fgid}MR" class="{frameCls}-mr {baseCls}-mr {baseCls}-{ui}-mr<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-mr</tpl></tpl>" style="background-position: {mr}; padding-right: {frameWidth}px" role="presentation"></tpl>',
- '<div id="{fgid}MC" class="{frameCls}-mc {baseCls}-mc {baseCls}-{ui}-mc<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-mc</tpl></tpl>" role="presentation"></div>',
- '<tpl if="right"></div></tpl>',
- '<tpl if="left"></div></tpl>',
- '<tpl if="bottom">',
- '<tpl if="left"><div id="{fgid}BL" class="{frameCls}-bl {baseCls}-bl {baseCls}-{ui}-bl<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-bl</tpl></tpl>" style="background-position: {bl}; padding-left: {frameWidth}px" role="presentation"></tpl>',
- '<tpl if="right"><div id="{fgid}BR" class="{frameCls}-br {baseCls}-br {baseCls}-{ui}-br<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-br</tpl></tpl>" style="background-position: {br}; padding-right: {frameWidth}px" role="presentation"></tpl>',
- '<div id="{fgid}BC" class="{frameCls}-bc {baseCls}-bc {baseCls}-{ui}-bc<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-bc</tpl></tpl>" style="background-position: {bc}; height: {frameWidth}px" role="presentation"></div>',
- '<tpl if="right"></div></tpl>',
- '<tpl if="left"></div></tpl>',
- '</tpl>'
- ],
- frameTableTpl: [
- '<table><tbody>',
- '<tpl if="top">',
- '<tr>',
- '<tpl if="left"><td id="{fgid}TL" class="{frameCls}-tl {baseCls}-tl {baseCls}-{ui}-tl<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-tl</tpl></tpl>" style="background-position: {tl}; padding-left:{frameWidth}px" role="presentation"></td></tpl>',
- '<td id="{fgid}TC" class="{frameCls}-tc {baseCls}-tc {baseCls}-{ui}-tc<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-tc</tpl></tpl>" style="background-position: {tc}; height: {frameWidth}px" role="presentation"></td>',
- '<tpl if="right"><td id="{fgid}TR" class="{frameCls}-tr {baseCls}-tr {baseCls}-{ui}-tr<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-tr</tpl></tpl>" style="background-position: {tr}; padding-left: {frameWidth}px" role="presentation"></td></tpl>',
- '</tr>',
- '</tpl>',
- '<tr>',
- '<tpl if="left"><td id="{fgid}ML" class="{frameCls}-ml {baseCls}-ml {baseCls}-{ui}-ml<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-ml</tpl></tpl>" style="background-position: {ml}; padding-left: {frameWidth}px" role="presentation"></td></tpl>',
- '<td id="{fgid}MC" class="{frameCls}-mc {baseCls}-mc {baseCls}-{ui}-mc<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-mc</tpl></tpl>" style="background-position: 0 0;" role="presentation"></td>',
- '<tpl if="right"><td id="{fgid}MR" class="{frameCls}-mr {baseCls}-mr {baseCls}-{ui}-mr<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-mr</tpl></tpl>" style="background-position: {mr}; padding-left: {frameWidth}px" role="presentation"></td></tpl>',
- '</tr>',
- '<tpl if="bottom">',
- '<tr>',
- '<tpl if="left"><td id="{fgid}BL" class="{frameCls}-bl {baseCls}-bl {baseCls}-{ui}-bl<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-bl</tpl></tpl>" style="background-position: {bl}; padding-left: {frameWidth}px" role="presentation"></td></tpl>',
- '<td id="{fgid}BC" class="{frameCls}-bc {baseCls}-bc {baseCls}-{ui}-bc<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-bc</tpl></tpl>" style="background-position: {bc}; height: {frameWidth}px" role="presentation"></td>',
- '<tpl if="right"><td id="{fgid}BR" class="{frameCls}-br {baseCls}-br {baseCls}-{ui}-br<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-{parent.ui}-{.}-br</tpl></tpl>" style="background-position: {br}; padding-left: {frameWidth}px" role="presentation"></td></tpl>',
- '</tr>',
- '</tpl>',
- '</tbody></table>'
- ],
- /**
- * @private
- */
- initFrame : function() {
- if (Ext.supports.CSS3BorderRadius) {
- return false;
- }
- var me = this,
- frameInfo = me.getFrameInfo(),
- frameWidth = frameInfo.width,
- frameTpl = me.getFrameTpl(frameInfo.table),
- frameGenId;
- if (me.frame) {
- // since we render id's into the markup and id's NEED to be unique, we have a
- // simple strategy for numbering their generations.
- me.frameGenId = frameGenId = (me.frameGenId || 0) + 1;
- frameGenId = me.id + '-frame' + frameGenId;
- // Here we render the frameTpl to this component. This inserts the 9point div or the table framing.
- frameTpl.insertFirst(me.el, Ext.apply({}, {
- fgid: frameGenId,
- ui: me.ui,
- uiCls: me.uiCls,
- frameCls: me.frameCls,
- baseCls: me.baseCls,
- frameWidth: frameWidth,
- top: !!frameInfo.top,
- left: !!frameInfo.left,
- right: !!frameInfo.right,
- bottom: !!frameInfo.bottom
- }, me.getFramePositions(frameInfo)));
- // The frameBody is returned in getTargetEl, so that layouts render items to the correct target.=
- me.frameBody = me.el.down('.' + me.frameCls + '-mc');
- // Clean out the childEls for the old frame elements (the majority of the els)
- me.removeChildEls(function (c) {
- return c.id && me.frameIdRegex.test(c.id);
- });
- // Add the childEls for each of the new frame elements
- Ext.each(['TL','TC','TR','ML','MC','MR','BL','BC','BR'], function (suffix) {
- me.childEls.push({ name: 'frame' + suffix, id: frameGenId + suffix });
- });
- }
- },
- updateFrame: function() {
- if (Ext.supports.CSS3BorderRadius) {
- return false;
- }
- var me = this,
- wasTable = this.frameSize && this.frameSize.table,
- oldFrameTL = this.frameTL,
- oldFrameBL = this.frameBL,
- oldFrameML = this.frameML,
- oldFrameMC = this.frameMC,
- newMCClassName;
- this.initFrame();
- if (oldFrameMC) {
- if (me.frame) {
- // Reapply render selectors
- delete me.frameTL;
- delete me.frameTC;
- delete me.frameTR;
- delete me.frameML;
- delete me.frameMC;
- delete me.frameMR;
- delete me.frameBL;
- delete me.frameBC;
- delete me.frameBR;
- this.applyRenderSelectors();
- // Store the class names set on the new mc
- newMCClassName = this.frameMC.dom.className;
- // Replace the new mc with the old mc
- oldFrameMC.insertAfter(this.frameMC);
- this.frameMC.remove();
- // Restore the reference to the old frame mc as the framebody
- this.frameBody = this.frameMC = oldFrameMC;
- // Apply the new mc classes to the old mc element
- oldFrameMC.dom.className = newMCClassName;
- // Remove the old framing
- if (wasTable) {
- me.el.query('> table')[1].remove();
- }
- else {
- if (oldFrameTL) {
- oldFrameTL.remove();
- }
- if (oldFrameBL) {
- oldFrameBL.remove();
- }
- oldFrameML.remove();
- }
- }
- else {
- // We were framed but not anymore. Move all content from the old frame to the body
- }
- }
- else if (me.frame) {
- this.applyRenderSelectors();
- }
- },
- getFrameInfo: function() {
- if (Ext.supports.CSS3BorderRadius) {
- return false;
- }
- var me = this,
- left = me.el.getStyle('background-position-x'),
- top = me.el.getStyle('background-position-y'),
- info, frameInfo = false, max;
- // Some browsers dont support background-position-x and y, so for those
- // browsers let's split background-position into two parts.
- if (!left && !top) {
- info = me.el.getStyle('background-position').split(' ');
- left = info[0];
- top = info[1];
- }
- // We actually pass a string in the form of '[type][tl][tr]px [type][br][bl]px' as
- // the background position of this.el from the css to indicate to IE that this component needs
- // framing. We parse it here and change the markup accordingly.
- if (parseInt(left, 10) >= 1000000 && parseInt(top, 10) >= 1000000) {
- max = Math.max;
- frameInfo = {
- // Table markup starts with 110, div markup with 100.
- table: left.substr(0, 3) == '110',
- // Determine if we are dealing with a horizontal or vertical component
- vertical: top.substr(0, 3) == '110',
- // Get and parse the different border radius sizes
- top: max(left.substr(3, 2), left.substr(5, 2)),
- right: max(left.substr(5, 2), top.substr(3, 2)),
- bottom: max(top.substr(3, 2), top.substr(5, 2)),
- left: max(top.substr(5, 2), left.substr(3, 2))
- };
- frameInfo.width = max(frameInfo.top, frameInfo.right, frameInfo.bottom, frameInfo.left);
- // Just to be sure we set the background image of the el to none.
- me.el.setStyle('background-image', 'none');
- }
- // This happens when you set frame: true explicitly without using the x-frame mixin in sass.
- // This way IE can't figure out what sizes to use and thus framing can't work.
- if (me.frame === true && !frameInfo) {
- }
- me.frame = me.frame || !!frameInfo;
- me.frameSize = frameInfo || false;
- return frameInfo;
- },
- getFramePositions: function(frameInfo) {
- var me = this,
- frameWidth = frameInfo.width,
- dock = me.dock,
- positions, tc, bc, ml, mr;
- if (frameInfo.vertical) {
- tc = '0 -' + (frameWidth * 0) + 'px';
- bc = '0 -' + (frameWidth * 1) + 'px';
- if (dock && dock == "right") {
- tc = 'right -' + (frameWidth * 0) + 'px';
- bc = 'right -' + (frameWidth * 1) + 'px';
- }
- positions = {
- tl: '0 -' + (frameWidth * 0) + 'px',
- tr: '0 -' + (frameWidth * 1) + 'px',
- bl: '0 -' + (frameWidth * 2) + 'px',
- br: '0 -' + (frameWidth * 3) + 'px',
- ml: '-' + (frameWidth * 1) + 'px 0',
- mr: 'right 0',
- tc: tc,
- bc: bc
- };
- } else {
- ml = '-' + (frameWidth * 0) + 'px 0';
- mr = 'right 0';
- if (dock && dock == "bottom") {
- ml = 'left bottom';
- mr = 'right bottom';
- }
- positions = {
- tl: '0 -' + (frameWidth * 2) + 'px',
- tr: 'right -' + (frameWidth * 3) + 'px',
- bl: '0 -' + (frameWidth * 4) + 'px',
- br: 'right -' + (frameWidth * 5) + 'px',
- ml: ml,
- mr: mr,
- tc: '0 -' + (frameWidth * 0) + 'px',
- bc: '0 -' + (frameWidth * 1) + 'px'
- };
- }
- return positions;
- },
- /**
- * @private
- */
- getFrameTpl : function(table) {
- return table ? this.getTpl('frameTableTpl') : this.getTpl('frameTpl');
- },
- /**
- * Creates an array of class names from the configurations to add to this Component's `el` on render.
- *
- * Private, but (possibly) used by ComponentQuery for selection by class name if Component is not rendered.
- *
- * @return {String[]} An array of class names with which the Component's element will be rendered.
- * @private
- */
- initCls: function() {
- var me = this,
- cls = [];
- cls.push(me.baseCls);
- if (Ext.isDefined(me.cmpCls)) {
- if (Ext.isDefined(Ext.global.console)) {
- Ext.global.console.warn('Ext.Component: cmpCls has been deprecated. Please use componentCls.');
- }
- me.componentCls = me.cmpCls;
- delete me.cmpCls;
- }
- if (me.componentCls) {
- cls.push(me.componentCls);
- } else {
- me.componentCls = me.baseCls;
- }
- if (me.cls) {
- cls.push(me.cls);
- delete me.cls;
- }
- return cls.concat(me.additionalCls);
- },
- /**
- * Sets the UI for the component. This will remove any existing UIs on the component. It will also loop through any
- * uiCls set on the component and rename them so they include the new UI
- * @param {String} ui The new UI for the component
- */
- setUI: function(ui) {
- var me = this,
- oldUICls = Ext.Array.clone(me.uiCls),
- newUICls = [],
- classes = [],
- cls,
- i;
- //loop through all exisiting uiCls and update the ui in them
- for (i = 0; i < oldUICls.length; i++) {
- cls = oldUICls[i];
- classes = classes.concat(me.removeClsWithUI(cls, true));
- newUICls.push(cls);
- }
- if (classes.length) {
- me.removeCls(classes);
- }
- //remove the UI from the element
- me.removeUIFromElement();
- //set the UI
- me.ui = ui;
- //add the new UI to the elemend
- me.addUIToElement();
- //loop through all exisiting uiCls and update the ui in them
- classes = [];
- for (i = 0; i < newUICls.length; i++) {
- cls = newUICls[i];
- classes = classes.concat(me.addClsWithUI(cls, true));
- }
- if (classes.length) {
- me.addCls(classes);
- }
- },
- /**
- * Adds a cls to the uiCls array, which will also call {@link #addUIClsToElement} and adds to all elements of this
- * component.
- * @param {String/String[]} cls A string or an array of strings to add to the uiCls
- * @param {Object} skip (Boolean) skip True to skip adding it to the class and do it later (via the return)
- */
- addClsWithUI: function(cls, skip) {
- var me = this,
- classes = [],
- i;
- if (!Ext.isArray(cls)) {
- cls = [cls];
- }
- for (i = 0; i < cls.length; i++) {
- if (cls[i] && !me.hasUICls(cls[i])) {
- me.uiCls = Ext.Array.clone(me.uiCls);
- me.uiCls.push(cls[i]);
- classes = classes.concat(me.addUIClsToElement(cls[i]));
- }
- }
- if (skip !== true) {
- me.addCls(classes);
- }
- return classes;
- },
- /**
- * Removes a cls to the uiCls array, which will also call {@link #removeUIClsFromElement} and removes it from all
- * elements of this component.
- * @param {String/String[]} cls A string or an array of strings to remove to the uiCls
- */
- removeClsWithUI: function(cls, skip) {
- var me = this,
- classes = [],
- i;
- if (!Ext.isArray(cls)) {
- cls = [cls];
- }
- for (i = 0; i < cls.length; i++) {
- if (cls[i] && me.hasUICls(cls[i])) {
- me.uiCls = Ext.Array.remove(me.uiCls, cls[i]);
- classes = classes.concat(me.removeUIClsFromElement(cls[i]));
- }
- }
- if (skip !== true) {
- me.removeCls(classes);
- }
- return classes;
- },
- /**
- * Checks if there is currently a specified uiCls
- * @param {String} cls The cls to check
- */
- hasUICls: function(cls) {
- var me = this,
- uiCls = me.uiCls || [];
- return Ext.Array.contains(uiCls, cls);
- },
- /**
- * Method which adds a specified UI + uiCls to the components element. Can be overridden to remove the UI from more
- * than just the components element.
- * @param {String} ui The UI to remove from the element
- */
- addUIClsToElement: function(cls, force) {
- var me = this,
- result = [],
- frameElementCls = me.frameElementCls;
- result.push(Ext.baseCSSPrefix + cls);
- result.push(me.baseCls + '-' + cls);
- result.push(me.baseCls + '-' + me.ui + '-' + cls);
- if (!force && me.frame && !Ext.supports.CSS3BorderRadius) {
- // define each element of the frame
- var els = ['tl', 'tc', 'tr', 'ml', 'mc', 'mr', 'bl', 'bc', 'br'],
- classes, i, j, el;
- // loop through each of them, and if they are defined add the ui
- for (i = 0; i < els.length; i++) {
- el = me['frame' + els[i].toUpperCase()];
- classes = [me.baseCls + '-' + me.ui + '-' + els[i], me.baseCls + '-' + me.ui + '-' + cls + '-' + els[i]];
- if (el && el.dom) {
- el.addCls(classes);
- } else {
- for (j = 0; j < classes.length; j++) {
- if (Ext.Array.indexOf(frameElementCls[els[i]], classes[j]) == -1) {
- frameElementCls[els[i]].push(classes[j]);
- }
- }
- }
- }
- }
- me.frameElementCls = frameElementCls;
- return result;
- },
- /**
- * Method which removes a specified UI + uiCls from the components element. The cls which is added to the element
- * will be: `this.baseCls + '-' + ui`
- * @param {String} ui The UI to add to the element
- */
- removeUIClsFromElement: function(cls, force) {
- var me = this,
- result = [],
- frameElementCls = me.frameElementCls;
- result.push(Ext.baseCSSPrefix + cls);
- result.push(me.baseCls + '-' + cls);
- result.push(me.baseCls + '-' + me.ui + '-' + cls);
- if (!force && me.frame && !Ext.supports.CSS3BorderRadius) {
- // define each element of the frame
- var els = ['tl', 'tc', 'tr', 'ml', 'mc', 'mr', 'bl', 'bc', 'br'],
- i, el;
- cls = me.baseCls + '-' + me.ui + '-' + cls + '-' + els[i];
- // loop through each of them, and if they are defined add the ui
- for (i = 0; i < els.length; i++) {
- el = me['frame' + els[i].toUpperCase()];
- if (el && el.dom) {
- el.removeCls(cls);
- } else {
- Ext.Array.remove(frameElementCls[els[i]], cls);
- }
- }
- }
- me.frameElementCls = frameElementCls;
- return result;
- },
- /**
- * Method which adds a specified UI to the components element.
- * @private
- */
- addUIToElement: function(force) {
- var me = this,
- frameElementCls = me.frameElementCls;
- me.addCls(me.baseCls + '-' + me.ui);
- if (me.frame && !Ext.supports.CSS3BorderRadius) {
- // define each element of the frame
- var els = ['tl', 'tc', 'tr', 'ml', 'mc', 'mr', 'bl', 'bc', 'br'],
- i, el, cls;
- // loop through each of them, and if they are defined add the ui
- for (i = 0; i < els.length; i++) {
- el = me['frame' + els[i].toUpperCase()];
- cls = me.baseCls + '-' + me.ui + '-' + els[i];
- if (el) {
- el.addCls(cls);
- } else {
- if (!Ext.Array.contains(frameElementCls[els[i]], cls)) {
- frameElementCls[els[i]].push(cls);
- }
- }
- }
- }
- },
- /**
- * Method which removes a specified UI from the components element.
- * @private
- */
- removeUIFromElement: function() {
- var me = this,
- frameElementCls = me.frameElementCls;
- me.removeCls(me.baseCls + '-' + me.ui);
- if (me.frame && !Ext.supports.CSS3BorderRadius) {
- // define each element of the frame
- var els = ['tl', 'tc', 'tr', 'ml', 'mc', 'mr', 'bl', 'bc', 'br'],
- i, j, el, cls;
- // loop through each of them, and if they are defined add the ui
- for (i = 0; i < els.length; i++) {
- el = me['frame' + els[i].toUpperCase()];
- cls = me.baseCls + '-' + me.ui + '-' + els[i];
- if (el) {
- el.removeCls(cls);
- } else {
- Ext.Array.remove(frameElementCls[els[i]], cls);
- }
- }
- }
- },
- getElConfig : function() {
- if (Ext.isString(this.autoEl)) {
- this.autoEl = {
- tag: this.autoEl
- };
- }
- var result = this.autoEl || {tag: 'div'};
- result.id = this.id;
- return result;
- },
- /**
- * This function takes the position argument passed to onRender and returns a DOM element that you can use in the
- * insertBefore.
- * @param {String/Number/Ext.Element/HTMLElement} position Index, element id or element you want to put this
- * component before.
- * @return {HTMLElement} DOM element that you can use in the insertBefore
- */
- getInsertPosition: function(position) {
- // Convert the position to an element to insert before
- if (position !== undefined) {
- if (Ext.isNumber(position)) {
- position = this.container.dom.childNodes[position];
- }
- else {
- position = Ext.getDom(position);
- }
- }
- return position;
- },
- /**
- * Adds ctCls to container.
- * @return {Ext.Element} The initialized container
- * @private
- */
- initContainer: function(container) {
- var me = this;
- // If you render a component specifying the el, we get the container
- // of the el, and make sure we dont move the el around in the dom
- // during the render
- if (!container && me.el) {
- container = me.el.dom.parentNode;
- me.allowDomMove = false;
- }
- me.container = Ext.get(container);
- if (me.ctCls) {
- me.container.addCls(me.ctCls);
- }
- return me.container;
- },
- /**
- * Initialized the renderData to be used when rendering the renderTpl.
- * @return {Object} Object with keys and values that are going to be applied to the renderTpl
- * @private
- */
- initRenderData: function() {
- var me = this;
- return Ext.applyIf(me.renderData, {
- id: me.id,
- ui: me.ui,
- uiCls: me.uiCls,
- baseCls: me.baseCls,
- componentCls: me.componentCls,
- frame: me.frame
- });
- },
- /**
- * @private
- */
- getTpl: function(name) {
- var me = this,
- prototype = me.self.prototype,
- ownerPrototype,
- tpl;
- if (me.hasOwnProperty(name)) {
- tpl = me[name];
- if (tpl && !(tpl instanceof Ext.XTemplate)) {
- me[name] = Ext.ClassManager.dynInstantiate('Ext.XTemplate', tpl);
- }
- return me[name];
- }
- if (!(prototype[name] instanceof Ext.XTemplate)) {
- ownerPrototype = prototype;
- do {
- if (ownerPrototype.hasOwnProperty(name)) {
- tpl = ownerPrototype[name];
- if (tpl && !(tpl instanceof Ext.XTemplate)) {
- ownerPrototype[name] = Ext.ClassManager.dynInstantiate('Ext.XTemplate', tpl);
- break;
- }
- }
- ownerPrototype = ownerPrototype.superclass;
- } while (ownerPrototype);
- }
- return prototype[name];
- },
- /**
- * Initializes the renderTpl.
- * @return {Ext.XTemplate} The renderTpl XTemplate instance.
- * @private
- */
- initRenderTpl: function() {
- return this.getTpl('renderTpl');
- },
- /**
- * Converts style definitions to String.
- * @return {String} A CSS style string with style, padding, margin and border.
- * @private
- */
- initStyles: function() {
- var style = {},
- me = this,
- Element = Ext.Element;
- if (Ext.isString(me.style)) {
- style = Element.parseStyles(me.style);
- } else {
- style = Ext.apply({}, me.style);
- }
- // Convert the padding, margin and border properties from a space seperated string
- // into a proper style string
- if (me.padding !== undefined) {
- style.padding = Element.unitizeBox((me.padding === true) ? 5 : me.padding);
- }
- if (me.margin !== undefined) {
- style.margin = Element.unitizeBox((me.margin === true) ? 5 : me.margin);
- }
- delete me.style;
- return style;
- },
- /**
- * Initializes this components contents. It checks for the properties html, contentEl and tpl/data.
- * @private
- */
- initContent: function() {
- var me = this,
- target = me.getTargetEl(),
- contentEl,
- pre;
- if (me.html) {
- target.update(Ext.DomHelper.markup(me.html));
- delete me.html;
- }
- if (me.contentEl) {
- contentEl = Ext.get(me.contentEl);
- pre = Ext.baseCSSPrefix;
- contentEl.removeCls([pre + 'hidden', pre + 'hide-display', pre + 'hide-offsets', pre + 'hide-nosize']);
- target.appendChild(contentEl.dom);
- }
- if (me.tpl) {
- // Make sure this.tpl is an instantiated XTemplate
- if (!me.tpl.isTemplate) {
- me.tpl = Ext.create('Ext.XTemplate', me.tpl);
- }
- if (me.data) {
- me.tpl[me.tplWriteMode](target, me.data);
- delete me.data;
- }
- }
- },
- // @private
- initEvents : function() {
- var me = this,
- afterRenderEvents = me.afterRenderEvents,
- el,
- property,
- fn = function(listeners){
- me.mon(el, listeners);
- };
- if (afterRenderEvents) {
- for (property in afterRenderEvents) {
- if (afterRenderEvents.hasOwnProperty(property)) {
- el = me[property];
- if (el && el.on) {
- Ext.each(afterRenderEvents[property], fn);
- }
- }
- }
- }
- },
- /**
- * Adds each argument passed to this method to the {@link #childEls} array.
- */
- addChildEls: function () {
- var me = this,
- childEls = me.childEls || (me.childEls = []);
- childEls.push.apply(childEls, arguments);
- },
- /**
- * Removes items in the childEls array based on the return value of a supplied test function. The function is called
- * with a entry in childEls and if the test function return true, that entry is removed. If false, that entry is
- * kept.
- * @param {Function} testFn The test function.
- */
- removeChildEls: function (testFn) {
- var me = this,
- old = me.childEls,
- keepers = (me.childEls = []),
- n, i, cel;
- for (i = 0, n = old.length; i < n; ++i) {
- cel = old[i];
- if (!testFn(cel)) {
- keepers.push(cel);
- }
- }
- },
- /**
- * Sets references to elements inside the component. This applies {@link #renderSelectors}
- * as well as {@link #childEls}.
- * @private
- */
- applyRenderSelectors: function() {
- var me = this,
- childEls = me.childEls,
- selectors = me.renderSelectors,
- el = me.el,
- dom = el.dom,
- baseId, childName, childId, i, selector;
- if (childEls) {
- baseId = me.id + '-';
- for (i = childEls.length; i--; ) {
- childName = childId = childEls[i];
- if (typeof(childName) != 'string') {
- childId = childName.id || (baseId + childName.itemId);
- childName = childName.name;
- } else {
- childId = baseId + childId;
- }
- // We don't use Ext.get because that is 3x (or more) slower on IE6-8. Since
- // we know the el's are children of our el we use getById instead:
- me[childName] = el.getById(childId);
- }
- }
- // We still support renderSelectors. There are a few places in the framework that
- // need them and they are a documented part of the API. In fact, we support mixing
- // childEls and renderSelectors (no reason not to).
- if (selectors) {
- for (selector in selectors) {
- if (selectors.hasOwnProperty(selector) && selectors[selector]) {
- me[selector] = Ext.get(Ext.DomQuery.selectNode(selectors[selector], dom));
- }
- }
- }
- },
- /**
- * Tests whether this Component matches the selector string.
- * @param {String} selector The selector string to test against.
- * @return {Boolean} True if this Component matches the selector.
- */
- is: function(selector) {
- return Ext.ComponentQuery.is(this, selector);
- },
- /**
- * Walks up the `ownerCt` axis looking for an ancestor Container which matches the passed simple selector.
- *
- * Example:
- *
- * var owningTabPanel = grid.up('tabpanel');
- *
- * @param {String} [selector] The simple selector to test.
- * @return {Ext.container.Container} The matching ancestor Container (or `undefined` if no match was found).
- */
- up: function(selector) {
- var result = this.ownerCt;
- if (selector) {
- for (; result; result = result.ownerCt) {
- if (Ext.ComponentQuery.is(result, selector)) {
- return result;
- }
- }
- }
- return result;
- },
- /**
- * Returns the next sibling of this Component.
- *
- * Optionally selects the next sibling which matches the passed {@link Ext.ComponentQuery ComponentQuery} selector.
- *
- * May also be refered to as **`next()`**
- *
- * Note that this is limited to siblings, and if no siblings of the item match, `null` is returned. Contrast with
- * {@link #nextNode}
- * @param {String} [selector] A {@link Ext.ComponentQuery ComponentQuery} selector to filter the following items.
- * @return {Ext.Component} The next sibling (or the next sibling which matches the selector).
- * Returns null if there is no matching sibling.
- */
- nextSibling: function(selector) {
- var o = this.ownerCt, it, last, idx, c;
- if (o) {
- it = o.items;
- idx = it.indexOf(this) + 1;
- if (idx) {
- if (selector) {
- for (last = it.getCount(); idx < last; idx++) {
- if ((c = it.getAt(idx)).is(selector)) {
- return c;
- }
- }
- } else {
- if (idx < it.getCount()) {
- return it.getAt(idx);
- }
- }
- }
- }
- return null;
- },
- /**
- * Returns the previous sibling of this Component.
- *
- * Optionally selects the previous sibling which matches the passed {@link Ext.ComponentQuery ComponentQuery}
- * selector.
- *
- * May also be refered to as **`prev()`**
- *
- * Note that this is limited to siblings, and if no siblings of the item match, `null` is returned. Contrast with
- * {@link #previousNode}
- * @param {String} [selector] A {@link Ext.ComponentQuery ComponentQuery} selector to filter the preceding items.
- * @return {Ext.Component} The previous sibling (or the previous sibling which matches the selector).
- * Returns null if there is no matching sibling.
- */
- previousSibling: function(selector) {
- var o = this.ownerCt, it, idx, c;
- if (o) {
- it = o.items;
- idx = it.indexOf(this);
- if (idx != -1) {
- if (selector) {
- for (--idx; idx >= 0; idx--) {
- if ((c = it.getAt(idx)).is(selector)) {
- return c;
- }
- }
- } else {
- if (idx) {
- return it.getAt(--idx);
- }
- }
- }
- }
- return null;
- },
- /**
- * Returns the previous node in the Component tree in tree traversal order.
- *
- * Note that this is not limited to siblings, and if invoked upon a node with no matching siblings, will walk the
- * tree in reverse order to attempt to find a match. Contrast with {@link #previousSibling}.
- * @param {String} [selector] A {@link Ext.ComponentQuery ComponentQuery} selector to filter the preceding nodes.
- * @return {Ext.Component} The previous node (or the previous node which matches the selector).
- * Returns null if there is no matching node.
- */
- previousNode: function(selector, includeSelf) {
- var node = this,
- result,
- it, len, i;
- // If asked to include self, test me
- if (includeSelf && node.is(selector)) {
- return node;
- }
- result = this.prev(selector);
- if (result) {
- return result;
- }
- if (node.ownerCt) {
- for (it = node.ownerCt.items.items, i = Ext.Array.indexOf(it, node) - 1; i > -1; i--) {
- if (it[i].query) {
- result = it[i].query(selector);
- result = result[result.length - 1];
- if (result) {
- return result;
- }
- }
- }
- return node.ownerCt.previousNode(selector, true);
- }
- },
- /**
- * Returns the next node in the Component tree in tree traversal order.
- *
- * Note that this is not limited to siblings, and if invoked upon a node with no matching siblings, will walk the
- * tree to attempt to find a match. Contrast with {@link #nextSibling}.
- * @param {String} [selector] A {@link Ext.ComponentQuery ComponentQuery} selector to filter the following nodes.
- * @return {Ext.Component} The next node (or the next node which matches the selector).
- * Returns null if there is no matching node.
- */
- nextNode: function(selector, includeSelf) {
- var node = this,
- result,
- it, len, i;
- // If asked to include self, test me
- if (includeSelf && node.is(selector)) {
- return node;
- }
- result = this.next(selector);
- if (result) {
- return result;
- }
- if (node.ownerCt) {
- for (it = node.ownerCt.items, i = it.indexOf(node) + 1, it = it.items, len = it.length; i < len; i++) {
- if (it[i].down) {
- result = it[i].down(selector);
- if (result) {
- return result;
- }
- }
- }
- return node.ownerCt.nextNode(selector);
- }
- },
- /**
- * Retrieves the id of this component. Will autogenerate an id if one has not already been set.
- * @return {String}
- */
- getId : function() {
- return this.id || (this.id = 'ext-comp-' + (this.getAutoId()));
- },
- getItemId : function() {
- return this.itemId || this.id;
- },
- /**
- * Retrieves the top level element representing this component.
- * @return {Ext.core.Element}
- */
- getEl : function() {
- return this.el;
- },
- /**
- * This is used to determine where to insert the 'html', 'contentEl' and 'items' in this component.
- * @private
- */
- getTargetEl: function() {
- return this.frameBody || this.el;
- },
- /**
- * Tests whether or not this Component is of a specific xtype. This can test whether this Component is descended
- * from the xtype (default) or whether it is directly of the xtype specified (shallow = true).
- *
- * **If using your own subclasses, be aware that a Component must register its own xtype to participate in
- * determination of inherited xtypes.**
- *
- * For a list of all available xtypes, see the {@link Ext.Component} header.
- *
- * Example usage:
- *
- * var t = new Ext.form.field.Text();
- * var isText = t.isXType('textfield'); // true
- * var isBoxSubclass = t.isXType('field'); // true, descended from Ext.form.field.Base
- * var isBoxInstance = t.isXType('field', true); // false, not a direct Ext.form.field.Base instance
- *
- * @param {String} xtype The xtype to check for this Component
- * @param {Boolean} [shallow=false] True to check whether this Component is directly of the specified xtype, false to
- * check whether this Component is descended from the xtype.
- * @return {Boolean} True if this component descends from the specified xtype, false otherwise.
- */
- isXType: function(xtype, shallow) {
- //assume a string by default
- if (Ext.isFunction(xtype)) {
- xtype = xtype.xtype;
- //handle being passed the class, e.g. Ext.Component
- } else if (Ext.isObject(xtype)) {
- xtype = xtype.statics().xtype;
- //handle being passed an instance
- }
- return !shallow ? ('/' + this.getXTypes() + '/').indexOf('/' + xtype + '/') != -1: this.self.xtype == xtype;
- },
- /**
- * Returns this Component's xtype hierarchy as a slash-delimited string. For a list of all available xtypes, see the
- * {@link Ext.Component} header.
- *
- * **If using your own subclasses, be aware that a Component must register its own xtype to participate in
- * determination of inherited xtypes.**
- *
- * Example usage:
- *
- * var t = new Ext.form.field.Text();
- * alert(t.getXTypes()); // alerts 'component/field/textfield'
- *
- * @return {String} The xtype hierarchy string
- */
- getXTypes: function() {
- var self = this.self,
- xtypes, parentPrototype, parentXtypes;
- if (!self.xtypes) {
- xtypes = [];
- parentPrototype = this;
- while (parentPrototype) {
- parentXtypes = parentPrototype.xtypes;
- if (parentXtypes !== undefined) {
- xtypes.unshift.apply(xtypes, parentXtypes);
- }
- parentPrototype = parentPrototype.superclass;
- }
- self.xtypeChain = xtypes;
- self.xtypes = xtypes.join('/');
- }
- return self.xtypes;
- },
- /**
- * Update the content area of a component.
- * @param {String/Object} htmlOrData If this component has been configured with a template via the tpl config then
- * it will use this argument as data to populate the template. If this component was not configured with a template,
- * the components content area will be updated via Ext.Element update
- * @param {Boolean} [loadScripts=false] Only legitimate when using the html configuration.
- * @param {Function} [callback] Only legitimate when using the html configuration. Callback to execute when
- * scripts have finished loading
- */
- update : function(htmlOrData, loadScripts, cb) {
- var me = this;
- if (me.tpl && !Ext.isString(htmlOrData)) {
- me.data = htmlOrData;
- if (me.rendered) {
- me.tpl[me.tplWriteMode](me.getTargetEl(), htmlOrData || {});
- }
- } else {
- me.html = Ext.isObject(htmlOrData) ? Ext.DomHelper.markup(htmlOrData) : htmlOrData;
- if (me.rendered) {
- me.getTargetEl().update(me.html, loadScripts, cb);
- }
- }
- if (me.rendered) {
- me.doComponentLayout();
- }
- },
- /**
- * Convenience function to hide or show this component by boolean.
- * @param {Boolean} visible True to show, false to hide
- * @return {Ext.Component} this
- */
- setVisible : function(visible) {
- return this[visible ? 'show': 'hide']();
- },
- /**
- * Returns true if this component is visible.
- *
- * @param {Boolean} [deep=false] Pass `true` to interrogate the visibility status of all parent Containers to
- * determine whether this Component is truly visible to the user.
- *
- * Generally, to determine whether a Component is hidden, the no argument form is needed. For example when creating
- * dynamically laid out UIs in a hidden Container before showing them.
- *
- * @return {Boolean} True if this component is visible, false otherwise.
- */
- isVisible: function(deep) {
- var me = this,
- child = me,
- visible = !me.hidden,
- ancestor = me.ownerCt;
- // Clear hiddenOwnerCt property
- me.hiddenAncestor = false;
- if (me.destroyed) {
- return false;
- }
- if (deep && visible && me.rendered && ancestor) {
- while (ancestor) {
- // If any ancestor is hidden, then this is hidden.
- // If an ancestor Panel (only Panels have a collapse method) is collapsed,
- // then its layoutTarget (body) is hidden, so this is hidden unless its within a
- // docked item; they are still visible when collapsed (Unless they themseves are hidden)
- if (ancestor.hidden || (ancestor.collapsed &&
- !(ancestor.getDockedItems && Ext.Array.contains(ancestor.getDockedItems(), child)))) {
- // Store hiddenOwnerCt property if needed
- me.hiddenAncestor = ancestor;
- visible = false;
- break;
- }
- child = ancestor;
- ancestor = ancestor.ownerCt;
- }
- }
- return visible;
- },
- /**
- * Enable the component
- * @param {Boolean} [silent=false] Passing true will supress the 'enable' event from being fired.
- */
- enable: function(silent) {
- var me = this;
- if (me.rendered) {
- me.el.removeCls(me.disabledCls);
- me.el.dom.disabled = false;
- me.onEnable();
- }
- me.disabled = false;
- if (silent !== true) {
- me.fireEvent('enable', me);
- }
- return me;
- },
- /**
- * Disable the component.
- * @param {Boolean} [silent=false] Passing true will supress the 'disable' event from being fired.
- */
- disable: function(silent) {
- var me = this;
- if (me.rendered) {
- me.el.addCls(me.disabledCls);
- me.el.dom.disabled = true;
- me.onDisable();
- }
- me.disabled = true;
- if (silent !== true) {
- me.fireEvent('disable', me);
- }
- return me;
- },
- // @private
- onEnable: function() {
- if (this.maskOnDisable) {
- this.el.unmask();
- }
- },
- // @private
- onDisable : function() {
- if (this.maskOnDisable) {
- this.el.mask();
- }
- },
- /**
- * Method to determine whether this Component is currently disabled.
- * @return {Boolean} the disabled state of this Component.
- */
- isDisabled : function() {
- return this.disabled;
- },
- /**
- * Enable or disable the component.
- * @param {Boolean} disabled True to disable.
- */
- setDisabled : function(disabled) {
- return this[disabled ? 'disable': 'enable']();
- },
- /**
- * Method to determine whether this Component is currently set to hidden.
- * @return {Boolean} the hidden state of this Component.
- */
- isHidden : function() {
- return this.hidden;
- },
- /**
- * Adds a CSS class to the top level element representing this component.
- * @param {String} cls The CSS class name to add
- * @return {Ext.Component} Returns the Component to allow method chaining.
- */
- addCls : function(className) {
- var me = this;
- if (!className) {
- return me;
- }
- if (!Ext.isArray(className)){
- className = className.replace(me.trimRe, '').split(me.spacesRe);
- }
- if (me.rendered) {
- me.el.addCls(className);
- }
- else {
- me.additionalCls = Ext.Array.unique(me.additionalCls.concat(className));
- }
- return me;
- },
- /**
- * Adds a CSS class to the top level element representing this component.
- * @param {String} cls The CSS class name to add
- * @return {Ext.Component} Returns the Component to allow method chaining.
- */
- addClass : function() {
- return this.addCls.apply(this, arguments);
- },
- /**
- * Removes a CSS class from the top level element representing this component.
- * @param {Object} className
- * @return {Ext.Component} Returns the Component to allow method chaining.
- */
- removeCls : function(className) {
- var me = this;
- if (!className) {
- return me;
- }
- if (!Ext.isArray(className)){
- className = className.replace(me.trimRe, '').split(me.spacesRe);
- }
- if (me.rendered) {
- me.el.removeCls(className);
- }
- else if (me.additionalCls.length) {
- Ext.each(className, function(cls) {
- Ext.Array.remove(me.additionalCls, cls);
- });
- }
- return me;
- },
- addOverCls: function() {
- var me = this;
- if (!me.disabled) {
- me.el.addCls(me.overCls);
- }
- },
- removeOverCls: function() {
- this.el.removeCls(this.overCls);
- },
- addListener : function(element, listeners, scope, options) {
- var me = this,
- fn,
- option;
- if (Ext.isString(element) && (Ext.isObject(listeners) || options && options.element)) {
- if (options.element) {
- fn = listeners;
- listeners = {};
- listeners[element] = fn;
- element = options.element;
- if (scope) {
- listeners.scope = scope;
- }
- for (option in options) {
- if (options.hasOwnProperty(option)) {
- if (me.eventOptionsRe.test(option)) {
- listeners[option] = options[option];
- }
- }
- }
- }
- // At this point we have a variable called element,
- // and a listeners object that can be passed to on
- if (me[element] && me[element].on) {
- me.mon(me[element], listeners);
- } else {
- me.afterRenderEvents = me.afterRenderEvents || {};
- if (!me.afterRenderEvents[element]) {
- me.afterRenderEvents[element] = [];
- }
- me.afterRenderEvents[element].push(listeners);
- }
- }
- return me.mixins.observable.addListener.apply(me, arguments);
- },
- // inherit docs
- removeManagedListenerItem: function(isClear, managedListener, item, ename, fn, scope){
- var me = this,
- element = managedListener.options ? managedListener.options.element : null;
- if (element) {
- element = me[element];
- if (element && element.un) {
- if (isClear || (managedListener.item === item && managedListener.ename === ename && (!fn || managedListener.fn === fn) && (!scope || managedListener.scope === scope))) {
- element.un(managedListener.ename, managedListener.fn, managedListener.scope);
- if (!isClear) {
- Ext.Array.remove(me.managedListeners, managedListener);
- }
- }
- }
- } else {
- return me.mixins.observable.removeManagedListenerItem.apply(me, arguments);
- }
- },
- /**
- * Provides the link for Observable's fireEvent method to bubble up the ownership hierarchy.
- * @return {Ext.container.Container} the Container which owns this Component.
- */
- getBubbleTarget : function() {
- return this.ownerCt;
- },
- /**
- * Method to determine whether this Component is floating.
- * @return {Boolean} the floating state of this component.
- */
- isFloating : function() {
- return this.floating;
- },
- /**
- * Method to determine whether this Component is draggable.
- * @return {Boolean} the draggable state of this component.
- */
- isDraggable : function() {
- return !!this.draggable;
- },
- /**
- * Method to determine whether this Component is droppable.
- * @return {Boolean} the droppable state of this component.
- */
- isDroppable : function() {
- return !!this.droppable;
- },
- /**
- * @private
- * Method to manage awareness of when components are added to their
- * respective Container, firing an added event.
- * References are established at add time rather than at render time.
- * @param {Ext.container.Container} container Container which holds the component
- * @param {Number} pos Position at which the component was added
- */
- onAdded : function(container, pos) {
- this.ownerCt = container;
- this.fireEvent('added', this, container, pos);
- },
- /**
- * @private
- * Method to manage awareness of when components are removed from their
- * respective Container, firing an removed event. References are properly
- * cleaned up after removing a component from its owning container.
- */
- onRemoved : function() {
- var me = this;
- me.fireEvent('removed', me, me.ownerCt);
- delete me.ownerCt;
- },
- // @private
- beforeDestroy : Ext.emptyFn,
- // @private
- // @private
- onResize : Ext.emptyFn,
- /**
- * Sets the width and height of this Component. This method fires the {@link #resize} event. This method can accept
- * either width and height as separate arguments, or you can pass a size object like `{width:10, height:20}`.
- *
- * @param {Number/String/Object} width The new width to set. This may be one of:
- *
- * - A Number specifying the new width in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).
- * - A String used to set the CSS width style.
- * - A size object in the format `{width: widthValue, height: heightValue}`.
- * - `undefined` to leave the width unchanged.
- *
- * @param {Number/String} height The new height to set (not required if a size object is passed as the first arg).
- * This may be one of:
- *
- * - A Number specifying the new height in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).
- * - A String used to set the CSS height style. Animation may **not** be used.
- * - `undefined` to leave the height unchanged.
- *
- * @return {Ext.Component} this
- */
- setSize : function(width, height) {
- var me = this,
- layoutCollection;
- // support for standard size objects
- if (Ext.isObject(width)) {
- height = width.height;
- width = width.width;
- }
- // Constrain within configured maxima
- if (Ext.isNumber(width)) {
- width = Ext.Number.constrain(width, me.minWidth, me.maxWidth);
- }
- if (Ext.isNumber(height)) {
- height = Ext.Number.constrain(height, me.minHeight, me.maxHeight);
- }
- if (!me.rendered || !me.isVisible()) {
- // If an ownerCt is hidden, add my reference onto the layoutOnShow stack. Set the needsLayout flag.
- if (me.hiddenAncestor) {
- layoutCollection = me.hiddenAncestor.layoutOnShow;
- layoutCollection.remove(me);
- layoutCollection.add(me);
- }
- me.needsLayout = {
- width: width,
- height: height,
- isSetSize: true
- };
- if (!me.rendered) {
- me.width = (width !== undefined) ? width : me.width;
- me.height = (height !== undefined) ? height : me.height;
- }
- return me;
- }
- me.doComponentLayout(width, height, true);
- return me;
- },
- isFixedWidth: function() {
- var me = this,
- layoutManagedWidth = me.layoutManagedWidth;
- if (Ext.isDefined(me.width) || layoutManagedWidth == 1) {
- return true;
- }
- if (layoutManagedWidth == 2) {
- return false;
- }
- return (me.ownerCt && me.ownerCt.isFixedWidth());
- },
- isFixedHeight: function() {
- var me = this,
- layoutManagedHeight = me.layoutManagedHeight;
- if (Ext.isDefined(me.height) || layoutManagedHeight == 1) {
- return true;
- }
- if (layoutManagedHeight == 2) {
- return false;
- }
- return (me.ownerCt && me.ownerCt.isFixedHeight());
- },
- setCalculatedSize : function(width, height, callingContainer) {
- var me = this,
- layoutCollection;
- // support for standard size objects
- if (Ext.isObject(width)) {
- callingContainer = width.ownerCt;
- height = width.height;
- width = width.width;
- }
- // Constrain within configured maxima
- if (Ext.isNumber(width)) {
- width = Ext.Number.constrain(width, me.minWidth, me.maxWidth);
- }
- if (Ext.isNumber(height)) {
- height = Ext.Number.constrain(height, me.minHeight, me.maxHeight);
- }
- if (!me.rendered || !me.isVisible()) {
- // If an ownerCt is hidden, add my reference onto the layoutOnShow stack. Set the needsLayout flag.
- if (me.hiddenAncestor) {
- layoutCollection = me.hiddenAncestor.layoutOnShow;
- layoutCollection.remove(me);
- layoutCollection.add(me);
- }
- me.needsLayout = {
- width: width,
- height: height,
- isSetSize: false,
- ownerCt: callingContainer
- };
- return me;
- }
- me.doComponentLayout(width, height, false, callingContainer);
- return me;
- },
- /**
- * This method needs to be called whenever you change something on this component that requires the Component's
- * layout to be recalculated.
- * @param {Object} width
- * @param {Object} height
- * @param {Object} isSetSize
- * @param {Object} callingContainer
- * @return {Ext.container.Container} this
- */
- doComponentLayout : function(width, height, isSetSize, callingContainer) {
- var me = this,
- componentLayout = me.getComponentLayout(),
- lastComponentSize = componentLayout.lastComponentSize || {
- width: undefined,
- height: undefined
- };
- // collapsed state is not relevant here, so no testing done.
- // Only Panels have a collapse method, and that just sets the width/height such that only
- // a single docked Header parallel to the collapseTo side are visible, and the Panel body is hidden.
- if (me.rendered && componentLayout) {
- // If no width passed, then only insert a value if the Component is NOT ALLOWED to autowidth itself.
- if (!Ext.isDefined(width)) {
- if (me.isFixedWidth()) {
- width = Ext.isDefined(me.width) ? me.width : lastComponentSize.width;
- }
- }
- // If no height passed, then only insert a value if the Component is NOT ALLOWED to autoheight itself.
- if (!Ext.isDefined(height)) {
- if (me.isFixedHeight()) {
- height = Ext.isDefined(me.height) ? me.height : lastComponentSize.height;
- }
- }
- if (isSetSize) {
- me.width = width;
- me.height = height;
- }
- componentLayout.layout(width, height, isSetSize, callingContainer);
- }
- return me;
- },
- /**
- * Forces this component to redo its componentLayout.
- */
- forceComponentLayout: function () {
- this.doComponentLayout();
- },
- // @private
- setComponentLayout : function(layout) {
- var currentLayout = this.componentLayout;
- if (currentLayout && currentLayout.isLayout && currentLayout != layout) {
- currentLayout.setOwner(null);
- }
- this.componentLayout = layout;
- layout.setOwner(this);
- },
- getComponentLayout : function() {
- var me = this;
- if (!me.componentLayout || !me.componentLayout.isLayout) {
- me.setComponentLayout(Ext.layout.Layout.create(me.componentLayout, 'autocomponent'));
- }
- return me.componentLayout;
- },
- /**
- * Occurs after componentLayout is run.
- * @param {Number} adjWidth The box-adjusted width that was set
- * @param {Number} adjHeight The box-adjusted height that was set
- * @param {Boolean} isSetSize Whether or not the height/width are stored on the component permanently
- * @param {Ext.Component} callingContainer Container requesting the layout. Only used when isSetSize is false.
- */
- afterComponentLayout: function(width, height, isSetSize, callingContainer) {
- var me = this,
- layout = me.componentLayout,
- oldSize = me.preLayoutSize;
- ++me.componentLayoutCounter;
- if (!oldSize || ((width !== oldSize.width) || (height !== oldSize.height))) {
- me.fireEvent('resize', me, width, height);
- }
- },
- /**
- * Occurs before componentLayout is run. Returning false from this method will prevent the componentLayout from
- * being executed.
- * @param {Number} adjWidth The box-adjusted width that was set
- * @param {Number} adjHeight The box-adjusted height that was set
- * @param {Boolean} isSetSize Whether or not the height/width are stored on the component permanently
- * @param {Ext.Component} callingContainer Container requesting sent the layout. Only used when isSetSize is false.
- */
- beforeComponentLayout: function(width, height, isSetSize, callingContainer) {
- this.preLayoutSize = this.componentLayout.lastComponentSize;
- return true;
- },
- /**
- * Sets the left and top of the component. To set the page XY position instead, use
- * {@link Ext.Component#setPagePosition setPagePosition}. This method fires the {@link #move} event.
- * @param {Number} left The new left
- * @param {Number} top The new top
- * @return {Ext.Component} this
- */
- setPosition : function(x, y) {
- var me = this;
- if (Ext.isObject(x)) {
- y = x.y;
- x = x.x;
- }
- if (!me.rendered) {
- return me;
- }
- if (x !== undefined || y !== undefined) {
- me.el.setBox(x, y);
- me.onPosition(x, y);
- me.fireEvent('move', me, x, y);
- }
- return me;
- },
- /**
- * @private
- * Called after the component is moved, this method is empty by default but can be implemented by any
- * subclass that needs to perform custom logic after a move occurs.
- * @param {Number} x The new x position
- * @param {Number} y The new y position
- */
- onPosition: Ext.emptyFn,
- /**
- * Sets the width of the component. This method fires the {@link #resize} event.
- *
- * @param {Number} width The new width to setThis may be one of:
- *
- * - A Number specifying the new width in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).
- * - A String used to set the CSS width style.
- *
- * @return {Ext.Component} this
- */
- setWidth : function(width) {
- return this.setSize(width);
- },
- /**
- * Sets the height of the component. This method fires the {@link #resize} event.
- *
- * @param {Number} height The new height to set. This may be one of:
- *
- * - A Number specifying the new height in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).
- * - A String used to set the CSS height style.
- * - _undefined_ to leave the height unchanged.
- *
- * @return {Ext.Component} this
- */
- setHeight : function(height) {
- return this.setSize(undefined, height);
- },
- /**
- * Gets the current size of the component's underlying element.
- * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
- */
- getSize : function() {
- return this.el.getSize();
- },
- /**
- * Gets the current width of the component's underlying element.
- * @return {Number}
- */
- getWidth : function() {
- return this.el.getWidth();
- },
- /**
- * Gets the current height of the component's underlying element.
- * @return {Number}
- */
- getHeight : function() {
- return this.el.getHeight();
- },
- /**
- * Gets the {@link Ext.ComponentLoader} for this Component.
- * @return {Ext.ComponentLoader} The loader instance, null if it doesn't exist.
- */
- getLoader: function(){
- var me = this,
- autoLoad = me.autoLoad ? (Ext.isObject(me.autoLoad) ? me.autoLoad : {url: me.autoLoad}) : null,
- loader = me.loader || autoLoad;
- if (loader) {
- if (!loader.isLoader) {
- me.loader = Ext.create('Ext.ComponentLoader', Ext.apply({
- target: me,
- autoLoad: autoLoad
- }, loader));
- } else {
- loader.setTarget(me);
- }
- return me.loader;
- }
- return null;
- },
- /**
- * This method allows you to show or hide a LoadMask on top of this component.
- *
- * @param {Boolean/Object/String} load True to show the default LoadMask, a config object that will be passed to the
- * LoadMask constructor, or a message String to show. False to hide the current LoadMask.
- * @param {Boolean} [targetEl=false] True to mask the targetEl of this Component instead of the `this.el`. For example,
- * setting this to true on a Panel will cause only the body to be masked.
- * @return {Ext.LoadMask} The LoadMask instance that has just been shown.
- */
- setLoading : function(load, targetEl) {
- var me = this,
- config;
- if (me.rendered) {
- if (load !== false && !me.collapsed) {
- if (Ext.isObject(load)) {
- config = load;
- }
- else if (Ext.isString(load)) {
- config = {msg: load};
- }
- else {
- config = {};
- }
- me.loadMask = me.loadMask || Ext.create('Ext.LoadMask', targetEl ? me.getTargetEl() : me.el, config);
- me.loadMask.show();
- } else if (me.loadMask) {
- Ext.destroy(me.loadMask);
- me.loadMask = null;
- }
- }
- return me.loadMask;
- },
- /**
- * Sets the dock position of this component in its parent panel. Note that this only has effect if this item is part
- * of the dockedItems collection of a parent that has a DockLayout (note that any Panel has a DockLayout by default)
- * @param {Object} dock The dock position.
- * @param {Boolean} [layoutParent=false] True to re-layout parent.
- * @return {Ext.Component} this
- */
- setDocked : function(dock, layoutParent) {
- var me = this;
- me.dock = dock;
- if (layoutParent && me.ownerCt && me.rendered) {
- me.ownerCt.doComponentLayout();
- }
- return me;
- },
- onDestroy : function() {
- var me = this;
- if (me.monitorResize && Ext.EventManager.resizeEvent) {
- Ext.EventManager.resizeEvent.removeListener(me.setSize, me);
- }
- // Destroying the floatingItems ZIndexManager will also destroy descendant floating Components
- Ext.destroy(
- me.componentLayout,
- me.loadMask,
- me.floatingItems
- );
- },
- /**
- * Remove any references to elements added via renderSelectors/childEls
- * @private
- */
- cleanElementRefs: function(){
- var me = this,
- i = 0,
- childEls = me.childEls,
- selectors = me.renderSelectors,
- selector,
- name,
- len;
- if (me.rendered) {
- if (childEls) {
- for (len = childEls.length; i < len; ++i) {
- name = childEls[i];
- if (typeof(name) != 'string') {
- name = name.name;
- }
- delete me[name];
- }
- }
- if (selectors) {
- for (selector in selectors) {
- if (selectors.hasOwnProperty(selector)) {
- delete me[selector];
- }
- }
- }
- }
- delete me.rendered;
- delete me.el;
- delete me.frameBody;
- },
- /**
- * Destroys the Component.
- */
- destroy : function() {
- var me = this;
- if (!me.isDestroyed) {
- if (me.fireEvent('beforedestroy', me) !== false) {
- me.destroying = true;
- me.beforeDestroy();
- if (me.floating) {
- delete me.floatParent;
- // A zIndexManager is stamped into a *floating* Component when it is added to a Container.
- // If it has no zIndexManager at render time, it is assigned to the global Ext.WindowManager instance.
- if (me.zIndexManager) {
- me.zIndexManager.unregister(me);
- }
- } else if (me.ownerCt && me.ownerCt.remove) {
- me.ownerCt.remove(me, false);
- }
- me.onDestroy();
- // Attempt to destroy all plugins
- Ext.destroy(me.plugins);
- if (me.rendered) {
- me.el.remove();
- }
- me.fireEvent('destroy', me);
- Ext.ComponentManager.unregister(me);
- me.mixins.state.destroy.call(me);
- me.clearListeners();
- // make sure we clean up the element references after removing all events
- me.cleanElementRefs();
- me.destroying = false;
- me.isDestroyed = true;
- }
- }
- },
- /**
- * Retrieves a plugin by its pluginId which has been bound to this component.
- * @param {Object} pluginId
- * @return {Ext.AbstractPlugin} plugin instance.
- */
- getPlugin: function(pluginId) {
- var i = 0,
- plugins = this.plugins,
- ln = plugins.length;
- for (; i < ln; i++) {
- if (plugins[i].pluginId === pluginId) {
- return plugins[i];
- }
- }
- },
- /**
- * Determines whether this component is the descendant of a particular container.
- * @param {Ext.Container} container
- * @return {Boolean} True if it is.
- */
- isDescendantOf: function(container) {
- return !!this.findParentBy(function(p){
- return p === container;
- });
- }
- }, function() {
- this.createAlias({
- on: 'addListener',
- prev: 'previousSibling',
- next: 'nextSibling'
- });
- });
- /**
- * The AbstractPlugin class is the base class from which user-implemented plugins should inherit.
- *
- * This class defines the essential API of plugins as used by Components by defining the following methods:
- *
- * - `init` : The plugin initialization method which the owning Component calls at Component initialization time.
- *
- * The Component passes itself as the sole parameter.
- *
- * Subclasses should set up bidirectional links between the plugin and its client Component here.
- *
- * - `destroy` : The plugin cleanup method which the owning Component calls at Component destruction time.
- *
- * Use this method to break links between the plugin and the Component and to free any allocated resources.
- *
- * - `enable` : The base implementation just sets the plugin's `disabled` flag to `false`
- *
- * - `disable` : The base implementation just sets the plugin's `disabled` flag to `true`
- */
- Ext.define('Ext.AbstractPlugin', {
- disabled: false,
- constructor: function(config) {
- Ext.apply(this, config);
- },
- getCmp: function() {
- return this.cmp;
- },
- /**
- * @method
- * The init method is invoked after initComponent method has been run for the client Component.
- *
- * The supplied implementation is empty. Subclasses should perform plugin initialization, and set up bidirectional
- * links between the plugin and its client Component in their own implementation of this method.
- * @param {Ext.Component} client The client Component which owns this plugin.
- */
- init: Ext.emptyFn,
- /**
- * @method
- * The destroy method is invoked by the owning Component at the time the Component is being destroyed.
- *
- * The supplied implementation is empty. Subclasses should perform plugin cleanup in their own implementation of
- * this method.
- */
- destroy: Ext.emptyFn,
- /**
- * The base implementation just sets the plugin's `disabled` flag to `false`
- *
- * Plugin subclasses which need more complex processing may implement an overriding implementation.
- */
- enable: function() {
- this.disabled = false;
- },
- /**
- * The base implementation just sets the plugin's `disabled` flag to `true`
- *
- * Plugin subclasses which need more complex processing may implement an overriding implementation.
- */
- disable: function() {
- this.disabled = true;
- }
- });
- /**
- * The Connection class encapsulates a connection to the page's originating domain, allowing requests to be made either
- * to a configured URL, or to a URL specified at request time.
- *
- * Requests made by this class are asynchronous, and will return immediately. No data from the server will be available
- * to the statement immediately following the {@link #request} call. To process returned data, use a success callback
- * in the request options object, or an {@link #requestcomplete event listener}.
- *
- * # File Uploads
- *
- * File uploads are not performed using normal "Ajax" techniques, that is they are not performed using XMLHttpRequests.
- * Instead the form is submitted in the standard manner with the DOM <form> element temporarily modified to have its
- * target set to refer to a dynamically generated, hidden <iframe> which is inserted into the document but removed
- * after the return data has been gathered.
- *
- * The server response is parsed by the browser to create the document for the IFRAME. If the server is using JSON to
- * send the return object, then the Content-Type header must be set to "text/html" in order to tell the browser to
- * insert the text unchanged into the document body.
- *
- * Characters which are significant to an HTML parser must be sent as HTML entities, so encode `<` as `<`, `&` as
- * `&` etc.
- *
- * The response text is retrieved from the document, and a fake XMLHttpRequest object is created containing a
- * responseText property in order to conform to the requirements of event handlers and callbacks.
- *
- * Be aware that file upload packets are sent with the content type multipart/form and some server technologies
- * (notably JEE) may require some custom processing in order to retrieve parameter names and parameter values from the
- * packet content.
- *
- * Also note that it's not possible to check the response code of the hidden iframe, so the success handler will ALWAYS fire.
- */
- Ext.define('Ext.data.Connection', {
- mixins: {
- observable: 'Ext.util.Observable'
- },
- statics: {
- requestId: 0
- },
- url: null,
- async: true,
- method: null,
- username: '',
- password: '',
- /**
- * @cfg {Boolean} disableCaching
- * True to add a unique cache-buster param to GET requests.
- */
- disableCaching: true,
- /**
- * @cfg {Boolean} withCredentials
- * True to set `withCredentials = true` on the XHR object
- */
- withCredentials: false,
- /**
- * @cfg {Boolean} cors
- * True to enable CORS support on the XHR object. Currently the only effect of this option
- * is to use the XDomainRequest object instead of XMLHttpRequest if the browser is IE8 or above.
- */
- cors: false,
- /**
- * @cfg {String} disableCachingParam
- * Change the parameter which is sent went disabling caching through a cache buster.
- */
- disableCachingParam: '_dc',
- /**
- * @cfg {Number} timeout
- * The timeout in milliseconds to be used for requests.
- */
- timeout : 30000,
- /**
- * @cfg {Object} extraParams
- * Any parameters to be appended to the request.
- */
- useDefaultHeader : true,
- defaultPostHeader : 'application/x-www-form-urlencoded; charset=UTF-8',
- useDefaultXhrHeader : true,
- defaultXhrHeader : 'XMLHttpRequest',
- constructor : function(config) {
- config = config || {};
- Ext.apply(this, config);
- this.addEvents(
- /**
- * @event beforerequest
- * Fires before a network request is made to retrieve a data object.
- * @param {Ext.data.Connection} conn This Connection object.
- * @param {Object} options The options config object passed to the {@link #request} method.
- */
- 'beforerequest',
- /**
- * @event requestcomplete
- * Fires if the request was successfully completed.
- * @param {Ext.data.Connection} conn This Connection object.
- * @param {Object} response The XHR object containing the response data.
- * See [The XMLHttpRequest Object](http://www.w3.org/TR/XMLHttpRequest/) for details.
- * @param {Object} options The options config object passed to the {@link #request} method.
- */
- 'requestcomplete',
- /**
- * @event requestexception
- * Fires if an error HTTP status was returned from the server.
- * See [HTTP Status Code Definitions](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
- * for details of HTTP status codes.
- * @param {Ext.data.Connection} conn This Connection object.
- * @param {Object} response The XHR object containing the response data.
- * See [The XMLHttpRequest Object](http://www.w3.org/TR/XMLHttpRequest/) for details.
- * @param {Object} options The options config object passed to the {@link #request} method.
- */
- 'requestexception'
- );
- this.requests = {};
- this.mixins.observable.constructor.call(this);
- },
- /**
- * Sends an HTTP request to a remote server.
- *
- * **Important:** Ajax server requests are asynchronous, and this call will
- * return before the response has been received. Process any returned data
- * in a callback function.
- *
- * Ext.Ajax.request({
- * url: 'ajax_demo/sample.json',
- * success: function(response, opts) {
- * var obj = Ext.decode(response.responseText);
- * console.dir(obj);
- * },
- * failure: function(response, opts) {
- * console.log('server-side failure with status code ' + response.status);
- * }
- * });
- *
- * To execute a callback function in the correct scope, use the `scope` option.
- *
- * @param {Object} options An object which may contain the following properties:
- *
- * (The options object may also contain any other property which might be needed to perform
- * postprocessing in a callback because it is passed to callback functions.)
- *
- * @param {String/Function} options.url The URL to which to send the request, or a function
- * to call which returns a URL string. The scope of the function is specified by the `scope` option.
- * Defaults to the configured `url`.
- *
- * @param {Object/String/Function} options.params An object containing properties which are
- * used as parameters to the request, a url encoded string or a function to call to get either. The scope
- * of the function is specified by the `scope` option.
- *
- * @param {String} options.method The HTTP method to use
- * for the request. Defaults to the configured method, or if no method was configured,
- * "GET" if no parameters are being sent, and "POST" if parameters are being sent. Note that
- * the method name is case-sensitive and should be all caps.
- *
- * @param {Function} options.callback The function to be called upon receipt of the HTTP response.
- * The callback is called regardless of success or failure and is passed the following parameters:
- * @param {Object} options.callback.options The parameter to the request call.
- * @param {Boolean} options.callback.success True if the request succeeded.
- * @param {Object} options.callback.response The XMLHttpRequest object containing the response data.
- * See [www.w3.org/TR/XMLHttpRequest/](http://www.w3.org/TR/XMLHttpRequest/) for details about
- * accessing elements of the response.
- *
- * @param {Function} options.success The function to be called upon success of the request.
- * The callback is passed the following parameters:
- * @param {Object} options.success.response The XMLHttpRequest object containing the response data.
- * @param {Object} options.success.options The parameter to the request call.
- *
- * @param {Function} options.failure The function to be called upon success of the request.
- * The callback is passed the following parameters:
- * @param {Object} options.failure.response The XMLHttpRequest object containing the response data.
- * @param {Object} options.failure.options The parameter to the request call.
- *
- * @param {Object} options.scope The scope in which to execute the callbacks: The "this" object for
- * the callback function. If the `url`, or `params` options were specified as functions from which to
- * draw values, then this also serves as the scope for those function calls. Defaults to the browser
- * window.
- *
- * @param {Number} options.timeout The timeout in milliseconds to be used for this request.
- * Defaults to 30 seconds.
- *
- * @param {Ext.Element/HTMLElement/String} options.form The `<form>` Element or the id of the `<form>`
- * to pull parameters from.
- *
- * @param {Boolean} options.isUpload **Only meaningful when used with the `form` option.**
- *
- * True if the form object is a file upload (will be set automatically if the form was configured
- * with **`enctype`** `"multipart/form-data"`).
- *
- * File uploads are not performed using normal "Ajax" techniques, that is they are **not**
- * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the
- * DOM `<form>` element temporarily modified to have its [target][] set to refer to a dynamically
- * generated, hidden `<iframe>` which is inserted into the document but removed after the return data
- * has been gathered.
- *
- * The server response is parsed by the browser to create the document for the IFRAME. If the
- * server is using JSON to send the return object, then the [Content-Type][] header must be set to
- * "text/html" in order to tell the browser to insert the text unchanged into the document body.
- *
- * The response text is retrieved from the document, and a fake XMLHttpRequest object is created
- * containing a `responseText` property in order to conform to the requirements of event handlers
- * and callbacks.
- *
- * Be aware that file upload packets are sent with the content type [multipart/form][] and some server
- * technologies (notably JEE) may require some custom processing in order to retrieve parameter names
- * and parameter values from the packet content.
- *
- * [target]: http://www.w3.org/TR/REC-html40/present/frames.html#adef-target
- * [Content-Type]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17
- * [multipart/form]: http://www.faqs.org/rfcs/rfc2388.html
- *
- * @param {Object} options.headers Request headers to set for the request.
- *
- * @param {Object} options.xmlData XML document to use for the post. Note: This will be used instead
- * of params for the post data. Any params will be appended to the URL.
- *
- * @param {Object/String} options.jsonData JSON data to use as the post. Note: This will be used
- * instead of params for the post data. Any params will be appended to the URL.
- *
- * @param {Boolean} options.disableCaching True to add a unique cache-buster param to GET requests.
- *
- * @param {Boolean} options.withCredentials True to add the withCredentials property to the XHR object
- *
- * @return {Object} The request object. This may be used to cancel the request.
- */
- request : function(options) {
- options = options || {};
- var me = this,
- scope = options.scope || window,
- username = options.username || me.username,
- password = options.password || me.password || '',
- async,
- requestOptions,
- request,
- headers,
- xhr;
- if (me.fireEvent('beforerequest', me, options) !== false) {
- requestOptions = me.setOptions(options, scope);
- if (this.isFormUpload(options) === true) {
- this.upload(options.form, requestOptions.url, requestOptions.data, options);
- return null;
- }
- // if autoabort is set, cancel the current transactions
- if (options.autoAbort === true || me.autoAbort) {
- me.abort();
- }
- // create a connection object
- if ((options.cors === true || me.cors === true) && Ext.isIe && Ext.ieVersion >= 8) {
- xhr = new XDomainRequest();
- } else {
- xhr = this.getXhrInstance();
- }
- async = options.async !== false ? (options.async || me.async) : false;
- // open the request
- if (username) {
- xhr.open(requestOptions.method, requestOptions.url, async, username, password);
- } else {
- xhr.open(requestOptions.method, requestOptions.url, async);
- }
- if (options.withCredentials === true || me.withCredentials === true) {
- xhr.withCredentials = true;
- }
- headers = me.setupHeaders(xhr, options, requestOptions.data, requestOptions.params);
- // create the transaction object
- request = {
- id: ++Ext.data.Connection.requestId,
- xhr: xhr,
- headers: headers,
- options: options,
- async: async,
- timeout: setTimeout(function() {
- request.timedout = true;
- me.abort(request);
- }, options.timeout || me.timeout)
- };
- me.requests[request.id] = request;
- me.latestId = request.id;
- // bind our statechange listener
- if (async) {
- xhr.onreadystatechange = Ext.Function.bind(me.onStateChange, me, [request]);
- }
- // start the request!
- xhr.send(requestOptions.data);
- if (!async) {
- return this.onComplete(request);
- }
- return request;
- } else {
- Ext.callback(options.callback, options.scope, [options, undefined, undefined]);
- return null;
- }
- },
- /**
- * Uploads a form using a hidden iframe.
- * @param {String/HTMLElement/Ext.Element} form The form to upload
- * @param {String} url The url to post to
- * @param {String} params Any extra parameters to pass
- * @param {Object} options The initial options
- */
- upload: function(form, url, params, options) {
- form = Ext.getDom(form);
- options = options || {};
- var id = Ext.id(),
- frame = document.createElement('iframe'),
- hiddens = [],
- encoding = 'multipart/form-data',
- buf = {
- target: form.target,
- method: form.method,
- encoding: form.encoding,
- enctype: form.enctype,
- action: form.action
- }, hiddenItem;
- /*
- * Originally this behaviour was modified for Opera 10 to apply the secure URL after
- * the frame had been added to the document. It seems this has since been corrected in
- * Opera so the behaviour has been reverted, the URL will be set before being added.
- */
- Ext.fly(frame).set({
- id: id,
- name: id,
- cls: Ext.baseCSSPrefix + 'hide-display',
- src: Ext.SSL_SECURE_URL
- });
- document.body.appendChild(frame);
- // This is required so that IE doesn't pop the response up in a new window.
- if (document.frames) {
- document.frames[id].name = id;
- }
- Ext.fly(form).set({
- target: id,
- method: 'POST',
- enctype: encoding,
- encoding: encoding,
- action: url || buf.action
- });
- // add dynamic params
- if (params) {
- Ext.iterate(Ext.Object.fromQueryString(params), function(name, value){
- hiddenItem = document.createElement('input');
- Ext.fly(hiddenItem).set({
- type: 'hidden',
- value: value,
- name: name
- });
- form.appendChild(hiddenItem);
- hiddens.push(hiddenItem);
- });
- }
- Ext.fly(frame).on('load', Ext.Function.bind(this.onUploadComplete, this, [frame, options]), null, {single: true});
- form.submit();
- Ext.fly(form).set(buf);
- Ext.each(hiddens, function(h) {
- Ext.removeNode(h);
- });
- },
- /**
- * @private
- * Callback handler for the upload function. After we've submitted the form via the iframe this creates a bogus
- * response object to simulate an XHR and populates its responseText from the now-loaded iframe's document body
- * (or a textarea inside the body). We then clean up by removing the iframe
- */
- onUploadComplete: function(frame, options) {
- var me = this,
- // bogus response object
- response = {
- responseText: '',
- responseXML: null
- }, doc, firstChild;
- try {
- doc = frame.contentWindow.document || frame.contentDocument || window.frames[frame.id].document;
- if (doc) {
- if (doc.body) {
- if (/textarea/i.test((firstChild = doc.body.firstChild || {}).tagName)) { // json response wrapped in textarea
- response.responseText = firstChild.value;
- } else {
- response.responseText = doc.body.innerHTML;
- }
- }
- //in IE the document may still have a body even if returns XML.
- response.responseXML = doc.XMLDocument || doc;
- }
- } catch (e) {
- }
- me.fireEvent('requestcomplete', me, response, options);
- Ext.callback(options.success, options.scope, [response, options]);
- Ext.callback(options.callback, options.scope, [options, true, response]);
- setTimeout(function(){
- Ext.removeNode(frame);
- }, 100);
- },
- /**
- * Detects whether the form is intended to be used for an upload.
- * @private
- */
- isFormUpload: function(options){
- var form = this.getForm(options);
- if (form) {
- return (options.isUpload || (/multipart\/form-data/i).test(form.getAttribute('enctype')));
- }
- return false;
- },
- /**
- * Gets the form object from options.
- * @private
- * @param {Object} options The request options
- * @return {HTMLElement} The form, null if not passed
- */
- getForm: function(options){
- return Ext.getDom(options.form) || null;
- },
- /**
- * Sets various options such as the url, params for the request
- * @param {Object} options The initial options
- * @param {Object} scope The scope to execute in
- * @return {Object} The params for the request
- */
- setOptions: function(options, scope){
- var me = this,
- params = options.params || {},
- extraParams = me.extraParams,
- urlParams = options.urlParams,
- url = options.url || me.url,
- jsonData = options.jsonData,
- method,
- disableCache,
- data;
- // allow params to be a method that returns the params object
- if (Ext.isFunction(params)) {
- params = params.call(scope, options);
- }
- // allow url to be a method that returns the actual url
- if (Ext.isFunction(url)) {
- url = url.call(scope, options);
- }
- url = this.setupUrl(options, url);
- // check for xml or json data, and make sure json data is encoded
- data = options.rawData || options.xmlData || jsonData || null;
- if (jsonData && !Ext.isPrimitive(jsonData)) {
- data = Ext.encode(data);
- }
- // make sure params are a url encoded string and include any extraParams if specified
- if (Ext.isObject(params)) {
- params = Ext.Object.toQueryString(params);
- }
- if (Ext.isObject(extraParams)) {
- extraParams = Ext.Object.toQueryString(extraParams);
- }
- params = params + ((extraParams) ? ((params) ? '&' : '') + extraParams : '');
- urlParams = Ext.isObject(urlParams) ? Ext.Object.toQueryString(urlParams) : urlParams;
- params = this.setupParams(options, params);
- // decide the proper method for this request
- method = (options.method || me.method || ((params || data) ? 'POST' : 'GET')).toUpperCase();
- this.setupMethod(options, method);
- disableCache = options.disableCaching !== false ? (options.disableCaching || me.disableCaching) : false;
- // if the method is get append date to prevent caching
- if (method === 'GET' && disableCache) {
- url = Ext.urlAppend(url, (options.disableCachingParam || me.disableCachingParam) + '=' + (new Date().getTime()));
- }
- // if the method is get or there is json/xml data append the params to the url
- if ((method == 'GET' || data) && params) {
- url = Ext.urlAppend(url, params);
- params = null;
- }
- // allow params to be forced into the url
- if (urlParams) {
- url = Ext.urlAppend(url, urlParams);
- }
- return {
- url: url,
- method: method,
- data: data || params || null
- };
- },
- /**
- * Template method for overriding url
- * @template
- * @private
- * @param {Object} options
- * @param {String} url
- * @return {String} The modified url
- */
- setupUrl: function(options, url){
- var form = this.getForm(options);
- if (form) {
- url = url || form.action;
- }
- return url;
- },
- /**
- * Template method for overriding params
- * @template
- * @private
- * @param {Object} options
- * @param {String} params
- * @return {String} The modified params
- */
- setupParams: function(options, params) {
- var form = this.getForm(options),
- serializedForm;
- if (form && !this.isFormUpload(options)) {
- serializedForm = Ext.Element.serializeForm(form);
- params = params ? (params + '&' + serializedForm) : serializedForm;
- }
- return params;
- },
- /**
- * Template method for overriding method
- * @template
- * @private
- * @param {Object} options
- * @param {String} method
- * @return {String} The modified method
- */
- setupMethod: function(options, method){
- if (this.isFormUpload(options)) {
- return 'POST';
- }
- return method;
- },
- /**
- * Setup all the headers for the request
- * @private
- * @param {Object} xhr The xhr object
- * @param {Object} options The options for the request
- * @param {Object} data The data for the request
- * @param {Object} params The params for the request
- */
- setupHeaders: function(xhr, options, data, params){
- var me = this,
- headers = Ext.apply({}, options.headers || {}, me.defaultHeaders || {}),
- contentType = me.defaultPostHeader,
- jsonData = options.jsonData,
- xmlData = options.xmlData,
- key,
- header;
- if (!headers['Content-Type'] && (data || params)) {
- if (data) {
- if (options.rawData) {
- contentType = 'text/plain';
- } else {
- if (xmlData && Ext.isDefined(xmlData)) {
- contentType = 'text/xml';
- } else if (jsonData && Ext.isDefined(jsonData)) {
- contentType = 'application/json';
- }
- }
- }
- headers['Content-Type'] = contentType;
- }
- if (me.useDefaultXhrHeader && !headers['X-Requested-With']) {
- headers['X-Requested-With'] = me.defaultXhrHeader;
- }
- // set up all the request headers on the xhr object
- try{
- for (key in headers) {
- if (headers.hasOwnProperty(key)) {
- header = headers[key];
- xhr.setRequestHeader(key, header);
- }
- }
- } catch(e) {
- me.fireEvent('exception', key, header);
- }
- return headers;
- },
- /**
- * Creates the appropriate XHR transport for the browser.
- * @private
- */
- getXhrInstance: (function(){
- var options = [function(){
- return new XMLHttpRequest();
- }, function(){
- return new ActiveXObject('MSXML2.XMLHTTP.3.0');
- }, function(){
- return new ActiveXObject('MSXML2.XMLHTTP');
- }, function(){
- return new ActiveXObject('Microsoft.XMLHTTP');
- }], i = 0,
- len = options.length,
- xhr;
- for(; i < len; ++i) {
- try{
- xhr = options[i];
- xhr();
- break;
- }catch(e){}
- }
- return xhr;
- })(),
- /**
- * Determines whether this object has a request outstanding.
- * @param {Object} [request] Defaults to the last transaction
- * @return {Boolean} True if there is an outstanding request.
- */
- isLoading : function(request) {
- if (!request) {
- request = this.getLatest();
- }
- if (!(request && request.xhr)) {
- return false;
- }
- // if there is a connection and readyState is not 0 or 4
- var state = request.xhr.readyState;
- return !(state === 0 || state == 4);
- },
- /**
- * Aborts an active request.
- * @param {Object} [request] Defaults to the last request
- */
- abort : function(request) {
- var me = this;
-
- if (!request) {
- request = me.getLatest();
- }
- if (request && me.isLoading(request)) {
- /*
- * Clear out the onreadystatechange here, this allows us
- * greater control, the browser may/may not fire the function
- * depending on a series of conditions.
- */
- request.xhr.onreadystatechange = null;
- request.xhr.abort();
- me.clearTimeout(request);
- if (!request.timedout) {
- request.aborted = true;
- }
- me.onComplete(request);
- me.cleanup(request);
- }
- },
-
- /**
- * Aborts all active requests
- */
- abortAll: function(){
- var requests = this.requests,
- id;
-
- for (id in requests) {
- if (requests.hasOwnProperty(id)) {
- this.abort(requests[id]);
- }
- }
- },
-
- /**
- * Gets the most recent request
- * @private
- * @return {Object} The request. Null if there is no recent request
- */
- getLatest: function(){
- var id = this.latestId,
- request;
-
- if (id) {
- request = this.requests[id];
- }
- return request || null;
- },
- /**
- * Fires when the state of the xhr changes
- * @private
- * @param {Object} request The request
- */
- onStateChange : function(request) {
- if (request.xhr.readyState == 4) {
- this.clearTimeout(request);
- this.onComplete(request);
- this.cleanup(request);
- }
- },
- /**
- * Clears t