X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/3789b528d8dd8aad4558e38e22d775bcab1cbd36..6746dc89c47ed01b165cc1152533605f97eb8e8d:/pkgs/foundation.js
diff --git a/pkgs/foundation.js b/pkgs/foundation.js
index ac71e155..ef385550 100644
--- a/pkgs/foundation.js
+++ b/pkgs/foundation.js
@@ -1,8 +1,16 @@
/*
-Ext JS - JavaScript Library
-Copyright (c) 2006-2011, Sencha Inc.
-All rights reserved.
-licensing@sencha.com
+
+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
@@ -11,7 +19,7 @@ licensing@sencha.com
(function() {
var global = this,
objectPrototype = Object.prototype,
- toString = Object.prototype.toString,
+ toString = objectPrototype.toString,
enumerables = true,
enumerablesTest = { toString: 1 },
i;
@@ -86,7 +94,6 @@ licensing@sencha.com
/**
* Copies all the properties of config to object if they don't already exist.
- * @function
* @param {Object} object The receiver of the properties
* @param {Object} config The source of the properties
* @return {Object} returns obj
@@ -380,7 +387,8 @@ licensing@sencha.com
*/
isObject: (toString.call(null) === '[object Object]') ?
function(value) {
- return value !== null && value !== undefined && toString.call(value) === '[object Object]' && value.nodeType === undefined;
+ // 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]';
@@ -554,7 +562,7 @@ licensing@sencha.com
var i = 0;
do {
- uniqueGlobalNamespace = 'ExtSandbox' + (++i);
+ uniqueGlobalNamespace = 'ExtBox' + (++i);
} while (Ext.global[uniqueGlobalNamespace] !== undefined);
Ext.global[uniqueGlobalNamespace] = Ext;
@@ -583,6 +591,7 @@ licensing@sencha.com
* Old alias to {@link Ext#typeOf}
* @deprecated 4.0.0 Use {@link Ext#typeOf} instead
* @method
+ * @alias Ext#typeOf
*/
Ext.type = Ext.typeOf;
@@ -619,15 +628,13 @@ licensing@sencha.com
(function() {
// Current core version
-var version = '4.0.1', Version;
+var version = '4.0.2', Version;
Ext.Version = Version = Ext.extend(Object, {
/**
- * @constructor
* @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
- * @param version
*/
constructor: function(version) {
var parts, releaseStartIndex;
@@ -1126,7 +1133,7 @@ var isToFixedBroken = (0.9).toFixed() !== '1';
Ext.Number = {
/**
- * Checks whether or not the current number is within a desired range. If the number is already within the
+ * 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
@@ -1146,6 +1153,33 @@ Ext.Number = {
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
@@ -1207,6 +1241,34 @@ Ext.num = 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,
@@ -1219,6 +1281,7 @@ Ext.num = function() {
}(),
supportsSliceOnNodeList = true,
ExtArray;
+
try {
// IE 6 - 8 will throw an error when using Array.prototype.slice on NodeList
if (typeof document !== 'undefined') {
@@ -1228,50 +1291,173 @@ Ext.num = function() {
supportsSliceOnNodeList = false;
}
- ExtArray = Ext.Array = {
- /**
- * Iterates an array or an iterable value and invoke the given callback function for each item.
+ function fixArrayIndex (array, index) {
+ return (index < 0) ? Math.max(0, array.length + index)
+ : Math.min(array.length, index);
+ }
- var countries = ['Vietnam', 'Singapore', 'United States', 'Russia'];
+ /*
+ 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;
- Ext.Array.each(countries, function(name, index, countriesItSelf) {
- console.log(name);
- });
+ 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)
- var sum = function() {
- var sum = 0;
+ 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];
+ }
+ }
+ }
- Ext.Array.each(arguments, function(value) {
- sum += value;
- });
+ return array;
+ }
- return sum;
- };
+ 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;
+ }
- sum(1, 2, 3); // returns 6
+ function eraseSim (array, index, removeCount) {
+ return replaceSim(array, index, removeCount);
+ }
- * The iteration can be stopped by returning false in the function callback.
+ 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));
- Ext.Array.each(countries, function(name, index, countriesItSelf) {
- if (name === 'Singapore') {
- return false; // break here
+ 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/Mixed} 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`. Arguments passed to this callback function are:
-
-- `item`: {Mixed} The item at the current `index` in the passed `array`
-- `index`: {Number} The current `index` within the `array`
-- `allItems`: {Array/NodeList/Mixed} The `array` passed as the first argument to `Ext.Array.each`
-
+ *
+ * - `item` : Mixed - The item at the current `index` in the passed `array`
+ * - `index` : Number - The current `index` within the `array`
+ * - `allItems` : Array/NodeList/Mixed - The `array` passed as the first argument to `Ext.Array.each`
+ *
* @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.
- * @markdown
*/
each: function(array, fn, scope, reverse) {
array = ExtArray.from(array);
@@ -1307,12 +1493,11 @@ Ext.num = function() {
* @param {Array} array The array to iterate
* @param {Function} fn The function callback, to be invoked these arguments:
*
-- `item`: {Mixed} The item at the current `index` in the passed `array`
-- `index`: {Number} The current `index` within the `array`
-- `allItems`: {Array} The `array` itself which was passed as the first argument
-
+ * - `item` : Mixed - The item at the current `index` in the passed `array`
+ * - `index` : Number - The current `index` within the `array`
+ * - `allItems` : Array - 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.
- * @markdown
*/
forEach: function(array, fn, scope) {
if (supportsForEach) {
@@ -1335,7 +1520,6 @@ Ext.num = function() {
* @param {Mixed} 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)
- * @markdown
*/
indexOf: function(array, item, from) {
if (supportsIndexOf) {
@@ -1359,7 +1543,6 @@ Ext.num = function() {
* @param {Array} array The array to check
* @param {Mixed} item The item to look for
* @return {Boolean} True if the array contains the item, false otherwise
- * @markdown
*/
contains: function(array, item) {
if (supportsIndexOf) {
@@ -1379,28 +1562,29 @@ Ext.num = function() {
/**
* 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']
-
+ *
+ * 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 {Mixed} 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
- * @markdown
*/
toArray: function(iterable, start, end){
if (!iterable || !iterable.length) {
@@ -1431,8 +1615,8 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
/**
* 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]
-
+ * 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.
@@ -1452,6 +1636,7 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
/**
* 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
@@ -1539,7 +1724,8 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
/**
* Filter through an array and remove empty item as defined in {@link Ext#isEmpty Ext.isEmpty}
*
- * @see Ext.Array.filter
+ * See {@link Ext.Array#filter}
+ *
* @param {Array} array
* @return {Array} results
*/
@@ -1586,6 +1772,7 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
/**
* 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
@@ -1621,7 +1808,6 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
* @param {Boolean} (Optional) newReference True to clone the given array and return a new reference if necessary,
* defaults to false
* @return {Array} array
- * @markdown
*/
from: function(value, newReference) {
if (value === undefined || value === null) {
@@ -1650,7 +1836,7 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
var index = ExtArray.indexOf(array, item);
if (index !== -1) {
- array.splice(index, 1);
+ erase(array, index, 1);
}
return array;
@@ -1661,7 +1847,6 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
*
* @param {Array} array The array
* @param {Mixed} item The item to include
- * @return {Array} The passed array itself
*/
include: function(array, item) {
if (!ExtArray.contains(array, item)) {
@@ -1682,9 +1867,13 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
},
/**
- * Merge multiple arrays into one with unique items. Alias to {@link Ext.Array#union}.
+ * Merge multiple arrays into one with unique items.
*
- * @param {Array} array,...
+ * {@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() {
@@ -1702,7 +1891,9 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
/**
* Merge multiple arrays into one with unique items that exist in all of the arrays.
*
- * @param {Array} array,...
+ * @param {Array} array1
+ * @param {Array} array2
+ * @param {Array} etc
* @return {Array} intersect
*/
intersect: function() {
@@ -1722,8 +1913,8 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
}
}
- minArray = Ext.Array.unique(minArray);
- arrays.splice(x, 1);
+ 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
@@ -1751,8 +1942,8 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
/**
* Perform a set difference A-B by subtracting all items in array B from array A.
*
- * @param {Array} array A
- * @param {Array} array B
+ * @param {Array} arrayA
+ * @param {Array} arrayB
* @return {Array} difference
*/
difference: function(arrayA, arrayB) {
@@ -1763,7 +1954,7 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
for (i = 0,lnB = arrayB.length; i < lnB; i++) {
for (j = 0; j < ln; j++) {
if (clone[j] === arrayB[i]) {
- clone.splice(j, 1);
+ erase(clone, j, 1);
j--;
ln--;
}
@@ -1773,6 +1964,24 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
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.
+ */
+ slice: function(array, begin, end) {
+ return slice.call(array, begin, end);
+ },
+
/**
* Sorts the elements of an Array.
* By default, this method sorts the elements alphabetically and ascending.
@@ -1819,8 +2028,7 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
/**
* Recursively flattens into 1-d Array. Injects Arrays inline.
- * @param {Array} array The array to flatten
- * @return {Array} The new, flattened array.
+ *
*/
flatten: function(array) {
var worker = [];
@@ -1846,9 +2054,10 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
/**
* 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
+ * If omitted the "<" operator will be used. Note: gt = 1; eq = 0; lt = -1
* @return {Mixed} minValue The minimum value
*/
min: function(array, comparisonFn) {
@@ -1874,10 +2083,11 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
},
/**
- * Returns the maximum value in the Array
+ * 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
+ * If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1
* @return {Mixed} maxValue The maximum value
*/
max: function(array, comparisonFn) {
@@ -1903,7 +2113,8 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
},
/**
- * Calculates the mean of all items in the array
+ * Calculates the mean of all items in the array.
+ *
* @param {Array} array The Array to calculate the mean value of.
* @return {Number} The mean.
*/
@@ -1912,7 +2123,8 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
},
/**
- * Calculates the sum of all items in the given array
+ * 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.
*/
@@ -1927,98 +2139,162 @@ Ext.Array.toArray('splitted', 0, 3); // returns ['s', 'p', 'l', 'i']
}
return sum;
- }
+ },
+
+ //name
and value
.
+ * 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
-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'
-});
- *
+ *
+ * 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
*/
@@ -2091,13 +2364,15 @@ setValue({
};
},
- /**
- * Create a new function from the provided fn
, change this
to the provided scope, optionally
+ /**
+ * 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 {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
@@ -2105,19 +2380,18 @@ setValue({
*/
bind: function(fn, scope, args, appendArgs) {
var method = fn,
- applyArgs;
+ slice = Array.prototype.slice;
return function() {
var callArgs = args || arguments;
if (appendArgs === true) {
- callArgs = Array.prototype.slice.call(arguments, 0);
+ callArgs = slice.call(arguments, 0);
callArgs = callArgs.concat(args);
}
else if (Ext.isNumber(appendArgs)) {
- callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
- applyArgs = [appendArgs, 0].concat(args); // create method call params
- Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
+ callArgs = slice.call(arguments, 0); // copy arguments first
+ Ext.Array.insert(callArgs, appendArgs, args);
}
return method.apply(scope || window, callArgs);
@@ -2125,23 +2399,26 @@ setValue({
},
/**
- * Create a new function from the provided fn
, the arguments of which are pre-set to `args`.
+ * 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'
-
+ * 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.
+ * @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) {
@@ -2155,8 +2432,8 @@ setValue({
},
/**
- * 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.
+ * 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
@@ -2172,26 +2449,26 @@ setValue({
* 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"
-
+ *
+ * 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} 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 {Mixed} returnValue (optional) The value to return if the passed function return false (defaults to null).
* @return {Function} The new function
*/
@@ -2212,16 +2489,17 @@ sayHiToFriend('Brian'); // alerts "Hi, Brian"
},
/**
- * 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.
- */
+ * 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);
@@ -2236,27 +2514,30 @@ sayHiToFriend('Brian'); // alerts "Hi, Brian"
/**
* 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);
-
+ *
+ * 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 {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
@@ -2276,23 +2557,21 @@ Ext.Function.defer(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
- *
+ * 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.
+ * @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
*/
@@ -2310,15 +2589,15 @@ sayGoodbye('Fred'); // both alerts show
},
/**
- * Creates a delegate function, optionally with a bound scope which, when called, buffers + * 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.
+ * 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
+ * @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.
@@ -2341,16 +2620,16 @@ sayGoodbye('Fred'); // both alerts show
},
/**
- * Creates a throttled version of the passed function which, when called repeatedly and + * 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.
+ * 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.
+ * 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 fn {Function} The function to execute at a regular time interval. - * @param interval {Number} The interval in milliseconds on which the passed function is executed. - * @param scope (optional) The scope (this
reference) in which
+ * @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.
*/
@@ -2375,23 +2654,23 @@ sayGoodbye('Fred'); // both alerts show
};
/**
- * Shorthand for {@link Ext.Function#defer}
+ * @method
* @member Ext
- * @method defer
+ * @alias Ext.Function#defer
*/
Ext.defer = Ext.Function.alias(Ext.Function, 'defer');
/**
- * Shorthand for {@link Ext.Function#pass}
+ * @method
* @member Ext
- * @method pass
+ * @alias Ext.Function#pass
*/
Ext.pass = Ext.Function.alias(Ext.Function, 'pass');
/**
- * Shorthand for {@link Ext.Function#bind}
+ * @method
* @member Ext
- * @method bind
+ * @alias Ext.Function#bind
*/
Ext.bind = Ext.Function.alias(Ext.Function, 'bind');
@@ -3340,8 +3619,8 @@ Ext.Date.monthNumbers = {
Dec:11
},
/**
- * The date format string that the {@link #dateRenderer} and {@link #date} functions use. - * see {@link #Date} for details.
+ *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.
*This defaults to m/d/Y
, but may be overridden in a locale file.
Other.awesome.Class
- * will simply be loaded from ./Other/awesome/Class.js
+ * If not being specified, for example, `Other.awesome.Class`
+ * will simply be loaded from `./Other/awesome/Class.js`
*/
paths: {
'Ext': '.'
@@ -6959,30 +7352,30 @@ This process will be automated with Sencha Command, to be released and documente
/**
* 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, i.e:
-
-
-
-
- * Refer to {@link Ext.Loader#configs} for the list of possible properties
- *
- * @param {Object} config The config object to override the default values in {@link Ext.Loader#config}
+ * (or ext-core-debug.js) is included in the page, e.g.:
+ *
+ *
+ *
+ *
+ * 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
- * @markdown
*/
setConfig: function(name, value) {
if (Ext.isObject(name) && arguments.length === 1) {
@@ -6996,7 +7389,8 @@ This process will be automated with Sencha Command, to be released and documente
},
/**
- * Get the config value corresponding to the specified name. If no name is given, will return the config object
+ * 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/Mixed}
*/
@@ -7009,16 +7403,14 @@ This process will be automated with Sencha Command, to be released and documente
},
/**
- * Sets the path of a namespace.
- * For Example:
-
- Ext.Loader.setPath('Ext', '.');
-
+ * 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
- * @markdown
*/
setPath: flexSetter(function(name, path) {
//this
) of the callback function
+ * @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) {
@@ -7635,36 +8032,49 @@ This process will be automated with Sencha Command, to be released and documente
};
/**
- * Convenient alias of {@link Ext.Loader#require}. Please see the introduction documentation of
- * {@link Ext.Loader} for examples.
* @member Ext
* @method require
+ * @alias Ext.Loader#require
*/
Ext.require = alias(Loader, 'require');
/**
- * Synchronous version of {@link Ext#require}, convenient alias of {@link Ext.Loader#syncRequire}.
- *
* @member Ext
* @method syncRequire
+ * @alias Ext.Loader#syncRequire
*/
Ext.syncRequire = alias(Loader, 'syncRequire');
/**
- * Convenient shortcut to {@link Ext.Loader#exclude}
* @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 instanciating 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 = [],
@@ -7812,6 +8222,23 @@ This process will be automated with Sencha Command, to be released and documente
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 instanciated. 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 = [],
@@ -7890,7 +8317,7 @@ If a console is available (that supports the `console.dir` function) you'll see
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
+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.
@@ -8041,7 +8468,6 @@ error to the browser, otherwise the error will be thrown and execution will halt
name: 'Ext.Error',
/**
- * @constructor
* @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.