2010-04-01 21:10:28 +00:00
|
|
|
////////////////////////////////////
|
2010-04-01 00:56:16 +00:00
|
|
|
|
2010-08-18 23:23:12 +00:00
|
|
|
if (typeof document.getAttribute == $undefined)
|
2010-01-12 00:15:12 +00:00
|
|
|
document.getAttribute = function() {};
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-11-01 20:44:39 +00:00
|
|
|
/**
|
2010-11-19 00:28:42 +00:00
|
|
|
* @workInProgress
|
2010-11-17 19:34:23 +00:00
|
|
|
* @ngdoc function
|
2010-11-01 20:44:39 +00:00
|
|
|
* @name angular.lowercase
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description Converts string to lowercase
|
2010-11-17 21:09:21 +00:00
|
|
|
* @param {string} string String to be lowercased.
|
2010-10-27 22:31:10 +00:00
|
|
|
* @returns {string} Lowercased string.
|
2010-11-01 20:44:39 +00:00
|
|
|
*/
|
2010-11-17 21:09:21 +00:00
|
|
|
var lowercase = function (string){ return isString(string) ? string.toLowerCase() : string; };
|
2010-11-01 20:44:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-11-19 00:28:42 +00:00
|
|
|
* @workInProgress
|
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
|
|
|
|
|
*
|
|
|
|
|
* @description Converts string to uppercase.
|
2010-11-17 21:09:21 +00:00
|
|
|
* @param {string} string String to be uppercased.
|
2010-10-27 22:31:10 +00:00
|
|
|
* @returns {string} Uppercased string.
|
2010-11-01 20:44:39 +00:00
|
|
|
*/
|
2010-11-17 21:09:21 +00:00
|
|
|
var uppercase = function (string){ return isString(string) ? string.toUpperCase() : string; };
|
2010-11-01 20:44:39 +00:00
|
|
|
|
|
|
|
|
|
2010-10-19 04:20:47 +00:00
|
|
|
var manualLowercase = function (s) {
|
|
|
|
|
return isString(s) ? s.replace(/[A-Z]/g,
|
|
|
|
|
function (ch) {return fromCharCode(ch.charCodeAt(0) | 32); }) : s;
|
|
|
|
|
};
|
|
|
|
|
var manualUppercase = function (s) {
|
|
|
|
|
return isString(s) ? s.replace(/[a-z]/g,
|
|
|
|
|
function (ch) {return fromCharCode(ch.charCodeAt(0) & ~32); }) : s;
|
|
|
|
|
};
|
2010-11-01 20:44:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// String#toLowerCase and String#toUpperCase don't produce correct results in browsers with Turkish
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fromCharCode(code) { return String.fromCharCode(code); }
|
|
|
|
|
|
|
|
|
|
|
2010-08-18 23:23:12 +00:00
|
|
|
var _undefined = undefined,
|
|
|
|
|
_null = null,
|
|
|
|
|
$$element = '$element',
|
2010-12-02 04:29:54 +00:00
|
|
|
$$update = '$update',
|
|
|
|
|
$$scope = '$scope',
|
|
|
|
|
$$validate = '$validate',
|
2010-08-18 23:23:12 +00:00
|
|
|
$angular = 'angular',
|
|
|
|
|
$array = 'array',
|
|
|
|
|
$boolean = 'boolean',
|
|
|
|
|
$console = 'console',
|
|
|
|
|
$date = 'date',
|
|
|
|
|
$display = 'display',
|
|
|
|
|
$element = 'element',
|
|
|
|
|
$function = 'function',
|
|
|
|
|
$length = 'length',
|
|
|
|
|
$name = 'name',
|
|
|
|
|
$none = 'none',
|
|
|
|
|
$noop = 'noop',
|
|
|
|
|
$null = 'null',
|
|
|
|
|
$number = 'number',
|
|
|
|
|
$object = 'object',
|
|
|
|
|
$string = 'string',
|
2010-12-02 04:29:54 +00:00
|
|
|
$value = 'value',
|
|
|
|
|
$selected = 'selected',
|
2010-08-18 23:23:12 +00:00
|
|
|
$undefined = 'undefined',
|
|
|
|
|
NG_EXCEPTION = 'ng-exception',
|
|
|
|
|
NG_VALIDATION_ERROR = 'ng-validation-error',
|
|
|
|
|
NOOP = 'noop',
|
2010-04-04 00:04:36 +00:00
|
|
|
PRIORITY_FIRST = -99999,
|
|
|
|
|
PRIORITY_WATCH = -1000,
|
|
|
|
|
PRIORITY_LAST = 99999,
|
2010-04-12 23:24:28 +00:00
|
|
|
PRIORITY = {'FIRST': PRIORITY_FIRST, 'LAST': PRIORITY_LAST, 'WATCH':PRIORITY_WATCH},
|
2010-11-16 21:57:41 +00:00
|
|
|
Error = window.Error,
|
2010-03-23 21:57:11 +00:00
|
|
|
jQuery = window['jQuery'] || window['$'], // weirdness to make IE happy
|
2010-03-26 23:27:18 +00:00
|
|
|
_ = window['_'],
|
2010-10-16 04:38:41 +00:00
|
|
|
/** holds major version number for IE or NaN for real browsers */
|
|
|
|
|
msie = parseInt((/msie (\d+)/.exec(lowercase(navigator.userAgent)) || [])[1], 10),
|
2010-03-30 03:25:42 +00:00
|
|
|
jqLite = jQuery || jqLiteWrap,
|
2010-03-23 21:57:11 +00:00
|
|
|
slice = Array.prototype.slice,
|
2010-09-22 11:24:40 +00:00
|
|
|
push = Array.prototype.push,
|
2010-08-18 23:23:12 +00:00
|
|
|
error = window[$console] ? bind(window[$console], window[$console]['error'] || noop) : noop,
|
2010-11-01 20:44:39 +00:00
|
|
|
|
2010-08-18 23:23:12 +00:00
|
|
|
angular = window[$angular] || (window[$angular] = {}),
|
2010-07-30 22:19:43 +00:00
|
|
|
angularTextMarkup = extensionMap(angular, 'markup'),
|
2010-03-25 21:43:05 +00:00
|
|
|
angularAttrMarkup = extensionMap(angular, 'attrMarkup'),
|
2010-11-22 20:05:01 +00:00
|
|
|
/** @name angular.directive */
|
2010-03-23 21:57:11 +00:00
|
|
|
angularDirective = extensionMap(angular, 'directive'),
|
2010-11-22 20:05:01 +00:00
|
|
|
/** @name angular.widget */
|
2010-07-20 23:55:32 +00:00
|
|
|
angularWidget = extensionMap(angular, 'widget', lowercase),
|
2010-11-22 20:05:01 +00:00
|
|
|
/** @name angular.validator */
|
2010-03-23 21:57:11 +00:00
|
|
|
angularValidator = extensionMap(angular, 'validator'),
|
2010-11-22 20:05:01 +00:00
|
|
|
/** @name angular.fileter */
|
2010-03-23 21:57:11 +00:00
|
|
|
angularFilter = extensionMap(angular, 'filter'),
|
2010-11-22 20:05:01 +00:00
|
|
|
/** @name angular.formatter */
|
2010-03-23 21:57:11 +00:00
|
|
|
angularFormatter = extensionMap(angular, 'formatter'),
|
2010-11-22 20:05:01 +00:00
|
|
|
/** @name angular.service */
|
2010-04-01 00:56:16 +00:00
|
|
|
angularService = extensionMap(angular, 'service'),
|
2010-04-21 19:50:05 +00:00
|
|
|
angularCallbacks = extensionMap(angular, 'callbacks'),
|
2011-01-06 07:56:57 +00:00
|
|
|
nodeName_,
|
2010-12-22 21:19:26 +00:00
|
|
|
rngScript = /^(|.*\/)angular(-.*?)?(\.min)?.js(\?[^#]*)?(#(.*))?$/,
|
|
|
|
|
DATE_ISOSTRING_LN = 24;
|
2010-04-01 00:56:16 +00:00
|
|
|
|
2010-11-25 05:12:52 +00:00
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.foreach
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Invokes the `iterator` function once for each item in `obj` collection. The collection can either
|
|
|
|
|
* be 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. Optionally, `context` can be specified for the iterator function.
|
|
|
|
|
*
|
|
|
|
|
<pre>
|
|
|
|
|
var values = {name: 'misko', gender: 'male'};
|
|
|
|
|
var log = [];
|
|
|
|
|
angular.foreach(values, function(value, key){
|
|
|
|
|
this.push(key + ': ' + value);
|
|
|
|
|
}, log);
|
|
|
|
|
expect(log).toEqual(['name: misko', 'gender:male']);
|
|
|
|
|
</pre>
|
|
|
|
|
*
|
|
|
|
|
* @param {Object|Array} obj Object to iterate over.
|
|
|
|
|
* @param {function()} iterator Iterator function.
|
|
|
|
|
* @param {Object} context Object to become context (`this`) for the iterator function.
|
|
|
|
|
* @returns {Objet|Array} Reference to `obj`.
|
|
|
|
|
*/
|
2010-03-23 21:57:11 +00:00
|
|
|
function foreach(obj, iterator, context) {
|
|
|
|
|
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) {
|
2010-08-18 23:23:12 +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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-04-17 03:10:09 +00:00
|
|
|
} else if (obj.forEach) {
|
|
|
|
|
obj.forEach(iterator, context);
|
2010-03-30 03:25:42 +00:00
|
|
|
} else if (isObject(obj) && isNumber(obj.length)) {
|
2010-03-23 21:57:11 +00:00
|
|
|
for (key = 0; key < obj.length; key++)
|
|
|
|
|
iterator.call(context, obj[key], key);
|
|
|
|
|
} else {
|
|
|
|
|
for (key in obj)
|
|
|
|
|
iterator.call(context, obj[key], key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-01 00:56:16 +00:00
|
|
|
function foreachSorted(obj, iterator, context) {
|
|
|
|
|
var keys = [];
|
|
|
|
|
for (var key in obj) keys.push(key);
|
|
|
|
|
keys.sort();
|
|
|
|
|
for ( var i = 0; i < keys.length; i++) {
|
|
|
|
|
iterator.call(context, obj[keys[i]], keys[i]);
|
|
|
|
|
}
|
|
|
|
|
return keys;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-11-16 21:57:41 +00:00
|
|
|
function formatError(arg) {
|
|
|
|
|
if (arg instanceof Error) {
|
|
|
|
|
if (arg.stack) {
|
|
|
|
|
arg = arg.stack;
|
|
|
|
|
} else if (arg.sourceURL) {
|
|
|
|
|
arg = arg.message + '\n' + arg.sourceURL + ':' + arg.line;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return arg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-11-25 05:03:56 +00:00
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.extend
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Extends the destination object `dst` by copying all of the properties from the `src` objects to
|
|
|
|
|
* `dst`. You can specify multiple `src` objects.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} dst The destination object.
|
|
|
|
|
* @param {...Object} src The source object(s).
|
|
|
|
|
*/
|
2010-03-30 03:25:42 +00:00
|
|
|
function extend(dst) {
|
|
|
|
|
foreach(arguments, function(obj){
|
|
|
|
|
if (obj !== dst) {
|
|
|
|
|
foreach(obj, function(value, key){
|
|
|
|
|
dst[key] = value;
|
|
|
|
|
});
|
|
|
|
|
}
|
2010-03-23 21:57:11 +00:00
|
|
|
});
|
|
|
|
|
return dst;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 05:03:56 +00:00
|
|
|
|
2010-07-15 20:13:21 +00:00
|
|
|
function inherit(parent, extra) {
|
|
|
|
|
return extend(new (extend(function(){}, {prototype:parent}))(), extra);
|
2010-09-14 21:22:15 +00:00
|
|
|
}
|
2010-07-15 20:13:21 +00:00
|
|
|
|
2010-11-25 02:23:21 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.noop
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Empty function that performs no operation whatsoever. This function is useful when writing code
|
|
|
|
|
* in the functional style.
|
|
|
|
|
<pre>
|
|
|
|
|
function foo(callback) {
|
|
|
|
|
var result = calculateResult();
|
|
|
|
|
(callback || angular.noop)(result);
|
|
|
|
|
}
|
|
|
|
|
</pre>
|
|
|
|
|
*/
|
2010-03-30 03:25:42 +00:00
|
|
|
function noop() {}
|
2010-11-25 02:23:21 +00:00
|
|
|
|
2010-11-25 02:55:34 +00:00
|
|
|
|
2010-11-25 02:23:21 +00:00
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.identity
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* A function that does nothing except for returning its first argument. This function is useful
|
|
|
|
|
* when writing code in the functional style.
|
|
|
|
|
*
|
|
|
|
|
<pre>
|
|
|
|
|
function transformer(transformationFn, value) {
|
|
|
|
|
return (transformationFn || identity)(value);
|
|
|
|
|
};
|
|
|
|
|
</pre>
|
|
|
|
|
*/
|
2010-03-30 03:25:42 +00:00
|
|
|
function identity($) {return $;}
|
2010-11-25 02:55:34 +00:00
|
|
|
|
|
|
|
|
|
2010-10-15 22:28:58 +00:00
|
|
|
function valueFn(value) {return function(){ return value; };}
|
2010-10-30 18:57:13 +00:00
|
|
|
|
2010-07-20 23:55:32 +00:00
|
|
|
function extensionMap(angular, name, transform) {
|
2010-03-30 03:25:42 +00:00
|
|
|
var extPoint;
|
|
|
|
|
return angular[name] || (extPoint = angular[name] = function (name, fn, prop){
|
2010-07-20 23:55:32 +00:00
|
|
|
name = (transform || identity)(name);
|
2010-03-30 03:25:42 +00:00
|
|
|
if (isDefined(fn)) {
|
|
|
|
|
extPoint[name] = extend(fn, prop || {});
|
|
|
|
|
}
|
|
|
|
|
return extPoint[name];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function jqLiteWrap(element) {
|
2010-08-18 23:23:12 +00:00
|
|
|
// for some reasons the parentNode of an orphan looks like _null but its typeof is object.
|
2010-04-26 23:49:34 +00:00
|
|
|
if (element) {
|
|
|
|
|
if (isString(element)) {
|
|
|
|
|
var div = document.createElement('div');
|
|
|
|
|
div.innerHTML = element;
|
|
|
|
|
element = new JQLite(div.childNodes);
|
2011-01-05 01:54:37 +00:00
|
|
|
} else if (!(element instanceof JQLite)) {
|
2010-04-26 23:49:34 +00:00
|
|
|
element = new JQLite(element);
|
|
|
|
|
}
|
2010-03-30 03:25:42 +00:00
|
|
|
}
|
2010-04-12 21:28:15 +00:00
|
|
|
return element;
|
2010-03-30 03:25:42 +00:00
|
|
|
}
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isUndefined
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Checks if a reference is undefined.
|
|
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is undefined.
|
|
|
|
|
*/
|
2010-08-18 23:23:12 +00:00
|
|
|
function isUndefined(value){ return typeof value == $undefined; }
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isDefined
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Checks if a reference is defined.
|
|
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is defined.
|
|
|
|
|
*/
|
2010-08-18 23:23:12 +00:00
|
|
|
function isDefined(value){ return typeof value != $undefined; }
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isObject
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Checks if a reference is an `Object`. Unlike in JavaScript `null`s are not considered to be
|
|
|
|
|
* objects.
|
|
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is an `Object` but not `null`.
|
|
|
|
|
*/
|
2010-09-21 17:20:34 +00:00
|
|
|
function isObject(value){ return value!=_null && typeof value == $object;}
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isString
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Checks if a reference is a `String`.
|
|
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is a `String`.
|
|
|
|
|
*/
|
2010-09-21 17:20:34 +00:00
|
|
|
function isString(value){ return typeof value == $string;}
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isNumber
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Checks if a reference is a `Number`.
|
|
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is a `Number`.
|
|
|
|
|
*/
|
2010-09-21 17:20:34 +00:00
|
|
|
function isNumber(value){ return typeof value == $number;}
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isDate
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
2010-11-22 20:05:01 +00:00
|
|
|
* Checks if 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`.
|
|
|
|
|
*/
|
2010-11-07 06:50:04 +00:00
|
|
|
function isDate(value){ return value instanceof Date; }
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isArray
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Checks if a reference is an `Array`.
|
|
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is an `Array`.
|
|
|
|
|
*/
|
2010-03-23 04:29:57 +00:00
|
|
|
function isArray(value) { return value instanceof Array; }
|
2010-11-25 16:19:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.isFunction
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Checks if a reference is a `Function`.
|
|
|
|
|
*
|
|
|
|
|
* @param {*} value Reference to check.
|
|
|
|
|
* @returns {boolean} True if `value` is a `Function`.
|
|
|
|
|
*/
|
2010-08-18 23:23:12 +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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-05 23:14:44 +00:00
|
|
|
function isBoolean(value) { return typeof value == $boolean;}
|
2011-01-06 07:56:57 +00:00
|
|
|
function isTextNode(node) { return nodeName_(node) == '#text'; }
|
2010-04-04 00:04:36 +00:00
|
|
|
function trim(value) { return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; }
|
2010-04-12 21:28:15 +00:00
|
|
|
function isElement(node) {
|
2010-04-23 00:11:56 +00:00
|
|
|
return node && (node.nodeName || node instanceof JQLite || (jQuery && node instanceof jQuery));
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-19 04:20:47 +00:00
|
|
|
/**
|
|
|
|
|
* HTML class which is the only class which can be used in ng:bind to inline HTML for security reasons.
|
|
|
|
|
* @constructor
|
|
|
|
|
* @param html raw (unsafe) html
|
|
|
|
|
* @param {string=} option if set to 'usafe' then get method will return raw (unsafe/unsanitized) html
|
|
|
|
|
*/
|
|
|
|
|
function HTML(html, option) {
|
2010-04-23 00:11:56 +00:00
|
|
|
this.html = html;
|
2010-10-19 04:20:47 +00:00
|
|
|
this.get = lowercase(option) == 'unsafe' ?
|
|
|
|
|
valueFn(html) :
|
|
|
|
|
function htmlSanitize() {
|
|
|
|
|
var buf = [];
|
|
|
|
|
htmlParser(html, htmlSanitizeWriter(buf));
|
|
|
|
|
return buf.join('');
|
|
|
|
|
};
|
2010-04-12 21:28:15 +00:00
|
|
|
}
|
2010-04-08 20:43:40 +00:00
|
|
|
|
2010-04-21 19:50:05 +00:00
|
|
|
if (msie) {
|
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];
|
2010-04-21 19:50:05 +00:00
|
|
|
return (element.scopeName && element.scopeName != 'HTML' ) ? uppercase(element.scopeName + ':' + element.nodeName) : element.nodeName;
|
|
|
|
|
};
|
|
|
|
|
} 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-10-04 23:08:18 +00:00
|
|
|
function quickClone(element) {
|
|
|
|
|
return jqLite(element[0].cloneNode(true));
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-08 20:43:40 +00:00
|
|
|
function isVisible(element) {
|
2010-04-19 21:36:41 +00:00
|
|
|
var rect = element[0].getBoundingClientRect(),
|
2010-04-19 21:41:36 +00:00
|
|
|
width = (rect.width || (rect.right||0 - rect.left||0)),
|
|
|
|
|
height = (rect.height || (rect.bottom||0 - rect.top||0));
|
2010-04-19 21:36:41 +00:00
|
|
|
return width>0 && height>0;
|
2010-04-08 20:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-30 03:25:42 +00:00
|
|
|
function map(obj, iterator, context) {
|
|
|
|
|
var results = [];
|
|
|
|
|
foreach(obj, function(value, index, list) {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.Object.size
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Determines the number of elements in an array or number of properties of an object.
|
|
|
|
|
*
|
|
|
|
|
* Note: this function is used to augment the Object type in angular expressions. See
|
|
|
|
|
* {@link angular.Object} for more info.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object|Array} obj Object or array to inspect.
|
|
|
|
|
* @returns {number} The size of `obj` or `0` if `obj` is not an object or array.
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* Number of items in array: {{ [1,2].$size() }}<br/>
|
|
|
|
|
* Number of items in object: {{ {a:1, b:2, c:3}.$size() }}<br/>
|
|
|
|
|
*/
|
2010-03-30 03:25:42 +00:00
|
|
|
function size(obj) {
|
|
|
|
|
var size = 0;
|
|
|
|
|
if (obj) {
|
|
|
|
|
if (isNumber(obj.length)) {
|
|
|
|
|
return obj.length;
|
|
|
|
|
} else if (isObject(obj)){
|
|
|
|
|
for (key in obj)
|
|
|
|
|
size++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return size;
|
|
|
|
|
}
|
2010-03-26 23:27:18 +00:00
|
|
|
function includes(array, obj) {
|
|
|
|
|
for ( var i = 0; i < array.length; i++) {
|
|
|
|
|
if (obj === array[i]) return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-03-20 05:18:39 +00:00
|
|
|
|
2010-03-30 03:25:42 +00:00
|
|
|
function indexOf(array, obj) {
|
|
|
|
|
for ( var i = 0; i < array.length; i++) {
|
|
|
|
|
if (obj === array[i]) return i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2010-09-21 16:55:09 +00:00
|
|
|
/**
|
2010-11-25 01:32:04 +00:00
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.Object.copy
|
|
|
|
|
* @function
|
2010-09-21 16:55:09 +00:00
|
|
|
*
|
2010-11-25 01:32:04 +00:00
|
|
|
* @description
|
|
|
|
|
* Creates a deep copy of `source`.
|
2010-09-21 16:55:09 +00:00
|
|
|
*
|
2010-11-25 01:32:04 +00:00
|
|
|
* If `destination` is not provided and `source` is an object or an array, a copy is created &
|
|
|
|
|
* returned, otherwise the `source` is returned.
|
2010-09-21 16:55:09 +00:00
|
|
|
*
|
2010-11-25 01:32:04 +00:00
|
|
|
* If `destination` is provided, all of its properties will be deleted.
|
|
|
|
|
*
|
|
|
|
|
* If `source` is an object or an array, all of its members will be copied into the `destination`
|
|
|
|
|
* object.
|
|
|
|
|
*
|
|
|
|
|
* Note: this function is used to augment the Object type in angular expressions. See
|
|
|
|
|
* {@link angular.Object} for more info.
|
|
|
|
|
*
|
|
|
|
|
* @param {*} source The source to be used to make a copy.
|
|
|
|
|
* Can be any type including primitives, `null` and `undefined`.
|
|
|
|
|
* @param {(Object|Array)=} destination Optional destination into which the source is copied.
|
|
|
|
|
* @returns {*} The copy or updated `destination` if `destination` was specified.
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
Salutation: <input type="text" name="master.salutation" value="Hello" /><br/>
|
|
|
|
|
Name: <input type="text" name="master.name" value="world"/><br/>
|
|
|
|
|
<button ng:click="form = master.$copy()">copy</button>
|
|
|
|
|
<hr/>
|
|
|
|
|
|
|
|
|
|
Master is <span ng:hide="master.$equals(form)">NOT</span> same as form.
|
|
|
|
|
|
|
|
|
|
<pre>master={{master}}</pre>
|
|
|
|
|
<pre>form={{form}}</pre>
|
2010-09-21 16:55:09 +00:00
|
|
|
*/
|
2010-03-15 21:36:50 +00:00
|
|
|
function copy(source, destination){
|
|
|
|
|
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)) {
|
2010-10-13 19:47:10 +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 {
|
2010-03-26 23:27:18 +00:00
|
|
|
if (isArray(source)) {
|
2010-03-15 21:36:50 +00:00
|
|
|
while(destination.length) {
|
|
|
|
|
destination.pop();
|
|
|
|
|
}
|
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 {
|
2010-03-30 03:25:42 +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]);
|
|
|
|
|
}
|
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
|
|
|
|
2010-11-25 00:55:44 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.Object.equals
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Determines if two objects or value are equivalent.
|
|
|
|
|
*
|
|
|
|
|
* To be equivalent, they must pass `==` comparison or be of the same type and have all their
|
|
|
|
|
* properties pass `==` comparison.
|
|
|
|
|
*
|
|
|
|
|
* Supports values types, arrays and objects.
|
|
|
|
|
*
|
|
|
|
|
* For objects `function` properties and properties that start with `$` are not considered during
|
|
|
|
|
* comparisons.
|
|
|
|
|
*
|
2010-11-25 01:21:37 +00:00
|
|
|
* Note: this function is used to augment the Object type in angular expressions. See
|
|
|
|
|
* {@link angular.Object} for more info.
|
|
|
|
|
*
|
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.
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
Salutation: <input type="text" name="master.salutation" value="Hello" /><br/>
|
|
|
|
|
Name: <input type="text" name="master.name" value="world"/><br/>
|
|
|
|
|
<button ng:click="form = master.$copy()">copy</button>
|
|
|
|
|
<hr/>
|
|
|
|
|
|
|
|
|
|
Master is <span ng:hide="master.$equals(form)">NOT</span> same as form.
|
|
|
|
|
|
|
|
|
|
<pre>master={{master}}</pre>
|
|
|
|
|
<pre>form={{form}}</pre>
|
|
|
|
|
*/
|
2010-07-19 19:29:24 +00:00
|
|
|
function equals(o1, o2) {
|
|
|
|
|
if (o1 == o2) return true;
|
|
|
|
|
var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
|
|
|
|
|
if (t1 == t2 && t1 == 'object') {
|
|
|
|
|
if (o1 instanceof Array) {
|
|
|
|
|
if ((length = o1.length) == o2.length) {
|
|
|
|
|
for(key=0; key<length; key++) {
|
|
|
|
|
if (!equals(o1[key], o2[key])) return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
keySet = {};
|
|
|
|
|
for(key in o1) {
|
2010-10-08 23:43:40 +00:00
|
|
|
if (key.charAt(0) !== '$' && !isFunction(o1[key]) && !equals(o1[key], o2[key])) return false;
|
2010-07-19 19:29:24 +00:00
|
|
|
keySet[key] = true;
|
|
|
|
|
}
|
|
|
|
|
for(key in o2) {
|
2010-10-08 23:43:40 +00:00
|
|
|
if (!keySet[key] && key.charAt(0) !== '$' && !isFunction(o2[key])) return false;
|
2010-07-19 19:29:24 +00:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-12 00:15:12 +00:00
|
|
|
function setHtml(node, html) {
|
2010-01-09 23:02:43 +00:00
|
|
|
if (isLeafNode(node)) {
|
|
|
|
|
if (msie) {
|
2010-01-06 00:36:58 +00:00
|
|
|
node.innerText = html;
|
|
|
|
|
} else {
|
|
|
|
|
node.textContent = html;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
node.innerHTML = html;
|
|
|
|
|
}
|
2010-01-12 00:15:12 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-04-05 18:46:53 +00:00
|
|
|
function isRenderableElement(element) {
|
|
|
|
|
var name = element && element[0] && element[0].nodeName;
|
|
|
|
|
return name && name.charAt(0) != '#' &&
|
|
|
|
|
!includes(['TR', 'COL', 'COLGROUP', 'TBODY', 'THEAD', 'TFOOT'], name);
|
|
|
|
|
}
|
2010-03-30 22:39:51 +00:00
|
|
|
function elementError(element, type, error) {
|
2010-04-05 18:46:53 +00:00
|
|
|
while (!isRenderableElement(element)) {
|
|
|
|
|
element = element.parent() || jqLite(document.body);
|
|
|
|
|
}
|
2010-05-30 23:34:59 +00:00
|
|
|
if (element[0]['$NG_ERROR'] !== error) {
|
|
|
|
|
element[0]['$NG_ERROR'] = error;
|
|
|
|
|
if (error) {
|
|
|
|
|
element.addClass(type);
|
|
|
|
|
element.attr(type, error);
|
|
|
|
|
} else {
|
|
|
|
|
element.removeClass(type);
|
|
|
|
|
element.removeAttr(type);
|
|
|
|
|
}
|
2010-03-30 04:36:34 +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) {
|
|
|
|
|
return array1.concat(slice.call(array2, index, array2.length));
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 06:33:40 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.bind
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Returns function which calls function `fn` bound to `self` (`self` becomes the `this` for `fn`).
|
|
|
|
|
* Optional `args` can be supplied which are prebound to the function, also known as
|
|
|
|
|
* [function currying](http://en.wikipedia.org/wiki/Currying).
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} self Context in which `fn` should be evaluated in.
|
|
|
|
|
* @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) {
|
|
|
|
|
var curryArgs = arguments.length > 2 ? slice.call(arguments, 2, arguments.length) : [];
|
2010-08-18 23:23:12 +00:00
|
|
|
if (typeof fn == $function) {
|
2010-08-11 18:44:12 +00:00
|
|
|
return curryArgs.length ? function() {
|
|
|
|
|
return arguments.length ? fn.apply(self, curryArgs.concat(slice.call(arguments, 0, arguments.length))) : fn.apply(self, curryArgs);
|
|
|
|
|
}: function() {
|
|
|
|
|
return arguments.length ? fn.apply(self, arguments) : fn.call(self);
|
|
|
|
|
};
|
2010-07-27 23:53:23 +00:00
|
|
|
} else {
|
2010-11-25 06:33:40 +00:00
|
|
|
// in IE, native methods are not functions and so they can not be bound (but 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
|
|
|
|
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
|
|
|
|
2010-01-12 00:15:12 +00:00
|
|
|
function merge(src, dst) {
|
2010-01-06 00:36:58 +00:00
|
|
|
for ( var key in src) {
|
|
|
|
|
var value = dst[key];
|
|
|
|
|
var type = typeof value;
|
2010-08-18 23:23:12 +00:00
|
|
|
if (type == $undefined) {
|
2010-01-09 23:02:43 +00:00
|
|
|
dst[key] = fromJson(toJson(src[key]));
|
|
|
|
|
} else if (type == 'object' && value.constructor != array &&
|
2010-01-06 00:36:58 +00:00
|
|
|
key.substring(0, 1) != "$") {
|
2010-01-09 23:02:43 +00:00
|
|
|
merge(src[key], value);
|
2010-01-06 00:36:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-01-12 00:15:12 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-11-25 03:14:34 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @workInProgress
|
|
|
|
|
* @ngdoc function
|
|
|
|
|
* @name angular.compile
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Compiles a piece of HTML or DOM into a {@link angular.scope scope} object.
|
|
|
|
|
<pre>
|
|
|
|
|
var scope1 = angular.compile(window.document);
|
|
|
|
|
scope1.$init();
|
|
|
|
|
|
|
|
|
|
var scope2 = angular.compile('<div ng:click="clicked = true">click me</div>');
|
|
|
|
|
scope2.$init();
|
|
|
|
|
</pre>
|
|
|
|
|
*
|
|
|
|
|
* @param {string|DOMElement} element Element to compile.
|
2010-11-25 03:29:45 +00:00
|
|
|
* @param {Object=} parentScope Scope to become the parent scope of the newly compiled scope.
|
2010-11-25 03:14:34 +00:00
|
|
|
* @returns {Object} Compiled scope object.
|
|
|
|
|
*/
|
|
|
|
|
function compile(element, parentScope) {
|
2010-04-09 23:20:15 +00:00
|
|
|
var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget),
|
2010-08-05 21:01:46 +00:00
|
|
|
$element = jqLite(element);
|
2010-11-25 03:14:34 +00:00
|
|
|
return compiler.compile($element)($element, parentScope);
|
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;
|
|
|
|
|
foreach((keyValue || "").split('&'), function(keyValue){
|
|
|
|
|
if (keyValue) {
|
|
|
|
|
key_value = keyValue.split('=');
|
2010-07-30 17:56:36 +00:00
|
|
|
key = unescape(key_value[0]);
|
2010-09-27 23:00:05 +00:00
|
|
|
obj[key] = isDefined(key_value[1]) ? unescape(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 = [];
|
2010-10-16 15:18:41 +00:00
|
|
|
foreach(obj, function(value, key) {
|
|
|
|
|
parts.push(escape(key) + (value === true ? '' : '=' + escape(value)));
|
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
|
|
|
|
2010-11-12 23:16:33 +00:00
|
|
|
/**
|
2010-11-19 00:28:42 +00:00
|
|
|
* @workInProgress
|
2010-11-12 23:16:33 +00:00
|
|
|
* @ngdoc directive
|
|
|
|
|
* @name angular.directive.ng:autobind
|
|
|
|
|
* @element script
|
|
|
|
|
*
|
2010-11-18 05:23:23 +00:00
|
|
|
* @TODO ng:autobind is not a directive!! it should be documented as bootstrap parameter in a
|
|
|
|
|
* separate bootstrap section.
|
|
|
|
|
* @TODO rename to ng:autobind to ng:autoboot
|
|
|
|
|
*
|
2010-11-12 23:16:33 +00:00
|
|
|
* @description
|
2010-11-18 05:23:23 +00:00
|
|
|
* This section explains how to bootstrap your application with angular using either the angular
|
|
|
|
|
* javascript file.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* ## The angular distribution
|
|
|
|
|
* Note that there are two versions of the angular javascript file that you can use:
|
2010-11-12 23:16:33 +00:00
|
|
|
*
|
2010-11-18 05:23:23 +00:00
|
|
|
* * `angular.js` - the development version - this file is unobfuscated, uncompressed, and thus
|
|
|
|
|
* human-readable and useful when developing your angular applications.
|
|
|
|
|
* * `angular.min.js` - the production version - this is a minified and obfuscated version of
|
|
|
|
|
* `angular.js`. You want to use this version when you want to load a smaller but functionally
|
|
|
|
|
* equivalent version of the code in your application. We use the Closure compiler to create this
|
|
|
|
|
* file.
|
2010-11-12 23:16:33 +00:00
|
|
|
*
|
|
|
|
|
*
|
2010-11-18 05:23:23 +00:00
|
|
|
* ## Auto-bootstrap with `ng:autobind`
|
|
|
|
|
* The simplest way to get an <angular/> application up and running is by inserting a script tag in
|
|
|
|
|
* your HTML file that bootstraps the `http://code.angularjs.org/angular-x.x.x.min.js` code and uses
|
|
|
|
|
* the special `ng:autobind` attribute, like in this snippet of HTML:
|
2010-11-12 23:16:33 +00:00
|
|
|
*
|
|
|
|
|
* <pre>
|
|
|
|
|
<!doctype html>
|
|
|
|
|
<html xmlns:ng="http://angularjs.org">
|
|
|
|
|
<head>
|
2010-11-18 05:23:23 +00:00
|
|
|
<script type="text/javascript" src="http://code.angularjs.org/angular-0.9.3.min.js"
|
|
|
|
|
ng:autobind></script>
|
2010-11-12 23:16:33 +00:00
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
Hello {{'world'}}!
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
* </pre>
|
2010-11-18 05:23:23 +00:00
|
|
|
*
|
|
|
|
|
* The `ng:autobind` attribute tells <angular/> to compile and manage the whole HTML document. The
|
|
|
|
|
* compilation occurs in the page's `onLoad` handler. Note that you don't need to explicitly add an
|
2010-11-12 23:16:33 +00:00
|
|
|
* `onLoad` event; auto bind mode takes care of all the magic for you.
|
2010-11-18 05:23:23 +00:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* ## Auto-bootstrap with `#autobind`
|
|
|
|
|
* In rare cases when you can't define the `ng` namespace before the script tag (e.g. in some CMS
|
|
|
|
|
* systems, etc), it is possible to auto-bootstrap angular by appending `#autobind` to the script
|
|
|
|
|
* src URL, like in this snippet:
|
|
|
|
|
*
|
|
|
|
|
* <pre>
|
|
|
|
|
<!doctype html>
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
|
|
|
|
<script type="text/javascript"
|
|
|
|
|
src="http://code.angularjs.org/angular-0.9.3.min.js#autobind"></script>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div xmlns:ng="http://angularjs.org">
|
|
|
|
|
Hello {{'world'}}!
|
|
|
|
|
</div>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* In this case it's the `#autobind` URL fragment that tells angular to auto-bootstrap.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* ## Filename Restrictions for Auto-bootstrap
|
|
|
|
|
* In order for us to find the auto-bootstrap script attribute or URL fragment, the value of the
|
|
|
|
|
* `script` `src` attribute that loads angular script must match one of these naming
|
|
|
|
|
* conventions:
|
|
|
|
|
*
|
|
|
|
|
* - `angular.js`
|
|
|
|
|
* - `angular-min.js`
|
|
|
|
|
* - `angular-x.x.x.js`
|
|
|
|
|
* - `angular-x.x.x.min.js`
|
|
|
|
|
* - `angular-x.x.x-xxxxxxxx.js` (dev snapshot)
|
|
|
|
|
* - `angular-x.x.x-xxxxxxxx.min.js` (dev snapshot)
|
|
|
|
|
* - `angular-bootstrap.js` (used for development of angular)
|
|
|
|
|
*
|
|
|
|
|
* Optionally, any of the filename format above can be prepended with relative or absolute URL that
|
|
|
|
|
* ends with `/`.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* ## Manual Bootstrap
|
|
|
|
|
* Using auto-bootstrap is a handy way to start using <angular/>, but advanced users who want more
|
|
|
|
|
* control over the initialization process might prefer to use manual bootstrap instead.
|
2010-11-12 23:16:33 +00:00
|
|
|
*
|
2010-11-18 05:23:23 +00:00
|
|
|
* The best way to get started with manual bootstraping is to look at the magic behind `ng:autobind`
|
|
|
|
|
* by writing out each step of the autobind process explicitly. Note that the following code is
|
|
|
|
|
* equivalent to the code in the previous section.
|
2010-11-12 23:16:33 +00:00
|
|
|
*
|
|
|
|
|
* <pre>
|
|
|
|
|
<!doctype html>
|
|
|
|
|
<html xmlns:ng="http://angularjs.org">
|
|
|
|
|
<head>
|
2010-11-18 05:23:23 +00:00
|
|
|
<script type="text/javascript" src="http://code.angularjs.org/angular-0.9.3.min.js"
|
|
|
|
|
ng:autobind></script>
|
2010-11-12 23:16:33 +00:00
|
|
|
<script type="text/javascript">
|
|
|
|
|
(function(window, previousOnLoad){
|
|
|
|
|
window.onload = function(){
|
|
|
|
|
try { (previousOnLoad||angular.noop)(); } catch(e) {}
|
|
|
|
|
angular.compile(window.document).$init();
|
|
|
|
|
};
|
|
|
|
|
})(window, window.onload);
|
|
|
|
|
</script>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
Hello {{'World'}}!
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
2010-11-18 05:23:23 +00:00
|
|
|
* This is the sequence that your code should follow if you're bootstrapping angular on your own:
|
2010-11-12 23:16:33 +00:00
|
|
|
*
|
2010-11-18 05:23:23 +00:00
|
|
|
* * After the page is loaded, find the root of the HTML template, which is typically the root of
|
|
|
|
|
* the document.
|
|
|
|
|
* * Run the HTML compiler, which converts the templates into an executable, bi-directionally bound
|
|
|
|
|
* application.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* ##XML Namespace
|
|
|
|
|
* *IMPORTANT:* When using <angular/> you must declare the ng namespace using the xmlns tag. If you
|
|
|
|
|
* don't declare the namespace, Internet Explorer does not render widgets properly.
|
2010-11-12 23:16:33 +00:00
|
|
|
*
|
|
|
|
|
* <pre>
|
|
|
|
|
* <html xmlns:ng="http://angularjs.org">
|
|
|
|
|
* </pre>
|
2010-11-18 05:23:23 +00:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* ## Create your own namespace
|
|
|
|
|
* If you want to define your own widgets, you must create your own namespace and use that namespace
|
|
|
|
|
* to form the fully qualified widget name. For example, you could map the alias `my` to your domain
|
|
|
|
|
* and create a widget called my:widget. To create your own namespace, simply add another xmlsn tag
|
|
|
|
|
* to your page, create an alias, and set it to your unique domain:
|
2010-11-12 23:16:33 +00:00
|
|
|
*
|
|
|
|
|
* <pre>
|
|
|
|
|
* <html xmlns:ng="http://angularjs.org" xmlns:my="http://mydomain.com">
|
|
|
|
|
* </pre>
|
2010-11-18 05:23:23 +00:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* ## Global Object
|
|
|
|
|
* The <angular/> script creates a single global variable `angular` in the global namespace. All
|
|
|
|
|
* APIs are bound to fields of this global object.
|
2010-11-12 23:16:33 +00:00
|
|
|
*
|
|
|
|
|
*/
|
2010-04-01 21:10:28 +00:00
|
|
|
function angularInit(config){
|
|
|
|
|
if (config.autobind) {
|
2010-05-12 22:25:16 +00:00
|
|
|
// TODO default to the source of angular.js
|
2010-10-16 04:38:41 +00:00
|
|
|
var scope = compile(window.document, _null, {'$config':config}),
|
2011-01-04 19:53:23 +00:00
|
|
|
$browser = scope.$service('$browser');
|
2010-10-16 04:38:41 +00:00
|
|
|
|
2010-07-29 22:26:10 +00:00
|
|
|
if (config.css)
|
2010-10-16 04:38:41 +00:00
|
|
|
$browser.addCss(config.base_url + config.css);
|
|
|
|
|
else if(msie<8)
|
|
|
|
|
$browser.addJs(config.base_url + config.ie_compat, config.ie_compat_id);
|
|
|
|
|
|
2010-04-06 03:53:33 +00:00
|
|
|
scope.$init();
|
2010-04-01 21:10:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-04-07 17:17:15 +00:00
|
|
|
|
2010-07-29 22:26:10 +00:00
|
|
|
function angularJsConfig(document, config) {
|
2010-10-20 00:07:20 +00:00
|
|
|
var scripts = document.getElementsByTagName("script"),
|
2010-04-07 17:17:15 +00:00
|
|
|
match;
|
2010-07-29 22:26:10 +00:00
|
|
|
config = extend({
|
2010-10-16 04:38:41 +00:00
|
|
|
ie_compat_id: 'ng-ie-compat'
|
2010-07-29 22:26:10 +00:00
|
|
|
}, config);
|
2010-04-07 17:17:15 +00:00
|
|
|
for(var j = 0; j < scripts.length; j++) {
|
2010-10-20 00:07:20 +00:00
|
|
|
match = (scripts[j].src || "").match(rngScript);
|
2010-04-07 17:17:15 +00:00
|
|
|
if (match) {
|
2010-10-16 04:38:41 +00:00
|
|
|
config.base_url = match[1];
|
2010-10-20 04:53:16 +00:00
|
|
|
config.ie_compat = match[1] + 'angular-ie-compat' + (match[2] || '') + '.js';
|
2010-09-15 17:19:11 +00:00
|
|
|
extend(config, parseKeyValue(match[6]));
|
2010-07-29 22:26:10 +00:00
|
|
|
eachAttribute(jqLite(scripts[j]), function(value, name){
|
|
|
|
|
if (/^ng:/.exec(name)) {
|
|
|
|
|
name = name.substring(3).replace(/-/g, '_');
|
|
|
|
|
if (name == 'autobind') value = true;
|
|
|
|
|
config[name] = value;
|
|
|
|
|
}
|
|
|
|
|
});
|
2010-04-07 17:17:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-07-29 22:26:10 +00:00
|
|
|
return config;
|
2010-04-07 17:17:15 +00:00
|
|
|
}
|