2011-07-17 08:05:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
2010-04-01 21:10:28 +00:00
|
|
|
////////////////////////////////////
|
2010-04-01 00:56:16 +00:00
|
|
|
|
2010-11-01 20:44:39 +00:00
|
|
|
/**
|
2010-11-17 19:34:23 +00:00
|
|
|
* @ngdoc function
|
2010-11-01 20:44:39 +00:00
|
|
|
* @name angular.lowercase
|
|
|
|
|
* @function
|
|
|
|
|
*
|
2011-09-01 07:06:09 +00:00
|
|
|
* @description Converts the specified string to lowercase.
|
|
|
|
|
* @param {string} string String to be converted to lowercase.
|
2010-10-27 22:31:10 +00:00
|
|
|
* @returns {string} Lowercased string.
|
2010-11-01 20:44:39 +00:00
|
|
|
*/
|
2011-10-25 16:09:32 +00:00
|
|
|
var lowercase = function(string){return isString(string) ? string.toLowerCase() : string;};
|
2010-11-01 20:44:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-11-17 19:34:23 +00:00
|
|
|
* @ngdoc function
|
2010-11-10 20:02:49 +00:00
|
|
|
* @name angular.uppercase
|
2010-11-01 20:44:39 +00:00
|
|
|
* @function
|
|
|
|
|
*
|
2011-09-01 07:06:09 +00:00
|
|
|
* @description Converts the specified string to uppercase.
|
|
|
|
|
* @param {string} string String to be converted to uppercase.
|
2010-10-27 22:31:10 +00:00
|
|
|
* @returns {string} Uppercased string.
|
2010-11-01 20:44:39 +00:00
|
|
|
*/
|
2011-10-25 16:09:32 +00:00
|
|
|
var uppercase = function(string){return isString(string) ? string.toUpperCase() : string;};
|
2010-11-01 20:44:39 +00:00
|
|
|
|
|
|
|
|
|
2011-10-07 18:27:49 +00:00
|
|
|
var manualLowercase = function(s) {
|
2011-02-12 16:58:11 +00:00
|
|
|
return isString(s)
|
2013-03-18 18:18:30 +00:00
|
|
|
? s.replace(/[A-Z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) | 32);})
|
2011-02-12 16:58:11 +00:00
|
|
|
: s;
|
2010-10-19 04:20:47 +00:00
|
|
|
};
|
2011-10-07 18:27:49 +00:00
|
|
|
var manualUppercase = function(s) {
|
2011-02-12 16:58:11 +00:00
|
|
|
return isString(s)
|
2013-03-18 18:18:30 +00:00
|
|
|
? s.replace(/[a-z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) & ~32);})
|
2011-02-12 16:58:11 +00:00
|
|
|
: s;
|
2010-10-19 04:20:47 +00:00
|
|
|
};
|
2010-11-01 20:44:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// String#toLowerCase and String#toUpperCase don't produce correct results in browsers with Turkish
|
2011-08-19 00:41:57 +00:00
|
|
|
// locale, for this reason we need to detect this case and redefine lowercase/uppercase methods
|
|
|
|
|
// with correct but slower alternatives.
|
2010-10-19 04:20:47 +00:00
|
|
|
if ('i' !== 'I'.toLowerCase()) {
|
|
|
|
|
lowercase = manualLowercase;
|
2010-10-31 18:24:20 +00:00
|
|
|
uppercase = manualUppercase;
|
2010-10-19 04:20:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-01-29 19:30:12 +00:00
|
|
|
var /** holds major version number for IE or NaN for real browsers */
|
2012-03-16 19:55:54 +00:00
|
|
|
msie = int((/msie (\d+)/.exec(lowercase(navigator.userAgent)) || [])[1]),
|
2011-02-05 00:42:21 +00:00
|
|
|
jqLite, // delay binding since jQuery could be loaded after us.
|
|
|
|
|
jQuery, // delay binding
|
2011-03-09 04:20:49 +00:00
|
|
|
slice = [].slice,
|
|
|
|
|
push = [].push,
|
2011-11-08 05:54:01 +00:00
|
|
|
toString = Object.prototype.toString,
|
2010-11-01 20:44:39 +00:00
|
|
|
|
2012-11-06 22:35:47 +00:00
|
|
|
|
2013-02-21 19:55:16 +00:00
|
|
|
_angular = window.angular,
|
2011-01-26 05:03:37 +00:00
|
|
|
/** @name angular */
|
2011-11-02 23:32:46 +00:00
|
|
|
angular = window.angular || (window.angular = {}),
|
2011-11-23 05:28:39 +00:00
|
|
|
angularModule,
|
2011-01-06 07:56:57 +00:00
|
|
|
nodeName_,
|
2012-03-16 18:28:32 +00:00
|
|
|
uid = ['0', '0', '0'];
|
2010-04-01 00:56:16 +00:00
|
|
|
|
2012-11-06 22:35:47 +00:00
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.noConflict
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Restores the previous global value of angular and returns the current instance. Other libraries may already use the
|
|
|
|
|
* angular namespace. Or a previous version of angular is already loaded on the page. In these cases you may want to
|
|
|
|
|
* restore the previous namespace and keep a reference to angular.
|
|
|
|
|
*
|
|
|
|
|
* @return {Object} The current angular namespace
|
|
|
|
|
*/
|
|
|
|
|
function noConflict() {
|
|
|
|
|
var a = window.angular;
|
|
|
|
|
window.angular = _angular;
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 07:41:43 +00:00
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @param {*} obj
|
|
|
|
|
* @return {boolean} Returns true if `obj` is an array or array-like object (NodeList, Arguments, ...)
|
|
|
|
|
*/
|
|
|
|
|
function isArrayLike(obj) {
|
|
|
|
|
if (!obj || (typeof obj.length !== 'number')) return false;
|
|
|
|
|
|
|
|
|
|
// We have on object which has length property. Should we treat it as array?
|
|
|
|
|
if (typeof obj.hasOwnProperty != 'function' &&
|
|
|
|
|
typeof obj.constructor != 'function') {
|
|
|
|
|
// This is here for IE8: it is a bogus object treat it as array;
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return obj instanceof JQLite || // JQLite
|
|
|
|
|
(jQuery && obj instanceof jQuery) || // jQuery
|
|
|
|
|
toString.call(obj) !== '[object Object]' || // some browser native object
|
|
|
|
|
typeof obj.callee === 'function'; // arguments (on IE8 looks like regular obj)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 05:12:52 +00:00
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
2011-01-08 06:02:23 +00:00
|
|
|
* @name angular.forEach
|
2010-11-25 05:12:52 +00:00
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-09-01 07:06:09 +00:00
|
|
|
* Invokes the `iterator` function once for each item in `obj` collection, which can be either an
|
|
|
|
|
* object or an array. The `iterator` function is invoked with `iterator(value, key)`, where `value`
|
|
|
|
|
* is the value of an object property or an array element and `key` is the object property key or
|
|
|
|
|
* array element index. Specifying a `context` for the function is optional.
|
2011-01-08 06:02:23 +00:00
|
|
|
*
|
|
|
|
|
* Note: this function was previously known as `angular.foreach`.
|
2010-11-25 05:12:52 +00:00
|
|
|
*
|
|
|
|
|
<pre>
|
|
|
|
|
var values = {name: 'misko', gender: 'male'};
|
|
|
|
|
var log = [];
|
2011-01-08 06:02:23 +00:00
|
|
|
angular.forEach(values, function(value, key){
|
2010-11-25 05:12:52 +00:00
|
|
|
this.push(key + ': ' + value);
|
|
|
|
|
}, log);
|
|
|
|
|
expect(log).toEqual(['name: misko', 'gender:male']);
|
|
|
|
|
</pre>
|
|
|
|
|
*
|
|
|
|
|
* @param {Object|Array} obj Object to iterate over.
|
2012-01-12 19:06:10 +00:00
|
|
|
* @param {Function} iterator Iterator function.
|
2011-09-01 07:06:09 +00:00
|
|
|
* @param {Object=} context Object to become context (`this`) for the iterator function.
|
2011-07-30 01:42:16 +00:00
|
|
|
* @returns {Object|Array} Reference to `obj`.
|
2010-11-25 05:12:52 +00:00
|
|
|
*/
|
2011-01-08 06:02:23 +00:00
|
|
|
function forEach(obj, iterator, context) {
|
2010-03-23 21:57:11 +00:00
|
|
|
var key;
|
|
|
|
|
if (obj) {
|
2010-04-17 03:10:09 +00:00
|
|
|
if (isFunction(obj)){
|
2010-04-16 21:01:29 +00:00
|
|
|
for (key in obj) {
|
2012-04-10 21:29:49 +00:00
|
|
|
if (key != 'prototype' && key != 'length' && key != 'name' && obj.hasOwnProperty(key)) {
|
2010-04-16 21:01:29 +00:00
|
|
|
iterator.call(context, obj[key], key);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-08 06:02:23 +00:00
|
|
|
} else if (obj.forEach && obj.forEach !== forEach) {
|
2010-04-17 03:10:09 +00:00
|
|
|
obj.forEach(iterator, context);
|
2013-02-11 20:25:34 +00:00
|
|
|
} else if (isArrayLike(obj)) {
|
2010-03-23 21:57:11 +00:00
|
|
|
for (key = 0; key < obj.length; key++)
|
|
|
|
|
iterator.call(context, obj[key], key);
|
|
|
|
|
} else {
|
2012-03-21 22:42:35 +00:00
|
|
|
for (key in obj) {
|
|
|
|
|
if (obj.hasOwnProperty(key)) {
|
|
|
|
|
iterator.call(context, obj[key], key);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-23 21:57:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-08 20:56:29 +00:00
|
|
|
function sortedKeys(obj) {
|
2010-04-01 00:56:16 +00:00
|
|
|
var keys = [];
|
2011-09-08 20:56:29 +00:00
|
|
|
for (var key in obj) {
|
|
|
|
|
if (obj.hasOwnProperty(key)) {
|
|
|
|
|
keys.push(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return keys.sort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function forEachSorted(obj, iterator, context) {
|
2012-04-10 21:29:49 +00:00
|
|
|
var keys = sortedKeys(obj);
|
2010-04-01 00:56:16 +00:00
|
|
|
for ( var i = 0; i < keys.length; i++) {
|
|
|
|
|
iterator.call(context, obj[keys[i]], keys[i]);
|
|
|
|
|
}
|
|
|
|
|
return keys;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-01-07 02:10:47 +00:00
|
|
|
/**
|
|
|
|
|
* when using forEach the params are value, key, but it is often useful to have key, value.
|
|
|
|
|
* @param {function(string, *)} iteratorFn
|
|
|
|
|
* @returns {function(*, string)}
|
|
|
|
|
*/
|
|
|
|
|
function reverseParams(iteratorFn) {
|
|
|
|
|
return function(value, key) { iteratorFn(key, value) };
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-12 20:40:23 +00:00
|
|
|
/**
|
|
|
|
|
* A consistent way of creating unique IDs in angular. The ID is a sequence of alpha numeric
|
|
|
|
|
* characters such as '012ABC'. The reason why we are not using simply a number counter is that
|
2013-01-27 22:55:55 +00:00
|
|
|
* the number string gets longer over time, and it can also overflow, where as the nextId
|
2011-04-12 20:40:23 +00:00
|
|
|
* will grow much slower, it is a string, and it will never overflow.
|
|
|
|
|
*
|
|
|
|
|
* @returns an unique alpha-numeric string
|
|
|
|
|
*/
|
|
|
|
|
function nextUid() {
|
|
|
|
|
var index = uid.length;
|
|
|
|
|
var digit;
|
|
|
|
|
|
|
|
|
|
while(index) {
|
|
|
|
|
index--;
|
|
|
|
|
digit = uid[index].charCodeAt(0);
|
|
|
|
|
if (digit == 57 /*'9'*/) {
|
|
|
|
|
uid[index] = 'A';
|
|
|
|
|
return uid.join('');
|
|
|
|
|
}
|
|
|
|
|
if (digit == 90 /*'Z'*/) {
|
|
|
|
|
uid[index] = '0';
|
|
|
|
|
} else {
|
|
|
|
|
uid[index] = String.fromCharCode(digit + 1);
|
|
|
|
|
return uid.join('');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
uid.unshift('0');
|
|
|
|
|
return uid.join('');
|
|
|
|
|
}
|
2010-11-16 21:57:41 +00:00
|
|
|
|
2013-04-17 00:09:43 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set or clear the hashkey for an object.
|
|
|
|
|
* @param obj object
|
|
|
|
|
* @param h the hashkey (!truthy to delete the hashkey)
|
|
|
|
|
*/
|
|
|
|
|
function setHashKey(obj, h) {
|
|
|
|
|
if (h) {
|
|
|
|
|
obj.$$hashKey = h;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
delete obj.$$hashKey;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 05:03:56 +00:00
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.extend
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-08-19 00:41:57 +00:00
|
|
|
* Extends the destination object `dst` by copying all of the properties from the `src` object(s)
|
|
|
|
|
* to `dst`. You can specify multiple `src` objects.
|
2010-11-25 05:03:56 +00:00
|
|
|
*
|
2011-09-01 07:06:09 +00:00
|
|
|
* @param {Object} dst Destination object.
|
|
|
|
|
* @param {...Object} src Source object(s).
|
2013-05-21 17:33:13 +00:00
|
|
|
* @returns {Object} Reference to `dst`.
|
2010-11-25 05:03:56 +00:00
|
|
|
*/
|
2010-03-30 03:25:42 +00:00
|
|
|
function extend(dst) {
|
2013-04-17 00:09:43 +00:00
|
|
|
var h = dst.$$hashKey;
|
2011-01-08 06:02:23 +00:00
|
|
|
forEach(arguments, function(obj){
|
2010-03-30 03:25:42 +00:00
|
|
|
if (obj !== dst) {
|
2011-01-08 06:02:23 +00:00
|
|
|
forEach(obj, function(value, key){
|
2010-03-30 03:25:42 +00:00
|
|
|
dst[key] = value;
|
|
|
|
|
});
|
|
|
|
|
}
|
2010-03-23 21:57:11 +00:00
|
|
|
});
|
2013-04-17 00:09:43 +00:00
|
|
|
|
|
|
|
|
setHashKey(dst,h);
|
2010-03-23 21:57:11 +00:00
|
|
|
return dst;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-16 19:55:54 +00:00
|
|
|
function int(str) {
|
|
|
|
|
return parseInt(str, 10);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 05:03:56 +00:00
|
|
|
|
2010-07-15 20:13:21 +00:00
|
|
|
function inherit(parent, extra) {
|
2011-10-07 18:27:49 +00:00
|
|
|
return extend(new (extend(function() {}, {prototype:parent}))(), extra);
|
2010-09-14 21:22:15 +00:00
|
|
|
}
|
2010-07-15 20:13:21 +00:00
|
|
|
|
2013-03-20 23:24:23 +00:00
|
|
|
var START_SPACE = /^\s*/;
|
|
|
|
|
var END_SPACE = /\s*$/;
|
|
|
|
|
function stripWhitespace(str) {
|
|
|
|
|
return isString(str) ? str.replace(START_SPACE, '').replace(END_SPACE, '') : str;
|
|
|
|
|
}
|
2010-11-25 02:23:21 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.noop
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-09-01 07:06:09 +00:00
|
|
|
* A function that performs no operations. This function can be useful when writing code in the
|
|
|
|
|
* functional style.
|
2010-11-25 02:23:21 +00:00
|
|
|
<pre>
|
|
|
|
|
function foo(callback) {
|
|
|
|
|
var result = calculateResult();
|
|
|
|
|
(callback || angular.noop)(result);
|
|
|
|
|
}
|
|
|
|
|
</pre>
|
|
|
|
|
*/
|
2010-03-30 03:25:42 +00:00
|
|
|
function noop() {}
|
2011-11-02 04:09:54 +00:00
|
|
|
noop.$inject = [];
|
2010-11-25 02:23:21 +00:00
|
|
|
|
2010-11-25 02:55:34 +00:00
|
|
|
|
2010-11-25 02:23:21 +00:00
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.identity
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-09-01 07:06:09 +00:00
|
|
|
* A function that returns its first argument. This function is useful when writing code in the
|
|
|
|
|
* functional style.
|
2010-11-25 02:23:21 +00:00
|
|
|
*
|
|
|
|
|
<pre>
|
|
|
|
|
function transformer(transformationFn, value) {
|
|
|
|
|
return (transformationFn || identity)(value);
|
|
|
|
|
};
|
|
|
|
|
</pre>
|
|
|
|
|
*/
|
2010-03-30 03:25:42 +00:00
|
|
|
function identity($) {return $;}
|
2011-11-02 04:09:54 +00:00
|
|
|
identity.$inject = [];
|
2010-11-25 02:55:34 +00:00
|
|
|
|
|
|
|
|
|
2011-10-25 16:09:32 +00:00
|
|
|
function valueFn(value) {return function() {return value;};}
|
2010-10-30 18:57:13 +00:00
|
|
|
|
2010-11-25 16:19:14 +00:00
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isUndefined
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-09-01 07:06:09 +00:00
|
|
|
* Determines if a reference is undefined.
|
2010-11-25 16:19:14 +00:00
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is undefined.
|
|
|
|
|
*/
|
2012-04-10 21:29:49 +00:00
|
|
|
function isUndefined(value){return typeof value == 'undefined';}
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isDefined
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-09-01 07:06:09 +00:00
|
|
|
* Determines if a reference is defined.
|
2010-11-25 16:19:14 +00:00
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is defined.
|
|
|
|
|
*/
|
2012-04-10 21:29:49 +00:00
|
|
|
function isDefined(value){return typeof value != 'undefined';}
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isObject
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-09-01 07:06:09 +00:00
|
|
|
* Determines if a reference is an `Object`. Unlike `typeof` in JavaScript, `null`s are not
|
|
|
|
|
* considered to be objects.
|
2010-11-25 16:19:14 +00:00
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is an `Object` but not `null`.
|
|
|
|
|
*/
|
2012-04-10 21:29:49 +00:00
|
|
|
function isObject(value){return value != null && typeof value == 'object';}
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isString
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-09-01 07:06:09 +00:00
|
|
|
* Determines if a reference is a `String`.
|
2010-11-25 16:19:14 +00:00
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is a `String`.
|
|
|
|
|
*/
|
2012-04-10 21:29:49 +00:00
|
|
|
function isString(value){return typeof value == 'string';}
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isNumber
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-09-01 07:06:09 +00:00
|
|
|
* Determines if a reference is a `Number`.
|
2010-11-25 16:19:14 +00:00
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is a `Number`.
|
|
|
|
|
*/
|
2011-11-08 05:54:01 +00:00
|
|
|
function isNumber(value){return typeof value == 'number';}
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isDate
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-09-01 07:06:09 +00:00
|
|
|
* Determines if a value is a date.
|
2010-11-25 16:19:14 +00:00
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is a `Date`.
|
|
|
|
|
*/
|
2011-11-08 05:54:01 +00:00
|
|
|
function isDate(value){
|
|
|
|
|
return toString.apply(value) == '[object Date]';
|
|
|
|
|
}
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isArray
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-09-01 07:06:09 +00:00
|
|
|
* Determines if a reference is an `Array`.
|
2010-11-25 16:19:14 +00:00
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is an `Array`.
|
|
|
|
|
*/
|
2011-11-08 05:54:01 +00:00
|
|
|
function isArray(value) {
|
|
|
|
|
return toString.apply(value) == '[object Array]';
|
|
|
|
|
}
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isFunction
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-09-01 07:06:09 +00:00
|
|
|
* Determines if a reference is a `Function`.
|
2010-11-25 16:19:14 +00:00
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is a `Function`.
|
|
|
|
|
*/
|
2011-10-25 16:09:32 +00:00
|
|
|
function isFunction(value){return typeof value == 'function';}
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
2011-01-10 07:21:48 +00:00
|
|
|
/**
|
|
|
|
|
* Checks if `obj` is a window object.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {*} obj Object to check
|
|
|
|
|
* @returns {boolean} True if `obj` is a window obj.
|
|
|
|
|
*/
|
|
|
|
|
function isWindow(obj) {
|
|
|
|
|
return obj && obj.document && obj.location && obj.alert && obj.setInterval;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-30 19:06:04 +00:00
|
|
|
|
|
|
|
|
function isScope(obj) {
|
|
|
|
|
return obj && obj.$evalAsync && obj.$watch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-02-26 02:49:54 +00:00
|
|
|
function isFile(obj) {
|
|
|
|
|
return toString.apply(obj) === '[object File]';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-04-10 21:29:49 +00:00
|
|
|
function isBoolean(value) {
|
|
|
|
|
return typeof value == 'boolean';
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-19 00:41:57 +00:00
|
|
|
|
|
|
|
|
function trim(value) {
|
|
|
|
|
return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-04 19:33:01 +00:00
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isElement
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Determines if a reference is a DOM element (or wrapped jQuery element).
|
|
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is a DOM element (or wrapped jQuery element).
|
|
|
|
|
*/
|
2010-04-12 21:28:15 +00:00
|
|
|
function isElement(node) {
|
2011-02-10 19:20:49 +00:00
|
|
|
return node &&
|
|
|
|
|
(node.nodeName // we are a direct element
|
|
|
|
|
|| (node.bind && node.find)); // we have a bind and find method part of jQuery API
|
2010-04-23 00:11:56 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-21 23:32:05 +00:00
|
|
|
/**
|
|
|
|
|
* @param str 'key1,key2,...'
|
|
|
|
|
* @returns {object} in the form of {key1:true, key2:true, ...}
|
|
|
|
|
*/
|
|
|
|
|
function makeMap(str){
|
|
|
|
|
var obj = {}, items = str.split(","), i;
|
|
|
|
|
for ( i = 0; i < items.length; i++ )
|
|
|
|
|
obj[ items[i] ] = true;
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-04-07 21:36:41 +00:00
|
|
|
if (msie < 9) {
|
2011-01-06 07:56:57 +00:00
|
|
|
nodeName_ = function(element) {
|
2010-10-19 22:34:58 +00:00
|
|
|
element = element.nodeName ? element : element[0];
|
2011-08-19 00:41:57 +00:00
|
|
|
return (element.scopeName && element.scopeName != 'HTML')
|
|
|
|
|
? uppercase(element.scopeName + ':' + element.nodeName) : element.nodeName;
|
2010-04-21 19:50:05 +00:00
|
|
|
};
|
|
|
|
|
} else {
|
2011-01-06 07:56:57 +00:00
|
|
|
nodeName_ = function(element) {
|
2010-10-19 22:34:58 +00:00
|
|
|
return element.nodeName ? element.nodeName : element[0].nodeName;
|
2010-04-21 19:50:05 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-08 20:43:40 +00:00
|
|
|
|
2010-03-30 03:25:42 +00:00
|
|
|
function map(obj, iterator, context) {
|
|
|
|
|
var results = [];
|
2011-01-08 06:02:23 +00:00
|
|
|
forEach(obj, function(value, index, list) {
|
2010-03-30 03:25:42 +00:00
|
|
|
results.push(iterator.call(context, value, index, list));
|
|
|
|
|
});
|
|
|
|
|
return results;
|
2010-04-04 00:04:36 +00:00
|
|
|
}
|
2010-11-25 01:21:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description
|
2011-08-19 00:41:57 +00:00
|
|
|
* Determines the number of elements in an array, the number of properties an object has, or
|
|
|
|
|
* the length of a string.
|
2010-11-25 01:21:37 +00:00
|
|
|
*
|
2011-08-19 00:41:57 +00:00
|
|
|
* Note: This function is used to augment the Object type in Angular expressions. See
|
|
|
|
|
* {@link angular.Object} for more information about Angular arrays.
|
2010-11-25 01:21:37 +00:00
|
|
|
*
|
2011-08-19 00:41:57 +00:00
|
|
|
* @param {Object|Array|string} obj Object, array, or string to inspect.
|
2011-03-27 22:58:24 +00:00
|
|
|
* @param {boolean} [ownPropsOnly=false] Count only "own" properties in an object
|
2011-09-01 07:06:09 +00:00
|
|
|
* @returns {number} The size of `obj` or `0` if `obj` is neither an object nor an array.
|
2010-11-25 01:21:37 +00:00
|
|
|
*/
|
2011-03-27 22:58:24 +00:00
|
|
|
function size(obj, ownPropsOnly) {
|
2011-01-18 21:50:52 +00:00
|
|
|
var size = 0, key;
|
2011-03-27 23:19:03 +00:00
|
|
|
|
|
|
|
|
if (isArray(obj) || isString(obj)) {
|
|
|
|
|
return obj.length;
|
|
|
|
|
} else if (isObject(obj)){
|
|
|
|
|
for (key in obj)
|
|
|
|
|
if (!ownPropsOnly || obj.hasOwnProperty(key))
|
|
|
|
|
size++;
|
2010-03-30 03:25:42 +00:00
|
|
|
}
|
2011-03-27 23:19:03 +00:00
|
|
|
|
2010-03-30 03:25:42 +00:00
|
|
|
return size;
|
|
|
|
|
}
|
2011-03-27 23:19:03 +00:00
|
|
|
|
|
|
|
|
|
2010-03-26 23:27:18 +00:00
|
|
|
function includes(array, obj) {
|
2012-03-13 17:02:56 +00:00
|
|
|
return indexOf(array, obj) != -1;
|
2010-03-26 23:27:18 +00:00
|
|
|
}
|
2010-03-20 05:18:39 +00:00
|
|
|
|
2010-03-30 03:25:42 +00:00
|
|
|
function indexOf(array, obj) {
|
2012-03-13 17:02:56 +00:00
|
|
|
if (array.indexOf) return array.indexOf(obj);
|
|
|
|
|
|
2010-03-30 03:25:42 +00:00
|
|
|
for ( var i = 0; i < array.length; i++) {
|
|
|
|
|
if (obj === array[i]) return i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-04 04:14:04 +00:00
|
|
|
function arrayRemove(array, value) {
|
2011-11-09 01:40:52 +00:00
|
|
|
var index = indexOf(array, value);
|
|
|
|
|
if (index >=0)
|
|
|
|
|
array.splice(index, 1);
|
|
|
|
|
return value;
|
|
|
|
|
}
|
2011-11-04 04:14:04 +00:00
|
|
|
|
2010-01-12 00:15:12 +00:00
|
|
|
function isLeafNode (node) {
|
2010-03-23 21:57:11 +00:00
|
|
|
if (node) {
|
|
|
|
|
switch (node.nodeName) {
|
|
|
|
|
case "OPTION":
|
|
|
|
|
case "PRE":
|
|
|
|
|
case "TITLE":
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
}
|
2010-03-23 21:57:11 +00:00
|
|
|
return false;
|
2010-01-12 00:15:12 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2011-03-23 16:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.copy
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-08-19 00:41:57 +00:00
|
|
|
* Creates a deep copy of `source`, which should be an object or an array.
|
2010-09-21 16:55:09 +00:00
|
|
|
*
|
2011-08-19 00:41:57 +00:00
|
|
|
* * If no destination is supplied, a copy of the object or array is created.
|
|
|
|
|
* * If a destination is provided, all of its elements (for array) or properties (for objects)
|
|
|
|
|
* are deleted and then all elements/properties from the source are copied to it.
|
|
|
|
|
* * If `source` is not an object or array, `source` is returned.
|
2011-01-18 21:50:52 +00:00
|
|
|
*
|
2011-08-19 00:41:57 +00:00
|
|
|
* Note: this function is used to augment the Object type in Angular expressions. See
|
2012-06-12 06:49:24 +00:00
|
|
|
* {@link ng.$filter} for more information about Angular arrays.
|
2010-09-21 16:55:09 +00:00
|
|
|
*
|
2011-08-19 00:41:57 +00:00
|
|
|
* @param {*} source The source that will be used to make a copy.
|
|
|
|
|
* Can be any type, including primitives, `null`, and `undefined`.
|
|
|
|
|
* @param {(Object|Array)=} destination Destination into which the source is copied. If
|
2011-04-07 19:48:14 +00:00
|
|
|
* provided, must be of the same type as `source`.
|
2011-08-19 00:41:57 +00:00
|
|
|
* @returns {*} The copy or updated `destination`, if `destination` was specified.
|
2010-09-21 16:55:09 +00:00
|
|
|
*/
|
2010-03-15 21:36:50 +00:00
|
|
|
function copy(source, destination){
|
2011-11-30 19:06:04 +00:00
|
|
|
if (isWindow(source) || isScope(source)) throw Error("Can't copy Window or Scope");
|
2010-03-15 21:36:50 +00:00
|
|
|
if (!destination) {
|
2010-10-13 19:47:10 +00:00
|
|
|
destination = source;
|
2010-05-07 19:09:14 +00:00
|
|
|
if (source) {
|
|
|
|
|
if (isArray(source)) {
|
2013-02-12 05:58:00 +00:00
|
|
|
destination = copy(source, []);
|
2010-11-07 06:50:04 +00:00
|
|
|
} else if (isDate(source)) {
|
2010-10-13 19:47:10 +00:00
|
|
|
destination = new Date(source.getTime());
|
2010-05-07 19:09:14 +00:00
|
|
|
} else if (isObject(source)) {
|
2010-10-13 19:47:10 +00:00
|
|
|
destination = copy(source, {});
|
2010-05-07 19:09:14 +00:00
|
|
|
}
|
2010-03-15 21:36:50 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2011-12-19 02:33:25 +00:00
|
|
|
if (source === destination) throw Error("Can't copy equivalent objects or arrays");
|
2010-03-26 23:27:18 +00:00
|
|
|
if (isArray(source)) {
|
2013-02-08 11:55:34 +00:00
|
|
|
destination.length = 0;
|
2010-05-31 03:21:40 +00:00
|
|
|
for ( var i = 0; i < source.length; i++) {
|
|
|
|
|
destination.push(copy(source[i]));
|
|
|
|
|
}
|
2010-03-15 21:36:50 +00:00
|
|
|
} else {
|
2013-04-17 00:09:43 +00:00
|
|
|
var h = destination.$$hashKey;
|
2011-01-08 06:02:23 +00:00
|
|
|
forEach(destination, function(value, key){
|
2010-03-15 21:36:50 +00:00
|
|
|
delete destination[key];
|
|
|
|
|
});
|
2010-05-31 03:21:40 +00:00
|
|
|
for ( var key in source) {
|
|
|
|
|
destination[key] = copy(source[key]);
|
|
|
|
|
}
|
2013-04-17 00:09:43 +00:00
|
|
|
setHashKey(destination,h);
|
2010-03-15 21:36:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-10-13 19:47:10 +00:00
|
|
|
return destination;
|
2010-04-04 00:04:36 +00:00
|
|
|
}
|
2010-03-15 21:36:50 +00:00
|
|
|
|
2011-11-29 20:11:32 +00:00
|
|
|
/**
|
|
|
|
|
* Create a shallow copy of an object
|
|
|
|
|
*/
|
2012-03-28 23:03:59 +00:00
|
|
|
function shallowCopy(src, dst) {
|
|
|
|
|
dst = dst || {};
|
|
|
|
|
|
|
|
|
|
for(var key in src) {
|
|
|
|
|
if (src.hasOwnProperty(key) && key.substr(0, 2) !== '$$') {
|
2011-11-29 20:11:32 +00:00
|
|
|
dst[key] = src[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-28 23:03:59 +00:00
|
|
|
|
2011-11-29 20:11:32 +00:00
|
|
|
return dst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-03-23 16:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.equals
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-08-19 00:41:57 +00:00
|
|
|
* Determines if two objects or two values are equivalent. Supports value types, arrays and
|
|
|
|
|
* objects.
|
2010-11-25 00:55:44 +00:00
|
|
|
*
|
2011-08-19 00:41:57 +00:00
|
|
|
* Two objects or values are considered equivalent if at least one of the following is true:
|
2010-11-25 00:55:44 +00:00
|
|
|
*
|
2011-08-19 00:41:57 +00:00
|
|
|
* * Both objects or values pass `===` comparison.
|
|
|
|
|
* * Both objects or values are of the same type and all of their properties pass `===` comparison.
|
2011-11-16 00:45:36 +00:00
|
|
|
* * Both values are NaN. (In JavasScript, NaN == NaN => false. But we consider two NaN as equal)
|
2010-11-25 00:55:44 +00:00
|
|
|
*
|
2013-03-21 19:09:47 +00:00
|
|
|
* During a property comparison, properties of `function` type and properties with names
|
2011-08-19 00:41:57 +00:00
|
|
|
* that begin with `$` are ignored.
|
|
|
|
|
*
|
2013-04-13 17:29:16 +00:00
|
|
|
* Scope and DOMWindow objects are being compared only by identify (`===`).
|
2010-11-25 01:21:37 +00:00
|
|
|
*
|
2010-11-25 00:55:44 +00:00
|
|
|
* @param {*} o1 Object or value to compare.
|
|
|
|
|
* @param {*} o2 Object or value to compare.
|
|
|
|
|
* @returns {boolean} True if arguments are equal.
|
|
|
|
|
*/
|
2010-07-19 19:29:24 +00:00
|
|
|
function equals(o1, o2) {
|
2011-03-23 16:33:29 +00:00
|
|
|
if (o1 === o2) return true;
|
2011-01-13 15:55:31 +00:00
|
|
|
if (o1 === null || o2 === null) return false;
|
2011-11-16 00:45:36 +00:00
|
|
|
if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN
|
2010-07-19 19:29:24 +00:00
|
|
|
var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
|
2012-01-21 08:01:44 +00:00
|
|
|
if (t1 == t2) {
|
|
|
|
|
if (t1 == 'object') {
|
|
|
|
|
if (isArray(o1)) {
|
|
|
|
|
if ((length = o1.length) == o2.length) {
|
|
|
|
|
for(key=0; key<length; key++) {
|
|
|
|
|
if (!equals(o1[key], o2[key])) return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2010-07-19 19:29:24 +00:00
|
|
|
}
|
2012-02-23 21:57:28 +00:00
|
|
|
} else if (isDate(o1)) {
|
|
|
|
|
return isDate(o2) && o1.getTime() == o2.getTime();
|
2012-01-21 08:01:44 +00:00
|
|
|
} else {
|
|
|
|
|
if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2)) return false;
|
|
|
|
|
keySet = {};
|
|
|
|
|
for(key in o1) {
|
2013-01-22 06:00:15 +00:00
|
|
|
if (key.charAt(0) === '$' || isFunction(o1[key])) continue;
|
|
|
|
|
if (!equals(o1[key], o2[key])) return false;
|
2012-01-21 08:01:44 +00:00
|
|
|
keySet[key] = true;
|
2011-08-19 00:41:57 +00:00
|
|
|
}
|
2012-01-21 08:01:44 +00:00
|
|
|
for(key in o2) {
|
2013-01-22 06:00:15 +00:00
|
|
|
if (!keySet[key] &&
|
|
|
|
|
key.charAt(0) !== '$' &&
|
|
|
|
|
o2[key] !== undefined &&
|
|
|
|
|
!isFunction(o2[key])) return false;
|
2012-01-21 08:01:44 +00:00
|
|
|
}
|
2013-01-22 06:00:15 +00:00
|
|
|
return true;
|
2010-07-19 19:29:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-06 00:36:58 +00:00
|
|
|
|
Introduced injector and $new to scope, and injection into link methods and controllers
- added angular.injector(scope, services, instanceCache) which returns inject
- inject method can return, instance, or call function which have $inject
property
- initialize services with $creation=[eager|eager-publish] this means that
only some of the services are now globally accessible
- upgraded $become on scope to use injector hence respect the $inject property
for injection
- $become should not be run multiple times and will most likely be removed
in future version
- added $new on scope to create a child scope
- $inject is respected on constructor function
- simplified scopes so that they no longer have separate __proto__ for
parent, api, behavior and instance this should speed up execution since
scope will now create one __proto__ chain per scope (not three).
BACKWARD COMPATIBILITY WARNING:
- services now need to have $inject instead of inject property for proper
injection this breaks backward compatibility
- not all services are now published into root scope
(only: $location, $cookie, $window)
- if you have widget/directive which uses services on scope
(such as this.$xhr), you will now have to inject that service in
(as it is not published on the root scope anymore)
2010-10-09 00:30:13 +00:00
|
|
|
function concat(array1, array2, index) {
|
2011-08-02 05:15:33 +00:00
|
|
|
return array1.concat(slice.call(array2, index));
|
Introduced injector and $new to scope, and injection into link methods and controllers
- added angular.injector(scope, services, instanceCache) which returns inject
- inject method can return, instance, or call function which have $inject
property
- initialize services with $creation=[eager|eager-publish] this means that
only some of the services are now globally accessible
- upgraded $become on scope to use injector hence respect the $inject property
for injection
- $become should not be run multiple times and will most likely be removed
in future version
- added $new on scope to create a child scope
- $inject is respected on constructor function
- simplified scopes so that they no longer have separate __proto__ for
parent, api, behavior and instance this should speed up execution since
scope will now create one __proto__ chain per scope (not three).
BACKWARD COMPATIBILITY WARNING:
- services now need to have $inject instead of inject property for proper
injection this breaks backward compatibility
- not all services are now published into root scope
(only: $location, $cookie, $window)
- if you have widget/directive which uses services on scope
(such as this.$xhr), you will now have to inject that service in
(as it is not published on the root scope anymore)
2010-10-09 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-23 16:33:29 +00:00
|
|
|
function sliceArgs(args, startIndex) {
|
2011-08-02 05:15:33 +00:00
|
|
|
return slice.call(args, startIndex || 0);
|
2011-03-23 16:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-25 06:33:40 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.bind
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2011-09-01 07:06:09 +00:00
|
|
|
* Returns a function which calls function `fn` bound to `self` (`self` becomes the `this` for
|
2013-04-11 21:14:20 +00:00
|
|
|
* `fn`). You can supply optional `args` that are prebound to the function. This feature is also
|
2011-09-01 07:06:09 +00:00
|
|
|
* known as [function currying](http://en.wikipedia.org/wiki/Currying).
|
2010-11-25 06:33:40 +00:00
|
|
|
*
|
2011-02-14 18:17:04 +00:00
|
|
|
* @param {Object} self Context which `fn` should be evaluated in.
|
2010-11-25 06:33:40 +00:00
|
|
|
* @param {function()} fn Function to be bound.
|
2010-12-08 00:06:31 +00:00
|
|
|
* @param {...*} args Optional arguments to be prebound to the `fn` function call.
|
2010-11-25 06:33:40 +00:00
|
|
|
* @returns {function()} Function that wraps the `fn` with all the specified bindings.
|
|
|
|
|
*/
|
2010-08-11 18:44:12 +00:00
|
|
|
function bind(self, fn) {
|
2011-03-23 16:33:29 +00:00
|
|
|
var curryArgs = arguments.length > 2 ? sliceArgs(arguments, 2) : [];
|
2011-08-05 23:24:12 +00:00
|
|
|
if (isFunction(fn) && !(fn instanceof RegExp)) {
|
2011-03-23 16:29:20 +00:00
|
|
|
return curryArgs.length
|
|
|
|
|
? function() {
|
|
|
|
|
return arguments.length
|
2011-08-02 05:15:33 +00:00
|
|
|
? fn.apply(self, curryArgs.concat(slice.call(arguments, 0)))
|
2011-03-23 16:29:20 +00:00
|
|
|
: fn.apply(self, curryArgs);
|
|
|
|
|
}
|
|
|
|
|
: function() {
|
|
|
|
|
return arguments.length
|
|
|
|
|
? fn.apply(self, arguments)
|
|
|
|
|
: fn.call(self);
|
|
|
|
|
};
|
2010-07-27 23:53:23 +00:00
|
|
|
} else {
|
2011-09-01 07:06:09 +00:00
|
|
|
// in IE, native methods are not functions so they cannot be bound (note: they don't need to be)
|
2010-08-11 18:44:12 +00:00
|
|
|
return fn;
|
2010-07-27 23:53:23 +00:00
|
|
|
}
|
2010-01-12 00:15:12 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2012-03-28 19:21:07 +00:00
|
|
|
|
|
|
|
|
function toJsonReplacer(key, value) {
|
|
|
|
|
var val = value;
|
|
|
|
|
|
|
|
|
|
if (/^\$+/.test(key)) {
|
|
|
|
|
val = undefined;
|
|
|
|
|
} else if (isWindow(value)) {
|
|
|
|
|
val = '$WINDOW';
|
|
|
|
|
} else if (value && document === value) {
|
|
|
|
|
val = '$DOCUMENT';
|
|
|
|
|
} else if (isScope(value)) {
|
|
|
|
|
val = '$SCOPE';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return val;
|
2012-04-10 21:29:49 +00:00
|
|
|
}
|
2012-03-28 19:21:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.toJson
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Serializes input into a JSON-formatted string.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object|Array|Date|string|number} obj Input to be serialized into JSON.
|
|
|
|
|
* @param {boolean=} pretty If set to true, the JSON output will contain newlines and whitespace.
|
|
|
|
|
* @returns {string} Jsonified string representing `obj`.
|
|
|
|
|
*/
|
|
|
|
|
function toJson(obj, pretty) {
|
|
|
|
|
return JSON.stringify(obj, toJsonReplacer, pretty ? ' ' : null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.fromJson
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Deserializes a JSON string.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} json JSON string to deserialize.
|
|
|
|
|
* @returns {Object|Array|Date|string|number} Deserialized thingy.
|
|
|
|
|
*/
|
|
|
|
|
function fromJson(json) {
|
|
|
|
|
return isString(json)
|
|
|
|
|
? JSON.parse(json)
|
|
|
|
|
: json;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-01-12 00:15:12 +00:00
|
|
|
function toBoolean(value) {
|
2010-03-30 21:55:04 +00:00
|
|
|
if (value && value.length !== 0) {
|
|
|
|
|
var v = lowercase("" + value);
|
2010-07-19 19:29:24 +00:00
|
|
|
value = !(v == 'f' || v == '0' || v == 'false' || v == 'no' || v == 'n' || v == '[]');
|
2010-03-30 21:55:04 +00:00
|
|
|
} else {
|
2010-01-06 00:36:58 +00:00
|
|
|
value = false;
|
2010-03-30 21:55:04 +00:00
|
|
|
}
|
|
|
|
|
return value;
|
2010-01-12 00:15:12 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2011-11-29 20:11:32 +00:00
|
|
|
/**
|
|
|
|
|
* @returns {string} Returns the string representation of the element.
|
|
|
|
|
*/
|
|
|
|
|
function startingTag(element) {
|
|
|
|
|
element = jqLite(element).clone();
|
|
|
|
|
try {
|
|
|
|
|
// turns out IE does not let you set .html() on elements which
|
|
|
|
|
// are not allowed to have children. So we just ignore it.
|
|
|
|
|
element.html('');
|
2012-04-10 21:29:49 +00:00
|
|
|
} catch(e) {}
|
2013-01-19 04:51:17 +00:00
|
|
|
// As Per DOM Standards
|
|
|
|
|
var TEXT_NODE = 3;
|
|
|
|
|
var elemHtml = jqLite('<div>').append(element).html();
|
|
|
|
|
try {
|
|
|
|
|
return element[0].nodeType === TEXT_NODE ? lowercase(elemHtml) :
|
|
|
|
|
elemHtml.
|
|
|
|
|
match(/^(<[^>]+>)/)[1].
|
|
|
|
|
replace(/^<([\w\-]+)/, function(match, nodeName) { return '<' + lowercase(nodeName); });
|
|
|
|
|
} catch(e) {
|
|
|
|
|
return lowercase(elemHtml);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-29 20:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-25 03:14:34 +00:00
|
|
|
|
2010-04-01 00:56:16 +00:00
|
|
|
/////////////////////////////////////////////////
|
|
|
|
|
|
2010-09-27 23:00:05 +00:00
|
|
|
/**
|
|
|
|
|
* Parses an escaped url query string into key-value pairs.
|
2010-10-27 22:31:10 +00:00
|
|
|
* @returns Object.<(string|boolean)>
|
2010-09-27 23:00:05 +00:00
|
|
|
*/
|
|
|
|
|
function parseKeyValue(/**string*/keyValue) {
|
2010-04-01 21:10:28 +00:00
|
|
|
var obj = {}, key_value, key;
|
2011-01-08 06:02:23 +00:00
|
|
|
forEach((keyValue || "").split('&'), function(keyValue){
|
2010-04-01 21:10:28 +00:00
|
|
|
if (keyValue) {
|
|
|
|
|
key_value = keyValue.split('=');
|
2011-09-02 20:28:52 +00:00
|
|
|
key = decodeURIComponent(key_value[0]);
|
|
|
|
|
obj[key] = isDefined(key_value[1]) ? decodeURIComponent(key_value[1]) : true;
|
2010-04-01 21:10:28 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-02 18:10:36 +00:00
|
|
|
function toKeyValue(obj) {
|
|
|
|
|
var parts = [];
|
2011-01-08 06:02:23 +00:00
|
|
|
forEach(obj, function(value, key) {
|
2011-09-02 20:28:52 +00:00
|
|
|
parts.push(encodeUriQuery(key, true) + (value === true ? '' : '=' + encodeUriQuery(value, true)));
|
2010-04-02 18:10:36 +00:00
|
|
|
});
|
|
|
|
|
return parts.length ? parts.join('&') : '';
|
2010-04-04 00:04:36 +00:00
|
|
|
}
|
2010-04-02 18:10:36 +00:00
|
|
|
|
2011-02-17 00:48:21 +00:00
|
|
|
|
|
|
|
|
/**
|
2013-03-21 19:09:47 +00:00
|
|
|
* We need our custom method because encodeURIComponent is too aggressive and doesn't follow
|
2011-04-01 04:45:28 +00:00
|
|
|
* http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
|
|
|
|
|
* segments:
|
|
|
|
|
* segment = *pchar
|
|
|
|
|
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
|
|
|
|
* pct-encoded = "%" HEXDIG HEXDIG
|
|
|
|
|
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
|
|
|
|
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
|
|
|
|
* / "*" / "+" / "," / ";" / "="
|
2011-02-17 00:48:21 +00:00
|
|
|
*/
|
|
|
|
|
function encodeUriSegment(val) {
|
2011-04-01 04:45:28 +00:00
|
|
|
return encodeUriQuery(val, true).
|
|
|
|
|
replace(/%26/gi, '&').
|
|
|
|
|
replace(/%3D/gi, '=').
|
|
|
|
|
replace(/%2B/gi, '+');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This method is intended for encoding *key* or *value* parts of query component. We need a custom
|
2013-03-21 19:09:47 +00:00
|
|
|
* method because encodeURIComponent is too aggressive and encodes stuff that doesn't have to be
|
2011-04-01 04:45:28 +00:00
|
|
|
* encoded per http://tools.ietf.org/html/rfc3986:
|
|
|
|
|
* query = *( pchar / "/" / "?" )
|
|
|
|
|
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
|
|
|
|
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
|
|
|
|
* pct-encoded = "%" HEXDIG HEXDIG
|
|
|
|
|
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
|
|
|
|
* / "*" / "+" / "," / ";" / "="
|
|
|
|
|
*/
|
|
|
|
|
function encodeUriQuery(val, pctEncodeSpaces) {
|
2011-02-17 00:48:21 +00:00
|
|
|
return encodeURIComponent(val).
|
|
|
|
|
replace(/%40/gi, '@').
|
|
|
|
|
replace(/%3A/gi, ':').
|
|
|
|
|
replace(/%24/g, '$').
|
2011-04-01 04:45:28 +00:00
|
|
|
replace(/%2C/gi, ',').
|
2013-02-26 05:25:18 +00:00
|
|
|
replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
|
2011-02-17 00:48:21 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-01 04:45:28 +00:00
|
|
|
|
2010-11-12 23:16:33 +00:00
|
|
|
/**
|
|
|
|
|
* @ngdoc directive
|
2012-06-12 06:49:24 +00:00
|
|
|
* @name ng.directive:ngApp
|
2010-11-12 23:16:33 +00:00
|
|
|
*
|
2012-01-07 02:10:47 +00:00
|
|
|
* @element ANY
|
2012-10-26 14:00:02 +00:00
|
|
|
* @param {angular.Module} ngApp an optional application
|
2012-01-07 02:10:47 +00:00
|
|
|
* {@link angular.module module} name to load.
|
2010-11-18 05:23:23 +00:00
|
|
|
*
|
2010-11-12 23:16:33 +00:00
|
|
|
* @description
|
2010-11-18 05:23:23 +00:00
|
|
|
*
|
2013-04-06 21:29:16 +00:00
|
|
|
* Use this directive to auto-bootstrap an application. Only
|
2012-01-07 02:10:47 +00:00
|
|
|
* one directive can be used per HTML document. The directive
|
|
|
|
|
* designates the root of the application and is typically placed
|
2013-02-02 19:05:00 +00:00
|
|
|
* at the root of the page.
|
2012-01-07 02:10:47 +00:00
|
|
|
*
|
2012-04-06 23:35:17 +00:00
|
|
|
* In the example below if the `ngApp` directive would not be placed
|
2012-01-07 02:10:47 +00:00
|
|
|
* on the `html` element then the document would not be compiled
|
|
|
|
|
* and the `{{ 1+2 }}` would not be resolved to `3`.
|
2011-04-08 23:03:39 +00:00
|
|
|
*
|
2012-04-06 23:35:17 +00:00
|
|
|
* `ngApp` is the easiest way to bootstrap an application.
|
2012-01-07 02:10:47 +00:00
|
|
|
*
|
|
|
|
|
<doc:example>
|
|
|
|
|
<doc:source>
|
|
|
|
|
I can add: 1 + 2 = {{ 1+2 }}
|
|
|
|
|
</doc:source>
|
|
|
|
|
</doc:example>
|
2011-01-19 20:16:38 +00:00
|
|
|
*
|
2010-11-12 23:16:33 +00:00
|
|
|
*/
|
2012-01-07 02:10:47 +00:00
|
|
|
function angularInit(element, bootstrap) {
|
|
|
|
|
var elements = [element],
|
|
|
|
|
appElement,
|
|
|
|
|
module,
|
|
|
|
|
names = ['ng:app', 'ng-app', 'x-ng-app', 'data-ng-app'],
|
|
|
|
|
NG_APP_CLASS_REGEXP = /\sng[:\-]app(:\s*([\w\d_]+);?)?\s/;
|
|
|
|
|
|
|
|
|
|
function append(element) {
|
|
|
|
|
element && elements.push(element);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
forEach(names, function(name) {
|
|
|
|
|
names[name] = true;
|
|
|
|
|
append(document.getElementById(name));
|
|
|
|
|
name = name.replace(':', '\\:');
|
|
|
|
|
if (element.querySelectorAll) {
|
|
|
|
|
forEach(element.querySelectorAll('.' + name), append);
|
|
|
|
|
forEach(element.querySelectorAll('.' + name + '\\:'), append);
|
|
|
|
|
forEach(element.querySelectorAll('[' + name + ']'), append);
|
2012-04-10 21:29:49 +00:00
|
|
|
}
|
2012-01-07 02:10:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
forEach(elements, function(element) {
|
|
|
|
|
if (!appElement) {
|
|
|
|
|
var className = ' ' + element.className + ' ';
|
|
|
|
|
var match = NG_APP_CLASS_REGEXP.exec(className);
|
|
|
|
|
if (match) {
|
|
|
|
|
appElement = element;
|
|
|
|
|
module = (match[2] || '').replace(/\s+/g, ',');
|
|
|
|
|
} else {
|
|
|
|
|
forEach(element.attributes, function(attr) {
|
|
|
|
|
if (!appElement && names[attr.name]) {
|
|
|
|
|
appElement = element;
|
|
|
|
|
module = attr.value;
|
|
|
|
|
}
|
|
|
|
|
});
|
2011-11-02 04:09:54 +00:00
|
|
|
}
|
2012-01-07 02:10:47 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (appElement) {
|
|
|
|
|
bootstrap(appElement, module ? [module] : []);
|
2010-04-01 21:10:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-04-07 17:17:15 +00:00
|
|
|
|
2011-11-11 04:04:15 +00:00
|
|
|
/**
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.bootstrap
|
|
|
|
|
* @description
|
|
|
|
|
* Use this function to manually start up angular application.
|
|
|
|
|
*
|
2012-02-25 00:14:44 +00:00
|
|
|
* See: {@link guide/bootstrap Bootstrap}
|
2011-11-11 04:04:15 +00:00
|
|
|
*
|
|
|
|
|
* @param {Element} element DOM element which is the root of angular application.
|
2012-04-10 20:21:29 +00:00
|
|
|
* @param {Array<String|Function>=} modules an array of module declarations. See: {@link angular.module modules}
|
2012-06-12 06:49:24 +00:00
|
|
|
* @returns {AUTO.$injector} Returns the newly created injector for this app.
|
2011-11-11 04:04:15 +00:00
|
|
|
*/
|
|
|
|
|
function bootstrap(element, modules) {
|
2013-02-21 19:55:16 +00:00
|
|
|
var resumeBootstrapInternal = function() {
|
|
|
|
|
element = jqLite(element);
|
|
|
|
|
modules = modules || [];
|
|
|
|
|
modules.unshift(['$provide', function($provide) {
|
|
|
|
|
$provide.value('$rootElement', element);
|
|
|
|
|
}]);
|
|
|
|
|
modules.unshift('ng');
|
|
|
|
|
var injector = createInjector(modules);
|
2013-04-16 16:53:35 +00:00
|
|
|
injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector', '$animator',
|
|
|
|
|
function(scope, element, compile, injector, animator) {
|
2013-02-21 19:55:16 +00:00
|
|
|
scope.$apply(function() {
|
|
|
|
|
element.data('$injector', injector);
|
|
|
|
|
compile(element)(scope);
|
|
|
|
|
});
|
2013-04-16 16:53:35 +00:00
|
|
|
animator.enabled(true);
|
2013-02-21 19:55:16 +00:00
|
|
|
}]
|
|
|
|
|
);
|
|
|
|
|
return injector;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var NG_DEFER_BOOTSTRAP = /^NG_DEFER_BOOTSTRAP!/;
|
|
|
|
|
|
|
|
|
|
if (window && !NG_DEFER_BOOTSTRAP.test(window.name)) {
|
|
|
|
|
return resumeBootstrapInternal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.name = window.name.replace(NG_DEFER_BOOTSTRAP, '');
|
|
|
|
|
angular.resumeBootstrap = function(extraModules) {
|
|
|
|
|
forEach(extraModules, function(module) {
|
|
|
|
|
modules.push(module);
|
|
|
|
|
});
|
|
|
|
|
resumeBootstrapInternal();
|
|
|
|
|
};
|
2011-11-11 04:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-29 20:11:32 +00:00
|
|
|
var SNAKE_CASE_REGEXP = /[A-Z]/g;
|
|
|
|
|
function snake_case(name, separator){
|
|
|
|
|
separator = separator || '_';
|
|
|
|
|
return name.replace(SNAKE_CASE_REGEXP, function(letter, pos) {
|
|
|
|
|
return (pos ? separator : '') + letter.toLowerCase();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-07 18:27:49 +00:00
|
|
|
function bindJQuery() {
|
2011-02-05 00:42:21 +00:00
|
|
|
// bind to jQuery if present;
|
|
|
|
|
jQuery = window.jQuery;
|
2011-02-07 21:28:42 +00:00
|
|
|
// reset to jQuery or default to us.
|
2011-02-10 19:20:49 +00:00
|
|
|
if (jQuery) {
|
|
|
|
|
jqLite = jQuery;
|
|
|
|
|
extend(jQuery.fn, {
|
2011-07-26 19:06:14 +00:00
|
|
|
scope: JQLitePrototype.scope,
|
2012-03-15 20:40:00 +00:00
|
|
|
controller: JQLitePrototype.controller,
|
2012-01-16 07:26:06 +00:00
|
|
|
injector: JQLitePrototype.injector,
|
2011-07-26 19:06:14 +00:00
|
|
|
inheritedData: JQLitePrototype.inheritedData
|
2011-02-12 18:12:10 +00:00
|
|
|
});
|
2011-07-26 19:06:14 +00:00
|
|
|
JQLitePatchJQueryRemove('remove', true);
|
|
|
|
|
JQLitePatchJQueryRemove('empty');
|
|
|
|
|
JQLitePatchJQueryRemove('html');
|
2011-02-07 21:28:42 +00:00
|
|
|
} else {
|
2012-03-16 05:18:06 +00:00
|
|
|
jqLite = JQLite;
|
2011-02-07 21:28:42 +00:00
|
|
|
}
|
|
|
|
|
angular.element = jqLite;
|
2011-02-05 00:42:21 +00:00
|
|
|
}
|
2011-02-12 18:12:10 +00:00
|
|
|
|
|
|
|
|
/**
|
2013-04-11 21:14:20 +00:00
|
|
|
* throw error if the argument is falsy.
|
2011-02-12 18:12:10 +00:00
|
|
|
*/
|
2011-02-17 00:18:35 +00:00
|
|
|
function assertArg(arg, name, reason) {
|
2011-02-12 18:12:10 +00:00
|
|
|
if (!arg) {
|
2012-04-10 21:29:49 +00:00
|
|
|
throw new Error("Argument '" + (name || '?') + "' is " + (reason || "required"));
|
2011-02-12 18:12:10 +00:00
|
|
|
}
|
2011-09-08 20:56:29 +00:00
|
|
|
return arg;
|
2011-03-29 06:15:28 +00:00
|
|
|
}
|
2011-02-17 00:18:35 +00:00
|
|
|
|
2012-03-26 19:21:42 +00:00
|
|
|
function assertArgFn(arg, name, acceptArrayAnnotation) {
|
|
|
|
|
if (acceptArrayAnnotation && isArray(arg)) {
|
|
|
|
|
arg = arg[arg.length - 1];
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-08 20:56:29 +00:00
|
|
|
assertArg(isFunction(arg), name, 'not a function, got ' +
|
2011-11-23 05:28:39 +00:00
|
|
|
(arg && typeof arg == 'object' ? arg.constructor.name || 'Object' : typeof arg));
|
2011-09-08 20:56:29 +00:00
|
|
|
return arg;
|
2011-03-29 06:15:28 +00:00
|
|
|
}
|