summaryrefslogtreecommitdiff
path: root/xstatic/pkg/angular/data/angular.js
diff options
context:
space:
mode:
Diffstat (limited to 'xstatic/pkg/angular/data/angular.js')
-rw-r--r--xstatic/pkg/angular/data/angular.js6389
1 files changed, 3861 insertions, 2528 deletions
diff --git a/xstatic/pkg/angular/data/angular.js b/xstatic/pkg/angular/data/angular.js
index d93e858..2f26bee 100644
--- a/xstatic/pkg/angular/data/angular.js
+++ b/xstatic/pkg/angular/data/angular.js
@@ -1,6 +1,6 @@
/**
- * @license AngularJS v1.2.1
- * (c) 2010-2012 Google, Inc. http://angularjs.org
+ * @license AngularJS v1.2.16
+ * (c) 2010-2014 Google, Inc. http://angularjs.org
* License: MIT
*/
(function(window, document, undefined) {'use strict';
@@ -30,7 +30,7 @@
* should all be static strings, not variables or general expressions.
*
* @param {string} module The namespace to use for the new minErr instance.
- * @returns {function(string, string, ...): Error} instance
+ * @returns {function(code:string, template:string, ...templateArgs): Error} minErr instance
*/
function minErr(module) {
@@ -68,7 +68,7 @@ function minErr(module) {
return match;
});
- message = message + '\nhttp://errors.angularjs.org/1.2.1/' +
+ message = message + '\nhttp://errors.angularjs.org/1.2.16/' +
(module ? module + '/' : '') + code;
for (i = 2; i < arguments.length; i++) {
message = message + (i == 2 ? '?' : '&') + 'p' + (i-2) + '=' +
@@ -124,6 +124,7 @@ function minErr(module) {
-isWindow,
-isScope,
-isFile,
+ -isBlob,
-isBoolean,
-trim,
-isElement,
@@ -159,15 +160,32 @@ function minErr(module) {
-assertArgFn,
-assertNotHasOwnProperty,
-getter,
- -getBlockElements
+ -getBlockElements,
+ -hasOwnProperty,
*/
////////////////////////////////////
/**
+ * @ngdoc module
+ * @name ng
+ * @module ng
+ * @description
+ *
+ * # ng (core module)
+ * The ng module is loaded by default when an AngularJS application is started. The module itself
+ * contains the essential components for an AngularJS application to function. The table below
+ * lists a high level breakdown of each of the services/factories, filters, directives and testing
+ * components available within this core module.
+ *
+ * <div doc-module-components="ng"></div>
+ */
+
+/**
* @ngdoc function
* @name angular.lowercase
+ * @module ng
* @function
*
* @description Converts the specified string to lowercase.
@@ -175,11 +193,12 @@ function minErr(module) {
* @returns {string} Lowercased string.
*/
var lowercase = function(string){return isString(string) ? string.toLowerCase() : string;};
-
+var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* @ngdoc function
* @name angular.uppercase
+ * @module ng
* @function
*
* @description Converts the specified string to uppercase.
@@ -263,6 +282,7 @@ function isArrayLike(obj) {
/**
* @ngdoc function
* @name angular.forEach
+ * @module ng
* @function
*
* @description
@@ -271,16 +291,17 @@ function isArrayLike(obj) {
* 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.
*
- * Note: this function was previously known as `angular.foreach`.
+ * It is worth noting that `.forEach` does not iterate over inherited properties because it filters
+ * using the `hasOwnProperty` method.
*
- <pre>
+ ```js
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>
+ expect(log).toEqual(['name: misko', 'gender: male']);
+ ```
*
* @param {Object|Array} obj Object to iterate over.
* @param {Function} iterator Iterator function.
@@ -292,7 +313,9 @@ function forEach(obj, iterator, context) {
if (obj) {
if (isFunction(obj)){
for (key in obj) {
- if (key != 'prototype' && key != 'length' && key != 'name' && obj.hasOwnProperty(key)) {
+ // Need to check if hasOwnProperty exists,
+ // as on IE8 the result of querySelectorAll is an object without a hasOwnProperty function
+ if (key != 'prototype' && key != 'length' && key != 'name' && (!obj.hasOwnProperty || obj.hasOwnProperty(key))) {
iterator.call(context, obj[key], key);
}
}
@@ -346,7 +369,7 @@ function reverseParams(iteratorFn) {
* the number string gets longer over time, and it can also overflow, where as the nextId
* will grow much slower, it is a string, and it will never overflow.
*
- * @returns an unique alpha-numeric string
+ * @returns {string} an unique alpha-numeric string
*/
function nextUid() {
var index = uid.length;
@@ -388,6 +411,7 @@ function setHashKey(obj, h) {
/**
* @ngdoc function
* @name angular.extend
+ * @module ng
* @function
*
* @description
@@ -424,17 +448,18 @@ function inherit(parent, extra) {
/**
* @ngdoc function
* @name angular.noop
+ * @module ng
* @function
*
* @description
* A function that performs no operations. This function can be useful when writing code in the
* functional style.
- <pre>
+ ```js
function foo(callback) {
var result = calculateResult();
(callback || angular.noop)(result);
}
- </pre>
+ ```
*/
function noop() {}
noop.$inject = [];
@@ -443,17 +468,18 @@ noop.$inject = [];
/**
* @ngdoc function
* @name angular.identity
+ * @module ng
* @function
*
* @description
* A function that returns its first argument. This function is useful when writing code in the
* functional style.
*
- <pre>
+ ```js
function transformer(transformationFn, value) {
return (transformationFn || angular.identity)(value);
};
- </pre>
+ ```
*/
function identity($) {return $;}
identity.$inject = [];
@@ -464,6 +490,7 @@ function valueFn(value) {return function() {return value;};}
/**
* @ngdoc function
* @name angular.isUndefined
+ * @module ng
* @function
*
* @description
@@ -472,12 +499,13 @@ function valueFn(value) {return function() {return value;};}
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is undefined.
*/
-function isUndefined(value){return typeof value == 'undefined';}
+function isUndefined(value){return typeof value === 'undefined';}
/**
* @ngdoc function
* @name angular.isDefined
+ * @module ng
* @function
*
* @description
@@ -486,27 +514,29 @@ function isUndefined(value){return typeof value == 'undefined';}
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is defined.
*/
-function isDefined(value){return typeof value != 'undefined';}
+function isDefined(value){return typeof value !== 'undefined';}
/**
* @ngdoc function
* @name angular.isObject
+ * @module ng
* @function
*
* @description
* Determines if a reference is an `Object`. Unlike `typeof` in JavaScript, `null`s are not
- * considered to be objects.
+ * considered to be objects. Note that JavaScript arrays are objects.
*
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is an `Object` but not `null`.
*/
-function isObject(value){return value != null && typeof value == 'object';}
+function isObject(value){return value != null && typeof value === 'object';}
/**
* @ngdoc function
* @name angular.isString
+ * @module ng
* @function
*
* @description
@@ -515,12 +545,13 @@ function isObject(value){return value != null && typeof value == 'object';}
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is a `String`.
*/
-function isString(value){return typeof value == 'string';}
+function isString(value){return typeof value === 'string';}
/**
* @ngdoc function
* @name angular.isNumber
+ * @module ng
* @function
*
* @description
@@ -529,12 +560,13 @@ function isString(value){return typeof value == 'string';}
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is a `Number`.
*/
-function isNumber(value){return typeof value == 'number';}
+function isNumber(value){return typeof value === 'number';}
/**
* @ngdoc function
* @name angular.isDate
+ * @module ng
* @function
*
* @description
@@ -544,13 +576,14 @@ function isNumber(value){return typeof value == 'number';}
* @returns {boolean} True if `value` is a `Date`.
*/
function isDate(value){
- return toString.apply(value) == '[object Date]';
+ return toString.call(value) === '[object Date]';
}
/**
* @ngdoc function
* @name angular.isArray
+ * @module ng
* @function
*
* @description
@@ -560,13 +593,14 @@ function isDate(value){
* @returns {boolean} True if `value` is an `Array`.
*/
function isArray(value) {
- return toString.apply(value) == '[object Array]';
+ return toString.call(value) === '[object Array]';
}
/**
* @ngdoc function
* @name angular.isFunction
+ * @module ng
* @function
*
* @description
@@ -575,7 +609,7 @@ function isArray(value) {
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is a `Function`.
*/
-function isFunction(value){return typeof value == 'function';}
+function isFunction(value){return typeof value === 'function';}
/**
@@ -586,7 +620,7 @@ function isFunction(value){return typeof value == 'function';}
* @returns {boolean} True if `value` is a `RegExp`.
*/
function isRegExp(value) {
- return toString.apply(value) == '[object RegExp]';
+ return toString.call(value) === '[object RegExp]';
}
@@ -608,12 +642,17 @@ function isScope(obj) {
function isFile(obj) {
- return toString.apply(obj) === '[object File]';
+ return toString.call(obj) === '[object File]';
+}
+
+
+function isBlob(obj) {
+ return toString.call(obj) === '[object Blob]';
}
function isBoolean(value) {
- return typeof value == 'boolean';
+ return typeof value === 'boolean';
}
@@ -623,7 +662,7 @@ var trim = (function() {
// TODO: we should move this into IE/ES5 polyfill
if (!String.prototype.trim) {
return function(value) {
- return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value;
+ return isString(value) ? value.replace(/^\s\s*/, '').replace(/\s\s*$/, '') : value;
};
}
return function(value) {
@@ -635,6 +674,7 @@ var trim = (function() {
/**
* @ngdoc function
* @name angular.isElement
+ * @module ng
* @function
*
* @description
@@ -644,9 +684,9 @@ var trim = (function() {
* @returns {boolean} True if `value` is a DOM element (or wrapped jQuery element).
*/
function isElement(node) {
- return node &&
+ return !!(node &&
(node.nodeName // we are a direct element
- || (node.on && node.find)); // we have an on and find method part of jQuery API
+ || (node.prop && node.attr && node.find))); // we have an on and find method part of jQuery API
}
/**
@@ -717,7 +757,7 @@ function includes(array, obj) {
function indexOf(array, obj) {
if (array.indexOf) return array.indexOf(obj);
- for ( var i = 0; i < array.length; i++) {
+ for (var i = 0; i < array.length; i++) {
if (obj === array[i]) return i;
}
return -1;
@@ -745,6 +785,7 @@ function isLeafNode (node) {
/**
* @ngdoc function
* @name angular.copy
+ * @module ng
* @function
*
* @description
@@ -763,8 +804,8 @@ function isLeafNode (node) {
* @returns {*} The copy or updated `destination`, if `destination` was specified.
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<div ng-controller="Controller">
<form novalidate class="simple-form">
Name: <input type="text" ng-model="user.name" /><br />
@@ -795,8 +836,8 @@ function isLeafNode (node) {
$scope.reset();
}
</script>
- </doc:source>
- </doc:example>
+ </file>
+ </example>
*/
function copy(source, destination){
if (isWindow(source) || isScope(source)) {
@@ -847,8 +888,8 @@ function shallowCopy(src, dst) {
for(var key in src) {
// shallowCopy is only ever called by $compile nodeLinkFn, which has control over src
- // so we don't need to worry hasOwnProperty here
- if (src.hasOwnProperty(key) && key.substr(0, 2) !== '$$') {
+ // so we don't need to worry about using our custom hasOwnProperty here
+ if (src.hasOwnProperty(key) && !(key.charAt(0) === '$' && key.charAt(1) === '$')) {
dst[key] = src[key];
}
}
@@ -860,6 +901,7 @@ function shallowCopy(src, dst) {
/**
* @ngdoc function
* @name angular.equals
+ * @module ng
* @function
*
* @description
@@ -946,6 +988,7 @@ function sliceArgs(args, startIndex) {
/**
* @ngdoc function
* @name angular.bind
+ * @module ng
* @function
*
* @description
@@ -1001,6 +1044,7 @@ function toJsonReplacer(key, value) {
/**
* @ngdoc function
* @name angular.toJson
+ * @module ng
* @function
*
* @description
@@ -1020,13 +1064,14 @@ function toJson(obj, pretty) {
/**
* @ngdoc function
* @name angular.fromJson
+ * @module ng
* @function
*
* @description
* Deserializes a JSON string.
*
* @param {string} json JSON string to deserialize.
- * @returns {Object|Array|Date|string|number} Deserialized thingy.
+ * @returns {Object|Array|string|number} Deserialized thingy.
*/
function fromJson(json) {
return isString(json)
@@ -1036,7 +1081,9 @@ function fromJson(json) {
function toBoolean(value) {
- if (value && value.length !== 0) {
+ if (typeof value === 'function') {
+ value = true;
+ } else if (value && value.length !== 0) {
var v = lowercase("" + value);
value = !(v == 'f' || v == '0' || v == 'false' || v == 'no' || v == 'n' || v == '[]');
} else {
@@ -1053,7 +1100,7 @@ function startingTag(element) {
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('');
+ element.empty();
} catch(e) {}
// As Per DOM Standards
var TEXT_NODE = 3;
@@ -1091,7 +1138,7 @@ function tryDecodeURIComponent(value) {
/**
* Parses an escaped url query string into key-value pairs.
- * @returns Object.<(string|boolean)>
+ * @returns {Object.<string,boolean|Array>}
*/
function parseKeyValue(/**string*/keyValue) {
var obj = {}, key_value, key;
@@ -1173,7 +1220,8 @@ function encodeUriQuery(val, pctEncodeSpaces) {
/**
* @ngdoc directive
- * @name ng.directive:ngApp
+ * @name ngApp
+ * @module ng
*
* @element ANY
* @param {angular.Module} ngApp an optional application
@@ -1181,26 +1229,39 @@ function encodeUriQuery(val, pctEncodeSpaces) {
*
* @description
*
- * Use this directive to auto-bootstrap an application. Only
- * one ngApp directive can be used per HTML document. The directive
- * designates the root of the application and is typically placed
- * at the root of the page.
+ * Use this directive to **auto-bootstrap** an AngularJS application. The `ngApp` directive
+ * designates the **root element** of the application and is typically placed near the root element
+ * of the page - e.g. on the `<body>` or `<html>` tags.
*
- * The first ngApp found in the document will be auto-bootstrapped. To use multiple applications in
- * an HTML document you must manually bootstrap them using {@link angular.bootstrap}.
- * Applications cannot be nested.
+ * Only one AngularJS application can be auto-bootstrapped per HTML document. The first `ngApp`
+ * found in the document will be used to define the root element to auto-bootstrap as an
+ * application. To run multiple applications in an HTML document you must manually bootstrap them using
+ * {@link angular.bootstrap} instead. AngularJS applications cannot be nested within each other.
*
- * In the example below if the `ngApp` directive were not placed
- * on the `html` element then the document would not be compiled
- * and the `{{ 1+2 }}` would not be resolved to `3`.
+ * You can specify an **AngularJS module** to be used as the root module for the application. This
+ * module will be loaded into the {@link auto.$injector} when the application is bootstrapped and
+ * should contain the application code needed or have dependencies on other modules that will
+ * contain the code. See {@link angular.module} for more information.
*
- * `ngApp` is the easiest way to bootstrap an application.
+ * In the example below if the `ngApp` directive were not placed on the `html` element then the
+ * document would not be compiled, the `AppController` would not be instantiated and the `{{ a+b }}`
+ * would not be resolved to `3`.
*
- <doc:example>
- <doc:source>
- I can add: 1 + 2 = {{ 1+2 }}
- </doc:source>
- </doc:example>
+ * `ngApp` is the easiest, and most common, way to bootstrap an application.
+ *
+ <example module="ngAppDemo">
+ <file name="index.html">
+ <div ng-controller="ngAppDemoController">
+ I can add: {{a}} + {{b}} = {{ a+b }}
+ </div>
+ </file>
+ <file name="script.js">
+ angular.module('ngAppDemo', []).controller('ngAppDemoController', function($scope) {
+ $scope.a = 1;
+ $scope.b = 2;
+ });
+ </file>
+ </example>
*
*/
function angularInit(element, bootstrap) {
@@ -1250,20 +1311,56 @@ function angularInit(element, bootstrap) {
/**
* @ngdoc function
* @name angular.bootstrap
+ * @module ng
* @description
* Use this function to manually start up angular application.
*
* See: {@link guide/bootstrap Bootstrap}
*
* Note that ngScenario-based end-to-end tests cannot use this function to bootstrap manually.
- * They must use {@link api/ng.directive:ngApp ngApp}.
+ * They must use {@link ng.directive:ngApp ngApp}.
+ *
+ * Angular will detect if it has been loaded into the browser more than once and only allow the
+ * first loaded script to be bootstrapped and will report a warning to the browser console for
+ * each of the subsequent scripts. This prevents strange results in applications, where otherwise
+ * multiple instances of Angular try to work on the DOM.
+ *
+ * <example name="multi-bootstrap" module="multi-bootstrap">
+ * <file name="index.html">
+ * <script src="../../../angular.js"></script>
+ * <div ng-controller="BrokenTable">
+ * <table>
+ * <tr>
+ * <th ng-repeat="heading in headings">{{heading}}</th>
+ * </tr>
+ * <tr ng-repeat="filling in fillings">
+ * <td ng-repeat="fill in filling">{{fill}}</td>
+ * </tr>
+ * </table>
+ * </div>
+ * </file>
+ * <file name="controller.js">
+ * var app = angular.module('multi-bootstrap', [])
+ *
+ * .controller('BrokenTable', function($scope) {
+ * $scope.headings = ['One', 'Two', 'Three'];
+ * $scope.fillings = [[1, 2, 3], ['A', 'B', 'C'], [7, 8, 9]];
+ * });
+ * </file>
+ * <file name="protractor.js" type="protractor">
+ * it('should only insert one table cell for each item in $scope.fillings', function() {
+ * expect(element.all(by.css('td')).count())
+ * .toBe(9);
+ * });
+ * </file>
+ * </example>
*
- * @param {Element} element DOM element which is the root of angular application.
+ * @param {DOMElement} element DOM element which is the root of angular application.
* @param {Array<String|Function|Array>=} modules an array of modules to load into the application.
* Each item in the array should be the name of a predefined module or a (DI annotated)
* function that will be invoked by the injector as a run block.
* See: {@link angular.module modules}
- * @returns {AUTO.$injector} Returns the newly created injector for this app.
+ * @returns {auto.$injector} Returns the newly created injector for this app.
*/
function bootstrap(element, modules) {
var doBootstrap = function() {
@@ -1372,9 +1469,9 @@ function assertNotHasOwnProperty(name, context) {
/**
* Return the value accessible from the object by path. Any undefined traversals are ignored
* @param {Object} obj starting object
- * @param {string} path path to traverse
- * @param {boolean=true} bindFnToScope
- * @returns value as accessible by path
+ * @param {String} path path to traverse
+ * @param {boolean} [bindFnToScope=true]
+ * @returns {Object} value as accessible by path
*/
//TODO(misko): this function needs to be removed
function getter(obj, path, bindFnToScope) {
@@ -1397,30 +1494,33 @@ function getter(obj, path, bindFnToScope) {
}
/**
- * Return the siblings between `startNode` and `endNode`, inclusive
- * @param {Object} object with `startNode` and `endNode` properties
- * @returns jQlite object containing the elements
+ * Return the DOM siblings between the first and last node in the given array.
+ * @param {Array} array like object
+ * @returns {DOMElement} object containing the elements
*/
-function getBlockElements(block) {
- if (block.startNode === block.endNode) {
- return jqLite(block.startNode);
+function getBlockElements(nodes) {
+ var startNode = nodes[0],
+ endNode = nodes[nodes.length - 1];
+ if (startNode === endNode) {
+ return jqLite(startNode);
}
- var element = block.startNode;
+ var element = startNode;
var elements = [element];
do {
element = element.nextSibling;
if (!element) break;
elements.push(element);
- } while (element !== block.endNode);
+ } while (element !== endNode);
return jqLite(elements);
}
/**
- * @ngdoc interface
+ * @ngdoc type
* @name angular.Module
+ * @module ng
* @description
*
* Interface for configuring angular {@link angular.module modules}.
@@ -1435,13 +1535,19 @@ function setupModuleLoader(window) {
return obj[name] || (obj[name] = factory());
}
- return ensure(ensure(window, 'angular', Object), 'module', function() {
+ var angular = ensure(window, 'angular', Object);
+
+ // We need to expose `angular.$$minErr` to modules such as `ngResource` that reference it during bootstrap
+ angular.$$minErr = angular.$$minErr || minErr;
+
+ return ensure(angular, 'module', function() {
/** @type {Object.<string, angular.Module>} */
var modules = {};
/**
* @ngdoc function
* @name angular.module
+ * @module ng
* @description
*
* The `angular.module` is a global place for creating, registering and retrieving Angular
@@ -1456,9 +1562,9 @@ function setupModuleLoader(window) {
* # Module
*
* A module is a collection of services, directives, filters, and configuration information.
- * `angular.module` is used to configure the {@link AUTO.$injector $injector}.
+ * `angular.module` is used to configure the {@link auto.$injector $injector}.
*
- * <pre>
+ * ```js
* // Create a new module
* var myModule = angular.module('myModule', []);
*
@@ -1466,27 +1572,27 @@ function setupModuleLoader(window) {
* myModule.value('appName', 'MyCoolApp');
*
* // configure existing services inside initialization blocks.
- * myModule.config(function($locationProvider) {
+ * myModule.config(['$locationProvider', function($locationProvider) {
* // Configure existing providers
* $locationProvider.hashPrefix('!');
- * });
- * </pre>
+ * }]);
+ * ```
*
* Then you can create an injector and load your modules like this:
*
- * <pre>
- * var injector = angular.injector(['ng', 'MyModule'])
- * </pre>
+ * ```js
+ * var injector = angular.injector(['ng', 'myModule'])
+ * ```
*
* However it's more likely that you'll just use
* {@link ng.directive:ngApp ngApp} or
* {@link angular.bootstrap} to simplify this process for you.
*
* @param {!string} name The name of the module to create or retrieve.
- * @param {Array.<string>=} requires If specified then new module is being created. If
- * unspecified then the the module is being retrieved for further configuration.
+<<<<<* @param {!Array.<string>=} requires If specified then new module is being created. If
+>>>>>* unspecified then the module is being retrieved for further configuration.
* @param {Function} configFn Optional configuration function for the module. Same as
- * {@link angular.Module#methods_config Module#config()}.
+ * {@link angular.Module#config Module#config()}.
* @returns {module} new module with the {@link angular.Module} api.
*/
return function module(name, requires, configFn) {
@@ -1524,7 +1630,7 @@ function setupModuleLoader(window) {
/**
* @ngdoc property
* @name angular.Module#requires
- * @propertyOf angular.Module
+ * @module ng
* @returns {Array.<string>} List of module names which must be loaded before this module.
* @description
* Holds the list of modules which the injector will load before the current module is
@@ -1535,7 +1641,7 @@ function setupModuleLoader(window) {
/**
* @ngdoc property
* @name angular.Module#name
- * @propertyOf angular.Module
+ * @module ng
* @returns {string} Name of the module.
* @description
*/
@@ -1545,64 +1651,64 @@ function setupModuleLoader(window) {
/**
* @ngdoc method
* @name angular.Module#provider
- * @methodOf angular.Module
+ * @module ng
* @param {string} name service name
* @param {Function} providerType Construction function for creating new instance of the
* service.
* @description
- * See {@link AUTO.$provide#provider $provide.provider()}.
+ * See {@link auto.$provide#provider $provide.provider()}.
*/
provider: invokeLater('$provide', 'provider'),
/**
* @ngdoc method
* @name angular.Module#factory
- * @methodOf angular.Module
+ * @module ng
* @param {string} name service name
* @param {Function} providerFunction Function for creating new instance of the service.
* @description
- * See {@link AUTO.$provide#factory $provide.factory()}.
+ * See {@link auto.$provide#factory $provide.factory()}.
*/
factory: invokeLater('$provide', 'factory'),
/**
* @ngdoc method
* @name angular.Module#service
- * @methodOf angular.Module
+ * @module ng
* @param {string} name service name
* @param {Function} constructor A constructor function that will be instantiated.
* @description
- * See {@link AUTO.$provide#service $provide.service()}.
+ * See {@link auto.$provide#service $provide.service()}.
*/
service: invokeLater('$provide', 'service'),
/**
* @ngdoc method
* @name angular.Module#value
- * @methodOf angular.Module
+ * @module ng
* @param {string} name service name
* @param {*} object Service instance object.
* @description
- * See {@link AUTO.$provide#value $provide.value()}.
+ * See {@link auto.$provide#value $provide.value()}.
*/
value: invokeLater('$provide', 'value'),
/**
* @ngdoc method
* @name angular.Module#constant
- * @methodOf angular.Module
+ * @module ng
* @param {string} name constant name
* @param {*} object Constant value.
* @description
* Because the constant are fixed, they get applied before other provide methods.
- * See {@link AUTO.$provide#constant $provide.constant()}.
+ * See {@link auto.$provide#constant $provide.constant()}.
*/
constant: invokeLater('$provide', 'constant', 'unshift'),
/**
* @ngdoc method
* @name angular.Module#animation
- * @methodOf angular.Module
+ * @module ng
* @param {string} name animation name
* @param {Function} animationFactory Factory function for creating new instance of an
* animation.
@@ -1614,7 +1720,7 @@ function setupModuleLoader(window) {
* Defines an animation hook that can be later used with
* {@link ngAnimate.$animate $animate} service and directives that use this service.
*
- * <pre>
+ * ```js
* module.animation('.animation-name', function($inject1, $inject2) {
* return {
* eventName : function(element, done) {
@@ -1626,7 +1732,7 @@ function setupModuleLoader(window) {
* }
* }
* })
- * </pre>
+ * ```
*
* See {@link ngAnimate.$animateProvider#register $animateProvider.register()} and
* {@link ngAnimate ngAnimate module} for more information.
@@ -1636,7 +1742,7 @@ function setupModuleLoader(window) {
/**
* @ngdoc method
* @name angular.Module#filter
- * @methodOf angular.Module
+ * @module ng
* @param {string} name Filter name.
* @param {Function} filterFactory Factory function for creating new instance of filter.
* @description
@@ -1647,7 +1753,7 @@ function setupModuleLoader(window) {
/**
* @ngdoc method
* @name angular.Module#controller
- * @methodOf angular.Module
+ * @module ng
* @param {string|Object} name Controller name, or an object map of controllers where the
* keys are the names and the values are the constructors.
* @param {Function} constructor Controller constructor function.
@@ -1659,20 +1765,20 @@ function setupModuleLoader(window) {
/**
* @ngdoc method
* @name angular.Module#directive
- * @methodOf angular.Module
+ * @module ng
* @param {string|Object} name Directive name, or an object map of directives where the
* keys are the names and the values are the factories.
* @param {Function} directiveFactory Factory function for creating new instance of
* directives.
* @description
- * See {@link ng.$compileProvider#methods_directive $compileProvider.directive()}.
+ * See {@link ng.$compileProvider#directive $compileProvider.directive()}.
*/
directive: invokeLater('$compileProvider', 'directive'),
/**
* @ngdoc method
* @name angular.Module#config
- * @methodOf angular.Module
+ * @module ng
* @param {Function} configFn Execute this function on module load. Useful for service
* configuration.
* @description
@@ -1683,7 +1789,7 @@ function setupModuleLoader(window) {
/**
* @ngdoc method
* @name angular.Module#run
- * @methodOf angular.Module
+ * @module ng
* @param {Function} initializationFn Execute this function after injector creation.
* Useful for application initialization.
* @description
@@ -1723,10 +1829,10 @@ function setupModuleLoader(window) {
/* global
angularModule: true,
version: true,
-
+
$LocaleProvider,
$CompileProvider,
-
+
htmlAnchorDirective,
inputDirective,
inputDirective,
@@ -1748,6 +1854,7 @@ function setupModuleLoader(window) {
ngHideDirective,
ngIfDirective,
ngIncludeDirective,
+ ngIncludeFillContentDirective,
ngInitDirective,
ngNonBindableDirective,
ngPluralizeDirective,
@@ -1785,18 +1892,22 @@ function setupModuleLoader(window) {
$ParseProvider,
$RootScopeProvider,
$QProvider,
+ $$SanitizeUriProvider,
$SceProvider,
$SceDelegateProvider,
$SnifferProvider,
$TemplateCacheProvider,
$TimeoutProvider,
+ $$RAFProvider,
+ $$AsyncCallbackProvider,
$WindowProvider
*/
/**
- * @ngdoc property
+ * @ngdoc object
* @name angular.version
+ * @module ng
* @description
* An object that contains information about the current AngularJS version. This object has the
* following properties:
@@ -1808,11 +1919,11 @@ function setupModuleLoader(window) {
* - `codeName` – `{string}` – Code name of the release, such as "jiggling-armfat".
*/
var version = {
- full: '1.2.1', // all of these placeholder strings will be replaced by grunt's
+ full: '1.2.16', // all of these placeholder strings will be replaced by grunt's
major: 1, // package task
minor: 2,
- dot: 1,
- codeName: 'underscore-empathy'
+ dot: 16,
+ codeName: 'badger-enumeration'
};
@@ -1856,6 +1967,10 @@ function publishExternalAPI(angular){
angularModule('ng', ['ngLocale'], ['$provide',
function ngModule($provide) {
+ // $$sanitizeUriProvider needs to be before $compileProvider as it is used by it.
+ $provide.provider({
+ $$sanitizeUri: $$SanitizeUriProvider
+ });
$provide.provider('$compile', $CompileProvider).
directive({
a: htmlAnchorDirective,
@@ -1896,6 +2011,9 @@ function publishExternalAPI(angular){
ngRequired: requiredDirective,
ngValue: ngValueDirective
}).
+ directive({
+ ngInclude: ngIncludeFillContentDirective
+ }).
directive(ngAttributeAliasDirectives).
directive(ngEventDirectives);
$provide.provider({
@@ -1921,7 +2039,9 @@ function publishExternalAPI(angular){
$sniffer: $SnifferProvider,
$templateCache: $TemplateCacheProvider,
$timeout: $TimeoutProvider,
- $window: $WindowProvider
+ $window: $WindowProvider,
+ $$rAF: $$RAFProvider,
+ $$asyncCallback : $$AsyncCallbackProvider
});
}
]);
@@ -1942,6 +2062,7 @@ function publishExternalAPI(angular){
/**
* @ngdoc function
* @name angular.element
+ * @module ng
* @function
*
* @description
@@ -1967,12 +2088,13 @@ function publishExternalAPI(angular){
* - [`after()`](http://api.jquery.com/after/)
* - [`append()`](http://api.jquery.com/append/)
* - [`attr()`](http://api.jquery.com/attr/)
- * - [`bind()`](http://api.jquery.com/on/) - Does not support namespaces, selectors or eventData
+ * - [`bind()`](http://api.jquery.com/bind/) - Does not support namespaces, selectors or eventData
* - [`children()`](http://api.jquery.com/children/) - Does not support selectors
* - [`clone()`](http://api.jquery.com/clone/)
* - [`contents()`](http://api.jquery.com/contents/)
* - [`css()`](http://api.jquery.com/css/)
* - [`data()`](http://api.jquery.com/data/)
+ * - [`empty()`](http://api.jquery.com/empty/)
* - [`eq()`](http://api.jquery.com/eq/)
* - [`find()`](http://api.jquery.com/find/) - Limited to lookups by tag name
* - [`hasClass()`](http://api.jquery.com/hasClass/)
@@ -1980,6 +2102,7 @@ function publishExternalAPI(angular){
* - [`next()`](http://api.jquery.com/next/) - Does not support selectors
* - [`on()`](http://api.jquery.com/on/) - Does not support namespaces, selectors or eventData
* - [`off()`](http://api.jquery.com/off/) - Does not support namespaces or selectors
+ * - [`one()`](http://api.jquery.com/one/) - Does not support namespaces or selectors
* - [`parent()`](http://api.jquery.com/parent/) - Does not support selectors
* - [`prepend()`](http://api.jquery.com/prepend/)
* - [`prop()`](http://api.jquery.com/prop/)
@@ -1992,7 +2115,7 @@ function publishExternalAPI(angular){
* - [`text()`](http://api.jquery.com/text/)
* - [`toggleClass()`](http://api.jquery.com/toggleClass/)
* - [`triggerHandler()`](http://api.jquery.com/triggerHandler/) - Passes a dummy event object to handlers.
- * - [`unbind()`](http://api.jquery.com/off/) - Does not support namespaces
+ * - [`unbind()`](http://api.jquery.com/unbind/) - Does not support namespaces
* - [`val()`](http://api.jquery.com/val/)
* - [`wrap()`](http://api.jquery.com/wrap/)
*
@@ -2010,9 +2133,9 @@ function publishExternalAPI(angular){
* camelCase directive name, then the controller for this directive will be retrieved (e.g.
* `'ngModel'`).
* - `injector()` - retrieves the injector of the current element or its parent.
- * - `scope()` - retrieves the {@link api/ng.$rootScope.Scope scope} of the current
+ * - `scope()` - retrieves the {@link ng.$rootScope.Scope scope} of the current
* element or its parent.
- * - `isolateScope()` - retrieves an isolate {@link api/ng.$rootScope.Scope scope} if one is attached directly to the
+ * - `isolateScope()` - retrieves an isolate {@link ng.$rootScope.Scope scope} if one is attached directly to the
* current element. This getter should be used only on elements that contain a directive which starts a new isolate
* scope. Calling `scope()` on this element always returns the original non-isolate scope.
* - `inheritedData()` - same as `data()`, but walks up the DOM until a value is found or the top
@@ -2032,6 +2155,14 @@ var jqCache = JQLite.cache = {},
? function(element, type, fn) {element.removeEventListener(type, fn, false); }
: function(element, type, fn) {element.detachEvent('on' + type, fn); });
+/*
+ * !!! This is an undocumented "private" function !!!
+ */
+var jqData = JQLite._data = function(node) {
+ //jQuery always returns an object on cache miss
+ return this.cache[node[this.expando]] || {};
+};
+
function jqNextId() { return ++jqId; }
@@ -2095,11 +2226,83 @@ function jqLitePatchJQueryRemove(name, dispatchThis, filterElems, getterIfNoArgu
}
}
+var SINGLE_TAG_REGEXP = /^<(\w+)\s*\/?>(?:<\/\1>|)$/;
+var HTML_REGEXP = /<|&#?\w+;/;
+var TAG_NAME_REGEXP = /<([\w:]+)/;
+var XHTML_TAG_REGEXP = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi;
+
+var wrapMap = {
+ 'option': [1, '<select multiple="multiple">', '</select>'],
+
+ 'thead': [1, '<table>', '</table>'],
+ 'col': [2, '<table><colgroup>', '</colgroup></table>'],
+ 'tr': [2, '<table><tbody>', '</tbody></table>'],
+ 'td': [3, '<table><tbody><tr>', '</tr></tbody></table>'],
+ '_default': [0, "", ""]
+};
+
+wrapMap.optgroup = wrapMap.option;
+wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
+wrapMap.th = wrapMap.td;
+
+function jqLiteIsTextNode(html) {
+ return !HTML_REGEXP.test(html);
+}
+
+function jqLiteBuildFragment(html, context) {
+ var elem, tmp, tag, wrap,
+ fragment = context.createDocumentFragment(),
+ nodes = [], i, j, jj;
+
+ if (jqLiteIsTextNode(html)) {
+ // Convert non-html into a text node
+ nodes.push(context.createTextNode(html));
+ } else {
+ tmp = fragment.appendChild(context.createElement('div'));
+ // Convert html into DOM nodes
+ tag = (TAG_NAME_REGEXP.exec(html) || ["", ""])[1].toLowerCase();
+ wrap = wrapMap[tag] || wrapMap._default;
+ tmp.innerHTML = '<div>&#160;</div>' +
+ wrap[1] + html.replace(XHTML_TAG_REGEXP, "<$1></$2>") + wrap[2];
+ tmp.removeChild(tmp.firstChild);
+
+ // Descend through wrappers to the right content
+ i = wrap[0];
+ while (i--) {
+ tmp = tmp.lastChild;
+ }
+
+ for (j=0, jj=tmp.childNodes.length; j<jj; ++j) nodes.push(tmp.childNodes[j]);
+
+ tmp = fragment.firstChild;
+ tmp.textContent = "";
+ }
+
+ // Remove wrapper from fragment
+ fragment.textContent = "";
+ fragment.innerHTML = ""; // Clear inner HTML
+ return nodes;
+}
+
+function jqLiteParseHTML(html, context) {
+ context = context || document;
+ var parsed;
+
+ if ((parsed = SINGLE_TAG_REGEXP.exec(html))) {
+ return [context.createElement(parsed[1])];
+ }
+
+ return jqLiteBuildFragment(html, context);
+}
+
/////////////////////////////////////////////
function JQLite(element) {
if (element instanceof JQLite) {
return element;
}
+ if (isString(element)) {
+ element = trim(element);
+ }
if (!(this instanceof JQLite)) {
if (isString(element) && element.charAt(0) != '<') {
throw jqLiteMinErr('nosel', 'Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element');
@@ -2108,14 +2311,9 @@ function JQLite(element) {
}
if (isString(element)) {
- var div = document.createElement('div');
- // Read about the NoScope elements here:
- // http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx
- div.innerHTML = '<div>&#160;</div>' + element; // IE insanity to make NoScope elements work!
- div.removeChild(div.firstChild); // remove the superfluous div
- jqLiteAddNodes(this, div.childNodes);
+ jqLiteAddNodes(this, jqLiteParseHTML(element));
var fragment = jqLite(document.createDocumentFragment());
- fragment.append(this); // detach the elements from the temporary DOM div.
+ fragment.append(this);
} else {
jqLiteAddNodes(this, element);
}
@@ -2277,11 +2475,24 @@ function jqLiteInheritedData(element, name, value) {
var names = isArray(name) ? name : [name];
while (element.length) {
-
+ var node = element[0];
for (var i = 0, ii = names.length; i < ii; i++) {
if ((value = element.data(names[i])) !== undefined) return value;
}
- element = element.parent();
+
+ // If dealing with a document fragment node with a host element, and no parent, use the host
+ // element as the parent. This enables directives within a Shadow DOM or polyfilled Shadow DOM
+ // to lookup parent controllers.
+ element = jqLite(node.parentNode || (node.nodeType === 11 && node.host));
+ }
+}
+
+function jqLiteEmpty(element) {
+ for (var i = 0, childNodes = element.childNodes; i < childNodes.length; i++) {
+ jqLiteDealoc(childNodes[i]);
+ }
+ while (element.firstChild) {
+ element.removeChild(element.firstChild);
}
}
@@ -2361,7 +2572,7 @@ forEach({
return jqLite(element).data('$isolateScope') || jqLite(element).data('$isolateScopeNoTemplate');
},
- controller: jqLiteController ,
+ controller: jqLiteController,
injector: function(element) {
return jqLiteInheritedData(element, '$injector');
@@ -2479,7 +2690,9 @@ forEach({
jqLiteDealoc(childNodes[i]);
}
element.innerHTML = value;
- }
+ },
+
+ empty: jqLiteEmpty
}, function(fn, name){
/**
* Properties: writes return selection, reads return first value
@@ -2489,11 +2702,13 @@ forEach({
// jqLiteHasClass has only two arguments, but is a getter-only fn, so we need to special-case it
// in a way that survives minification.
- if (((fn.length == 2 && (fn !== jqLiteHasClass && fn !== jqLiteController)) ? arg1 : arg2) === undefined) {
+ // jqLiteEmpty takes no arguments but is a setter.
+ if (fn !== jqLiteEmpty &&
+ (((fn.length == 2 && (fn !== jqLiteHasClass && fn !== jqLiteController)) ? arg1 : arg2) === undefined)) {
if (isObject(arg1)) {
// we are a write, but the object properties are the key/values
- for(i=0; i < this.length; i++) {
+ for (i = 0; i < this.length; i++) {
if (fn === jqLiteData) {
// data() takes the whole object in jQuery
fn(this[i], arg1);
@@ -2518,7 +2733,7 @@ forEach({
}
} else {
// we are a write, so apply to all children
- for(i=0; i < this.length; i++) {
+ for (i = 0; i < this.length; i++) {
fn(this[i], arg1, arg2);
}
// return self for chaining
@@ -2558,7 +2773,10 @@ function createEventHandler(element, events) {
return event.defaultPrevented || event.returnValue === false;
};
- forEach(events[type || event.type], function(fn) {
+ // Copy event handlers in case event handlers array is modified during execution.
+ var eventHandlersCopy = shallowCopy(events[type || event.type] || []);
+
+ forEach(eventHandlersCopy, function(fn) {
fn.call(element, event);
});
@@ -2654,6 +2872,19 @@ forEach({
off: jqLiteOff,
+ one: function(element, type, fn) {
+ element = jqLite(element);
+
+ //add the listener twice so that when it is called
+ //you can remove the original function and still be
+ //able to call element.off(ev, fn) normally
+ element.on(type, function onFn() {
+ element.off(type, fn);
+ element.off(type, onFn);
+ });
+ element.on(type, fn);
+ },
+
replaceWith: function(element, replaceNode) {
var index, parent = element.parentNode;
jqLiteDealoc(element);
@@ -2677,7 +2908,7 @@ forEach({
},
contents: function(element) {
- return element.childNodes || [];
+ return element.contentDocument || element.childNodes || [];
},
append: function(element, node) {
@@ -2724,10 +2955,15 @@ forEach({
removeClass: jqLiteRemoveClass,
toggleClass: function(element, selector, condition) {
- if (isUndefined(condition)) {
- condition = !jqLiteHasClass(element, selector);
+ if (selector) {
+ forEach(selector.split(' '), function(className){
+ var classCondition = condition;
+ if (isUndefined(classCondition)) {
+ classCondition = !jqLiteHasClass(element, className);
+ }
+ (classCondition ? jqLiteAddClass : jqLiteRemoveClass)(element, className);
+ });
}
- (condition ? jqLiteAddClass : jqLiteRemoveClass)(element, selector);
},
parent: function(element) {
@@ -2749,7 +2985,11 @@ forEach({
},
find: function(element, selector) {
- return element.getElementsByTagName(selector);
+ if (element.getElementsByTagName) {
+ return element.getElementsByTagName(selector);
+ } else {
+ return [];
+ }
},
clone: jqLiteClone,
@@ -2841,7 +3081,7 @@ HashMap.prototype = {
/**
* @param key
- * @returns the value for the key
+ * @returns {Object} the value for the key
*/
get: function(key) {
return this[hashKey(key)];
@@ -2860,6 +3100,7 @@ HashMap.prototype = {
/**
* @ngdoc function
+ * @module ng
* @name angular.injector
* @function
*
@@ -2870,11 +3111,11 @@ HashMap.prototype = {
* @param {Array.<string|Function>} modules A list of module functions or their aliases. See
* {@link angular.module}. The `ng` module must be explicitly added.
- * @returns {function()} Injector function. See {@link AUTO.$injector $injector}.
+ * @returns {function()} Injector function. See {@link auto.$injector $injector}.
*
* @example
* Typical usage
- * <pre>
+ * ```js
* // create an injector
* var $injector = angular.injector(['ng']);
*
@@ -2884,16 +3125,38 @@ HashMap.prototype = {
* $compile($document)($rootScope);
* $rootScope.$digest();
* });
- * </pre>
+ * ```
+ *
+ * Sometimes you want to get access to the injector of a currently running Angular app
+ * from outside Angular. Perhaps, you want to inject and compile some markup after the
+ * application has been bootstrapped. You can do this using extra `injector()` added
+ * to JQuery/jqLite elements. See {@link angular.element}.
+ *
+ * *This is fairly rare but could be the case if a third party library is injecting the
+ * markup.*
+ *
+ * In the following example a new block of HTML containing a `ng-controller`
+ * directive is added to the end of the document body by JQuery. We then compile and link
+ * it into the current AngularJS scope.
+ *
+ * ```js
+ * var $div = $('<div ng-controller="MyCtrl">{{content.label}}</div>');
+ * $(document.body).append($div);
+ *
+ * angular.element(document).injector().invoke(function($compile) {
+ * var scope = angular.element($div).scope();
+ * $compile($div)(scope);
+ * });
+ * ```
*/
/**
- * @ngdoc overview
- * @name AUTO
+ * @ngdoc module
+ * @name auto
* @description
*
- * Implicit module which gets automatically added to each {@link AUTO.$injector $injector}.
+ * Implicit module which gets automatically added to each {@link auto.$injector $injector}.
*/
var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
@@ -2934,32 +3197,32 @@ function annotate(fn) {
///////////////////////////////////////
/**
- * @ngdoc object
- * @name AUTO.$injector
+ * @ngdoc service
+ * @name $injector
* @function
*
* @description
*
* `$injector` is used to retrieve object instances as defined by
- * {@link AUTO.$provide provider}, instantiate types, invoke methods,
+ * {@link auto.$provide provider}, instantiate types, invoke methods,
* and load modules.
*
* The following always holds true:
*
- * <pre>
+ * ```js
* var $injector = angular.injector();
* expect($injector.get('$injector')).toBe($injector);
* expect($injector.invoke(function($injector){
* return $injector;
* }).toBe($injector);
- * </pre>
+ * ```
*
* # Injection Function Annotation
*
* JavaScript does not have annotations, and annotations are needed for dependency injection. The
* following are all valid ways of annotating function with injection arguments and are equivalent.
*
- * <pre>
+ * ```js
* // inferred (only works if code not minified/obfuscated)
* $injector.invoke(function(serviceA){});
*
@@ -2970,7 +3233,7 @@ function annotate(fn) {
*
* // inline
* $injector.invoke(['serviceA', function(serviceA){}]);
- * </pre>
+ * ```
*
* ## Inference
*
@@ -2987,8 +3250,7 @@ function annotate(fn) {
/**
* @ngdoc method
- * @name AUTO.$injector#get
- * @methodOf AUTO.$injector
+ * @name $injector#get
*
* @description
* Return an instance of the service.
@@ -2999,13 +3261,12 @@ function annotate(fn) {
/**
* @ngdoc method
- * @name AUTO.$injector#invoke
- * @methodOf AUTO.$injector
+ * @name $injector#invoke
*
* @description
* Invoke the method and supply the method arguments from the `$injector`.
*
- * @param {!function} fn The function to invoke. Function parameters are injected according to the
+ * @param {!Function} fn The function to invoke. Function parameters are injected according to the
* {@link guide/di $inject Annotation} rules.
* @param {Object=} self The `this` for the invoked method.
* @param {Object=} locals Optional object. If preset then any argument names are read from this
@@ -3015,8 +3276,7 @@ function annotate(fn) {
/**
* @ngdoc method
- * @name AUTO.$injector#has
- * @methodOf AUTO.$injector
+ * @name $injector#has
*
* @description
* Allows the user to query if the particular service exist.
@@ -3027,14 +3287,13 @@ function annotate(fn) {
/**
* @ngdoc method
- * @name AUTO.$injector#instantiate
- * @methodOf AUTO.$injector
+ * @name $injector#instantiate
* @description
* Create a new instance of JS type. The method takes a constructor function invokes the new
* operator and supplies all of the arguments to the constructor function as specified by the
* constructor annotation.
*
- * @param {function} Type Annotated constructor function.
+ * @param {Function} Type Annotated constructor function.
* @param {Object=} locals Optional object. If preset then any argument names are read from this
* object first, before the `$injector` is consulted.
* @returns {Object} new instance of `Type`.
@@ -3042,8 +3301,7 @@ function annotate(fn) {
/**
* @ngdoc method
- * @name AUTO.$injector#annotate
- * @methodOf AUTO.$injector
+ * @name $injector#annotate
*
* @description
* Returns an array of service names which the function is requesting for injection. This API is
@@ -3056,7 +3314,7 @@ function annotate(fn) {
* The simplest form is to extract the dependencies from the arguments of the function. This is done
* by converting the function into a string using `toString()` method and extracting the argument
* names.
- * <pre>
+ * ```js
* // Given
* function MyController($scope, $route) {
* // ...
@@ -3064,7 +3322,7 @@ function annotate(fn) {
*
* // Then
* expect(injector.annotate(MyController)).toEqual(['$scope', '$route']);
- * </pre>
+ * ```
*
* This method does not work with code minification / obfuscation. For this reason the following
* annotation strategies are supported.
@@ -3073,17 +3331,17 @@ function annotate(fn) {
*
* If a function has an `$inject` property and its value is an array of strings, then the strings
* represent names of services to be injected into the function.
- * <pre>
+ * ```js
* // Given
* var MyController = function(obfuscatedScope, obfuscatedRoute) {
* // ...
* }
* // Define function dependencies
- * MyController.$inject = ['$scope', '$route'];
+ * MyController['$inject'] = ['$scope', '$route'];
*
* // Then
* expect(injector.annotate(MyController)).toEqual(['$scope', '$route']);
- * </pre>
+ * ```
*
* # The array notation
*
@@ -3091,7 +3349,7 @@ function annotate(fn) {
* is very inconvenient. In these situations using the array notation to specify the dependencies in
* a way that survives minification is a better choice:
*
- * <pre>
+ * ```js
* // We wish to write this (not minification / obfuscation safe)
* injector.invoke(function($compile, $rootScope) {
* // ...
@@ -3113,9 +3371,9 @@ function annotate(fn) {
* expect(injector.annotate(
* ['$compile', '$rootScope', function(obfus_$compile, obfus_$rootScope) {}])
* ).toEqual(['$compile', '$rootScope']);
- * </pre>
+ * ```
*
- * @param {function|Array.<string|Function>} fn Function for which dependent service names need to
+ * @param {Function|Array.<string|Function>} fn Function for which dependent service names need to
* be retrieved as described above.
*
* @returns {Array.<string>} The names of the services which the function requires.
@@ -3126,12 +3384,12 @@ function annotate(fn) {
/**
* @ngdoc object
- * @name AUTO.$provide
+ * @name $provide
*
* @description
*
- * The {@link AUTO.$provide $provide} service has a number of methods for registering components
- * with the {@link AUTO.$injector $injector}. Many of these functions are also exposed on
+ * The {@link auto.$provide $provide} service has a number of methods for registering components
+ * with the {@link auto.$injector $injector}. Many of these functions are also exposed on
* {@link angular.Module}.
*
* An Angular **service** is a singleton object created by a **service factory**. These **service
@@ -3139,25 +3397,25 @@ function annotate(fn) {
* The **service providers** are constructor functions. When instantiated they must contain a
* property called `$get`, which holds the **service factory** function.
*
- * When you request a service, the {@link AUTO.$injector $injector} is responsible for finding the
+ * When you request a service, the {@link auto.$injector $injector} is responsible for finding the
* correct **service provider**, instantiating it and then calling its `$get` **service factory**
* function to get the instance of the **service**.
*
* Often services have no configuration options and there is no need to add methods to the service
* provider. The provider will be no more than a constructor function with a `$get` property. For
- * these cases the {@link AUTO.$provide $provide} service has additional helper methods to register
+ * these cases the {@link auto.$provide $provide} service has additional helper methods to register
* services without specifying a provider.
*
- * * {@link AUTO.$provide#methods_provider provider(provider)} - registers a **service provider** with the
- * {@link AUTO.$injector $injector}
- * * {@link AUTO.$provide#methods_constant constant(obj)} - registers a value/object that can be accessed by
+ * * {@link auto.$provide#provider provider(provider)} - registers a **service provider** with the
+ * {@link auto.$injector $injector}
+ * * {@link auto.$provide#constant constant(obj)} - registers a value/object that can be accessed by
* providers and services.
- * * {@link AUTO.$provide#methods_value value(obj)} - registers a value/object that can only be accessed by
+ * * {@link auto.$provide#value value(obj)} - registers a value/object that can only be accessed by
* services, not providers.
- * * {@link AUTO.$provide#methods_factory factory(fn)} - registers a service **factory function**, `fn`,
+ * * {@link auto.$provide#factory factory(fn)} - registers a service **factory function**, `fn`,
* that will be wrapped in a **service provider** object, whose `$get` property will contain the
* given factory function.
- * * {@link AUTO.$provide#methods_service service(class)} - registers a **constructor function**, `class` that
+ * * {@link auto.$provide#service service(class)} - registers a **constructor function**, `class`
* that will be wrapped in a **service provider** object, whose `$get` property will instantiate
* a new object using the given constructor function.
*
@@ -3166,11 +3424,10 @@ function annotate(fn) {
/**
* @ngdoc method
- * @name AUTO.$provide#provider
- * @methodOf AUTO.$provide
+ * @name $provide#provider
* @description
*
- * Register a **provider function** with the {@link AUTO.$injector $injector}. Provider functions
+ * Register a **provider function** with the {@link auto.$injector $injector}. Provider functions
* are constructor functions, whose instances are responsible for "providing" a factory for a
* service.
*
@@ -3190,20 +3447,18 @@ function annotate(fn) {
* @param {(Object|function())} provider If the provider is:
*
* - `Object`: then it should have a `$get` method. The `$get` method will be invoked using
- * {@link AUTO.$injector#invoke $injector.invoke()} when an instance needs to be
- * created.
+ * {@link auto.$injector#invoke $injector.invoke()} when an instance needs to be created.
* - `Constructor`: a new instance of the provider will be created using
- * {@link AUTO.$injector#instantiate $injector.instantiate()}, then treated as
- * `object`.
+ * {@link auto.$injector#instantiate $injector.instantiate()}, then treated as `object`.
*
* @returns {Object} registered provider instance
* @example
*
* The following example shows how to create a simple event tracking service and register it using
- * {@link AUTO.$provide#methods_provider $provide.provider()}.
+ * {@link auto.$provide#provider $provide.provider()}.
*
- * <pre>
+ * ```js
* // Define the eventTracker provider
* function EventTrackerProvider() {
* var trackingUrl = '/track';
@@ -3260,19 +3515,18 @@ function annotate(fn) {
* expect(postSpy.mostRecentCall.args[1]).toEqual({ 'login': 1 });
* }));
* });
- * </pre>
+ * ```
*/
/**
* @ngdoc method
- * @name AUTO.$provide#factory
- * @methodOf AUTO.$provide
+ * @name $provide#factory
* @description
*
* Register a **service factory**, which will be called to return the service instance.
* This is short for registering a service where its provider consists of only a `$get` property,
* which is the given service factory function.
- * You should use {@link AUTO.$provide#factory $provide.factory(getFn)} if you do not need to
+ * You should use {@link auto.$provide#factory $provide.factory(getFn)} if you do not need to
* configure your service in a provider.
*
* @param {string} name The name of the instance.
@@ -3282,26 +3536,25 @@ function annotate(fn) {
*
* @example
* Here is an example of registering a service
- * <pre>
+ * ```js
* $provide.factory('ping', ['$http', function($http) {
* return function ping() {
* return $http.send('/ping');
* };
* }]);
- * </pre>
+ * ```
* You would then inject and use this service like this:
- * <pre>
+ * ```js
* someModule.controller('Ctrl', ['ping', function(ping) {
* ping();
* }]);
- * </pre>
+ * ```
*/
/**
* @ngdoc method
- * @name AUTO.$provide#service
- * @methodOf AUTO.$provide
+ * @name $provide#service
* @description
*
* Register a **service constructor**, which will be invoked with `new` to create the service
@@ -3309,8 +3562,8 @@ function annotate(fn) {
* This is short for registering a service where its provider's `$get` property is the service
* constructor function that will be used to instantiate the service instance.
*
- * You should use {@link AUTO.$provide#methods_service $provide.service(class)} if you define your service
- * as a type/class. This is common when using {@link http://coffeescript.org CoffeeScript}.
+ * You should use {@link auto.$provide#service $provide.service(class)} if you define your service
+ * as a type/class.
*
* @param {string} name The name of the instance.
* @param {Function} constructor A class (constructor function) that will be instantiated.
@@ -3318,31 +3571,34 @@ function annotate(fn) {
*
* @example
* Here is an example of registering a service using
- * {@link AUTO.$provide#methods_service $provide.service(class)} that is defined as a CoffeeScript class.
- * <pre>
- * class Ping
- * constructor: (@$http)->
- * send: ()=>
- * @$http.get('/ping')
+ * {@link auto.$provide#service $provide.service(class)}.
+ * ```js
+ * var Ping = function($http) {
+ * this.$http = $http;
+ * };
*
- * $provide.service('ping', ['$http', Ping])
- * </pre>
+ * Ping.$inject = ['$http'];
+ *
+ * Ping.prototype.send = function() {
+ * return this.$http.get('/ping');
+ * };
+ * $provide.service('ping', Ping);
+ * ```
* You would then inject and use this service like this:
- * <pre>
- * someModule.controller 'Ctrl', ['ping', (ping)->
- * ping.send()
- * ]
- * </pre>
+ * ```js
+ * someModule.controller('Ctrl', ['ping', function(ping) {
+ * ping.send();
+ * }]);
+ * ```
*/
/**
* @ngdoc method
- * @name AUTO.$provide#value
- * @methodOf AUTO.$provide
+ * @name $provide#value
* @description
*
- * Register a **value service** with the {@link AUTO.$injector $injector}, such as a string, a
+ * Register a **value service** with the {@link auto.$injector $injector}, such as a string, a
* number, an array, an object or a function. This is short for registering a service where its
* provider's `$get` property is a factory function that takes no arguments and returns the **value
* service**.
@@ -3350,7 +3606,7 @@ function annotate(fn) {
* Value services are similar to constant services, except that they cannot be injected into a
* module configuration function (see {@link angular.Module#config}) but they can be overridden by
* an Angular
- * {@link AUTO.$provide#decorator decorator}.
+ * {@link auto.$provide#decorator decorator}.
*
* @param {string} name The name of the instance.
* @param {*} value The value.
@@ -3358,28 +3614,27 @@ function annotate(fn) {
*
* @example
* Here are some examples of creating value services.
- * <pre>
- * $provide.constant('ADMIN_USER', 'admin');
+ * ```js
+ * $provide.value('ADMIN_USER', 'admin');
*
- * $provide.constant('RoleLookup', { admin: 0, writer: 1, reader: 2 });
+ * $provide.value('RoleLookup', { admin: 0, writer: 1, reader: 2 });
*
- * $provide.constant('halfOf', function(value) {
+ * $provide.value('halfOf', function(value) {
* return value / 2;
* });
- * </pre>
+ * ```
*/
/**
* @ngdoc method
- * @name AUTO.$provide#constant
- * @methodOf AUTO.$provide
+ * @name $provide#constant
* @description
*
* Register a **constant service**, such as a string, a number, an array, an object or a function,
- * with the {@link AUTO.$injector $injector}. Unlike {@link AUTO.$provide#value value} it can be
+ * with the {@link auto.$injector $injector}. Unlike {@link auto.$provide#value value} it can be
* injected into a module configuration function (see {@link angular.Module#config}) and it cannot
- * be overridden by an Angular {@link AUTO.$provide#decorator decorator}.
+ * be overridden by an Angular {@link auto.$provide#decorator decorator}.
*
* @param {string} name The name of the constant.
* @param {*} value The constant value.
@@ -3387,7 +3642,7 @@ function annotate(fn) {
*
* @example
* Here a some examples of creating constants:
- * <pre>
+ * ```js
* $provide.constant('SHARD_HEIGHT', 306);
*
* $provide.constant('MY_COLOURS', ['red', 'blue', 'grey']);
@@ -3395,17 +3650,16 @@ function annotate(fn) {
* $provide.constant('double', function(value) {
* return value * 2;
* });
- * </pre>
+ * ```
*/
/**
* @ngdoc method
- * @name AUTO.$provide#decorator
- * @methodOf AUTO.$provide
+ * @name $provide#decorator
* @description
*
- * Register a **service decorator** with the {@link AUTO.$injector $injector}. A service decorator
+ * Register a **service decorator** with the {@link auto.$injector $injector}. A service decorator
* intercepts the creation of a service, allowing it to override or modify the behaviour of the
* service. The object returned by the decorator may be the original service, or a new service
* object which replaces or wraps and delegates to the original service.
@@ -3413,7 +3667,7 @@ function annotate(fn) {
* @param {string} name The name of the service to decorate.
* @param {function()} decorator This function will be invoked when the service needs to be
* instantiated and should return the decorated service instance. The function is called using
- * the {@link AUTO.$injector#invoke injector.invoke} method and is therefore fully injectable.
+ * the {@link auto.$injector#invoke injector.invoke} method and is therefore fully injectable.
* Local injection arguments:
*
* * `$delegate` - The original service instance, which can be monkey patched, configured,
@@ -3422,12 +3676,12 @@ function annotate(fn) {
* @example
* Here we decorate the {@link ng.$log $log} service to convert warnings to errors by intercepting
* calls to {@link ng.$log#error $log.warn()}.
- * <pre>
- * $provider.decorator('$log', ['$delegate', function($delegate) {
+ * ```js
+ * $provide.decorator('$log', ['$delegate', function($delegate) {
* $delegate.warn = $delegate.error;
* return $delegate;
* }]);
- * </pre>
+ * ```
*/
@@ -3576,6 +3830,11 @@ function createInjector(modulesToLoad) {
path.unshift(serviceName);
cache[serviceName] = INSTANTIATING;
return cache[serviceName] = factory(serviceName);
+ } catch (err) {
+ if (cache[serviceName] === INSTANTIATING) {
+ delete cache[serviceName];
+ }
+ throw err;
} finally {
path.shift();
}
@@ -3605,24 +3864,9 @@ function createInjector(modulesToLoad) {
fn = fn[length];
}
-
- // Performance optimization: http://jsperf.com/apply-vs-call-vs-invoke
- switch (self ? -1 : args.length) {
- case 0: return fn();
- case 1: return fn(args[0]);
- case 2: return fn(args[0], args[1]);
- case 3: return fn(args[0], args[1], args[2]);
- case 4: return fn(args[0], args[1], args[2], args[3]);
- case 5: return fn(args[0], args[1], args[2], args[3], args[4]);
- case 6: return fn(args[0], args[1], args[2], args[3], args[4], args[5]);
- case 7: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
- case 8: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
- case 9: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7],
- args[8]);
- case 10: return fn(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7],
- args[8], args[9]);
- default: return fn.apply(self, args);
- }
+ // http://jsperf.com/angularjs-invoke-apply-vs-switch
+ // #5388
+ return fn.apply(self, args);
}
function instantiate(Type, locals) {
@@ -3651,8 +3895,9 @@ function createInjector(modulesToLoad) {
}
/**
- * @ngdoc function
- * @name ng.$anchorScroll
+ * @ngdoc service
+ * @name $anchorScroll
+ * @kind function
* @requires $window
* @requires $location
* @requires $rootScope
@@ -3660,11 +3905,11 @@ function createInjector(modulesToLoad) {
* @description
* When called, it checks current value of `$location.hash()` and scroll to related element,
* according to rules specified in
- * {@link http://dev.w3.org/html5/spec/Overview.html#the-indicated-part-of-the-document Html5 spec}.
+ * [Html5 spec](http://dev.w3.org/html5/spec/Overview.html#the-indicated-part-of-the-document).
*
* It also watches the `$location.hash()` and scrolls whenever it changes to match any anchor.
* This can be disabled by calling `$anchorScrollProvider.disableAutoScrolling()`.
- *
+ *
* @example
<example>
<file name="index.html">
@@ -3679,10 +3924,10 @@ function createInjector(modulesToLoad) {
// set the location.hash to the id of
// the element you wish to scroll to.
$location.hash('bottom');
-
+
// call $anchorScroll()
$anchorScroll();
- }
+ };
}
</file>
<file name="style.css">
@@ -3753,8 +3998,8 @@ function $AnchorScrollProvider() {
var $animateMinErr = minErr('$animate');
/**
- * @ngdoc object
- * @name ng.$animateProvider
+ * @ngdoc provider
+ * @name $animateProvider
*
* @description
* Default implementation of $animate that doesn't perform any animations, instead just
@@ -3767,14 +4012,13 @@ var $animateMinErr = minErr('$animate');
*/
var $AnimateProvider = ['$provide', function($provide) {
-
+
this.$$selectors = {};
/**
- * @ngdoc function
- * @name ng.$animateProvider#register
- * @methodOf ng.$animateProvider
+ * @ngdoc method
+ * @name $animateProvider#register
*
* @description
* Registers a new injectable animation factory function. The factory function produces the
@@ -3787,7 +4031,7 @@ var $AnimateProvider = ['$provide', function($provide) {
* triggered.
*
*
- *<pre>
+ * ```js
* return {
* eventFn : function(element, done) {
* //code to run the animation
@@ -3797,10 +4041,10 @@ var $AnimateProvider = ['$provide', function($provide) {
* }
* }
* }
- *</pre>
+ * ```
*
* @param {string} name The name of the animation.
- * @param {function} factory The factory function that will be executed to return the animation
+ * @param {Function} factory The factory function that will be executed to return the animation
* object.
*/
this.register = function(name, factory) {
@@ -3811,12 +4055,37 @@ var $AnimateProvider = ['$provide', function($provide) {
$provide.factory(key, factory);
};
- this.$get = ['$timeout', function($timeout) {
+ /**
+ * @ngdoc method
+ * @name $animateProvider#classNameFilter
+ *
+ * @description
+ * Sets and/or returns the CSS class regular expression that is checked when performing
+ * an animation. Upon bootstrap the classNameFilter value is not set at all and will
+ * therefore enable $animate to attempt to perform an animation on any element.
+ * When setting the classNameFilter value, animations will only be performed on elements
+ * that successfully match the filter expression. This in turn can boost performance
+ * for low-powered devices as well as applications containing a lot of structural operations.
+ * @param {RegExp=} expression The className expression which will be checked against all animations
+ * @return {RegExp} The current CSS className expression value. If null then there is no expression value
+ */
+ this.classNameFilter = function(expression) {
+ if(arguments.length === 1) {
+ this.$$classNameFilter = (expression instanceof RegExp) ? expression : null;
+ }
+ return this.$$classNameFilter;
+ };
+
+ this.$get = ['$timeout', '$$asyncCallback', function($timeout, $$asyncCallback) {
+
+ function async(fn) {
+ fn && $$asyncCallback(fn);
+ }
/**
*
- * @ngdoc object
- * @name ng.$animate
+ * @ngdoc service
+ * @name $animate
* @description The $animate service provides rudimentary DOM manipulation functions to
* insert, remove and move elements within the DOM, as well as adding and removing classes.
* This service is the core service used by the ngAnimate $animator service which provides
@@ -3834,65 +4103,63 @@ var $AnimateProvider = ['$provide', function($provide) {
/**
*
- * @ngdoc function
- * @name ng.$animate#enter
- * @methodOf ng.$animate
+ * @ngdoc method
+ * @name $animate#enter
* @function
* @description Inserts the element into the DOM either after the `after` element or within
* the `parent` element. Once complete, the done() callback will be fired (if provided).
- * @param {jQuery/jqLite element} element the element which will be inserted into the DOM
- * @param {jQuery/jqLite element} parent the parent element which will append the element as
+ * @param {DOMElement} element the element which will be inserted into the DOM
+ * @param {DOMElement} parent the parent element which will append the element as
* a child (if the after element is not present)
- * @param {jQuery/jqLite element} after the sibling element which will append the element
+ * @param {DOMElement} after the sibling element which will append the element
* after itself
- * @param {function=} done callback function that will be called after the element has been
+ * @param {Function=} done callback function that will be called after the element has been
* inserted into the DOM
*/
enter : function(element, parent, after, done) {
- var afterNode = after && after[after.length - 1];
- var parentNode = parent && parent[0] || afterNode && afterNode.parentNode;
- // IE does not like undefined so we have to pass null.
- var afterNextSibling = (afterNode && afterNode.nextSibling) || null;
- forEach(element, function(node) {
- parentNode.insertBefore(node, afterNextSibling);
- });
- done && $timeout(done, 0, false);
+ if (after) {
+ after.after(element);
+ } else {
+ if (!parent || !parent[0]) {
+ parent = after.parent();
+ }
+ parent.append(element);
+ }
+ async(done);
},
/**
*
- * @ngdoc function
- * @name ng.$animate#leave
- * @methodOf ng.$animate
+ * @ngdoc method
+ * @name $animate#leave
* @function
* @description Removes the element from the DOM. Once complete, the done() callback will be
* fired (if provided).
- * @param {jQuery/jqLite element} element the element which will be removed from the DOM
- * @param {function=} done callback function that will be called after the element has been
+ * @param {DOMElement} element the element which will be removed from the DOM
+ * @param {Function=} done callback function that will be called after the element has been
* removed from the DOM
*/
leave : function(element, done) {
element.remove();
- done && $timeout(done, 0, false);
+ async(done);
},
/**
*
- * @ngdoc function
- * @name ng.$animate#move
- * @methodOf ng.$animate
+ * @ngdoc method
+ * @name $animate#move
* @function
* @description Moves the position of the provided element within the DOM to be placed
* either after the `after` element or inside of the `parent` element. Once complete, the
* done() callback will be fired (if provided).
- *
- * @param {jQuery/jqLite element} element the element which will be moved around within the
+ *
+ * @param {DOMElement} element the element which will be moved around within the
* DOM
- * @param {jQuery/jqLite element} parent the parent element where the element will be
+ * @param {DOMElement} parent the parent element where the element will be
* inserted into (if the after element is not present)
- * @param {jQuery/jqLite element} after the sibling element where the element will be
+ * @param {DOMElement} after the sibling element where the element will be
* positioned next to
- * @param {function=} done the callback function (if provided) that will be fired after the
+ * @param {Function=} done the callback function (if provided) that will be fired after the
* element has been moved to its new position
*/
move : function(element, parent, after, done) {
@@ -3903,16 +4170,15 @@ var $AnimateProvider = ['$provide', function($provide) {
/**
*
- * @ngdoc function
- * @name ng.$animate#addClass
- * @methodOf ng.$animate
+ * @ngdoc method
+ * @name $animate#addClass
* @function
* @description Adds the provided className CSS class value to the provided element. Once
* complete, the done() callback will be fired (if provided).
- * @param {jQuery/jqLite element} element the element which will have the className value
+ * @param {DOMElement} element the element which will have the className value
* added to it
* @param {string} className the CSS class which will be added to the element
- * @param {function=} done the callback function (if provided) that will be fired after the
+ * @param {Function=} done the callback function (if provided) that will be fired after the
* className value has been added to the element
*/
addClass : function(element, className, done) {
@@ -3922,21 +4188,20 @@ var $AnimateProvider = ['$provide', function($provide) {
forEach(element, function (element) {
jqLiteAddClass(element, className);
});
- done && $timeout(done, 0, false);
+ async(done);
},
/**
*
- * @ngdoc function
- * @name ng.$animate#removeClass
- * @methodOf ng.$animate
+ * @ngdoc method
+ * @name $animate#removeClass
* @function
* @description Removes the provided className CSS class value from the provided element.
* Once complete, the done() callback will be fired (if provided).
- * @param {jQuery/jqLite element} element the element which will have the className value
+ * @param {DOMElement} element the element which will have the className value
* removed from it
* @param {string} className the CSS class which will be removed from the element
- * @param {function=} done the callback function (if provided) that will be fired after the
+ * @param {Function=} done the callback function (if provided) that will be fired after the
* className value has been removed from the element
*/
removeClass : function(element, className, done) {
@@ -3946,7 +4211,29 @@ var $AnimateProvider = ['$provide', function($provide) {
forEach(element, function (element) {
jqLiteRemoveClass(element, className);
});
- done && $timeout(done, 0, false);
+ async(done);
+ },
+
+ /**
+ *
+ * @ngdoc method
+ * @name $animate#setClass
+ * @function
+ * @description Adds and/or removes the given CSS classes to and from the element.
+ * Once complete, the done() callback will be fired (if provided).
+ * @param {DOMElement} element the element which will it's CSS classes changed
+ * removed from it
+ * @param {string} add the CSS classes which will be added to the element
+ * @param {string} remove the CSS class which will be removed from the element
+ * @param {Function=} done the callback function (if provided) that will be fired after the
+ * CSS classes have been set on the element
+ */
+ setClass : function(element, add, remove, done) {
+ forEach(element, function (element) {
+ jqLiteAddClass(element, add);
+ jqLiteRemoveClass(element, remove);
+ });
+ async(done);
},
enabled : noop
@@ -3954,10 +4241,20 @@ var $AnimateProvider = ['$provide', function($provide) {
}];
}];
+function $$AsyncCallbackProvider(){
+ this.$get = ['$$rAF', '$timeout', function($$rAF, $timeout) {
+ return $$rAF.supported
+ ? function(fn) { return $$rAF(fn); }
+ : function(fn) {
+ return $timeout(fn, 0, false);
+ };
+ }];
+}
+
/**
* ! This is a private undocumented service !
*
- * @name ng.$browser
+ * @name $browser
* @requires $log
* @description
* This object has two goals:
@@ -4041,8 +4338,7 @@ function Browser(window, document, $log, $sniffer) {
pollTimeout;
/**
- * @name ng.$browser#addPollFn
- * @methodOf ng.$browser
+ * @name $browser#addPollFn
*
* @param {function()} fn Poll function to add
*
@@ -4082,8 +4378,7 @@ function Browser(window, document, $log, $sniffer) {
newLocation = null;
/**
- * @name ng.$browser#url
- * @methodOf ng.$browser
+ * @name $browser#url
*
* @description
* GETTER:
@@ -4102,8 +4397,9 @@ function Browser(window, document, $log, $sniffer) {
* @param {boolean=} replace Should new url replace current history record ?
*/
self.url = function(url, replace) {
- // Android Browser BFCache causes location reference to become stale.
+ // Android Browser BFCache causes location, history reference to become stale.
if (location !== window.location) location = window.location;
+ if (history !== window.history) history = window.history;
// setter
if (url) {
@@ -4148,14 +4444,12 @@ function Browser(window, document, $log, $sniffer) {
}
/**
- * @name ng.$browser#onUrlChange
- * @methodOf ng.$browser
- * @TODO(vojta): refactor to use node's syntax for events
+ * @name $browser#onUrlChange
*
* @description
* Register callback function that will be called, when url changes.
*
- * It's only called when the url is changed by outside of angular:
+ * It's only called when the url is changed from outside of angular:
* - user types different url into address bar
* - user clicks on history (forward/back) button
* - user clicks on a link
@@ -4171,6 +4465,7 @@ function Browser(window, document, $log, $sniffer) {
* @return {function(string)} Returns the registered listener fn - handy if the fn is anonymous.
*/
self.onUrlChange = function(callback) {
+ // TODO(vojta): refactor to use node's syntax for events
if (!urlChangeInit) {
// We listen on both (hashchange/popstate) when available, as some browsers (e.g. Opera)
// don't fire popstate when user change the address bar and don't fire hashchange when url
@@ -4195,18 +4490,17 @@ function Browser(window, document, $log, $sniffer) {
//////////////////////////////////////////////////////////////
/**
- * @name ng.$browser#baseHref
- * @methodOf ng.$browser
- *
+ * @name $browser#baseHref
+ *
* @description
* Returns current <base href>
* (always relative - without domain)
*
- * @returns {string=} current <base href>
+ * @returns {string} The current base href
*/
self.baseHref = function() {
var href = baseElement.attr('href');
- return href ? href.replace(/^https?\:\/\/[^\/]*/, '') : '';
+ return href ? href.replace(/^(https?\:)?\/\/[^\/]*/, '') : '';
};
//////////////////////////////////////////////////////////////
@@ -4217,8 +4511,7 @@ function Browser(window, document, $log, $sniffer) {
var cookiePath = self.baseHref();
/**
- * @name ng.$browser#cookies
- * @methodOf ng.$browser
+ * @name $browser#cookies
*
* @param {string=} name Cookie name
* @param {string=} value Cookie value
@@ -4228,13 +4521,13 @@ function Browser(window, document, $log, $sniffer) {
* It is not meant to be used directly, use the $cookie service instead.
*
* The return values vary depending on the arguments that the method was called with as follows:
- *
+ *
* - cookies() -> hash of all cookies, this is NOT a copy of the internal state, so do not modify
* it
* - cookies(name, value) -> set name to value, if value is undefined delete the cookie
* - cookies(name) -> the same as (name, undefined) == DELETES (no one calls it right now that
* way)
- *
+ *
* @returns {Object} Hash of all cookies (if called without any parameter)
*/
self.cookies = function(name, value) {
@@ -4287,8 +4580,7 @@ function Browser(window, document, $log, $sniffer) {
/**
- * @name ng.$browser#defer
- * @methodOf ng.$browser
+ * @name $browser#defer
* @param {function()} fn A function, who's execution should be deferred.
* @param {number=} [delay=0] of milliseconds to defer the function execution.
* @returns {*} DeferId that can be used to cancel the task via `$browser.defer.cancel()`.
@@ -4314,8 +4606,7 @@ function Browser(window, document, $log, $sniffer) {
/**
- * @name ng.$browser#defer.cancel
- * @methodOf ng.$browser.defer
+ * @name $browser#defer.cancel
*
* @description
* Cancels a deferred task identified with `deferId`.
@@ -4344,14 +4635,15 @@ function $BrowserProvider(){
}
/**
- * @ngdoc object
- * @name ng.$cacheFactory
+ * @ngdoc service
+ * @name $cacheFactory
*
* @description
- * Factory that constructs cache objects and gives access to them.
- *
- * <pre>
- *
+ * Factory that constructs {@link $cacheFactory.Cache Cache} objects and gives access to
+ * them.
+ *
+ * ```js
+ *
* var cache = $cacheFactory('cacheId');
* expect($cacheFactory.get('cacheId')).toBe(cache);
* expect($cacheFactory.get('noSuchCacheId')).not.toBeDefined();
@@ -4360,9 +4652,9 @@ function $BrowserProvider(){
* cache.put("another key", "another value");
*
* // We've specified no options on creation
- * expect(cache.info()).toEqual({id: 'cacheId', size: 2});
- *
- * </pre>
+ * expect(cache.info()).toEqual({id: 'cacheId', size: 2});
+ *
+ * ```
*
*
* @param {string} cacheId Name or id of the newly created cache.
@@ -4380,6 +4672,46 @@ function $BrowserProvider(){
* - `{void}` `removeAll()` — Removes all cached values.
* - `{void}` `destroy()` — Removes references to this cache from $cacheFactory.
*
+ * @example
+ <example module="cacheExampleApp">
+ <file name="index.html">
+ <div ng-controller="CacheController">
+ <input ng-model="newCacheKey" placeholder="Key">
+ <input ng-model="newCacheValue" placeholder="Value">
+ <button ng-click="put(newCacheKey, newCacheValue)">Cache</button>
+
+ <p ng-if="keys.length">Cached Values</p>
+ <div ng-repeat="key in keys">
+ <span ng-bind="key"></span>
+ <span>: </span>
+ <b ng-bind="cache.get(key)"></b>
+ </div>
+
+ <p>Cache Info</p>
+ <div ng-repeat="(key, value) in cache.info()">
+ <span ng-bind="key"></span>
+ <span>: </span>
+ <b ng-bind="value"></b>
+ </div>
+ </div>
+ </file>
+ <file name="script.js">
+ angular.module('cacheExampleApp', []).
+ controller('CacheController', ['$scope', '$cacheFactory', function($scope, $cacheFactory) {
+ $scope.keys = [];
+ $scope.cache = $cacheFactory('cacheId');
+ $scope.put = function(key, value) {
+ $scope.cache.put(key, value);
+ $scope.keys.push(key);
+ };
+ }]);
+ </file>
+ <file name="style.css">
+ p {
+ margin: 10px 0 3px;
+ }
+ </file>
+ </example>
*/
function $CacheFactoryProvider() {
@@ -4399,12 +4731,71 @@ function $CacheFactoryProvider() {
freshEnd = null,
staleEnd = null;
+ /**
+ * @ngdoc type
+ * @name $cacheFactory.Cache
+ *
+ * @description
+ * A cache object used to store and retrieve data, primarily used by
+ * {@link $http $http} and the {@link ng.directive:script script} directive to cache
+ * templates and other data.
+ *
+ * ```js
+ * angular.module('superCache')
+ * .factory('superCache', ['$cacheFactory', function($cacheFactory) {
+ * return $cacheFactory('super-cache');
+ * }]);
+ * ```
+ *
+ * Example test:
+ *
+ * ```js
+ * it('should behave like a cache', inject(function(superCache) {
+ * superCache.put('key', 'value');
+ * superCache.put('another key', 'another value');
+ *
+ * expect(superCache.info()).toEqual({
+ * id: 'super-cache',
+ * size: 2
+ * });
+ *
+ * superCache.remove('another key');
+ * expect(superCache.get('another key')).toBeUndefined();
+ *
+ * superCache.removeAll();
+ * expect(superCache.info()).toEqual({
+ * id: 'super-cache',
+ * size: 0
+ * });
+ * }));
+ * ```
+ */
return caches[cacheId] = {
+ /**
+ * @ngdoc method
+ * @name $cacheFactory.Cache#put
+ * @function
+ *
+ * @description
+ * Inserts a named entry into the {@link $cacheFactory.Cache Cache} object to be
+ * retrieved later, and incrementing the size of the cache if the key was not already
+ * present in the cache. If behaving like an LRU cache, it will also remove stale
+ * entries from the set.
+ *
+ * It will not insert undefined values into the cache.
+ *
+ * @param {string} key the key under which the cached data is stored.
+ * @param {*} value the value to store alongside the key. If it is undefined, the key
+ * will not be stored.
+ * @returns {*} the value stored.
+ */
put: function(key, value) {
- var lruEntry = lruHash[key] || (lruHash[key] = {key: key});
+ if (capacity < Number.MAX_VALUE) {
+ var lruEntry = lruHash[key] || (lruHash[key] = {key: key});
- refresh(lruEntry);
+ refresh(lruEntry);
+ }
if (isUndefined(value)) return;
if (!(key in data)) size++;
@@ -4417,33 +4808,66 @@ function $CacheFactoryProvider() {
return value;
},
-
+ /**
+ * @ngdoc method
+ * @name $cacheFactory.Cache#get
+ * @function
+ *
+ * @description
+ * Retrieves named data stored in the {@link $cacheFactory.Cache Cache} object.
+ *
+ * @param {string} key the key of the data to be retrieved
+ * @returns {*} the value stored.
+ */
get: function(key) {
- var lruEntry = lruHash[key];
+ if (capacity < Number.MAX_VALUE) {
+ var lruEntry = lruHash[key];
- if (!lruEntry) return;
+ if (!lruEntry) return;
- refresh(lruEntry);
+ refresh(lruEntry);
+ }
return data[key];
},
+ /**
+ * @ngdoc method
+ * @name $cacheFactory.Cache#remove
+ * @function
+ *
+ * @description
+ * Removes an entry from the {@link $cacheFactory.Cache Cache} object.
+ *
+ * @param {string} key the key of the entry to be removed
+ */
remove: function(key) {
- var lruEntry = lruHash[key];
+ if (capacity < Number.MAX_VALUE) {
+ var lruEntry = lruHash[key];
+
+ if (!lruEntry) return;
- if (!lruEntry) return;
+ if (lruEntry == freshEnd) freshEnd = lruEntry.p;
+ if (lruEntry == staleEnd) staleEnd = lruEntry.n;
+ link(lruEntry.n,lruEntry.p);
- if (lruEntry == freshEnd) freshEnd = lruEntry.p;
- if (lruEntry == staleEnd) staleEnd = lruEntry.n;
- link(lruEntry.n,lruEntry.p);
+ delete lruHash[key];
+ }
- delete lruHash[key];
delete data[key];
size--;
},
+ /**
+ * @ngdoc method
+ * @name $cacheFactory.Cache#removeAll
+ * @function
+ *
+ * @description
+ * Clears the cache object of any entries.
+ */
removeAll: function() {
data = {};
size = 0;
@@ -4452,6 +4876,15 @@ function $CacheFactoryProvider() {
},
+ /**
+ * @ngdoc method
+ * @name $cacheFactory.Cache#destroy
+ * @function
+ *
+ * @description
+ * Destroys the {@link $cacheFactory.Cache Cache} object entirely,
+ * removing it from the {@link $cacheFactory $cacheFactory} set.
+ */
destroy: function() {
data = null;
stats = null;
@@ -4460,6 +4893,22 @@ function $CacheFactoryProvider() {
},
+ /**
+ * @ngdoc method
+ * @name $cacheFactory.Cache#info
+ * @function
+ *
+ * @description
+ * Retrieve information regarding a particular {@link $cacheFactory.Cache Cache}.
+ *
+ * @returns {object} an object with the following properties:
+ * <ul>
+ * <li>**id**: the id of the cache instance</li>
+ * <li>**size**: the number of entries kept in the cache instance</li>
+ * <li>**...**: any additional properties from the options object when creating the
+ * cache.</li>
+ * </ul>
+ */
info: function() {
return extend({}, stats, {size: size});
}
@@ -4499,8 +4948,7 @@ function $CacheFactoryProvider() {
/**
* @ngdoc method
- * @name ng.$cacheFactory#info
- * @methodOf ng.$cacheFactory
+ * @name $cacheFactory#info
*
* @description
* Get information about all the of the caches that have been created
@@ -4518,8 +4966,7 @@ function $CacheFactoryProvider() {
/**
* @ngdoc method
- * @name ng.$cacheFactory#get
- * @methodOf ng.$cacheFactory
+ * @name $cacheFactory#get
*
* @description
* Get access to a cache object by the `cacheId` used when it was created.
@@ -4537,48 +4984,44 @@ function $CacheFactoryProvider() {
}
/**
- * @ngdoc object
- * @name ng.$templateCache
+ * @ngdoc service
+ * @name $templateCache
*
* @description
* The first time a template is used, it is loaded in the template cache for quick retrieval. You
* can load templates directly into the cache in a `script` tag, or by consuming the
* `$templateCache` service directly.
- *
+ *
* Adding via the `script` tag:
- * <pre>
- * <html ng-app>
- * <head>
- * <script type="text/ng-template" id="templateId.html">
- * This is the content of the template
- * </script>
- * </head>
- * ...
- * </html>
- * </pre>
- *
+ *
+ * ```html
+ * <script type="text/ng-template" id="templateId.html">
+ * <p>This is the content of the template</p>
+ * </script>
+ * ```
+ *
* **Note:** the `script` tag containing the template does not need to be included in the `head` of
* the document, but it must be below the `ng-app` definition.
- *
+ *
* Adding via the $templateCache service:
- *
- * <pre>
+ *
+ * ```js
* var myApp = angular.module('myApp', []);
* myApp.run(function($templateCache) {
* $templateCache.put('templateId.html', 'This is the content of the template');
* });
- * </pre>
- *
+ * ```
+ *
* To retrieve the template later, simply use it in your HTML:
- * <pre>
+ * ```html
* <div ng-include=" 'templateId.html' "></div>
- * </pre>
- *
+ * ```
+ *
* or get it via Javascript:
- * <pre>
+ * ```js
* $templateCache.get('templateId.html')
- * </pre>
- *
+ * ```
+ *
* See {@link ng.$cacheFactory $cacheFactory}.
*
*/
@@ -4607,16 +5050,16 @@ function $TemplateCacheProvider() {
/**
- * @ngdoc function
- * @name ng.$compile
+ * @ngdoc service
+ * @name $compile
* @function
*
* @description
- * Compiles a piece of HTML string or DOM into a template and produces a template function, which
+ * Compiles an HTML string or DOM into a template and produces a template function, which
* can then be used to link {@link ng.$rootScope.Scope `scope`} and the template together.
*
* The compilation is a process of walking the DOM tree and matching DOM elements to
- * {@link ng.$compileProvider#methods_directive directives}.
+ * {@link ng.$compileProvider#directive directives}.
*
* <div class="alert alert-warning">
* **Note:** This document is an in-depth reference of all directive options.
@@ -4638,7 +5081,7 @@ function $TemplateCacheProvider() {
*
* Here's an example directive declared with a Directive Definition Object:
*
- * <pre>
+ * ```js
* var myModule = angular.module(...);
*
* myModule.directive('directiveName', function factory(injectables) {
@@ -4652,6 +5095,7 @@ function $TemplateCacheProvider() {
* restrict: 'A',
* scope: false,
* controller: function($scope, $element, $attrs, $transclude, otherInjectables) { ... },
+ * controllerAs: 'stringAlias',
* require: 'siblingDirectiveName', // or // ['^parentDirectiveName', '?optionalDirectiveName', '?^optionalParent'],
* compile: function compile(tElement, tAttrs, transclude) {
* return {
@@ -4671,7 +5115,7 @@ function $TemplateCacheProvider() {
* };
* return directiveDefinitionObject;
* });
- * </pre>
+ * ```
*
* <div class="alert alert-warning">
* **Note:** Any unspecified options will use the default value. You can see the default values below.
@@ -4679,7 +5123,7 @@ function $TemplateCacheProvider() {
*
* Therefore the above can be simplified as:
*
- * <pre>
+ * ```js
* var myModule = angular.module(...);
*
* myModule.directive('directiveName', function factory(injectables) {
@@ -4690,13 +5134,13 @@ function $TemplateCacheProvider() {
* // or
* // return function postLink(scope, iElement, iAttrs) { ... }
* });
- * </pre>
+ * ```
*
*
*
* ### Directive Definition Object
*
- * The directive definition object provides instructions to the {@link api/ng.$compile
+ * The directive definition object provides instructions to the {@link ng.$compile
* compiler}. The attributes are:
*
* #### `priority`
@@ -4780,7 +5224,7 @@ function $TemplateCacheProvider() {
* * (no prefix) - Locate the required controller on the current element. Throw an error if not found.
* * `?` - Attempt to locate the required controller or pass `null` to the `link` fn if not found.
* * `^` - Locate the required controller by searching the element's parents. Throw an error if not found.
- * * `?^` - Attempt to locate the required controller by searching the element's parentsor pass `null` to the
+ * * `?^` - Attempt to locate the required controller by searching the element's parents or pass `null` to the
* `link` fn if not found.
*
*
@@ -4819,7 +5263,7 @@ function $TemplateCacheProvider() {
* You can specify `templateUrl` as a string representing the URL or as a function which takes two
* arguments `tElement` and `tAttrs` (described in the `compile` function api below) and returns
* a string value representing the url. In either case, the template URL is passed through {@link
- * api/ng.$sce#methods_getTrustedResourceUrl $sce.getTrustedResourceUrl}.
+ * api/ng.$sce#getTrustedResourceUrl $sce.getTrustedResourceUrl}.
*
*
* #### `replace`
@@ -4831,7 +5275,7 @@ function $TemplateCacheProvider() {
*
* #### `transclude`
* compile the content of the element and make it available to the directive.
- * Typically used with {@link api/ng.directive:ngTransclude
+ * Typically used with {@link ng.directive:ngTransclude
* ngTransclude}. The advantage of transclusion is that the linking function receives a
* transclusion function which is pre-bound to the correct scope. In a typical setup the widget
* creates an `isolate` scope, but the transclusion is not a child, but a sibling of the `isolate`
@@ -4844,15 +5288,15 @@ function $TemplateCacheProvider() {
*
* #### `compile`
*
- * <pre>
+ * ```js
* function compile(tElement, tAttrs, transclude) { ... }
- * </pre>
+ * ```
*
* The compile function deals with transforming the template DOM. Since most directives do not do
* template transformation, it is not used often. Examples that require compile functions are
* directives that transform template DOM, such as {@link
* api/ng.directive:ngRepeat ngRepeat}, or load the contents
- * asynchronously, such as {@link api/ngRoute.directive:ngView ngView}. The
+ * asynchronously, such as {@link ngRoute.directive:ngView ngView}. The
* compile function takes the following arguments.
*
* * `tElement` - template element - The element where the directive has been declared. It is
@@ -4869,9 +5313,19 @@ function $TemplateCacheProvider() {
* apply to all cloned DOM nodes within the compile function. Specifically, DOM listener registration
* should be done in a linking function rather than in a compile function.
* </div>
+
+ * <div class="alert alert-warning">
+ * **Note:** The compile function cannot handle directives that recursively use themselves in their
+ * own templates or compile functions. Compiling these directives results in an infinite loop and a
+ * stack overflow errors.
+ *
+ * This can be avoided by manually using $compile in the postLink function to imperatively compile
+ * a directive's template instead of relying on automatic template compilation via `template` or
+ * `templateUrl` declaration or manual compilation inside the compile function.
+ * </div>
*
* <div class="alert alert-error">
- * **Note:** The `transclude` function that is passed to the compile function is deperecated, as it
+ * **Note:** The `transclude` function that is passed to the compile function is deprecated, as it
* e.g. does not know about the right outer scope. Please use the transclude function that is passed
* to the link function instead.
* </div>
@@ -4889,16 +5343,16 @@ function $TemplateCacheProvider() {
* #### `link`
* This property is used only if the `compile` property is not defined.
*
- * <pre>
+ * ```js
* function link(scope, iElement, iAttrs, controller, transcludeFn) { ... }
- * </pre>
+ * ```
*
* The link function is responsible for registering DOM listeners as well as updating the DOM. It is
* executed after the template has been cloned. This is where most of the directive logic will be
* put.
*
- * * `scope` - {@link api/ng.$rootScope.Scope Scope} - The scope to be used by the
- * directive for registering {@link api/ng.$rootScope.Scope#methods_$watch watches}.
+ * * `scope` - {@link ng.$rootScope.Scope Scope} - The scope to be used by the
+ * directive for registering {@link ng.$rootScope.Scope#$watch watches}.
*
* * `iElement` - instance element - The element where the directive is to be used. It is safe to
* manipulate the children of the element only in `postLink` function since the children have
@@ -4929,7 +5383,7 @@ function $TemplateCacheProvider() {
* <a name="Attributes"></a>
* ### Attributes
*
- * The {@link api/ng.$compile.directive.Attributes Attributes} object - passed as a parameter in the
+ * The {@link ng.$compile.directive.Attributes Attributes} object - passed as a parameter in the
* `link()` or `compile()` functions. It has a variety of uses.
*
* accessing *Normalized attribute names:*
@@ -4949,7 +5403,7 @@ function $TemplateCacheProvider() {
* the only way to easily get the actual value because during the linking phase the interpolation
* hasn't been evaluated yet and so the value is at this time set to `undefined`.
*
- * <pre>
+ * ```js
* function linkingFn(scope, elm, attrs, ctrl) {
* // get the attribute value
* console.log(attrs.ngModel);
@@ -4962,7 +5416,7 @@ function $TemplateCacheProvider() {
* console.log('ngModel has changed value to ' + value);
* });
* }
- * </pre>
+ * ```
*
* Below is an example using `$compileProvider`.
*
@@ -4971,8 +5425,8 @@ function $TemplateCacheProvider() {
* to illustrate how `$compile` works.
* </div>
*
- <doc:example module="compile">
- <doc:source>
+ <example module="compile">
+ <file name="index.html">
<script>
angular.module('compile', [], function($compileProvider) {
// configure new 'compile' directive by passing a directive
@@ -5011,23 +5465,27 @@ function $TemplateCacheProvider() {
<textarea ng-model="html"></textarea> <br>
<div compile="html"></div>
</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should auto compile', function() {
- expect(element('div[compile]').text()).toBe('Hello Angular');
- input('html').enter('{{name}}!');
- expect(element('div[compile]').text()).toBe('Angular!');
+ var textarea = $('textarea');
+ var output = $('div[compile]');
+ // The initial state reads 'Hello Angular'.
+ expect(output.getText()).toBe('Hello Angular');
+ textarea.clear();
+ textarea.sendKeys('{{name}}!');
+ expect(output.getText()).toBe('Angular!');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*
*
* @param {string|DOMElement} element Element or HTML string to compile into a template function.
- * @param {function(angular.Scope[, cloneAttachFn]} transclude function available to directives.
- * @param {number} maxPriority only apply directives lower then given priority (Only effects the
+ * @param {function(angular.Scope, cloneAttachFn=)} transclude function available to directives.
+ * @param {number} maxPriority only apply directives lower than given priority (Only effects the
* root element(s), not their children)
- * @returns {function(scope[, cloneAttachFn])} a link function which is used to bind template
+ * @returns {function(scope, cloneAttachFn=)} a link function which is used to bind template
* (a DOM element/tree) to a scope. Where:
*
* * `scope` - A {@link ng.$rootScope.Scope Scope} to bind to.
@@ -5049,23 +5507,23 @@ function $TemplateCacheProvider() {
*
* - If you are not asking the linking function to clone the template, create the DOM element(s)
* before you send them to the compiler and keep this reference around.
- * <pre>
+ * ```js
* var element = $compile('<p>{{total}}</p>')(scope);
- * </pre>
+ * ```
*
* - if on the other hand, you need the element to be cloned, the view reference from the original
* example would not point to the clone, but rather to the original template that was cloned. In
* this case, you can access the clone via the cloneAttachFn:
- * <pre>
- * var templateHTML = angular.element('<p>{{total}}</p>'),
+ * ```js
+ * var templateElement = angular.element('<p>{{total}}</p>'),
* scope = ....;
*
- * var clonedElement = $compile(templateHTML)(scope, function(clonedElement, scope) {
+ * var clonedElement = $compile(templateElement)(scope, function(clonedElement, scope) {
* //attach the clone to DOM document at the right place
* });
*
- * //now we have reference to the cloned DOM via `clone`
- * </pre>
+ * //now we have reference to the cloned DOM via `clonedElement`
+ * ```
*
*
* For information on how the compiler works, see the
@@ -5075,20 +5533,18 @@ function $TemplateCacheProvider() {
var $compileMinErr = minErr('$compile');
/**
- * @ngdoc service
- * @name ng.$compileProvider
+ * @ngdoc provider
+ * @name $compileProvider
* @function
*
* @description
*/
-$CompileProvider.$inject = ['$provide'];
-function $CompileProvider($provide) {
+$CompileProvider.$inject = ['$provide', '$$sanitizeUriProvider'];
+function $CompileProvider($provide, $$sanitizeUriProvider) {
var hasDirectives = {},
Suffix = 'Directive',
COMMENT_DIRECTIVE_REGEXP = /^\s*directive\:\s*([\d\w\-_]+)\s+(.*)$/,
- CLASS_DIRECTIVE_REGEXP = /(([\d\w\-_]+)(?:\:([^;]+))?;?)/,
- aHrefSanitizationWhitelist = /^\s*(https?|ftp|mailto|tel|file):/,
- imgSrcSanitizationWhitelist = /^\s*(https?|ftp|file):|data:image\//;
+ CLASS_DIRECTIVE_REGEXP = /(([\d\w\-_]+)(?:\:([^;]+))?;?)/;
// Ref: http://developers.whatwg.org/webappapis.html#event-handler-idl-attributes
// The assumption is that future DOM event attribute names will begin with
@@ -5096,9 +5552,8 @@ function $CompileProvider($provide) {
var EVENT_HANDLER_ATTR_REGEXP = /^(on[a-z]+|formaction)$/;
/**
- * @ngdoc function
- * @name ng.$compileProvider#directive
- * @methodOf ng.$compileProvider
+ * @ngdoc method
+ * @name $compileProvider#directive
* @function
*
* @description
@@ -5107,7 +5562,7 @@ function $CompileProvider($provide) {
* @param {string|Object} name Name of the directive in camel-case (i.e. <code>ngBind</code> which
* will match as <code>ng-bind</code>), or an object map of directives where the keys are the
* names and the values are the factories.
- * @param {function|Array} directiveFactory An injectable directive factory function. See
+ * @param {Function|Array} directiveFactory An injectable directive factory function. See
* {@link guide/directive} for more info.
* @returns {ng.$compileProvider} Self for chaining.
*/
@@ -5150,9 +5605,8 @@ function $CompileProvider($provide) {
/**
- * @ngdoc function
- * @name ng.$compileProvider#aHrefSanitizationWhitelist
- * @methodOf ng.$compileProvider
+ * @ngdoc method
+ * @name $compileProvider#aHrefSanitizationWhitelist
* @function
*
* @description
@@ -5172,17 +5626,17 @@ function $CompileProvider($provide) {
*/
this.aHrefSanitizationWhitelist = function(regexp) {
if (isDefined(regexp)) {
- aHrefSanitizationWhitelist = regexp;
+ $$sanitizeUriProvider.aHrefSanitizationWhitelist(regexp);
return this;
+ } else {
+ return $$sanitizeUriProvider.aHrefSanitizationWhitelist();
}
- return aHrefSanitizationWhitelist;
};
/**
- * @ngdoc function
- * @name ng.$compileProvider#imgSrcSanitizationWhitelist
- * @methodOf ng.$compileProvider
+ * @ngdoc method
+ * @name $compileProvider#imgSrcSanitizationWhitelist
* @function
*
* @description
@@ -5202,18 +5656,18 @@ function $CompileProvider($provide) {
*/
this.imgSrcSanitizationWhitelist = function(regexp) {
if (isDefined(regexp)) {
- imgSrcSanitizationWhitelist = regexp;
+ $$sanitizeUriProvider.imgSrcSanitizationWhitelist(regexp);
return this;
+ } else {
+ return $$sanitizeUriProvider.imgSrcSanitizationWhitelist();
}
- return imgSrcSanitizationWhitelist;
};
-
this.$get = [
'$injector', '$interpolate', '$exceptionHandler', '$http', '$templateCache', '$parse',
- '$controller', '$rootScope', '$document', '$sce', '$animate',
+ '$controller', '$rootScope', '$document', '$sce', '$animate', '$$sanitizeUri',
function($injector, $interpolate, $exceptionHandler, $http, $templateCache, $parse,
- $controller, $rootScope, $document, $sce, $animate) {
+ $controller, $rootScope, $document, $sce, $animate, $$sanitizeUri) {
var Attributes = function(element, attr) {
this.$$element = element;
@@ -5225,9 +5679,8 @@ function $CompileProvider($provide) {
/**
- * @ngdoc function
- * @name ng.$compile.directive.Attributes#$addClass
- * @methodOf ng.$compile.directive.Attributes
+ * @ngdoc method
+ * @name $compile.directive.Attributes#$addClass
* @function
*
* @description
@@ -5243,9 +5696,8 @@ function $CompileProvider($provide) {
},
/**
- * @ngdoc function
- * @name ng.$compile.directive.Attributes#$removeClass
- * @methodOf ng.$compile.directive.Attributes
+ * @ngdoc method
+ * @name $compile.directive.Attributes#$removeClass
* @function
*
* @description
@@ -5261,6 +5713,31 @@ function $CompileProvider($provide) {
},
/**
+ * @ngdoc method
+ * @name $compile.directive.Attributes#$updateClass
+ * @function
+ *
+ * @description
+ * Adds and removes the appropriate CSS class values to the element based on the difference
+ * between the new and old CSS class values (specified as newClasses and oldClasses).
+ *
+ * @param {string} newClasses The current CSS className value
+ * @param {string} oldClasses The former CSS className value
+ */
+ $updateClass : function(newClasses, oldClasses) {
+ var toAdd = tokenDifference(newClasses, oldClasses);
+ var toRemove = tokenDifference(oldClasses, newClasses);
+
+ if(toAdd.length === 0) {
+ $animate.removeClass(this.$$element, toRemove);
+ } else if(toRemove.length === 0) {
+ $animate.addClass(this.$$element, toAdd);
+ } else {
+ $animate.setClass(this.$$element, toAdd, toRemove);
+ }
+ },
+
+ /**
* Set a normalized attribute on the element in a way such that all directives
* can share the attribute. This function properly handles boolean attributes.
* @param {string} key Normalized key. (ie ngAttribute)
@@ -5270,59 +5747,44 @@ function $CompileProvider($provide) {
* @param {string=} attrName Optional none normalized name. Defaults to key.
*/
$set: function(key, value, writeAttr, attrName) {
- //special case for class attribute addition + removal
- //so that class changes can tap into the animation
- //hooks provided by the $animate service
- if(key == 'class') {
- value = value || '';
- var current = this.$$element.attr('class') || '';
- this.$removeClass(tokenDifference(current, value).join(' '));
- this.$addClass(tokenDifference(value, current).join(' '));
- } else {
- var booleanKey = getBooleanAttrName(this.$$element[0], key),
- normalizedVal,
- nodeName;
+ // TODO: decide whether or not to throw an error if "class"
+ //is set through this function since it may cause $updateClass to
+ //become unstable.
- if (booleanKey) {
- this.$$element.prop(key, value);
- attrName = booleanKey;
- }
+ var booleanKey = getBooleanAttrName(this.$$element[0], key),
+ normalizedVal,
+ nodeName;
- this[key] = value;
+ if (booleanKey) {
+ this.$$element.prop(key, value);
+ attrName = booleanKey;
+ }
- // translate normalized key to actual key
- if (attrName) {
- this.$attr[key] = attrName;
- } else {
- attrName = this.$attr[key];
- if (!attrName) {
- this.$attr[key] = attrName = snake_case(key, '-');
- }
- }
+ this[key] = value;
- nodeName = nodeName_(this.$$element);
-
- // sanitize a[href] and img[src] values
- if ((nodeName === 'A' && key === 'href') ||
- (nodeName === 'IMG' && key === 'src')) {
- // NOTE: urlResolve() doesn't support IE < 8 so we don't sanitize for that case.
- if (!msie || msie >= 8 ) {
- normalizedVal = urlResolve(value).href;
- if (normalizedVal !== '') {
- if ((key === 'href' && !normalizedVal.match(aHrefSanitizationWhitelist)) ||
- (key === 'src' && !normalizedVal.match(imgSrcSanitizationWhitelist))) {
- this[key] = value = 'unsafe:' + normalizedVal;
- }
- }
- }
+ // translate normalized key to actual key
+ if (attrName) {
+ this.$attr[key] = attrName;
+ } else {
+ attrName = this.$attr[key];
+ if (!attrName) {
+ this.$attr[key] = attrName = snake_case(key, '-');
}
+ }
- if (writeAttr !== false) {
- if (value === null || value === undefined) {
- this.$$element.removeAttr(attrName);
- } else {
- this.$$element.attr(attrName, value);
- }
+ nodeName = nodeName_(this.$$element);
+
+ // sanitize a[href] and img[src] values
+ if ((nodeName === 'A' && key === 'href') ||
+ (nodeName === 'IMG' && key === 'src')) {
+ this[key] = value = $$sanitizeUri(value, key === 'src');
+ }
+
+ if (writeAttr !== false) {
+ if (value === null || value === undefined) {
+ this.$$element.removeAttr(attrName);
+ } else {
+ this.$$element.attr(attrName, value);
}
}
@@ -5335,29 +5797,12 @@ function $CompileProvider($provide) {
$exceptionHandler(e);
}
});
-
- function tokenDifference(str1, str2) {
- var values = [],
- tokens1 = str1.split(/\s+/),
- tokens2 = str2.split(/\s+/);
-
- outer:
- for(var i=0;i<tokens1.length;i++) {
- var token = tokens1[i];
- for(var j=0;j<tokens2.length;j++) {
- if(token == tokens2[j]) continue outer;
- }
- values.push(token);
- }
- return values;
- }
},
/**
- * @ngdoc function
- * @name ng.$compile.directive.Attributes#$observe
- * @methodOf ng.$compile.directive.Attributes
+ * @ngdoc method
+ * @name $compile.directive.Attributes#$observe
* @function
*
* @description
@@ -5420,6 +5865,7 @@ function $CompileProvider($provide) {
var compositeLinkFn =
compileNodes($compileNodes, transcludeFn, $compileNodes,
maxPriority, ignoreDirective, previousCompileContext);
+ safeAddClass($compileNodes, 'ng-scope');
return function publicLinkFn(scope, cloneConnectFn, transcludeControllers){
assertArg(scope, 'scope');
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
@@ -5434,12 +5880,13 @@ function $CompileProvider($provide) {
// Attach scope only to non-text nodes.
for(var i = 0, ii = $linkNode.length; i<ii; i++) {
- var node = $linkNode[i];
- if (node.nodeType == 1 /* element */ || node.nodeType == 9 /* document */) {
+ var node = $linkNode[i],
+ nodeType = node.nodeType;
+ if (nodeType === 1 /* element */ || nodeType === 9 /* document */) {
$linkNode.eq(i).data('$scope', scope);
}
}
- safeAddClass($linkNode, 'ng-scope');
+
if (cloneConnectFn) cloneConnectFn($linkNode, scope);
if (compositeLinkFn) compositeLinkFn(scope, $linkNode, $linkNode);
return $linkNode;
@@ -5462,20 +5909,20 @@ function $CompileProvider($provide) {
* function, which is the a linking function for the node.
*
* @param {NodeList} nodeList an array of nodes or NodeList to compile
- * @param {function(angular.Scope[, cloneAttachFn]} transcludeFn A linking function, where the
+ * @param {function(angular.Scope, cloneAttachFn=)} transcludeFn A linking function, where the
* scope argument is auto-generated to the new child of the transcluded parent scope.
* @param {DOMElement=} $rootElement If the nodeList is the root of the compilation tree then
* the rootElement must be set the jqLite collection of the compile root. This is
* needed so that the jqLite collection items can be replaced with widgets.
- * @param {number=} max directive priority
- * @returns {?function} A composite linking function of all of the matched directives or null.
+ * @param {number=} maxPriority Max directive priority.
+ * @returns {Function} A composite linking function of all of the matched directives or null.
*/
function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective,
previousCompileContext) {
var linkFns = [],
- nodeLinkFn, childLinkFn, directives, attrs, linkFnFound;
+ attrs, directives, nodeLinkFn, childNodes, childLinkFn, linkFnFound;
- for(var i = 0; i < nodeList.length; i++) {
+ for (var i = 0; i < nodeList.length; i++) {
attrs = new Attributes();
// we must always refer to nodeList[i] since the nodes can be replaced underneath us.
@@ -5487,16 +5934,19 @@ function $CompileProvider($provide) {
null, [], [], previousCompileContext)
: null;
+ if (nodeLinkFn && nodeLinkFn.scope) {
+ safeAddClass(jqLite(nodeList[i]), 'ng-scope');
+ }
+
childLinkFn = (nodeLinkFn && nodeLinkFn.terminal ||
- !nodeList[i].childNodes ||
- !nodeList[i].childNodes.length)
+ !(childNodes = nodeList[i].childNodes) ||
+ !childNodes.length)
? null
- : compileNodes(nodeList[i].childNodes,
+ : compileNodes(childNodes,
nodeLinkFn ? nodeLinkFn.transclude : transcludeFn);
- linkFns.push(nodeLinkFn);
- linkFns.push(childLinkFn);
- linkFnFound = (linkFnFound || nodeLinkFn || childLinkFn);
+ linkFns.push(nodeLinkFn, childLinkFn);
+ linkFnFound = linkFnFound || nodeLinkFn || childLinkFn;
//use the previous context only for the first element in the virtual group
previousCompileContext = null;
}
@@ -5508,9 +5958,10 @@ function $CompileProvider($provide) {
var nodeLinkFn, childLinkFn, node, $node, childScope, childTranscludeFn, i, ii, n;
// copy nodeList so that linking doesn't break due to live list updates.
- var stableNodeList = [];
- for (i = 0, ii = nodeList.length; i < ii; i++) {
- stableNodeList.push(nodeList[i]);
+ var nodeListLength = nodeList.length,
+ stableNodeList = new Array(nodeListLength);
+ for (i = 0; i < nodeListLength; i++) {
+ stableNodeList[i] = nodeList[i];
}
for(i = 0, n = 0, ii = linkFns.length; i < ii; n++) {
@@ -5523,7 +5974,6 @@ function $CompileProvider($provide) {
if (nodeLinkFn.scope) {
childScope = scope.$new();
$node.data('$scope', childScope);
- safeAddClass($node, 'ng-scope');
} else {
childScope = scope;
}
@@ -5533,7 +5983,7 @@ function $CompileProvider($provide) {
createBoundTranscludeFn(scope, childTranscludeFn || transcludeFn)
);
} else {
- nodeLinkFn(childLinkFn, childScope, node, undefined, boundTranscludeFn);
+ nodeLinkFn(childLinkFn, childScope, node, $rootElement, boundTranscludeFn);
}
} else if (childLinkFn) {
childLinkFn(scope, node.childNodes, undefined, boundTranscludeFn);
@@ -5606,9 +6056,7 @@ function $CompileProvider($provide) {
nName = directiveNormalize(name.toLowerCase());
attrsMap[nName] = name;
- attrs[nName] = value = trim((msie && name == 'href')
- ? decodeURIComponent(node.getAttribute(name, 2))
- : attr.value);
+ attrs[nName] = value = trim(attr.value);
if (getBooleanAttrName(node, nName)) {
attrs[nName] = true; // presence means true
}
@@ -5711,7 +6159,7 @@ function $CompileProvider($provide) {
* this needs to be pre-sorted by priority order.
* @param {Node} compileNode The raw DOM node to apply the compile functions to
* @param {Object} templateAttrs The shared attribute function
- * @param {function(angular.Scope[, cloneAttachFn]} transcludeFn A linking function, where the
+ * @param {function(angular.Scope, cloneAttachFn=)} transcludeFn A linking function, where the
* scope argument is auto-generated to the new
* child of the transcluded parent scope.
* @param {JQLite} jqCollection If we are working on the root of the compile tree then this
@@ -5723,7 +6171,7 @@ function $CompileProvider($provide) {
* @param {Array.<Function>} postLinkFns
* @param {Object} previousCompileContext Context used for previous compilation of the current
* node
- * @returns linkFn
+ * @returns {Function} linkFn
*/
function applyDirectivesToNode(directives, compileNode, templateAttrs, transcludeFn,
jqCollection, originalReplaceDirective, preLinkFns, postLinkFns,
@@ -5737,7 +6185,7 @@ function $CompileProvider($provide) {
templateDirective = previousCompileContext.templateDirective,
nonTlbTranscludeDirective = previousCompileContext.nonTlbTranscludeDirective,
hasTranscludeDirective = false,
- hasElementTranscludeDirective = false,
+ hasElementTranscludeDirective = previousCompileContext.hasElementTranscludeDirective,
$compileNode = templateAttrs.$$element = jqLite(compileNode),
directive,
directiveName,
@@ -5791,7 +6239,7 @@ function $CompileProvider($provide) {
hasTranscludeDirective = true;
// Special case ngIf and ngRepeat so that we don't complain about duplicate transclusion.
- // This option should only be used by directives that know how to how to safely handle element transclusion,
+ // This option should only be used by directives that know how to safely handle element transclusion,
// where the transcluded nodes are added or replaced after linking.
if (!directive.$$tlb) {
assertNoDuplicate('transclusion', nonTlbTranscludeDirective, directive, $compileNode);
@@ -5821,7 +6269,7 @@ function $CompileProvider($provide) {
});
} else {
$template = jqLite(jqLiteClone(compileNode)).contents();
- $compileNode.html(''); // clear contents
+ $compileNode.empty(); // clear contents
childTranscludeFn = compile($template, transcludeFn);
}
}
@@ -5838,9 +6286,11 @@ function $CompileProvider($provide) {
if (directive.replace) {
replaceDirective = directive;
- $template = jqLite('<div>' +
- trim(directiveValue) +
- '</div>').contents();
+ if (jqLiteIsTextNode(directiveValue)) {
+ $template = [];
+ } else {
+ $template = jqLite(directiveValue);
+ }
compileNode = $template[0];
if ($template.length != 1 || compileNode.nodeType !== 1) {
@@ -5911,6 +6361,7 @@ function $CompileProvider($provide) {
nodeLinkFn.scope = newScopeDirective && newScopeDirective.scope === true;
nodeLinkFn.transclude = hasTranscludeDirective && childTranscludeFn;
+ previousCompileContext.hasElementTranscludeDirective = hasElementTranscludeDirective;
// might be normal or delayed nodeLinkFn depending on if templateUrl is present
return nodeLinkFn;
@@ -6002,7 +6453,7 @@ function $CompileProvider($provide) {
optional = (match[2] == '?'),
mode = match[1], // @, =, or &
lastValue,
- parentGet, parentSet;
+ parentGet, parentSet, compare;
isolateScope.$$isolateBindings[scopeName] = mode + attrName;
@@ -6025,6 +6476,11 @@ function $CompileProvider($provide) {
return;
}
parentGet = $parse(attrs[attrName]);
+ if (parentGet.literal) {
+ compare = equals;
+ } else {
+ compare = function(a,b) { return a === b; };
+ }
parentSet = parentGet.assign || function() {
// reset the change, or we will throw this exception on every $digest
lastValue = isolateScope[scopeName] = parentGet(scope);
@@ -6035,19 +6491,18 @@ function $CompileProvider($provide) {
lastValue = isolateScope[scopeName] = parentGet(scope);
isolateScope.$watch(function parentValueWatch() {
var parentValue = parentGet(scope);
-
- if (parentValue !== isolateScope[scopeName]) {
+ if (!compare(parentValue, isolateScope[scopeName])) {
// we are out of sync and need to copy
- if (parentValue !== lastValue) {
+ if (!compare(parentValue, lastValue)) {
// parent changed and it has precedence
- lastValue = isolateScope[scopeName] = parentValue;
+ isolateScope[scopeName] = parentValue;
} else {
// if the parent can be assigned then do so
- parentSet(scope, parentValue = lastValue = isolateScope[scopeName]);
+ parentSet(scope, parentValue = isolateScope[scopeName]);
}
}
- return parentValue;
- });
+ return lastValue = parentValue;
+ }, null, parentGet.literal);
break;
case '&':
@@ -6166,7 +6621,7 @@ function $CompileProvider($provide) {
* * `A': attribute
* * `C`: class
* * `M`: comment
- * @returns true if directive was added.
+ * @returns {boolean} true if directive was added.
*/
function addDirective(tDirectives, name, location, maxPriority, ignoreDirective, startAttrName,
endAttrName) {
@@ -6249,7 +6704,7 @@ function $CompileProvider($provide) {
? origAsyncDirective.templateUrl($compileNode, tAttrs)
: origAsyncDirective.templateUrl;
- $compileNode.html('');
+ $compileNode.empty();
$http.get($sce.getTrustedResourceUrl(templateUrl), {cache: $templateCache}).
success(function(content) {
@@ -6258,7 +6713,11 @@ function $CompileProvider($provide) {
content = denormalizeTemplate(content);
if (origAsyncDirective.replace) {
- $template = jqLite('<div>' + trim(content) + '</div>').contents();
+ if (jqLiteIsTextNode(content)) {
+ $template = [];
+ } else {
+ $template = jqLite(content);
+ }
compileNode = $template[0];
if ($template.length != 1 || compileNode.nodeType !== 1) {
@@ -6302,9 +6761,18 @@ function $CompileProvider($provide) {
linkNode = $compileNode[0];
if (beforeTemplateLinkNode !== beforeTemplateCompileNode) {
- // it was cloned therefore we have to clone as well.
- linkNode = jqLiteClone(compileNode);
+ var oldClasses = beforeTemplateLinkNode.className;
+
+ if (!(previousCompileContext.hasElementTranscludeDirective &&
+ origAsyncDirective.replace)) {
+ // it was cloned therefore we have to clone as well.
+ linkNode = jqLiteClone(compileNode);
+ }
+
replaceWith(linkRootElement, jqLite(beforeTemplateLinkNode), linkNode);
+
+ // Copy in CSS classes from original node
+ safeAddClass(jqLite(linkNode), oldClasses);
}
if (afterTemplateNodeLinkFn.transclude) {
childBoundTranscludeFn = createBoundTranscludeFn(scope, afterTemplateNodeLinkFn.transclude);
@@ -6372,10 +6840,15 @@ function $CompileProvider($provide) {
function getTrustedContext(node, attrNormalizedName) {
+ if (attrNormalizedName == "srcdoc") {
+ return $sce.HTML;
+ }
+ var tag = nodeName_(node);
// maction[xlink:href] can source SVG. It's not limited to <maction>.
if (attrNormalizedName == "xlinkHref" ||
- (nodeName_(node) != "IMG" && (attrNormalizedName == "src" ||
- attrNormalizedName == "ngSrc"))) {
+ (tag == "FORM" && attrNormalizedName == "action") ||
+ (tag != "IMG" && (attrNormalizedName == "src" ||
+ attrNormalizedName == "ngSrc"))) {
return $sce.RESOURCE_URL;
}
}
@@ -6420,9 +6893,19 @@ function $CompileProvider($provide) {
attr[name] = interpolateFn(scope);
($$observers[name] || ($$observers[name] = [])).$$inter = true;
(attr.$$observers && attr.$$observers[name].$$scope || scope).
- $watch(interpolateFn, function interpolateFnWatchAction(value) {
- attr.$set(name, value);
- });
+ $watch(interpolateFn, function interpolateFnWatchAction(newValue, oldValue) {
+ //special case for class attribute addition + removal
+ //so that class changes can tap into the animation
+ //hooks provided by the $animate service. Be sure to
+ //skip animations when the first digest occurs (when
+ //both the new and the old values are the same) since
+ //the CSS classes are the non-interpolated values
+ if(name === 'class' && newValue != oldValue) {
+ attr.$updateClass(newValue, oldValue);
+ } else {
+ attr.$set(name, newValue);
+ }
+ });
}
};
}
@@ -6506,8 +6989,8 @@ function directiveNormalize(name) {
}
/**
- * @ngdoc object
- * @name ng.$compile.directive.Attributes
+ * @ngdoc type
+ * @name $compile.directive.Attributes
*
* @description
* A shared object between directive compile / linking functions which contains normalized DOM
@@ -6519,17 +7002,15 @@ function directiveNormalize(name) {
/**
* @ngdoc property
- * @name ng.$compile.directive.Attributes#$attr
- * @propertyOf ng.$compile.directive.Attributes
+ * @name $compile.directive.Attributes#$attr
* @returns {object} A map of DOM element attribute names to the normalized name. This is
* needed to do reverse lookup from normalized name back to actual name.
*/
/**
- * @ngdoc function
- * @name ng.$compile.directive.Attributes#$set
- * @methodOf ng.$compile.directive.Attributes
+ * @ngdoc method
+ * @name $compile.directive.Attributes#$set
* @function
*
* @description
@@ -6537,7 +7018,7 @@ function directiveNormalize(name) {
*
*
* @param {string} name Normalized element attribute name of the property to modify. The name is
- * revers translated using the {@link ng.$compile.directive.Attributes#$attr $attr}
+ * reverse-translated using the {@link ng.$compile.directive.Attributes#$attr $attr}
* property to the original name.
* @param {string} value Value to set the attribute to. The value can be an interpolated string.
*/
@@ -6563,15 +7044,31 @@ function directiveLinkingFn(
/* function(Function) */ boundTranscludeFn
){}
+function tokenDifference(str1, str2) {
+ var values = '',
+ tokens1 = str1.split(/\s+/),
+ tokens2 = str2.split(/\s+/);
+
+ outer:
+ for(var i = 0; i < tokens1.length; i++) {
+ var token = tokens1[i];
+ for(var j = 0; j < tokens2.length; j++) {
+ if(token == tokens2[j]) continue outer;
+ }
+ values += (values.length > 0 ? ' ' : '') + token;
+ }
+ return values;
+}
+
/**
- * @ngdoc object
- * @name ng.$controllerProvider
+ * @ngdoc provider
+ * @name $controllerProvider
* @description
* The {@link ng.$controller $controller service} is used by Angular to create new
* controllers.
*
* This provider allows controller registration via the
- * {@link ng.$controllerProvider#methods_register register} method.
+ * {@link ng.$controllerProvider#register register} method.
*/
function $ControllerProvider() {
var controllers = {},
@@ -6579,9 +7076,8 @@ function $ControllerProvider() {
/**
- * @ngdoc function
- * @name ng.$controllerProvider#register
- * @methodOf ng.$controllerProvider
+ * @ngdoc method
+ * @name $controllerProvider#register
* @param {string|Object} name Controller name, or an object map of controllers where the keys are
* the names and the values are the constructors.
* @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI
@@ -6600,8 +7096,8 @@ function $ControllerProvider() {
this.$get = ['$injector', '$window', function($injector, $window) {
/**
- * @ngdoc function
- * @name ng.$controller
+ * @ngdoc service
+ * @name $controller
* @requires $injector
*
* @param {Function|string} constructor If called with a function then it's considered to be the
@@ -6618,9 +7114,8 @@ function $ControllerProvider() {
* @description
* `$controller` service is responsible for instantiating controllers.
*
- * It's just a simple call to {@link AUTO.$injector $injector}, but extracted into
- * a service, so that one can override this service with {@link https://gist.github.com/1649788
- * BC version}.
+ * It's just a simple call to {@link auto.$injector $injector}, but extracted into
+ * a service, so that one can override this service with [BC version](https://gist.github.com/1649788).
*/
return function(expression, locals) {
var instance, match, constructor, identifier;
@@ -6654,13 +7149,28 @@ function $ControllerProvider() {
}
/**
- * @ngdoc object
- * @name ng.$document
+ * @ngdoc service
+ * @name $document
* @requires $window
*
* @description
- * A {@link angular.element jQuery (lite)}-wrapped reference to the browser's `window.document`
- * element.
+ * A {@link angular.element jQuery or jqLite} wrapper for the browser's `window.document` object.
+ *
+ * @example
+ <example>
+ <file name="index.html">
+ <div ng-controller="MainCtrl">
+ <p>$document title: <b ng-bind="title"></b></p>
+ <p>window.document title: <b ng-bind="windowTitle"></b></p>
+ </div>
+ </file>
+ <file name="script.js">
+ function MainCtrl($scope, $document) {
+ $scope.title = $document[0].title;
+ $scope.windowTitle = angular.element(window.document)[0].title;
+ }
+ </file>
+ </example>
*/
function $DocumentProvider(){
this.$get = ['$window', function(window){
@@ -6669,29 +7179,29 @@ function $DocumentProvider(){
}
/**
- * @ngdoc function
- * @name ng.$exceptionHandler
- * @requires $log
+ * @ngdoc service
+ * @name $exceptionHandler
+ * @requires ng.$log
*
* @description
* Any uncaught exception in angular expressions is delegated to this service.
* The default implementation simply delegates to `$log.error` which logs it into
* the browser console.
- *
+ *
* In unit tests, if `angular-mocks.js` is loaded, this service is overridden by
* {@link ngMock.$exceptionHandler mock $exceptionHandler} which aids in testing.
*
* ## Example:
- *
- * <pre>
+ *
+ * ```js
* angular.module('exceptionOverride', []).factory('$exceptionHandler', function () {
* return function (exception, cause) {
* exception.message += ' (caused by "' + cause + '")';
* throw exception;
* };
* });
- * </pre>
- *
+ * ```
+ *
* This example will override the normal action of `$exceptionHandler`, to make angular
* exceptions fail hard when they happen, instead of just logging to the console.
*
@@ -6771,7 +7281,7 @@ function headersGetter(headers) {
*
* @param {*} data Data to transform.
* @param {function(string=)} headers Http headers getter fn.
- * @param {(function|Array.<function>)} fns Function or an array of functions.
+ * @param {(Function|Array.<Function>)} fns Function or an array of functions.
* @returns {*} Transformed data.
*/
function transformData(data, headers, fns) {
@@ -6811,7 +7321,7 @@ function $HttpProvider() {
// transform outgoing request data
transformRequest: [function(d) {
- return isObject(d) && !isFile(d) ? toJson(d) : d;
+ return isObject(d) && !isFile(d) && !isBlob(d) ? toJson(d) : d;
}],
// default headers
@@ -6819,9 +7329,9 @@ function $HttpProvider() {
common: {
'Accept': 'application/json, text/plain, */*'
},
- post: CONTENT_TYPE_APPLICATION_JSON,
- put: CONTENT_TYPE_APPLICATION_JSON,
- patch: CONTENT_TYPE_APPLICATION_JSON
+ post: copy(CONTENT_TYPE_APPLICATION_JSON),
+ put: copy(CONTENT_TYPE_APPLICATION_JSON),
+ patch: copy(CONTENT_TYPE_APPLICATION_JSON)
},
xsrfCookieName: 'XSRF-TOKEN',
@@ -6879,10 +7389,10 @@ function $HttpProvider() {
/**
- * @ngdoc function
- * @name ng.$http
- * @requires $httpBackend
- * @requires $browser
+ * @ngdoc service
+ * @kind function
+ * @name $http
+ * @requires ng.$httpBackend
* @requires $cacheFactory
* @requires $rootScope
* @requires $q
@@ -6890,8 +7400,8 @@ function $HttpProvider() {
*
* @description
* The `$http` service is a core Angular service that facilitates communication with the remote
- * HTTP servers via the browser's {@link https://developer.mozilla.org/en/xmlhttprequest
- * XMLHttpRequest} object or via {@link http://en.wikipedia.org/wiki/JSONP JSONP}.
+ * HTTP servers via the browser's [XMLHttpRequest](https://developer.mozilla.org/en/xmlhttprequest)
+ * object or via [JSONP](http://en.wikipedia.org/wiki/JSONP).
*
* For unit testing applications that use `$http` service, see
* {@link ngMock.$httpBackend $httpBackend mock}.
@@ -6909,7 +7419,7 @@ function $HttpProvider() {
* that is used to generate an HTTP request and returns a {@link ng.$q promise}
* with two $http specific methods: `success` and `error`.
*
- * <pre>
+ * ```js
* $http({method: 'GET', url: '/someUrl'}).
* success(function(data, status, headers, config) {
* // this callback will be called asynchronously
@@ -6919,7 +7429,7 @@ function $HttpProvider() {
* // called asynchronously if an error occurs
* // or server returns response with an error status.
* });
- * </pre>
+ * ```
*
* Since the returned value of calling the $http function is a `promise`, you can also use
* the `then` method to register callbacks, and these callbacks will receive a single argument –
@@ -6930,54 +7440,36 @@ function $HttpProvider() {
* will result in the success callback being called. Note that if the response is a redirect,
* XMLHttpRequest will transparently follow it, meaning that the error callback will not be
* called for such responses.
- *
- * # Calling $http from outside AngularJS
- * The `$http` service will not actually send the request until the next `$digest()` is
- * executed. Normally this is not an issue, since almost all the time your call to `$http` will
- * be from within a `$apply()` block.
- * If you are calling `$http` from outside Angular, then you should wrap it in a call to
- * `$apply` to cause a $digest to occur and also to handle errors in the block correctly.
- *
- * ```
- * $scope.$apply(function() {
- * $http(...);
- * });
- * ```
*
* # Writing Unit Tests that use $http
- * When unit testing you are mostly responsible for scheduling the `$digest` cycle. If you do
- * not trigger a `$digest` before calling `$httpBackend.flush()` then the request will not have
- * been made and `$httpBackend.expect(...)` expectations will fail. The solution is to run the
- * code that calls the `$http()` method inside a $apply block as explained in the previous
- * section.
+ * When unit testing (using {@link ngMock ngMock}), it is necessary to call
+ * {@link ngMock.$httpBackend#flush $httpBackend.flush()} to flush each pending
+ * request using trained responses.
*
* ```
* $httpBackend.expectGET(...);
- * $scope.$apply(function() {
- * $http.get(...);
- * });
+ * $http.get(...);
* $httpBackend.flush();
* ```
*
* # Shortcut methods
*
- * Since all invocations of the $http service require passing in an HTTP method and URL, and
- * POST/PUT requests require request data to be provided as well, shortcut methods
- * were created:
+ * Shortcut methods are also available. All shortcut methods require passing in the URL, and
+ * request data must be passed in for POST/PUT requests.
*
- * <pre>
+ * ```js
* $http.get('/someUrl').success(successCallback);
* $http.post('/someUrl', data).success(successCallback);
- * </pre>
+ * ```
*
* Complete list of shortcut methods:
*
- * - {@link ng.$http#methods_get $http.get}
- * - {@link ng.$http#methods_head $http.head}
- * - {@link ng.$http#methods_post $http.post}
- * - {@link ng.$http#methods_put $http.put}
- * - {@link ng.$http#methods_delete $http.delete}
- * - {@link ng.$http#methods_jsonp $http.jsonp}
+ * - {@link ng.$http#get $http.get}
+ * - {@link ng.$http#head $http.head}
+ * - {@link ng.$http#post $http.post}
+ * - {@link ng.$http#put $http.put}
+ * - {@link ng.$http#delete $http.delete}
+ * - {@link ng.$http#jsonp $http.jsonp}
*
*
* # Setting HTTP Headers
@@ -6999,7 +7491,15 @@ function $HttpProvider() {
* `$httpProvider.defaults.headers.get = { 'My-Header' : 'value' }.
*
* The defaults can also be set at runtime via the `$http.defaults` object in the same
- * fashion. In addition, you can supply a `headers` property in the config object passed when
+ * fashion. For example:
+ *
+ * ```
+ * module.run(function($http) {
+ * $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w'
+ * });
+ * ```
+ *
+ * In addition, you can supply a `headers` property in the config object passed when
* calling `$http(config)`, which overrides the defaults without changing them globally.
*
*
@@ -7023,7 +7523,9 @@ function $HttpProvider() {
* properties. These properties are by default an array of transform functions, which allows you
* to `push` or `unshift` a new transformation function into the transformation chain. You can
* also decide to completely override any default transformations by assigning your
- * transformation functions to these properties directly without the array wrapper.
+ * transformation functions to these properties directly without the array wrapper. These defaults
+ * are again available on the $http factory at run-time, which may be useful if you have run-time
+ * services you wish to be involved in your transformations.
*
* Similarly, to locally override the request/response transforms, augment the
* `transformRequest` and/or `transformResponse` properties of the configuration object passed
@@ -7083,7 +7585,7 @@ function $HttpProvider() {
* resolved with a rejection.
*
*
- * <pre>
+ * ```js
* // register the interceptor as a service
* $provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) {
* return {
@@ -7117,25 +7619,26 @@ function $HttpProvider() {
* return responseOrNewPromise
* }
* return $q.reject(rejection);
- * };
- * }
+ * }
+ * };
* });
*
* $httpProvider.interceptors.push('myHttpInterceptor');
*
*
- * // register the interceptor via an anonymous factory
+ * // alternatively, register the interceptor via an anonymous factory
* $httpProvider.interceptors.push(function($q, dependency1, dependency2) {
* return {
* 'request': function(config) {
* // same as above
* },
+ *
* 'response': function(response) {
* // same as above
* }
* };
* });
- * </pre>
+ * ```
*
* # Response interceptors (DEPRECATED)
*
@@ -7153,7 +7656,7 @@ function $HttpProvider() {
* injected with dependencies (if specified) and returns the interceptor — a function that
* takes a {@link ng.$q promise} and returns the original or a new promise.
*
- * <pre>
+ * ```js
* // register the interceptor as a service
* $provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) {
* return function(promise) {
@@ -7179,16 +7682,15 @@ function $HttpProvider() {
* // same as above
* }
* });
- * </pre>
+ * ```
*
*
* # Security Considerations
*
* When designing web applications, consider security threats from:
*
- * - {@link http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx
- * JSON vulnerability}
- * - {@link http://en.wikipedia.org/wiki/Cross-site_request_forgery XSRF}
+ * - [JSON vulnerability](http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx)
+ * - [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery)
*
* Both server and the client must cooperate in order to eliminate these threats. Angular comes
* pre-configured with strategies that address these issues, but for this to work backend server
@@ -7196,29 +7698,29 @@ function $HttpProvider() {
*
* ## JSON Vulnerability Protection
*
- * A {@link http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx
- * JSON vulnerability} allows third party website to turn your JSON resource URL into
- * {@link http://en.wikipedia.org/wiki/JSONP JSONP} request under some conditions. To
+ * A [JSON vulnerability](http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx)
+ * allows third party website to turn your JSON resource URL into
+ * [JSONP](http://en.wikipedia.org/wiki/JSONP) request under some conditions. To
* counter this your server can prefix all JSON requests with following string `")]}',\n"`.
* Angular will automatically strip the prefix before processing it as JSON.
*
* For example if your server needs to return:
- * <pre>
+ * ```js
* ['one','two']
- * </pre>
+ * ```
*
* which is vulnerable to attack, your server can return:
- * <pre>
+ * ```js
* )]}',
* ['one','two']
- * </pre>
+ * ```
*
* Angular will strip the prefix, before processing the JSON.
*
*
* ## Cross Site Request Forgery (XSRF) Protection
*
- * {@link http://en.wikipedia.org/wiki/Cross-site_request_forgery XSRF} is a technique by which
+ * [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery) is a technique by which
* an unauthorized site can gain your user's private data. Angular provides a mechanism
* to counter XSRF. When performing XHR requests, the $http service reads a token from a cookie
* (by default, `XSRF-TOKEN`) and sets it as an HTTP header (`X-XSRF-TOKEN`). Since only
@@ -7232,11 +7734,12 @@ function $HttpProvider() {
* that only JavaScript running on your domain could have sent the request. The token must be
* unique for each user and must be verifiable by the server (to prevent the JavaScript from
* making up its own tokens). We recommend that the token is a digest of your site's
- * authentication cookie with a {@link https://en.wikipedia.org/wiki/Salt_(cryptography) salt}
+ * authentication cookie with a [salt](https://en.wikipedia.org/wiki/Salt_(cryptography))
* for added security.
*
* The name of the headers can be specified using the xsrfHeaderName and xsrfCookieName
- * properties of either $httpProvider.defaults, or the per-request config object.
+ * properties of either $httpProvider.defaults at config-time, $http.defaults at run-time,
+ * or the per-request config object.
*
*
* @param {object} config Object describing the request to be made and how it should be
@@ -7268,10 +7771,10 @@ function $HttpProvider() {
* - **timeout** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise}
* that should abort the request when resolved.
* - **withCredentials** - `{boolean}` - whether to to set the `withCredentials` flag on the
- * XHR object. See {@link https://developer.mozilla.org/en/http_access_control#section_5
- * requests with credentials} for more information.
- * - **responseType** - `{string}` - see {@link
- * https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType requestType}.
+ * XHR object. See [requests with credentials]https://developer.mozilla.org/en/http_access_control#section_5
+ * for more information.
+ * - **responseType** - `{string}` - see
+ * [requestType](https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType).
*
* @returns {HttpPromise} Returns a {@link ng.$q promise} object with the
* standard `then` method and two http specific methods: `success` and `error`. The `then`
@@ -7286,6 +7789,7 @@ function $HttpProvider() {
* - **status** – `{number}` – HTTP status code of the response.
* - **headers** – `{function([headerName])}` – Header getter function.
* - **config** – `{Object}` – The configuration object that was used to generate the request.
+ * - **statusText** – `{string}` – HTTP status text of the response.
*
* @property {Array.<Object>} pendingRequests Array of config objects for currently pending
* requests. This is primarily meant to be used for debugging purposes.
@@ -7300,14 +7804,14 @@ function $HttpProvider() {
<option>JSONP</option>
</select>
<input type="text" ng-model="url" size="80"/>
- <button ng-click="fetch()">fetch</button><br>
- <button ng-click="updateModel('GET', 'http-hello.html')">Sample GET</button>
- <button
+ <button id="fetchbtn" ng-click="fetch()">fetch</button><br>
+ <button id="samplegetbtn" ng-click="updateModel('GET', 'http-hello.html')">Sample GET</button>
+ <button id="samplejsonpbtn"
ng-click="updateModel('JSONP',
'http://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero')">
Sample JSONP
</button>
- <button
+ <button id="invalidjsonpbtn"
ng-click="updateModel('JSONP', 'http://angularjs.org/doesntexist&callback=JSON_CALLBACK')">
Invalid JSONP
</button>
@@ -7344,33 +7848,41 @@ function $HttpProvider() {
<file name="http-hello.html">
Hello, $http!
</file>
-<file name="scenario.js">
+<file name="protractor.js" type="protractor">
+ var status = element(by.binding('status'));
+ var data = element(by.binding('data'));
+ var fetchBtn = element(by.id('fetchbtn'));
+ var sampleGetBtn = element(by.id('samplegetbtn'));
+ var sampleJsonpBtn = element(by.id('samplejsonpbtn'));
+ var invalidJsonpBtn = element(by.id('invalidjsonpbtn'));
+
it('should make an xhr GET request', function() {
- element(':button:contains("Sample GET")').click();
- element(':button:contains("fetch")').click();
- expect(binding('status')).toBe('200');
- expect(binding('data')).toMatch(/Hello, \$http!/);
+ sampleGetBtn.click();
+ fetchBtn.click();
+ expect(status.getText()).toMatch('200');
+ expect(data.getText()).toMatch(/Hello, \$http!/);
});
it('should make a JSONP request to angularjs.org', function() {
- element(':button:contains("Sample JSONP")').click();
- element(':button:contains("fetch")').click();
- expect(binding('status')).toBe('200');
- expect(binding('data')).toMatch(/Super Hero!/);
+ sampleJsonpBtn.click();
+ fetchBtn.click();
+ expect(status.getText()).toMatch('200');
+ expect(data.getText()).toMatch(/Super Hero!/);
});
it('should make JSONP request to invalid URL and invoke the error handler',
function() {
- element(':button:contains("Invalid JSONP")').click();
- element(':button:contains("fetch")').click();
- expect(binding('status')).toBe('0');
- expect(binding('data')).toBe('Request failed');
+ invalidJsonpBtn.click();
+ fetchBtn.click();
+ expect(status.getText()).toMatch('0');
+ expect(data.getText()).toMatch('Request failed');
});
</file>
</example>
*/
function $http(requestConfig) {
var config = {
+ method: 'get',
transformRequest: defaults.transformRequest,
transformResponse: defaults.transformResponse
};
@@ -7466,7 +7978,7 @@ function $HttpProvider() {
execHeaders(defHeaders);
execHeaders(reqHeaders);
- // using for-in instead of forEach to avoid unnecessary iteration after header has been found
+ // using for-in instead of forEach to avoid unecessary iteration after header has been found
defaultHeadersIteration:
for (defHeaderName in defHeaders) {
lowercaseDefHeaderName = lowercase(defHeaderName);
@@ -7503,8 +8015,7 @@ function $HttpProvider() {
/**
* @ngdoc method
- * @name ng.$http#get
- * @methodOf ng.$http
+ * @name $http#get
*
* @description
* Shortcut method to perform `GET` request.
@@ -7516,8 +8027,7 @@ function $HttpProvider() {
/**
* @ngdoc method
- * @name ng.$http#delete
- * @methodOf ng.$http
+ * @name $http#delete
*
* @description
* Shortcut method to perform `DELETE` request.
@@ -7529,8 +8039,7 @@ function $HttpProvider() {
/**
* @ngdoc method
- * @name ng.$http#head
- * @methodOf ng.$http
+ * @name $http#head
*
* @description
* Shortcut method to perform `HEAD` request.
@@ -7542,8 +8051,7 @@ function $HttpProvider() {
/**
* @ngdoc method
- * @name ng.$http#jsonp
- * @methodOf ng.$http
+ * @name $http#jsonp
*
* @description
* Shortcut method to perform `JSONP` request.
@@ -7557,8 +8065,7 @@ function $HttpProvider() {
/**
* @ngdoc method
- * @name ng.$http#post
- * @methodOf ng.$http
+ * @name $http#post
*
* @description
* Shortcut method to perform `POST` request.
@@ -7571,8 +8078,7 @@ function $HttpProvider() {
/**
* @ngdoc method
- * @name ng.$http#put
- * @methodOf ng.$http
+ * @name $http#put
*
* @description
* Shortcut method to perform `PUT` request.
@@ -7586,8 +8092,7 @@ function $HttpProvider() {
/**
* @ngdoc property
- * @name ng.$http#defaults
- * @propertyOf ng.$http
+ * @name $http#defaults
*
* @description
* Runtime equivalent of the `$httpProvider.defaults` property. Allows configuration of
@@ -7659,9 +8164,9 @@ function $HttpProvider() {
} else {
// serving from cache
if (isArray(cachedResp)) {
- resolvePromise(cachedResp[1], cachedResp[0], copy(cachedResp[2]));
+ resolvePromise(cachedResp[1], cachedResp[0], copy(cachedResp[2]), cachedResp[3]);
} else {
- resolvePromise(cachedResp, 200, {});
+ resolvePromise(cachedResp, 200, {}, 'OK');
}
}
} else {
@@ -7685,17 +8190,17 @@ function $HttpProvider() {
* - resolves the raw $http promise
* - calls $apply
*/
- function done(status, response, headersString) {
+ function done(status, response, headersString, statusText) {
if (cache) {
if (isSuccess(status)) {
- cache.put(url, [status, response, parseHeaders(headersString)]);
+ cache.put(url, [status, response, parseHeaders(headersString), statusText]);
} else {
// remove promise from the cache
cache.remove(url);
}
}
- resolvePromise(response, status, headersString);
+ resolvePromise(response, status, headersString, statusText);
if (!$rootScope.$$phase) $rootScope.$apply();
}
@@ -7703,7 +8208,7 @@ function $HttpProvider() {
/**
* Resolves the raw $http promise.
*/
- function resolvePromise(response, status, headers) {
+ function resolvePromise(response, status, headers, statusText) {
// normalize internal statuses to 0
status = Math.max(status, 0);
@@ -7711,7 +8216,8 @@ function $HttpProvider() {
data: response,
status: status,
headers: headersGetter(headers),
- config: config
+ config: config,
+ statusText : statusText
});
}
@@ -7738,26 +8244,33 @@ function $HttpProvider() {
encodeUriQuery(v));
});
});
- return url + ((url.indexOf('?') == -1) ? '?' : '&') + parts.join('&');
+ if(parts.length > 0) {
+ url += ((url.indexOf('?') == -1) ? '?' : '&') + parts.join('&');
+ }
+ return url;
}
}];
}
-var XHR = window.XMLHttpRequest || function() {
- /* global ActiveXObject */
- try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e1) {}
- try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e2) {}
- try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e3) {}
- throw minErr('$httpBackend')('noxhr', "This browser does not support XMLHttpRequest.");
-};
+function createXhr(method) {
+ //if IE and the method is not RFC2616 compliant, or if XMLHttpRequest
+ //is not available, try getting an ActiveXObject. Otherwise, use XMLHttpRequest
+ //if it is available
+ if (msie <= 8 && (!method.match(/^(get|post|head|put|delete|options)$/i) ||
+ !window.XMLHttpRequest)) {
+ return new window.ActiveXObject("Microsoft.XMLHTTP");
+ } else if (window.XMLHttpRequest) {
+ return new window.XMLHttpRequest();
+ }
+ throw minErr('$httpBackend')('noxhr', "This browser does not support XMLHttpRequest.");
+}
/**
- * @ngdoc object
- * @name ng.$httpBackend
- * @requires $browser
+ * @ngdoc service
+ * @name $httpBackend
* @requires $window
* @requires $document
*
@@ -7773,12 +8286,13 @@ var XHR = window.XMLHttpRequest || function() {
*/
function $HttpBackendProvider() {
this.$get = ['$browser', '$window', '$document', function($browser, $window, $document) {
- return createHttpBackend($browser, XHR, $browser.defer, $window.angular.callbacks,
- $document[0], $window.location.protocol.replace(':', ''));
+ return createHttpBackend($browser, createXhr, $browser.defer, $window.angular.callbacks, $document[0]);
}];
}
-function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, locationProtocol) {
+function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDocument) {
+ var ABORTED = -1;
+
// TODO(vojta): fix the signature
return function(method, url, post, callback, headers, timeout, withCredentials, responseType) {
var status;
@@ -7798,10 +8312,12 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
} else {
completeRequest(callback, status || -2);
}
- delete callbacks[callbackId];
+ callbacks[callbackId] = angular.noop;
});
} else {
- var xhr = new XHR();
+
+ var xhr = createXhr(method);
+
xhr.open(method, url, true);
forEach(headers, function(value, key) {
if (isDefined(value)) {
@@ -7813,15 +8329,30 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
// response is in the cache. the promise api will ensure that to the app code the api is
// always async
xhr.onreadystatechange = function() {
- if (xhr.readyState == 4) {
- var responseHeaders = xhr.getAllResponseHeaders();
+ // onreadystatechange might get called multiple times with readyState === 4 on mobile webkit caused by
+ // xhrs that are resolved while the app is in the background (see #5426).
+ // since calling completeRequest sets the `xhr` variable to null, we just check if it's not null before
+ // continuing
+ //
+ // we can't set xhr.onreadystatechange to undefined or delete it because that breaks IE8 (method=PATCH) and
+ // Safari respectively.
+ if (xhr && xhr.readyState == 4) {
+ var responseHeaders = null,
+ response = null;
+
+ if(status !== ABORTED) {
+ responseHeaders = xhr.getAllResponseHeaders();
+
+ // responseText is the old-school way of retrieving response (supported by IE8 & 9)
+ // response/responseType properties were introduced in XHR Level2 spec (supported by IE10)
+ response = ('response' in xhr) ? xhr.response : xhr.responseText;
+ }
- // responseText is the old-school way of retrieving response (supported by IE8 & 9)
- // response/responseType properties were introduced in XHR Level2 spec (supported by IE10)
completeRequest(callback,
status || xhr.status,
- (xhr.responseType ? xhr.response : xhr.responseText),
- responseHeaders);
+ response,
+ responseHeaders,
+ xhr.statusText || '');
}
};
@@ -7830,7 +8361,20 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
}
if (responseType) {
- xhr.responseType = responseType;
+ try {
+ xhr.responseType = responseType;
+ } catch (e) {
+ // WebKit added support for the json responseType value on 09/03/2013
+ // https://bugs.webkit.org/show_bug.cgi?id=73648. Versions of Safari prior to 7 are
+ // known to throw when setting the value "json" as the response type. Other older
+ // browsers implementing the responseType
+ //
+ // The json response type can be ignored if not supported, because JSON payloads are
+ // parsed on the client-side regardless.
+ if (responseType !== 'json') {
+ throw e;
+ }
+ }
}
xhr.send(post || null);
@@ -7844,25 +8388,28 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
function timeoutRequest() {
- status = -1;
+ status = ABORTED;
jsonpDone && jsonpDone();
xhr && xhr.abort();
}
- function completeRequest(callback, status, response, headersString) {
- var protocol = locationProtocol || urlResolve(url).protocol;
-
+ function completeRequest(callback, status, response, headersString, statusText) {
// cancel timeout and subsequent timeout promise resolution
timeoutId && $browserDefer.cancel(timeoutId);
jsonpDone = xhr = null;
- // fix status code for file protocol (it's always 0)
- status = (protocol == 'file') ? (response ? 200 : 404) : status;
+ // fix status code when it is 0 (0 status is undocumented).
+ // Occurs when accessing file resources or on Android 4.1 stock browser
+ // while retrieving files from application cache.
+ if (status === 0) {
+ status = response ? 200 : urlResolve(url).protocol == 'file' ? 404 : 0;
+ }
// normalize IE bug (http://bugs.jquery.com/ticket/1450)
- status = status == 1223 ? 204 : status;
+ status = status === 1223 ? 204 : status;
+ statusText = statusText || '';
- callback(status, response, headersString);
+ callback(status, response, headersString, statusText);
$browser.$$completeOutstandingRequest(noop);
}
};
@@ -7873,6 +8420,7 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
// - adds and immediately removes script elements from the document
var script = rawDocument.createElement('script'),
doneWrapper = function() {
+ script.onreadystatechange = script.onload = script.onerror = null;
rawDocument.body.removeChild(script);
if (done) done();
};
@@ -7880,12 +8428,16 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
script.type = 'text/javascript';
script.src = url;
- if (msie) {
+ if (msie && msie <= 8) {
script.onreadystatechange = function() {
- if (/loaded|complete/.test(script.readyState)) doneWrapper();
+ if (/loaded|complete/.test(script.readyState)) {
+ doneWrapper();
+ }
};
} else {
- script.onload = script.onerror = doneWrapper;
+ script.onload = script.onerror = function() {
+ doneWrapper();
+ };
}
rawDocument.body.appendChild(script);
@@ -7896,8 +8448,8 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
var $interpolateMinErr = minErr('$interpolate');
/**
- * @ngdoc object
- * @name ng.$interpolateProvider
+ * @ngdoc provider
+ * @name $interpolateProvider
* @function
*
* @description
@@ -7905,8 +8457,8 @@ var $interpolateMinErr = minErr('$interpolate');
* Used for configuring the interpolation markup. Defaults to `{{` and `}}`.
*
* @example
-<doc:example module="customInterpolationApp">
-<doc:source>
+<example module="customInterpolationApp">
+<file name="index.html">
<script>
var customInterpolationApp = angular.module('customInterpolationApp', []);
@@ -7923,13 +8475,13 @@ var $interpolateMinErr = minErr('$interpolate');
<div ng-app="App" ng-controller="DemoController as demo">
//demo.label//
</div>
-</doc:source>
-<doc:scenario>
- it('should interpolate binding with custom symbols', function() {
- expect(binding('demo.label')).toBe('This binding is brought you by // interpolation symbols.');
- });
-</doc:scenario>
-</doc:example>
+</file>
+<file name="protractor.js" type="protractor">
+ it('should interpolate binding with custom symbols', function() {
+ expect(element(by.binding('demo.label')).getText()).toBe('This binding is brought you by // interpolation symbols.');
+ });
+</file>
+</example>
*/
function $InterpolateProvider() {
var startSymbol = '{{';
@@ -7937,8 +8489,7 @@ function $InterpolateProvider() {
/**
* @ngdoc method
- * @name ng.$interpolateProvider#startSymbol
- * @methodOf ng.$interpolateProvider
+ * @name $interpolateProvider#startSymbol
* @description
* Symbol to denote start of expression in the interpolated string. Defaults to `{{`.
*
@@ -7956,8 +8507,7 @@ function $InterpolateProvider() {
/**
* @ngdoc method
- * @name ng.$interpolateProvider#endSymbol
- * @methodOf ng.$interpolateProvider
+ * @name $interpolateProvider#endSymbol
* @description
* Symbol to denote the end of expression in the interpolated string. Defaults to `}}`.
*
@@ -7979,8 +8529,8 @@ function $InterpolateProvider() {
endSymbolLength = endSymbol.length;
/**
- * @ngdoc function
- * @name ng.$interpolate
+ * @ngdoc service
+ * @name $interpolate
* @function
*
* @requires $parse
@@ -7994,11 +8544,11 @@ function $InterpolateProvider() {
* interpolation markup.
*
*
- <pre>
- var $interpolate = ...; // injected
- var exp = $interpolate('Hello {{name}}!');
- expect(exp({name:'Angular'}).toEqual('Hello Angular!');
- </pre>
+ * ```js
+ * var $interpolate = ...; // injected
+ * var exp = $interpolate('Hello {{name | uppercase}}!');
+ * expect(exp({name:'Angular'}).toEqual('Hello ANGULAR!');
+ * ```
*
*
* @param {string} text The text with markup to interpolate.
@@ -8006,7 +8556,7 @@ function $InterpolateProvider() {
* embedded expression in order to return an interpolation function. Strings with no
* embedded expression will return null for the interpolation function.
* @param {string=} trustedContext when provided, the returned function passes the interpolated
- * result through {@link ng.$sce#methods_getTrusted $sce.getTrusted(interpolatedResult,
+ * result through {@link ng.$sce#getTrusted $sce.getTrusted(interpolatedResult,
* trustedContext)} before returning it. Refer to the {@link ng.$sce $sce} service that
* provides Strict Contextual Escaping for details.
* @returns {function(context)} an interpolation function which is used to compute the
@@ -8098,8 +8648,7 @@ function $InterpolateProvider() {
/**
* @ngdoc method
- * @name ng.$interpolate#startSymbol
- * @methodOf ng.$interpolate
+ * @name $interpolate#startSymbol
* @description
* Symbol to denote the start of expression in the interpolated string. Defaults to `{{`.
*
@@ -8115,15 +8664,14 @@ function $InterpolateProvider() {
/**
* @ngdoc method
- * @name ng.$interpolate#endSymbol
- * @methodOf ng.$interpolate
+ * @name $interpolate#endSymbol
* @description
* Symbol to denote the end of expression in the interpolated string. Defaults to `}}`.
*
* Use {@link ng.$interpolateProvider#endSymbol $interpolateProvider#endSymbol} to change
* the symbol.
*
- * @returns {string} start symbol.
+ * @returns {string} end symbol.
*/
$interpolate.endSymbol = function() {
return endSymbol;
@@ -8140,8 +8688,8 @@ function $IntervalProvider() {
/**
- * @ngdoc function
- * @name ng.$interval
+ * @ngdoc service
+ * @name $interval
*
* @description
* Angular's wrapper for `window.setInterval`. The `fn` function is executed every `delay`
@@ -8153,17 +8701,114 @@ function $IntervalProvider() {
* number of iterations that have run.
* To cancel an interval, call `$interval.cancel(promise)`.
*
- * In tests you can use {@link ngMock.$interval#methods_flush `$interval.flush(millis)`} to
+ * In tests you can use {@link ngMock.$interval#flush `$interval.flush(millis)`} to
* move forward by `millis` milliseconds and trigger any functions scheduled to run in that
* time.
*
+ * <div class="alert alert-warning">
+ * **Note**: Intervals created by this service must be explicitly destroyed when you are finished
+ * with them. In particular they are not automatically destroyed when a controller's scope or a
+ * directive's element are destroyed.
+ * You should take this into consideration and make sure to always cancel the interval at the
+ * appropriate moment. See the example below for more details on how and when to do this.
+ * </div>
+ *
* @param {function()} fn A function that should be called repeatedly.
* @param {number} delay Number of milliseconds between each function call.
* @param {number=} [count=0] Number of times to repeat. If not set, or 0, will repeat
* indefinitely.
* @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise
- * will invoke `fn` within the {@link ng.$rootScope.Scope#methods_$apply $apply} block.
+ * will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block.
* @returns {promise} A promise which will be notified on each iteration.
+ *
+ * @example
+ * <example module="time">
+ * <file name="index.html">
+ * <script>
+ * function Ctrl2($scope,$interval) {
+ * $scope.format = 'M/d/yy h:mm:ss a';
+ * $scope.blood_1 = 100;
+ * $scope.blood_2 = 120;
+ *
+ * var stop;
+ * $scope.fight = function() {
+ * // Don't start a new fight if we are already fighting
+ * if ( angular.isDefined(stop) ) return;
+ *
+ * stop = $interval(function() {
+ * if ($scope.blood_1 > 0 && $scope.blood_2 > 0) {
+ * $scope.blood_1 = $scope.blood_1 - 3;
+ * $scope.blood_2 = $scope.blood_2 - 4;
+ * } else {
+ * $scope.stopFight();
+ * }
+ * }, 100);
+ * };
+ *
+ * $scope.stopFight = function() {
+ * if (angular.isDefined(stop)) {
+ * $interval.cancel(stop);
+ * stop = undefined;
+ * }
+ * };
+ *
+ * $scope.resetFight = function() {
+ * $scope.blood_1 = 100;
+ * $scope.blood_2 = 120;
+ * }
+ *
+ * $scope.$on('$destroy', function() {
+ * // Make sure that the interval is destroyed too
+ * $scope.stopFight();
+ * });
+ * }
+ *
+ * angular.module('time', [])
+ * // Register the 'myCurrentTime' directive factory method.
+ * // We inject $interval and dateFilter service since the factory method is DI.
+ * .directive('myCurrentTime', function($interval, dateFilter) {
+ * // return the directive link function. (compile function not needed)
+ * return function(scope, element, attrs) {
+ * var format, // date format
+ * stopTime; // so that we can cancel the time updates
+ *
+ * // used to update the UI
+ * function updateTime() {
+ * element.text(dateFilter(new Date(), format));
+ * }
+ *
+ * // watch the expression, and update the UI on change.
+ * scope.$watch(attrs.myCurrentTime, function(value) {
+ * format = value;
+ * updateTime();
+ * });
+ *
+ * stopTime = $interval(updateTime, 1000);
+ *
+ * // listen on DOM destroy (removal) event, and cancel the next UI update
+ * // to prevent updating time ofter the DOM element was removed.
+ * element.bind('$destroy', function() {
+ * $interval.cancel(stopTime);
+ * });
+ * }
+ * });
+ * </script>
+ *
+ * <div>
+ * <div ng-controller="Ctrl2">
+ * Date format: <input ng-model="format"> <hr/>
+ * Current time is: <span my-current-time="format"></span>
+ * <hr/>
+ * Blood 1 : <font color='red'>{{blood_1}}</font>
+ * Blood 2 : <font color='red'>{{blood_2}}</font>
+ * <button type="button" data-ng-click="fight()">Fight</button>
+ * <button type="button" data-ng-click="stopFight()">StopFight</button>
+ * <button type="button" data-ng-click="resetFight()">resetFight</button>
+ * </div>
+ * </div>
+ *
+ * </file>
+ * </example>
*/
function interval(fn, delay, count, invokeApply) {
var setInterval = $window.setInterval,
@@ -8172,8 +8817,8 @@ function $IntervalProvider() {
promise = deferred.promise,
iteration = 0,
skipApply = (isDefined(invokeApply) && !invokeApply);
-
- count = isDefined(count) ? count : 0,
+
+ count = isDefined(count) ? count : 0;
promise.then(null, null, fn);
@@ -8197,14 +8842,13 @@ function $IntervalProvider() {
/**
- * @ngdoc function
- * @name ng.$interval#cancel
- * @methodOf ng.$interval
+ * @ngdoc method
+ * @name $interval#cancel
*
* @description
* Cancels a task associated with the `promise`.
*
- * @param {number} promise Promise returned by the `$interval` function.
+ * @param {promise} promise returned by the `$interval` function.
* @returns {boolean} Returns `true` if the task was successfully canceled.
*/
interval.cancel = function(promise) {
@@ -8222,8 +8866,8 @@ function $IntervalProvider() {
}
/**
- * @ngdoc object
- * @name ng.$locale
+ * @ngdoc service
+ * @name $locale
*
* @description
* $locale service provides localization rules for various Angular components. As of right now the
@@ -8472,7 +9116,47 @@ function LocationHashbangUrl(appBase, hashPrefix) {
hashPrefix);
}
parseAppUrl(withoutHashUrl, this, appBase);
+
+ this.$$path = removeWindowsDriveName(this.$$path, withoutHashUrl, appBase);
+
this.$$compose();
+
+ /*
+ * In Windows, on an anchor node on documents loaded from
+ * the filesystem, the browser will return a pathname
+ * prefixed with the drive name ('/C:/path') when a
+ * pathname without a drive is set:
+ * * a.setAttribute('href', '/foo')
+ * * a.pathname === '/C:/foo' //true
+ *
+ * Inside of Angular, we're always using pathnames that
+ * do not include drive names for routing.
+ */
+ function removeWindowsDriveName (path, url, base) {
+ /*
+ Matches paths for file protocol on windows,
+ such as /C:/foo/bar, and captures only /foo/bar.
+ */
+ var windowsFilePathExp = /^\/?.*?:(\/.*)/;
+
+ var firstPathSegmentMatch;
+
+ //Get the relative path from the input URL.
+ if (url.indexOf(base) === 0) {
+ url = url.replace(base, '');
+ }
+
+ /*
+ * The input URL intentionally contains a
+ * first path segment that ends with a colon.
+ */
+ if (windowsFilePathExp.exec(url)) {
+ return path;
+ }
+
+ firstPathSegmentMatch = windowsFilePathExp.exec(path);
+ return firstPathSegmentMatch ? firstPathSegmentMatch[1] : path;
+ }
};
/**
@@ -8542,14 +9226,13 @@ LocationHashbangInHtml5Url.prototype =
/**
* @ngdoc method
- * @name ng.$location#absUrl
- * @methodOf ng.$location
+ * @name $location#absUrl
*
* @description
* This method is getter only.
*
* Return full url representation with all segments encoded according to rules specified in
- * {@link http://www.ietf.org/rfc/rfc3986.txt RFC 3986}.
+ * [RFC 3986](http://www.ietf.org/rfc/rfc3986.txt).
*
* @return {string} full url
*/
@@ -8557,8 +9240,7 @@ LocationHashbangInHtml5Url.prototype =
/**
* @ngdoc method
- * @name ng.$location#url
- * @methodOf ng.$location
+ * @name $location#url
*
* @description
* This method is getter / setter.
@@ -8585,8 +9267,7 @@ LocationHashbangInHtml5Url.prototype =
/**
* @ngdoc method
- * @name ng.$location#protocol
- * @methodOf ng.$location
+ * @name $location#protocol
*
* @description
* This method is getter only.
@@ -8599,8 +9280,7 @@ LocationHashbangInHtml5Url.prototype =
/**
* @ngdoc method
- * @name ng.$location#host
- * @methodOf ng.$location
+ * @name $location#host
*
* @description
* This method is getter only.
@@ -8613,8 +9293,7 @@ LocationHashbangInHtml5Url.prototype =
/**
* @ngdoc method
- * @name ng.$location#port
- * @methodOf ng.$location
+ * @name $location#port
*
* @description
* This method is getter only.
@@ -8627,8 +9306,7 @@ LocationHashbangInHtml5Url.prototype =
/**
* @ngdoc method
- * @name ng.$location#path
- * @methodOf ng.$location
+ * @name $location#path
*
* @description
* This method is getter / setter.
@@ -8649,8 +9327,7 @@ LocationHashbangInHtml5Url.prototype =
/**
* @ngdoc method
- * @name ng.$location#search
- * @methodOf ng.$location
+ * @name $location#search
*
* @description
* This method is getter / setter.
@@ -8697,8 +9374,7 @@ LocationHashbangInHtml5Url.prototype =
/**
* @ngdoc method
- * @name ng.$location#hash
- * @methodOf ng.$location
+ * @name $location#hash
*
* @description
* This method is getter / setter.
@@ -8714,8 +9390,7 @@ LocationHashbangInHtml5Url.prototype =
/**
* @ngdoc method
- * @name ng.$location#replace
- * @methodOf ng.$location
+ * @name $location#replace
*
* @description
* If called, all changes to $location during current `$digest` will be replacing current history
@@ -8748,16 +9423,14 @@ function locationGetterSetter(property, preprocess) {
/**
- * @ngdoc object
- * @name ng.$location
+ * @ngdoc service
+ * @name $location
*
- * @requires $browser
- * @requires $sniffer
* @requires $rootElement
*
* @description
* The $location service parses the URL in the browser address bar (based on the
- * {@link https://developer.mozilla.org/en/window.location window.location}) and makes the URL
+ * [window.location](https://developer.mozilla.org/en/window.location)) and makes the URL
* available to your application. Changes to the URL in the address bar are reflected into
* $location service and changes to $location are reflected into the browser address bar.
*
@@ -8772,13 +9445,12 @@ function locationGetterSetter(property, preprocess) {
* - Clicks on a link.
* - Represents the URL object as a set of methods (protocol, host, port, path, search, hash).
*
- * For more information see {@link guide/dev_guide.services.$location Developer Guide: Angular
- * Services: Using $location}
+ * For more information see {@link guide/$location Developer Guide: Using $location}
*/
/**
- * @ngdoc object
- * @name ng.$locationProvider
+ * @ngdoc provider
+ * @name $locationProvider
* @description
* Use the `$locationProvider` to configure how the application deep linking paths are stored.
*/
@@ -8788,8 +9460,7 @@ function $LocationProvider(){
/**
* @ngdoc property
- * @name ng.$locationProvider#hashPrefix
- * @methodOf ng.$locationProvider
+ * @name $locationProvider#hashPrefix
* @description
* @param {string=} prefix Prefix for hash part (containing path and search)
* @returns {*} current value if used as getter or itself (chaining) if used as setter
@@ -8805,8 +9476,7 @@ function $LocationProvider(){
/**
* @ngdoc property
- * @name ng.$locationProvider#html5Mode
- * @methodOf ng.$locationProvider
+ * @name $locationProvider#html5Mode
* @description
* @param {boolean=} mode Use HTML5 strategy if available.
* @returns {*} current value if used as getter or itself (chaining) if used as setter
@@ -8822,14 +9492,13 @@ function $LocationProvider(){
/**
* @ngdoc event
- * @name ng.$location#$locationChangeStart
- * @eventOf ng.$location
+ * @name $location#$locationChangeStart
* @eventType broadcast on root scope
* @description
* Broadcasted before a URL will change. This change can be prevented by calling
* `preventDefault` method of the event. See {@link ng.$rootScope.Scope#$on} for more
* details about event object. Upon successful change
- * {@link ng.$location#$locationChangeSuccess $locationChangeSuccess} is fired.
+ * {@link ng.$location#events_$locationChangeSuccess $locationChangeSuccess} is fired.
*
* @param {Object} angularEvent Synthetic event object.
* @param {string} newUrl New URL
@@ -8838,8 +9507,7 @@ function $LocationProvider(){
/**
* @ngdoc event
- * @name ng.$location#$locationChangeSuccess
- * @eventOf ng.$location
+ * @name $location#$locationChangeSuccess
* @eventType broadcast on root scope
* @description
* Broadcasted after a URL was changed.
@@ -8882,6 +9550,13 @@ function $LocationProvider(){
}
var absHref = elm.prop('href');
+
+ if (isObject(absHref) && absHref.toString() === '[object SVGAnimatedString]') {
+ // SVGAnimatedString.animVal should be identical to SVGAnimatedString.baseVal, unless during
+ // an animation.
+ absHref = urlResolve(absHref.animVal).href;
+ }
+
var rewrittenUrl = $location.$$rewrite(absHref);
if (absHref && !elm.attr('target') && rewrittenUrl && !event.isDefaultPrevented()) {
@@ -8905,16 +9580,17 @@ function $LocationProvider(){
// update $location when $browser url changes
$browser.onUrlChange(function(newUrl) {
if ($location.absUrl() != newUrl) {
- if ($rootScope.$broadcast('$locationChangeStart', newUrl,
- $location.absUrl()).defaultPrevented) {
- $browser.url($location.absUrl());
- return;
- }
$rootScope.$evalAsync(function() {
var oldUrl = $location.absUrl();
$location.$$parse(newUrl);
- afterLocationChange(oldUrl);
+ if ($rootScope.$broadcast('$locationChangeStart', newUrl,
+ oldUrl).defaultPrevented) {
+ $location.$$parse(oldUrl);
+ $browser.url(oldUrl);
+ } else {
+ afterLocationChange(oldUrl);
+ }
});
if (!$rootScope.$$phase) $rootScope.$digest();
}
@@ -8952,17 +9628,17 @@ function $LocationProvider(){
}
/**
- * @ngdoc object
- * @name ng.$log
+ * @ngdoc service
+ * @name $log
* @requires $window
*
* @description
* Simple service for logging. Default implementation safely writes the message
* into the browser's console (if present).
- *
+ *
* The main purpose of this service is to simplify debugging and troubleshooting.
*
- * The default is not to log `debug` messages. You can use
+ * The default is to log `debug` messages. You can use
* {@link ng.$logProvider ng.$logProvider#debugEnabled} to change this.
*
* @example
@@ -8988,21 +9664,20 @@ function $LocationProvider(){
*/
/**
- * @ngdoc object
- * @name ng.$logProvider
+ * @ngdoc provider
+ * @name $logProvider
* @description
* Use the `$logProvider` to configure how the application logs messages
*/
function $LogProvider(){
var debug = true,
self = this;
-
+
/**
* @ngdoc property
- * @name ng.$logProvider#debugEnabled
- * @methodOf ng.$logProvider
+ * @name $logProvider#debugEnabled
* @description
- * @param {string=} flag enable or disable debug level messages
+ * @param {boolean=} flag enable or disable debug level messages
* @returns {*} current value if used as getter or itself (chaining) if used as setter
*/
this.debugEnabled = function(flag) {
@@ -9013,13 +9688,12 @@ function $LogProvider(){
return debug;
}
};
-
+
this.$get = ['$window', function($window){
return {
/**
* @ngdoc method
- * @name ng.$log#log
- * @methodOf ng.$log
+ * @name $log#log
*
* @description
* Write a log message
@@ -9028,8 +9702,7 @@ function $LogProvider(){
/**
* @ngdoc method
- * @name ng.$log#info
- * @methodOf ng.$log
+ * @name $log#info
*
* @description
* Write an information message
@@ -9038,8 +9711,7 @@ function $LogProvider(){
/**
* @ngdoc method
- * @name ng.$log#warn
- * @methodOf ng.$log
+ * @name $log#warn
*
* @description
* Write a warning message
@@ -9048,19 +9720,17 @@ function $LogProvider(){
/**
* @ngdoc method
- * @name ng.$log#error
- * @methodOf ng.$log
+ * @name $log#error
*
* @description
* Write an error message
*/
error: consoleLog('error'),
-
+
/**
* @ngdoc method
- * @name ng.$log#debug
- * @methodOf ng.$log
- *
+ * @name $log#debug
+ *
* @description
* Write a debug message
*/
@@ -9090,9 +9760,16 @@ function $LogProvider(){
function consoleLog(type) {
var console = $window.console || {},
- logFn = console[type] || console.log || noop;
+ logFn = console[type] || console.log || noop,
+ hasApply = false;
+
+ // Note: reading logFn.apply throws an error in IE11 in IE8 document mode.
+ // The reason behind this is that console.log has type "object" in IE8...
+ try {
+ hasApply = !!logFn.apply;
+ } catch (e) {}
- if (logFn.apply) {
+ if (hasApply) {
return function() {
var args = [];
forEach(arguments, function(arg) {
@@ -9155,23 +9832,24 @@ function ensureSafeMemberName(name, fullExpression) {
function ensureSafeObject(obj, fullExpression) {
// nifty check if obj is Function that is fast and works across iframes and other contexts
- if (obj && obj.constructor === obj) {
- throw $parseMinErr('isecfn',
- 'Referencing Function in Angular expressions is disallowed! Expression: {0}',
- fullExpression);
- } else if (// isWindow(obj)
- obj && obj.document && obj.location && obj.alert && obj.setInterval) {
- throw $parseMinErr('isecwindow',
- 'Referencing the Window in Angular expressions is disallowed! Expression: {0}',
- fullExpression);
- } else if (// isElement(obj)
- obj && (obj.nodeName || (obj.on && obj.find))) {
- throw $parseMinErr('isecdom',
- 'Referencing DOM nodes in Angular expressions is disallowed! Expression: {0}',
- fullExpression);
- } else {
- return obj;
+ if (obj) {
+ if (obj.constructor === obj) {
+ throw $parseMinErr('isecfn',
+ 'Referencing Function in Angular expressions is disallowed! Expression: {0}',
+ fullExpression);
+ } else if (// isWindow(obj)
+ obj.document && obj.location && obj.alert && obj.setInterval) {
+ throw $parseMinErr('isecwindow',
+ 'Referencing the Window in Angular expressions is disallowed! Expression: {0}',
+ fullExpression);
+ } else if (// isElement(obj)
+ obj.children && (obj.nodeName || (obj.prop && obj.attr && obj.find))) {
+ throw $parseMinErr('isecdom',
+ 'Referencing DOM nodes in Angular expressions is disallowed! Expression: {0}',
+ fullExpression);
+ }
}
+ return obj;
}
var OPERATORS = {
@@ -9503,7 +10181,11 @@ var Parser = function (lexer, $filter, options) {
this.options = options;
};
-Parser.ZERO = function () { return 0; };
+Parser.ZERO = extend(function () {
+ return 0;
+}, {
+ constant: true
+});
Parser.prototype = {
constructor: Parser,
@@ -9817,7 +10499,7 @@ Parser.prototype = {
var getter = getterFn(field, this.options, this.text);
return extend(function(scope, locals, self) {
- return getter(self || object(scope, locals), locals);
+ return getter(self || object(scope, locals));
}, {
assign: function(scope, value, locals) {
return setter(object(scope, locals), field, value, parser.text, parser.options);
@@ -9895,6 +10577,10 @@ Parser.prototype = {
var allConstant = true;
if (this.peekToken().text !== ']') {
do {
+ if (this.peek(']')) {
+ // Support trailing commas per ES5.1.
+ break;
+ }
var elementFn = this.expression();
elementFns.push(elementFn);
if (!elementFn.constant) {
@@ -9921,6 +10607,10 @@ Parser.prototype = {
var allConstant = true;
if (this.peekToken().text !== '}') {
do {
+ if (this.peek('}')) {
+ // Support trailing commas per ES5.1.
+ break;
+ }
var token = this.expect(),
key = token.string || token.text;
this.consume(':');
@@ -10001,19 +10691,23 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) {
? function cspSafeGetter(scope, locals) {
var pathVal = (locals && locals.hasOwnProperty(key0)) ? locals : scope;
- if (pathVal === null || pathVal === undefined) return pathVal;
+ if (pathVal == null) return pathVal;
pathVal = pathVal[key0];
- if (!key1 || pathVal === null || pathVal === undefined) return pathVal;
+ if (!key1) return pathVal;
+ if (pathVal == null) return undefined;
pathVal = pathVal[key1];
- if (!key2 || pathVal === null || pathVal === undefined) return pathVal;
+ if (!key2) return pathVal;
+ if (pathVal == null) return undefined;
pathVal = pathVal[key2];
- if (!key3 || pathVal === null || pathVal === undefined) return pathVal;
+ if (!key3) return pathVal;
+ if (pathVal == null) return undefined;
pathVal = pathVal[key3];
- if (!key4 || pathVal === null || pathVal === undefined) return pathVal;
+ if (!key4) return pathVal;
+ if (pathVal == null) return undefined;
pathVal = pathVal[key4];
return pathVal;
@@ -10022,7 +10716,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) {
var pathVal = (locals && locals.hasOwnProperty(key0)) ? locals : scope,
promise;
- if (pathVal === null || pathVal === undefined) return pathVal;
+ if (pathVal == null) return pathVal;
pathVal = pathVal[key0];
if (pathVal && pathVal.then) {
@@ -10034,8 +10728,9 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) {
}
pathVal = pathVal.$$v;
}
- if (!key1 || pathVal === null || pathVal === undefined) return pathVal;
+ if (!key1) return pathVal;
+ if (pathVal == null) return undefined;
pathVal = pathVal[key1];
if (pathVal && pathVal.then) {
promiseWarning(fullExp);
@@ -10046,8 +10741,9 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) {
}
pathVal = pathVal.$$v;
}
- if (!key2 || pathVal === null || pathVal === undefined) return pathVal;
+ if (!key2) return pathVal;
+ if (pathVal == null) return undefined;
pathVal = pathVal[key2];
if (pathVal && pathVal.then) {
promiseWarning(fullExp);
@@ -10058,8 +10754,9 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) {
}
pathVal = pathVal.$$v;
}
- if (!key3 || pathVal === null || pathVal === undefined) return pathVal;
+ if (!key3) return pathVal;
+ if (pathVal == null) return undefined;
pathVal = pathVal[key3];
if (pathVal && pathVal.then) {
promiseWarning(fullExp);
@@ -10070,8 +10767,9 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) {
}
pathVal = pathVal.$$v;
}
- if (!key4 || pathVal === null || pathVal === undefined) return pathVal;
+ if (!key4) return pathVal;
+ if (pathVal == null) return undefined;
pathVal = pathVal[key4];
if (pathVal && pathVal.then) {
promiseWarning(fullExp);
@@ -10086,6 +10784,26 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) {
};
}
+function simpleGetterFn1(key0, fullExp) {
+ ensureSafeMemberName(key0, fullExp);
+
+ return function simpleGetterFn1(scope, locals) {
+ if (scope == null) return undefined;
+ return ((locals && locals.hasOwnProperty(key0)) ? locals : scope)[key0];
+ };
+}
+
+function simpleGetterFn2(key0, key1, fullExp) {
+ ensureSafeMemberName(key0, fullExp);
+ ensureSafeMemberName(key1, fullExp);
+
+ return function simpleGetterFn2(scope, locals) {
+ if (scope == null) return undefined;
+ scope = ((locals && locals.hasOwnProperty(key0)) ? locals : scope)[key0];
+ return scope == null ? undefined : scope[key1];
+ };
+}
+
function getterFn(path, options, fullExp) {
// Check whether the cache has this getter already.
// We can use hasOwnProperty directly on the cache because we ensure,
@@ -10098,7 +10816,13 @@ function getterFn(path, options, fullExp) {
pathKeysLength = pathKeys.length,
fn;
- if (options.csp) {
+ // When we have only 1 or 2 tokens, use optimized special case closures.
+ // http://jsperf.com/angularjs-parse-getter/6
+ if (!options.unwrapPromises && pathKeysLength === 1) {
+ fn = simpleGetterFn1(pathKeys[0], fullExp);
+ } else if (!options.unwrapPromises && pathKeysLength === 2) {
+ fn = simpleGetterFn2(pathKeys[0], pathKeys[1], fullExp);
+ } else if (options.csp) {
if (pathKeysLength < 6) {
fn = cspSafeGetterFn(pathKeys[0], pathKeys[1], pathKeys[2], pathKeys[3], pathKeys[4], fullExp,
options);
@@ -10116,11 +10840,10 @@ function getterFn(path, options, fullExp) {
};
}
} else {
- var code = 'var l, fn, p;\n';
+ var code = 'var p;\n';
forEach(pathKeys, function(key, index) {
ensureSafeMemberName(key, fullExp);
- code += 'if(s === null || s === undefined) return s;\n' +
- 'l=s;\n' +
+ code += 'if(s == null) return undefined;\n' +
's='+ (index
// we simply dereference 's' on any .dot notation
? 's'
@@ -10128,7 +10851,7 @@ function getterFn(path, options, fullExp) {
: '((k&&k.hasOwnProperty("' + key + '"))?k:s)') + '["' + key + '"]' + ';\n' +
(options.unwrapPromises
? 'if (s && s.then) {\n' +
- ' pw("' + fullExp.replace(/\"/g, '\\"') + '");\n' +
+ ' pw("' + fullExp.replace(/(["\r\n])/g, '\\$1') + '");\n' +
' if (!("$$v" in s)) {\n' +
' p=s;\n' +
' p.$$v = undefined;\n' +
@@ -10143,10 +10866,10 @@ function getterFn(path, options, fullExp) {
/* jshint -W054 */
var evaledFnGetter = new Function('s', 'k', 'pw', code); // s=scope, k=locals, pw=promiseWarning
/* jshint +W054 */
- evaledFnGetter.toString = function() { return code; };
- fn = function(scope, locals) {
+ evaledFnGetter.toString = valueFn(code);
+ fn = options.unwrapPromises ? function(scope, locals) {
return evaledFnGetter(scope, locals, promiseWarning);
- };
+ } : evaledFnGetter;
}
// Only cache the value if it's not going to mess up the cache object
@@ -10160,15 +10883,15 @@ function getterFn(path, options, fullExp) {
///////////////////////////////////
/**
- * @ngdoc function
- * @name ng.$parse
- * @function
+ * @ngdoc service
+ * @name $parse
+ * @kind function
*
* @description
*
* Converts Angular {@link guide/expression expression} into a function.
*
- * <pre>
+ * ```js
* var getter = $parse('user.name');
* var setter = getter.assign;
* var context = {user:{name:'angular'}};
@@ -10178,7 +10901,7 @@ function getterFn(path, options, fullExp) {
* setter(context, 'newValue');
* expect(context.user.name).toEqual('newValue');
* expect(getter(context, locals)).toEqual('local');
- * </pre>
+ * ```
*
*
* @param {string} expression String expression to compile.
@@ -10201,8 +10924,8 @@ function getterFn(path, options, fullExp) {
/**
- * @ngdoc object
- * @name ng.$parseProvider
+ * @ngdoc provider
+ * @name $parseProvider
* @function
*
* @description
@@ -10223,8 +10946,7 @@ function $ParseProvider() {
* @deprecated Promise unwrapping via $parse is deprecated and will be removed in the future.
*
* @ngdoc method
- * @name ng.$parseProvider#unwrapPromises
- * @methodOf ng.$parseProvider
+ * @name $parseProvider#unwrapPromises
* @description
*
* **This feature is deprecated, see deprecation notes below for more info**
@@ -10278,8 +11000,7 @@ function $ParseProvider() {
* @deprecated Promise unwrapping via $parse is deprecated and will be removed in the future.
*
* @ngdoc method
- * @name ng.$parseProvider#logPromiseWarnings
- * @methodOf ng.$parseProvider
+ * @name $parseProvider#logPromiseWarnings
* @description
*
* Controls whether Angular should log a warning on any encounter of a promise in an expression.
@@ -10346,7 +11067,7 @@ function $ParseProvider() {
/**
* @ngdoc service
- * @name ng.$q
+ * @name $q
* @requires $rootScope
*
* @description
@@ -10359,9 +11080,9 @@ function $ParseProvider() {
* From the perspective of dealing with error handling, deferred and promise APIs are to
* asynchronous programming what `try`, `catch` and `throw` keywords are to synchronous programming.
*
- * <pre>
- * // for the purpose of this example let's assume that variables `$q` and `scope` are
- * // available in the current lexical scope (they could have been injected or passed in).
+ * ```js
+ * // for the purpose of this example let's assume that variables `$q`, `scope` and `okToGreet`
+ * // are available in the current lexical scope (they could have been injected or passed in).
*
* function asyncGreet(name) {
* var deferred = $q.defer();
@@ -10391,7 +11112,7 @@ function $ParseProvider() {
* }, function(update) {
* alert('Got notification: ' + update);
* });
- * </pre>
+ * ```
*
* At first it might not be obvious why this extra complexity is worth the trouble. The payoff
* comes in the way of guarantees that promise and deferred APIs make, see
@@ -10417,7 +11138,7 @@ function $ParseProvider() {
* constructed via `$q.reject`, the promise will be rejected instead.
* - `reject(reason)` – rejects the derived promise with the `reason`. This is equivalent to
* resolving it with a rejection constructed via `$q.reject`.
- * - `notify(value)` - provides updates on the status of the promises execution. This may be called
+ * - `notify(value)` - provides updates on the status of the promise's execution. This may be called
* multiple times before the promise is either resolved or rejected.
*
* **Properties**
@@ -10456,21 +11177,21 @@ function $ParseProvider() {
*
* Because `finally` is a reserved word in JavaScript and reserved keywords are not supported as
* property names by ES3, you'll need to invoke the method like `promise['finally'](callback)` to
- * make your code IE8 compatible.
+ * make your code IE8 and Android 2.x compatible.
*
* # Chaining promises
*
* Because calling the `then` method of a promise returns a new derived promise, it is easily
* possible to create a chain of promises:
*
- * <pre>
+ * ```js
* promiseB = promiseA.then(function(result) {
* return result + 1;
* });
*
* // promiseB will be resolved immediately after promiseA is resolved and its value
* // will be the result of promiseA incremented by 1
- * </pre>
+ * ```
*
* It is possible to create chains of any length and since a promise can be resolved with another
* promise (which will defer its resolution further), it is possible to pause/defer resolution of
@@ -10480,7 +11201,7 @@ function $ParseProvider() {
*
* # Differences between Kris Kowal's Q and $q
*
- * There are three main differences:
+ * There are two main differences:
*
* - $q is integrated with the {@link ng.$rootScope.Scope} Scope model observation
* mechanism in angular, which means faster propagation of resolution or rejection into your
@@ -10490,7 +11211,7 @@ function $ParseProvider() {
*
* # Testing
*
- * <pre>
+ * ```js
* it('should simulate promise', inject(function($q, $rootScope) {
* var deferred = $q.defer();
* var promise = deferred.promise;
@@ -10510,7 +11231,7 @@ function $ParseProvider() {
* $rootScope.$apply();
* expect(resolvedValue).toEqual(123);
* }));
- * </pre>
+ * ```
*/
function $QProvider() {
@@ -10525,7 +11246,7 @@ function $QProvider() {
/**
* Constructs a promise manager.
*
- * @param {function(function)} nextTick Function for executing functions in the next turn.
+ * @param {function(Function)} nextTick Function for executing functions in the next turn.
* @param {function(...*)} exceptionHandler Function into which unexpected exceptions are passed for
* debugging purposes.
* @returns {object} Promise manager.
@@ -10533,9 +11254,10 @@ function $QProvider() {
function qFactory(nextTick, exceptionHandler) {
/**
- * @ngdoc
- * @name ng.$q#defer
- * @methodOf ng.$q
+ * @ngdoc method
+ * @name $q#defer
+ * @function
+ *
* @description
* Creates a `Deferred` object which represents a task which will finish in the future.
*
@@ -10567,7 +11289,7 @@ function qFactory(nextTick, exceptionHandler) {
reject: function(reason) {
- deferred.resolve(reject(reason));
+ deferred.resolve(createInternalRejectedPromise(reason));
},
@@ -10689,9 +11411,10 @@ function qFactory(nextTick, exceptionHandler) {
/**
- * @ngdoc
- * @name ng.$q#reject
- * @methodOf ng.$q
+ * @ngdoc method
+ * @name $q#reject
+ * @function
+ *
* @description
* Creates a promise that is resolved as rejected with the specified `reason`. This api should be
* used to forward rejection in a chain of promises. If you are dealing with the last promise in
@@ -10703,7 +11426,7 @@ function qFactory(nextTick, exceptionHandler) {
* current promise, you have to "rethrow" the error by returning a rejection constructed via
* `reject`.
*
- * <pre>
+ * ```js
* promiseB = promiseA.then(function(result) {
* // success: do something and resolve promiseB
* // with the old or a new result
@@ -10718,12 +11441,18 @@ function qFactory(nextTick, exceptionHandler) {
* }
* return $q.reject(reason);
* });
- * </pre>
+ * ```
*
* @param {*} reason Constant, message, exception or an object representing the rejection reason.
* @returns {Promise} Returns a promise that was already resolved as rejected with the `reason`.
*/
var reject = function(reason) {
+ var result = defer();
+ result.reject(reason);
+ return result.promise;
+ };
+
+ var createInternalRejectedPromise = function(reason) {
return {
then: function(callback, errback) {
var result = defer();
@@ -10742,9 +11471,10 @@ function qFactory(nextTick, exceptionHandler) {
/**
- * @ngdoc
- * @name ng.$q#when
- * @methodOf ng.$q
+ * @ngdoc method
+ * @name $q#when
+ * @function
+ *
* @description
* Wraps an object that might be a value or a (3rd party) then-able promise into a $q promise.
* This is useful when you are dealing with an object that might or might not be a promise, or if
@@ -10813,9 +11543,10 @@ function qFactory(nextTick, exceptionHandler) {
/**
- * @ngdoc
- * @name ng.$q#all
- * @methodOf ng.$q
+ * @ngdoc method
+ * @name $q#all
+ * @function
+ *
* @description
* Combines multiple promises into a single promise that is resolved when all of the input
* promises are resolved.
@@ -10858,6 +11589,38 @@ function qFactory(nextTick, exceptionHandler) {
};
}
+function $$RAFProvider(){ //rAF
+ this.$get = ['$window', '$timeout', function($window, $timeout) {
+ var requestAnimationFrame = $window.requestAnimationFrame ||
+ $window.webkitRequestAnimationFrame ||
+ $window.mozRequestAnimationFrame;
+
+ var cancelAnimationFrame = $window.cancelAnimationFrame ||
+ $window.webkitCancelAnimationFrame ||
+ $window.mozCancelAnimationFrame ||
+ $window.webkitCancelRequestAnimationFrame;
+
+ var rafSupported = !!requestAnimationFrame;
+ var raf = rafSupported
+ ? function(fn) {
+ var id = requestAnimationFrame(fn);
+ return function() {
+ cancelAnimationFrame(id);
+ };
+ }
+ : function(fn) {
+ var timer = $timeout(fn, 16.66, false); // 1000 / 60 = 16.666
+ return function() {
+ $timeout.cancel(timer);
+ };
+ };
+
+ raf.supported = rafSupported;
+
+ return raf;
+ }];
+}
+
/**
* DESIGN NOTES
*
@@ -10885,17 +11648,16 @@ function qFactory(nextTick, exceptionHandler) {
/**
- * @ngdoc object
- * @name ng.$rootScopeProvider
+ * @ngdoc provider
+ * @name $rootScopeProvider
* @description
*
* Provider for the $rootScope service.
*/
/**
- * @ngdoc function
- * @name ng.$rootScopeProvider#digestTtl
- * @methodOf ng.$rootScopeProvider
+ * @ngdoc method
+ * @name $rootScopeProvider#digestTtl
* @description
*
* Sets the number of `$digest` iterations the scope should attempt to execute before giving up and
@@ -10916,8 +11678,8 @@ function qFactory(nextTick, exceptionHandler) {
/**
- * @ngdoc object
- * @name ng.$rootScope
+ * @ngdoc service
+ * @name $rootScope
* @description
*
* Every application has a single root {@link ng.$rootScope.Scope scope}.
@@ -10929,6 +11691,7 @@ function qFactory(nextTick, exceptionHandler) {
function $RootScopeProvider(){
var TTL = 10;
var $rootScopeMinErr = minErr('$rootScope');
+ var lastDirtyWatch = null;
this.digestTtl = function(value) {
if (arguments.length) {
@@ -10941,23 +11704,23 @@ function $RootScopeProvider(){
function( $injector, $exceptionHandler, $parse, $browser) {
/**
- * @ngdoc function
- * @name ng.$rootScope.Scope
+ * @ngdoc type
+ * @name $rootScope.Scope
*
* @description
* A root scope can be retrieved using the {@link ng.$rootScope $rootScope} key from the
- * {@link AUTO.$injector $injector}. Child scopes are created using the
- * {@link ng.$rootScope.Scope#methods_$new $new()} method. (Most scopes are created automatically when
+ * {@link auto.$injector $injector}. Child scopes are created using the
+ * {@link ng.$rootScope.Scope#$new $new()} method. (Most scopes are created automatically when
* compiled HTML template is executed.)
*
* Here is a simple scope snippet to show how you can interact with the scope.
- * <pre>
+ * ```html
* <file src="./test/ng/rootScopeSpec.js" tag="docs1" />
- * </pre>
+ * ```
*
* # Inheritance
* A scope can inherit from a parent scope, as in this example:
- * <pre>
+ * ```js
var parent = $rootScope;
var child = parent.$new();
@@ -10968,7 +11731,7 @@ function $RootScopeProvider(){
child.salutation = "Welcome";
expect(child.salutation).toEqual('Welcome');
expect(parent.salutation).toEqual('Hello');
- * </pre>
+ * ```
*
*
* @param {Object.<string, function()>=} providers Map of service factory which need to be
@@ -10990,13 +11753,13 @@ function $RootScopeProvider(){
this.$$asyncQueue = [];
this.$$postDigestQueue = [];
this.$$listeners = {};
+ this.$$listenerCount = {};
this.$$isolateBindings = {};
}
/**
* @ngdoc property
- * @name ng.$rootScope.Scope#$id
- * @propertyOf ng.$rootScope.Scope
+ * @name $rootScope.Scope#$id
* @returns {number} Unique scope ID (monotonically increasing alphanumeric sequence) useful for
* debugging.
*/
@@ -11005,9 +11768,8 @@ function $RootScopeProvider(){
Scope.prototype = {
constructor: Scope,
/**
- * @ngdoc function
- * @name ng.$rootScope.Scope#$new
- * @methodOf ng.$rootScope.Scope
+ * @ngdoc method
+ * @name $rootScope.Scope#$new
* @function
*
* @description
@@ -11030,7 +11792,7 @@ function $RootScopeProvider(){
*
*/
$new: function(isolate) {
- var Child,
+ var ChildScope,
child;
if (isolate) {
@@ -11040,15 +11802,16 @@ function $RootScopeProvider(){
child.$$asyncQueue = this.$$asyncQueue;
child.$$postDigestQueue = this.$$postDigestQueue;
} else {
- Child = function() {}; // should be anonymous; This is so that when the minifier munges
+ ChildScope = function() {}; // should be anonymous; This is so that when the minifier munges
// the name it does not become random set of chars. This will then show up as class
- // name in the debugger.
- Child.prototype = this;
- child = new Child();
+ // name in the web inspector.
+ ChildScope.prototype = this;
+ child = new ChildScope();
child.$id = nextUid();
}
child['this'] = child;
child.$$listeners = {};
+ child.$$listenerCount = {};
child.$parent = this;
child.$$watchers = child.$$nextSibling = child.$$childHead = child.$$childTail = null;
child.$$prevSibling = this.$$childTail;
@@ -11062,9 +11825,8 @@ function $RootScopeProvider(){
},
/**
- * @ngdoc function
- * @name ng.$rootScope.Scope#$watch
- * @methodOf ng.$rootScope.Scope
+ * @ngdoc method
+ * @name $rootScope.Scope#$watch
* @function
*
* @description
@@ -11102,7 +11864,7 @@ function $RootScopeProvider(){
*
*
* # Example
- * <pre>
+ * ```js
// let's assume that scope was dependency injected as the $rootScope
var scope = $rootScope;
scope.name = 'misko';
@@ -11124,7 +11886,7 @@ function $RootScopeProvider(){
- // Using a listener function
+ // Using a listener function
var food;
scope.foodCounter = 0;
expect(scope.foodCounter).toEqual(0);
@@ -11142,16 +11904,16 @@ function $RootScopeProvider(){
// No digest has been run so the counter will be zero
expect(scope.foodCounter).toEqual(0);
- // Run the digest but since food has not changed cout will still be zero
+ // Run the digest but since food has not changed count will still be zero
scope.$digest();
expect(scope.foodCounter).toEqual(0);
// Update food and run digest. Now the counter will increment
food = 'cheeseburger';
scope.$digest();
- expect(scope.foodCounter).toEqual(1);
+ expect(scope.foodCounter).toEqual(1);
- * </pre>
+ * ```
*
*
*
@@ -11168,7 +11930,8 @@ function $RootScopeProvider(){
* - `function(newValue, oldValue, scope)`: called with current and previous values as
* parameters.
*
- * @param {boolean=} objectEquality Compare object for equality rather than for reference.
+ * @param {boolean=} objectEquality Compare for object equality using {@link angular.equals} instead of
+ * comparing for reference equality.
* @returns {function()} Returns a deregistration function for this listener.
*/
$watch: function(watchExp, listener, objectEquality) {
@@ -11183,6 +11946,8 @@ function $RootScopeProvider(){
eq: !!objectEquality
};
+ lastDirtyWatch = null;
+
// in the case user pass string, we need to compile it, do we really need this ?
if (!isFunction(listener)) {
var listenFn = compileToFn(listener || noop, 'listener');
@@ -11206,14 +11971,14 @@ function $RootScopeProvider(){
return function() {
arrayRemove(array, watcher);
+ lastDirtyWatch = null;
};
},
/**
- * @ngdoc function
- * @name ng.$rootScope.Scope#$watchCollection
- * @methodOf ng.$rootScope.Scope
+ * @ngdoc method
+ * @name $rootScope.Scope#$watchCollection
* @function
*
* @description
@@ -11228,7 +11993,7 @@ function $RootScopeProvider(){
*
*
* # Example
- * <pre>
+ * ```js
$scope.names = ['igor', 'matias', 'misko', 'james'];
$scope.dataCount = 4;
@@ -11247,38 +12012,48 @@ function $RootScopeProvider(){
//now there's been a change
expect($scope.dataCount).toEqual(3);
- * </pre>
+ * ```
*
*
- * @param {string|Function(scope)} obj Evaluated as {@link guide/expression expression}. The
+ * @param {string|function(scope)} obj Evaluated as {@link guide/expression expression}. The
* expression value should evaluate to an object or an array which is observed on each
* {@link ng.$rootScope.Scope#$digest $digest} cycle. Any shallow change within the
* collection will trigger a call to the `listener`.
*
- * @param {function(newCollection, oldCollection, scope)} listener a callback function that is
- * fired with both the `newCollection` and `oldCollection` as parameters.
- * The `newCollection` object is the newly modified data obtained from the `obj` expression
- * and the `oldCollection` object is a copy of the former collection data.
- * The `scope` refers to the current scope.
+ * @param {function(newCollection, oldCollection, scope)} listener a callback function called
+ * when a change is detected.
+ * - The `newCollection` object is the newly modified data obtained from the `obj` expression
+ * - The `oldCollection` object is a copy of the former collection data.
+ * Due to performance considerations, the`oldCollection` value is computed only if the
+ * `listener` function declares two or more arguments.
+ * - The `scope` argument refers to the current scope.
*
* @returns {function()} Returns a de-registration function for this listener. When the
* de-registration function is executed, the internal watch operation is terminated.
*/
$watchCollection: function(obj, listener) {
var self = this;
- var oldValue;
+ // the current value, updated on each dirty-check run
var newValue;
+ // a shallow copy of the newValue from the last dirty-check run,
+ // updated to match newValue during dirty-check run
+ var oldValue;
+ // a shallow copy of the newValue from when the last change happened
+ var veryOldValue;
+ // only track veryOldValue if the listener is asking for it
+ var trackVeryOldValue = (listener.length > 1);
var changeDetected = 0;
var objGetter = $parse(obj);
var internalArray = [];
var internalObject = {};
+ var initRun = true;
var oldLength = 0;
function $watchCollectionWatch() {
newValue = objGetter(self);
var newLength, key;
- if (!isObject(newValue)) {
+ if (!isObject(newValue)) { // if primitive
if (oldValue !== newValue) {
oldValue = newValue;
changeDetected++;
@@ -11300,7 +12075,9 @@ function $RootScopeProvider(){
}
// copy the items to oldValue and look for changes.
for (var i = 0; i < newLength; i++) {
- if (oldValue[i] !== newValue[i]) {
+ var bothNaN = (oldValue[i] !== oldValue[i]) &&
+ (newValue[i] !== newValue[i]);
+ if (!bothNaN && (oldValue[i] !== newValue[i])) {
changeDetected++;
oldValue[i] = newValue[i];
}
@@ -11344,16 +12121,40 @@ function $RootScopeProvider(){
}
function $watchCollectionAction() {
- listener(newValue, oldValue, self);
+ if (initRun) {
+ initRun = false;
+ listener(newValue, newValue, self);
+ } else {
+ listener(newValue, veryOldValue, self);
+ }
+
+ // make a copy for the next time a collection is changed
+ if (trackVeryOldValue) {
+ if (!isObject(newValue)) {
+ //primitive
+ veryOldValue = newValue;
+ } else if (isArrayLike(newValue)) {
+ veryOldValue = new Array(newValue.length);
+ for (var i = 0; i < newValue.length; i++) {
+ veryOldValue[i] = newValue[i];
+ }
+ } else { // if object
+ veryOldValue = {};
+ for (var key in newValue) {
+ if (hasOwnProperty.call(newValue, key)) {
+ veryOldValue[key] = newValue[key];
+ }
+ }
+ }
+ }
}
return this.$watch($watchCollectionWatch, $watchCollectionAction);
},
/**
- * @ngdoc function
- * @name ng.$rootScope.Scope#$digest
- * @methodOf ng.$rootScope.Scope
+ * @ngdoc method
+ * @name $rootScope.Scope#$digest
* @function
*
* @description
@@ -11366,9 +12167,9 @@ function $RootScopeProvider(){
*
* Usually, you don't call `$digest()` directly in
* {@link ng.directive:ngController controllers} or in
- * {@link ng.$compileProvider#methods_directive directives}.
+ * {@link ng.$compileProvider#directive directives}.
* Instead, you should call {@link ng.$rootScope.Scope#$apply $apply()} (typically from within
- * a {@link ng.$compileProvider#methods_directive directives}), which will force a `$digest()`.
+ * a {@link ng.$compileProvider#directive directives}), which will force a `$digest()`.
*
* If you want to be notified whenever `$digest()` is called,
* you can register a `watchExpression` function with
@@ -11377,7 +12178,7 @@ function $RootScopeProvider(){
* In unit tests, you may need to call `$digest()` to simulate the scope life cycle.
*
* # Example
- * <pre>
+ * ```js
var scope = ...;
scope.name = 'misko';
scope.counter = 0;
@@ -11395,7 +12196,7 @@ function $RootScopeProvider(){
scope.name = 'adam';
scope.$digest();
expect(scope.counter).toEqual(1);
- * </pre>
+ * ```
*
*/
$digest: function() {
@@ -11411,6 +12212,8 @@ function $RootScopeProvider(){
beginPhase('$digest');
+ lastDirtyWatch = null;
+
do { // "while dirty" loop
dirty = false;
current = target;
@@ -11420,10 +12223,13 @@ function $RootScopeProvider(){
asyncTask = asyncQueue.shift();
asyncTask.scope.$eval(asyncTask.expression);
} catch (e) {
+ clearPhase();
$exceptionHandler(e);
}
+ lastDirtyWatch = null;
}
+ traverseScopesLoop:
do { // "traverse the scopes" loop
if ((watchers = current.$$watchers)) {
// process our watches
@@ -11433,25 +12239,34 @@ function $RootScopeProvider(){
watch = watchers[length];
// Most common watches are on primitives, in which case we can short
// circuit it with === operator, only when === fails do we use .equals
- if (watch && (value = watch.get(current)) !== (last = watch.last) &&
- !(watch.eq
- ? equals(value, last)
- : (typeof value == 'number' && typeof last == 'number'
- && isNaN(value) && isNaN(last)))) {
- dirty = true;
- watch.last = watch.eq ? copy(value) : value;
- watch.fn(value, ((last === initWatchVal) ? value : last), current);
- if (ttl < 5) {
- logIdx = 4 - ttl;
- if (!watchLog[logIdx]) watchLog[logIdx] = [];
- logMsg = (isFunction(watch.exp))
- ? 'fn: ' + (watch.exp.name || watch.exp.toString())
- : watch.exp;
- logMsg += '; newVal: ' + toJson(value) + '; oldVal: ' + toJson(last);
- watchLog[logIdx].push(logMsg);
+ if (watch) {
+ if ((value = watch.get(current)) !== (last = watch.last) &&
+ !(watch.eq
+ ? equals(value, last)
+ : (typeof value == 'number' && typeof last == 'number'
+ && isNaN(value) && isNaN(last)))) {
+ dirty = true;
+ lastDirtyWatch = watch;
+ watch.last = watch.eq ? copy(value) : value;
+ watch.fn(value, ((last === initWatchVal) ? value : last), current);
+ if (ttl < 5) {
+ logIdx = 4 - ttl;
+ if (!watchLog[logIdx]) watchLog[logIdx] = [];
+ logMsg = (isFunction(watch.exp))
+ ? 'fn: ' + (watch.exp.name || watch.exp.toString())
+ : watch.exp;
+ logMsg += '; newVal: ' + toJson(value) + '; oldVal: ' + toJson(last);
+ watchLog[logIdx].push(logMsg);
+ }
+ } else if (watch === lastDirtyWatch) {
+ // If the most recently dirty watcher is now clean, short circuit since the remaining watchers
+ // have already been tested.
+ dirty = false;
+ break traverseScopesLoop;
}
}
} catch (e) {
+ clearPhase();
$exceptionHandler(e);
}
}
@@ -11460,20 +12275,24 @@ function $RootScopeProvider(){
// Insanity Warning: scope depth-first traversal
// yes, this code is a bit crazy, but it works and we have tests to prove it!
// this piece should be kept in sync with the traversal in $broadcast
- if (!(next = (current.$$childHead || (current !== target && current.$$nextSibling)))) {
+ if (!(next = (current.$$childHead ||
+ (current !== target && current.$$nextSibling)))) {
while(current !== target && !(next = current.$$nextSibling)) {
current = current.$parent;
}
}
} while ((current = next));
- if(dirty && !(ttl--)) {
+ // `break traverseScopesLoop;` takes us to here
+
+ if((dirty || asyncQueue.length) && !(ttl--)) {
clearPhase();
throw $rootScopeMinErr('infdig',
'{0} $digest() iterations reached. Aborting!\n' +
'Watchers fired in the last 5 iterations: {1}',
TTL, toJson(watchLog));
}
+
} while (dirty || asyncQueue.length);
clearPhase();
@@ -11490,8 +12309,7 @@ function $RootScopeProvider(){
/**
* @ngdoc event
- * @name ng.$rootScope.Scope#$destroy
- * @eventOf ng.$rootScope.Scope
+ * @name $rootScope.Scope#$destroy
* @eventType broadcast on scope being destroyed
*
* @description
@@ -11502,9 +12320,8 @@ function $RootScopeProvider(){
*/
/**
- * @ngdoc function
- * @name ng.$rootScope.Scope#$destroy
- * @methodOf ng.$rootScope.Scope
+ * @ngdoc method
+ * @name $rootScope.Scope#$destroy
* @function
*
* @description
@@ -11526,27 +12343,46 @@ function $RootScopeProvider(){
*/
$destroy: function() {
// we can't destroy the root scope or a scope that has been already destroyed
- if ($rootScope == this || this.$$destroyed) return;
+ if (this.$$destroyed) return;
var parent = this.$parent;
this.$broadcast('$destroy');
this.$$destroyed = true;
+ if (this === $rootScope) return;
+ forEach(this.$$listenerCount, bind(null, decrementListenerCount, this));
+
+ // sever all the references to parent scopes (after this cleanup, the current scope should
+ // not be retained by any of our references and should be eligible for garbage collection)
if (parent.$$childHead == this) parent.$$childHead = this.$$nextSibling;
if (parent.$$childTail == this) parent.$$childTail = this.$$prevSibling;
if (this.$$prevSibling) this.$$prevSibling.$$nextSibling = this.$$nextSibling;
if (this.$$nextSibling) this.$$nextSibling.$$prevSibling = this.$$prevSibling;
- // This is bogus code that works around Chrome's GC leak
- // see: https://github.com/angular/angular.js/issues/1313#issuecomment-10378451
+
+ // All of the code below is bogus code that works around V8's memory leak via optimized code
+ // and inline caches.
+ //
+ // see:
+ // - https://code.google.com/p/v8/issues/detail?id=2073#c26
+ // - https://github.com/angular/angular.js/issues/6794#issuecomment-38648909
+ // - https://github.com/angular/angular.js/issues/1313#issuecomment-10378451
+
this.$parent = this.$$nextSibling = this.$$prevSibling = this.$$childHead =
- this.$$childTail = null;
+ this.$$childTail = this.$root = null;
+
+ // don't reset these to null in case some async task tries to register a listener/watch/task
+ this.$$listeners = {};
+ this.$$watchers = this.$$asyncQueue = this.$$postDigestQueue = [];
+
+ // prevent NPEs since these methods have references to properties we nulled out
+ this.$destroy = this.$digest = this.$apply = noop;
+ this.$on = this.$watch = function() { return noop; };
},
/**
- * @ngdoc function
- * @name ng.$rootScope.Scope#$eval
- * @methodOf ng.$rootScope.Scope
+ * @ngdoc method
+ * @name $rootScope.Scope#$eval
* @function
*
* @description
@@ -11555,20 +12391,20 @@ function $RootScopeProvider(){
* expressions.
*
* # Example
- * <pre>
+ * ```js
var scope = ng.$rootScope.Scope();
scope.a = 1;
scope.b = 2;
expect(scope.$eval('a+b')).toEqual(3);
expect(scope.$eval(function(scope){ return scope.a + scope.b; })).toEqual(3);
- * </pre>
+ * ```
*
* @param {(string|function())=} expression An angular expression to be executed.
*
* - `string`: execute using the rules as defined in {@link guide/expression expression}.
* - `function(scope)`: execute the function with the current `scope` parameter.
- *
+ *
* @param {(object)=} locals Local variables object, useful for overriding values in scope.
* @returns {*} The result of evaluating the expression.
*/
@@ -11577,9 +12413,8 @@ function $RootScopeProvider(){
},
/**
- * @ngdoc function
- * @name ng.$rootScope.Scope#$evalAsync
- * @methodOf ng.$rootScope.Scope
+ * @ngdoc method
+ * @name $rootScope.Scope#$evalAsync
* @function
*
* @description
@@ -11625,9 +12460,8 @@ function $RootScopeProvider(){
},
/**
- * @ngdoc function
- * @name ng.$rootScope.Scope#$apply
- * @methodOf ng.$rootScope.Scope
+ * @ngdoc method
+ * @name $rootScope.Scope#$apply
* @function
*
* @description
@@ -11640,7 +12474,7 @@ function $RootScopeProvider(){
* ## Life cycle
*
* # Pseudo-Code of `$apply()`
- * <pre>
+ * ```js
function $apply(expr) {
try {
return $eval(expr);
@@ -11650,7 +12484,7 @@ function $RootScopeProvider(){
$root.$digest();
}
}
- * </pre>
+ * ```
*
*
* Scope's `$apply()` method transitions through the following stages:
@@ -11688,9 +12522,8 @@ function $RootScopeProvider(){
},
/**
- * @ngdoc function
- * @name ng.$rootScope.Scope#$on
- * @methodOf ng.$rootScope.Scope
+ * @ngdoc method
+ * @name $rootScope.Scope#$on
* @function
*
* @description
@@ -11711,7 +12544,7 @@ function $RootScopeProvider(){
* - `defaultPrevented` - `{boolean}`: true if `preventDefault` was called.
*
* @param {string} name Event name to listen on.
- * @param {function(event, args...)} listener Function to call when the event is emitted.
+ * @param {function(event, ...args)} listener Function to call when the event is emitted.
* @returns {function()} Returns a deregistration function for this listener.
*/
$on: function(name, listener) {
@@ -11721,16 +12554,25 @@ function $RootScopeProvider(){
}
namedListeners.push(listener);
+ var current = this;
+ do {
+ if (!current.$$listenerCount[name]) {
+ current.$$listenerCount[name] = 0;
+ }
+ current.$$listenerCount[name]++;
+ } while ((current = current.$parent));
+
+ var self = this;
return function() {
namedListeners[indexOf(namedListeners, listener)] = null;
+ decrementListenerCount(self, 1, name);
};
},
/**
- * @ngdoc function
- * @name ng.$rootScope.Scope#$emit
- * @methodOf ng.$rootScope.Scope
+ * @ngdoc method
+ * @name $rootScope.Scope#$emit
* @function
*
* @description
@@ -11747,7 +12589,7 @@ function $RootScopeProvider(){
* onto the {@link ng.$exceptionHandler $exceptionHandler} service.
*
* @param {string} name Event name to emit.
- * @param {...*} args Optional set of arguments which will be passed onto the event listeners.
+ * @param {...*} args Optional one or more arguments which will be passed onto the event listeners.
* @return {Object} Event object (see {@link ng.$rootScope.Scope#$on}).
*/
$emit: function(name, args) {
@@ -11797,9 +12639,8 @@ function $RootScopeProvider(){
/**
- * @ngdoc function
- * @name ng.$rootScope.Scope#$broadcast
- * @methodOf ng.$rootScope.Scope
+ * @ngdoc method
+ * @name $rootScope.Scope#$broadcast
* @function
*
* @description
@@ -11815,7 +12656,7 @@ function $RootScopeProvider(){
* onto the {@link ng.$exceptionHandler $exceptionHandler} service.
*
* @param {string} name Event name to broadcast.
- * @param {...*} args Optional set of arguments which will be passed onto the event listeners.
+ * @param {...*} args Optional one or more arguments which will be passed onto the event listeners.
* @return {Object} Event object, see {@link ng.$rootScope.Scope#$on}
*/
$broadcast: function(name, args) {
@@ -11834,8 +12675,7 @@ function $RootScopeProvider(){
listeners, i, length;
//down while you can, then up and next sibling or up and next sibling until back at root
- do {
- current = next;
+ while ((current = next)) {
event.currentScope = current;
listeners = current.$$listeners[name] || [];
for (i=0, length = listeners.length; i<length; i++) {
@@ -11857,12 +12697,14 @@ function $RootScopeProvider(){
// Insanity Warning: scope depth-first traversal
// yes, this code is a bit crazy, but it works and we have tests to prove it!
// this piece should be kept in sync with the traversal in $digest
- if (!(next = (current.$$childHead || (current !== target && current.$$nextSibling)))) {
+ // (though it differs due to having the extra check for $$listenerCount)
+ if (!(next = ((current.$$listenerCount[name] && current.$$childHead) ||
+ (current !== target && current.$$nextSibling)))) {
while(current !== target && !(next = current.$$nextSibling)) {
current = current.$parent;
}
}
- } while ((current = next));
+ }
return event;
}
@@ -11891,6 +12733,16 @@ function $RootScopeProvider(){
return fn;
}
+ function decrementListenerCount(current, count, name) {
+ do {
+ current.$$listenerCount[name] -= count;
+
+ if (current.$$listenerCount[name] === 0) {
+ delete current.$$listenerCount[name];
+ }
+ } while ((current = current.$parent));
+ }
+
/**
* function used as an initial value for watchers.
* because it's unique we can easily tell it apart from other values
@@ -11899,6 +12751,79 @@ function $RootScopeProvider(){
}];
}
+/**
+ * @description
+ * Private service to sanitize uris for links and images. Used by $compile and $sanitize.
+ */
+function $$SanitizeUriProvider() {
+ var aHrefSanitizationWhitelist = /^\s*(https?|ftp|mailto|tel|file):/,
+ imgSrcSanitizationWhitelist = /^\s*(https?|ftp|file):|data:image\//;
+
+ /**
+ * @description
+ * Retrieves or overrides the default regular expression that is used for whitelisting of safe
+ * urls during a[href] sanitization.
+ *
+ * The sanitization is a security measure aimed at prevent XSS attacks via html links.
+ *
+ * Any url about to be assigned to a[href] via data-binding is first normalized and turned into
+ * an absolute url. Afterwards, the url is matched against the `aHrefSanitizationWhitelist`
+ * regular expression. If a match is found, the original url is written into the dom. Otherwise,
+ * the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
+ *
+ * @param {RegExp=} regexp New regexp to whitelist urls with.
+ * @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
+ * chaining otherwise.
+ */
+ this.aHrefSanitizationWhitelist = function(regexp) {
+ if (isDefined(regexp)) {
+ aHrefSanitizationWhitelist = regexp;
+ return this;
+ }
+ return aHrefSanitizationWhitelist;
+ };
+
+
+ /**
+ * @description
+ * Retrieves or overrides the default regular expression that is used for whitelisting of safe
+ * urls during img[src] sanitization.
+ *
+ * The sanitization is a security measure aimed at prevent XSS attacks via html links.
+ *
+ * Any url about to be assigned to img[src] via data-binding is first normalized and turned into
+ * an absolute url. Afterwards, the url is matched against the `imgSrcSanitizationWhitelist`
+ * regular expression. If a match is found, the original url is written into the dom. Otherwise,
+ * the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
+ *
+ * @param {RegExp=} regexp New regexp to whitelist urls with.
+ * @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
+ * chaining otherwise.
+ */
+ this.imgSrcSanitizationWhitelist = function(regexp) {
+ if (isDefined(regexp)) {
+ imgSrcSanitizationWhitelist = regexp;
+ return this;
+ }
+ return imgSrcSanitizationWhitelist;
+ };
+
+ this.$get = function() {
+ return function sanitizeUri(uri, isImage) {
+ var regex = isImage ? imgSrcSanitizationWhitelist : aHrefSanitizationWhitelist;
+ var normalizedVal;
+ // NOTE: urlResolve() doesn't support IE < 8 so we don't sanitize for that case.
+ if (!msie || msie >= 8 ) {
+ normalizedVal = urlResolve(uri).href;
+ if (normalizedVal !== '' && !normalizedVal.match(regex)) {
+ return 'unsafe:'+normalizedVal;
+ }
+ }
+ return uri;
+ };
+ };
+}
+
var $sceMinErr = minErr('$sce');
var SCE_CONTEXTS = {
@@ -11963,7 +12888,7 @@ function adjustMatchers(matchers) {
/**
* @ngdoc service
- * @name ng.$sceDelegate
+ * @name $sceDelegate
* @function
*
* @description
@@ -11983,21 +12908,21 @@ function adjustMatchers(matchers) {
* can override it completely to change the behavior of `$sce`, the common case would
* involve configuring the {@link ng.$sceDelegateProvider $sceDelegateProvider} instead by setting
* your own whitelists and blacklists for trusting URLs used for loading AngularJS resources such as
- * templates. Refer {@link ng.$sceDelegateProvider#methods_resourceUrlWhitelist
+ * templates. Refer {@link ng.$sceDelegateProvider#resourceUrlWhitelist
* $sceDelegateProvider.resourceUrlWhitelist} and {@link
- * ng.$sceDelegateProvider#methods_resourceUrlBlacklist $sceDelegateProvider.resourceUrlBlacklist}
+ * ng.$sceDelegateProvider#resourceUrlBlacklist $sceDelegateProvider.resourceUrlBlacklist}
*/
/**
- * @ngdoc object
- * @name ng.$sceDelegateProvider
+ * @ngdoc provider
+ * @name $sceDelegateProvider
* @description
*
* The `$sceDelegateProvider` provider allows developers to configure the {@link ng.$sceDelegate
* $sceDelegate} service. This allows one to get/set the whitelists and blacklists used to ensure
* that the URLs used for sourcing Angular templates are safe. Refer {@link
- * ng.$sceDelegateProvider#methods_resourceUrlWhitelist $sceDelegateProvider.resourceUrlWhitelist} and
- * {@link ng.$sceDelegateProvider#methods_resourceUrlBlacklist $sceDelegateProvider.resourceUrlBlacklist}
+ * ng.$sceDelegateProvider#resourceUrlWhitelist $sceDelegateProvider.resourceUrlWhitelist} and
+ * {@link ng.$sceDelegateProvider#resourceUrlBlacklist $sceDelegateProvider.resourceUrlBlacklist}
*
* For the general details about this service in Angular, read the main page for {@link ng.$sce
* Strict Contextual Escaping (SCE)}.
@@ -12034,9 +12959,8 @@ function $SceDelegateProvider() {
resourceUrlBlacklist = [];
/**
- * @ngdoc function
- * @name ng.sceDelegateProvider#resourceUrlWhitelist
- * @methodOf ng.$sceDelegateProvider
+ * @ngdoc method
+ * @name $sceDelegateProvider#resourceUrlWhitelist
* @function
*
* @param {Array=} whitelist When provided, replaces the resourceUrlWhitelist with the value
@@ -12064,9 +12988,8 @@ function $SceDelegateProvider() {
};
/**
- * @ngdoc function
- * @name ng.sceDelegateProvider#resourceUrlBlacklist
- * @methodOf ng.$sceDelegateProvider
+ * @ngdoc method
+ * @name $sceDelegateProvider#resourceUrlBlacklist
* @function
*
* @param {Array=} blacklist When provided, replaces the resourceUrlBlacklist with the value
@@ -12098,8 +13021,7 @@ function $SceDelegateProvider() {
return resourceUrlBlacklist;
};
- this.$get = ['$log', '$document', '$injector', function(
- $log, $document, $injector) {
+ this.$get = ['$injector', function($injector) {
var htmlSanitizer = function htmlSanitizer(html) {
throw $sceMinErr('unsafe', 'Attempting to use an unsafe value in a safe context.');
@@ -12170,12 +13092,11 @@ function $SceDelegateProvider() {
/**
* @ngdoc method
- * @name ng.$sceDelegate#trustAs
- * @methodOf ng.$sceDelegate
+ * @name $sceDelegate#trustAs
*
* @description
* Returns an object that is trusted by angular for use in specified strict
- * contextual escaping contexts (such as ng-html-bind-unsafe, ng-include, any src
+ * contextual escaping contexts (such as ng-bind-html, ng-include, any src
* attribute interpolation, any dom event binding attribute interpolation
* such as for onclick, etc.) that uses the provided value.
* See {@link ng.$sce $sce} for enabling strict contextual escaping.
@@ -12208,20 +13129,19 @@ function $SceDelegateProvider() {
/**
* @ngdoc method
- * @name ng.$sceDelegate#valueOf
- * @methodOf ng.$sceDelegate
+ * @name $sceDelegate#valueOf
*
* @description
- * If the passed parameter had been returned by a prior call to {@link ng.$sceDelegate#methods_trustAs
+ * If the passed parameter had been returned by a prior call to {@link ng.$sceDelegate#trustAs
* `$sceDelegate.trustAs`}, returns the value that had been passed to {@link
- * ng.$sceDelegate#methods_trustAs `$sceDelegate.trustAs`}.
+ * ng.$sceDelegate#trustAs `$sceDelegate.trustAs`}.
*
* If the passed parameter is not a value that had been returned by {@link
- * ng.$sceDelegate#methods_trustAs `$sceDelegate.trustAs`}, returns it as-is.
+ * ng.$sceDelegate#trustAs `$sceDelegate.trustAs`}, returns it as-is.
*
- * @param {*} value The result of a prior {@link ng.$sceDelegate#methods_trustAs `$sceDelegate.trustAs`}
+ * @param {*} value The result of a prior {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs`}
* call or anything else.
- * @returns {*} The value the was originally provided to {@link ng.$sceDelegate#methods_trustAs
+ * @returns {*} The `value` that was originally provided to {@link ng.$sceDelegate#trustAs
* `$sceDelegate.trustAs`} if `value` is the result of such a call. Otherwise, returns
* `value` unchanged.
*/
@@ -12235,18 +13155,17 @@ function $SceDelegateProvider() {
/**
* @ngdoc method
- * @name ng.$sceDelegate#getTrusted
- * @methodOf ng.$sceDelegate
+ * @name $sceDelegate#getTrusted
*
* @description
- * Takes the result of a {@link ng.$sceDelegate#methods_trustAs `$sceDelegate.trustAs`} call and
+ * Takes the result of a {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs`} call and
* returns the originally supplied value if the queried context type is a supertype of the
* created type. If this condition isn't satisfied, throws an exception.
*
* @param {string} type The kind of context in which this value is to be used.
- * @param {*} maybeTrusted The result of a prior {@link ng.$sceDelegate#methods_trustAs
+ * @param {*} maybeTrusted The result of a prior {@link ng.$sceDelegate#trustAs
* `$sceDelegate.trustAs`} call.
- * @returns {*} The value the was originally provided to {@link ng.$sceDelegate#methods_trustAs
+ * @returns {*} The value the was originally provided to {@link ng.$sceDelegate#trustAs
* `$sceDelegate.trustAs`} if valid in this context. Otherwise, throws an exception.
*/
function getTrusted(type, maybeTrusted) {
@@ -12282,8 +13201,8 @@ function $SceDelegateProvider() {
/**
- * @ngdoc object
- * @name ng.$sceProvider
+ * @ngdoc provider
+ * @name $sceProvider
* @description
*
* The $sceProvider provider allows developers to configure the {@link ng.$sce $sce} service.
@@ -12297,7 +13216,7 @@ function $SceDelegateProvider() {
/**
* @ngdoc service
- * @name ng.$sce
+ * @name $sce
* @function
*
* @description
@@ -12351,20 +13270,20 @@ function $SceDelegateProvider() {
* allowing only the files in a specific directory to do this. Ensuring that the internal API
* exposed by that code doesn't markup arbitrary values as safe then becomes a more manageable task.
*
- * In the case of AngularJS' SCE service, one uses {@link ng.$sce#methods_trustAs $sce.trustAs}
- * (and shorthand methods such as {@link ng.$sce#methods_trustAsHtml $sce.trustAsHtml}, etc.) to
+ * In the case of AngularJS' SCE service, one uses {@link ng.$sce#trustAs $sce.trustAs}
+ * (and shorthand methods such as {@link ng.$sce#trustAsHtml $sce.trustAsHtml}, etc.) to
* obtain values that will be accepted by SCE / privileged contexts.
*
*
* ## How does it work?
*
- * In privileged contexts, directives and code will bind to the result of {@link ng.$sce#methods_getTrusted
+ * In privileged contexts, directives and code will bind to the result of {@link ng.$sce#getTrusted
* $sce.getTrusted(context, value)} rather than to the value directly. Directives use {@link
- * ng.$sce#methods_parse $sce.parseAs} rather than `$parse` to watch attribute bindings, which performs the
- * {@link ng.$sce#methods_getTrusted $sce.getTrusted} behind the scenes on non-constant literals.
+ * ng.$sce#parse $sce.parseAs} rather than `$parse` to watch attribute bindings, which performs the
+ * {@link ng.$sce#getTrusted $sce.getTrusted} behind the scenes on non-constant literals.
*
* As an example, {@link ng.directive:ngBindHtml ngBindHtml} uses {@link
- * ng.$sce#methods_parseAsHtml $sce.parseAsHtml(binding expression)}. Here's the actual code (slightly
+ * ng.$sce#parseAsHtml $sce.parseAsHtml(binding expression)}. Here's the actual code (slightly
* simplified):
*
* <pre class="prettyprint">
@@ -12383,15 +13302,15 @@ function $SceDelegateProvider() {
* `templateUrl`'s specified by {@link guide/directive directives}.
*
* By default, Angular only loads templates from the same domain and protocol as the application
- * document. This is done by calling {@link ng.$sce#methods_getTrustedResourceUrl
+ * document. This is done by calling {@link ng.$sce#getTrustedResourceUrl
* $sce.getTrustedResourceUrl} on the template URL. To load templates from other domains and/or
- * protocols, you may either either {@link ng.$sceDelegateProvider#methods_resourceUrlWhitelist whitelist
- * them} or {@link ng.$sce#methods_trustAsResourceUrl wrap it} into a trusted value.
+ * protocols, you may either either {@link ng.$sceDelegateProvider#resourceUrlWhitelist whitelist
+ * them} or {@link ng.$sce#trustAsResourceUrl wrap it} into a trusted value.
*
* *Please note*:
* The browser's
- * {@link https://code.google.com/p/browsersec/wiki/Part2#Same-origin_policy_for_XMLHttpRequest
- * Same Origin Policy} and {@link http://www.w3.org/TR/cors/ Cross-Origin Resource Sharing (CORS)}
+ * [Same Origin Policy](https://code.google.com/p/browsersec/wiki/Part2#Same-origin_policy_for_XMLHttpRequest)
+ * and [Cross-Origin Resource Sharing (CORS)](http://www.w3.org/TR/cors/)
* policy apply in addition to this and may further restrict whether the template is successfully
* loaded. This means that without the right CORS policy, loading templates from a different domain
* won't work on all browsers. Also, loading templates from `file://` URL does not work on some
@@ -12402,18 +13321,18 @@ function $SceDelegateProvider() {
* It's important to remember that SCE only applies to interpolation expressions.
*
* If your expressions are constant literals, they're automatically trusted and you don't need to
- * call `$sce.trustAs` on them. (e.g.
- * `<div ng-html-bind-unsafe="'<b>implicitly trusted</b>'"></div>`) just works.
+ * call `$sce.trustAs` on them (remember to include the `ngSanitize` module) (e.g.
+ * `<div ng-bind-html="'<b>implicitly trusted</b>'"></div>`) just works.
*
* Additionally, `a[href]` and `img[src]` automatically sanitize their URLs and do not pass them
- * through {@link ng.$sce#methods_getTrusted $sce.getTrusted}. SCE doesn't play a role here.
+ * through {@link ng.$sce#getTrusted $sce.getTrusted}. SCE doesn't play a role here.
*
* The included {@link ng.$sceDelegate $sceDelegate} comes with sane defaults to allow you to load
* templates in `ng-include` from your application's domain without having to even know about SCE.
* It blocks loading templates from other domains or loading templates over http from an https
* served document. You can change these by setting your own custom {@link
- * ng.$sceDelegateProvider#methods_resourceUrlWhitelist whitelists} and {@link
- * ng.$sceDelegateProvider#methods_resourceUrlBlacklist blacklists} for matching such URLs.
+ * ng.$sceDelegateProvider#resourceUrlWhitelist whitelists} and {@link
+ * ng.$sceDelegateProvider#resourceUrlBlacklist blacklists} for matching such URLs.
*
* This significantly reduces the overhead. It is far easier to pay the small overhead and have an
* application that's secure and can be audited to verify that with much more ease than bolting
@@ -12426,11 +13345,11 @@ function $SceDelegateProvider() {
* |---------------------|----------------|
* | `$sce.HTML` | For HTML that's safe to source into the application. The {@link ng.directive:ngBindHtml ngBindHtml} directive uses this context for bindings. |
* | `$sce.CSS` | For CSS that's safe to source into the application. Currently unused. Feel free to use it in your own directives. |
- * | `$sce.URL` | For URLs that are safe to follow as links. Currently unused (`<a href=` and `<img src=` sanitize their urls and don't consititute an SCE context. |
- * | `$sce.RESOURCE_URL` | For URLs that are not only safe to follow as links, but whose contens are also safe to include in your application. Examples include `ng-include`, `src` / `ngSrc` bindings for tags other than `IMG` (e.g. `IFRAME`, `OBJECT`, etc.) <br><br>Note that `$sce.RESOURCE_URL` makes a stronger statement about the URL than `$sce.URL` does and therefore contexts requiring values trusted for `$sce.RESOURCE_URL` can be used anywhere that values trusted for `$sce.URL` are required. |
+ * | `$sce.URL` | For URLs that are safe to follow as links. Currently unused (`<a href=` and `<img src=` sanitize their urls and don't constitute an SCE context. |
+ * | `$sce.RESOURCE_URL` | For URLs that are not only safe to follow as links, but whose contents are also safe to include in your application. Examples include `ng-include`, `src` / `ngSrc` bindings for tags other than `IMG` (e.g. `IFRAME`, `OBJECT`, etc.) <br><br>Note that `$sce.RESOURCE_URL` makes a stronger statement about the URL than `$sce.URL` does and therefore contexts requiring values trusted for `$sce.RESOURCE_URL` can be used anywhere that values trusted for `$sce.URL` are required. |
* | `$sce.JS` | For JavaScript that is safe to execute in your application's context. Currently unused. Feel free to use it in your own directives. |
*
- * ## Format of items in {@link ng.$sceDelegateProvider#methods_resourceUrlWhitelist resourceUrlWhitelist}/{@link ng.$sceDelegateProvider#methods_resourceUrlBlacklist Blacklist} <a name="resourceUrlPatternItem"></a>
+ * ## Format of items in {@link ng.$sceDelegateProvider#resourceUrlWhitelist resourceUrlWhitelist}/{@link ng.$sceDelegateProvider#resourceUrlBlacklist Blacklist} <a name="resourceUrlPatternItem"></a>
*
* Each element in these arrays must be one of the following:
*
@@ -12463,7 +13382,7 @@ function $SceDelegateProvider() {
* matched against the **entire** *normalized / absolute URL* of the resource being tested
* (even when the RegExp did not have the `^` and `$` codes.) In addition, any flags
* present on the RegExp (such as multiline, global, ignoreCase) are ignored.
- * - If you are generating your Javascript from some other templating engine (not
+ * - If you are generating your JavaScript from some other templating engine (not
* recommended, e.g. in issue [#4006](https://github.com/angular/angular.js/issues/4006)),
* remember to escape your regular expression (and be aware that you might need more than
* one level of escaping depending on your templating engine and the way you interpolated
@@ -12480,7 +13399,7 @@ function $SceDelegateProvider() {
* ## Show me an example using SCE.
*
* @example
-<example module="mySceApp">
+<example module="mySceApp" deps="angular-sanitize.js">
<file name="index.html">
<div ng-controller="myAppController as myCtrl">
<i ng-bind-html="myCtrl.explicitlyTrustedHtml" id="explicitlyTrustedHtml"></i><br><br>
@@ -12524,13 +13443,15 @@ function $SceDelegateProvider() {
]
</file>
-<file name="scenario.js">
+<file name="protractor.js" type="protractor">
describe('SCE doc demo', function() {
it('should sanitize untrusted values', function() {
- expect(element('.htmlComment').html()).toBe('<span>Is <i>anyone</i> reading this?</span>');
+ expect(element(by.css('.htmlComment')).getInnerHtml())
+ .toBe('<span>Is <i>anyone</i> reading this?</span>');
});
+
it('should NOT sanitize explicitly trusted values', function() {
- expect(element('#explicitlyTrustedHtml').html()).toBe(
+ expect(element(by.id('explicitlyTrustedHtml')).getInnerHtml()).toBe(
'<span onmouseover="this.textContent=&quot;Explicitly trusted HTML bypasses ' +
'sanitization.&quot;">Hover over this text.</span>');
});
@@ -12565,9 +13486,8 @@ function $SceProvider() {
var enabled = true;
/**
- * @ngdoc function
- * @name ng.sceProvider#enabled
- * @methodOf ng.$sceProvider
+ * @ngdoc method
+ * @name $sceProvider#enabled
* @function
*
* @param {boolean=} value If provided, then enables/disables SCE.
@@ -12630,26 +13550,22 @@ function $SceProvider() {
* sce.js and sceSpecs.js would need to be aware of this detail.
*/
- this.$get = ['$parse', '$document', '$sceDelegate', function(
- $parse, $document, $sceDelegate) {
+ this.$get = ['$parse', '$sniffer', '$sceDelegate', function(
+ $parse, $sniffer, $sceDelegate) {
// Prereq: Ensure that we're not running in IE8 quirks mode. In that mode, IE allows
// the "expression(javascript expression)" syntax which is insecure.
- if (enabled && msie) {
- var documentMode = $document[0].documentMode;
- if (documentMode !== undefined && documentMode < 8) {
- throw $sceMinErr('iequirks',
- 'Strict Contextual Escaping does not support Internet Explorer version < 9 in quirks ' +
- 'mode. You can fix this by adding the text <!doctype html> to the top of your HTML ' +
- 'document. See http://docs.angularjs.org/api/ng.$sce for more information.');
- }
+ if (enabled && $sniffer.msie && $sniffer.msieDocumentMode < 8) {
+ throw $sceMinErr('iequirks',
+ 'Strict Contextual Escaping does not support Internet Explorer version < 9 in quirks ' +
+ 'mode. You can fix this by adding the text <!doctype html> to the top of your HTML ' +
+ 'document. See http://docs.angularjs.org/api/ng.$sce for more information.');
}
var sce = copy(SCE_CONTEXTS);
/**
- * @ngdoc function
- * @name ng.sce#isEnabled
- * @methodOf ng.$sce
+ * @ngdoc method
+ * @name $sce#isEnabled
* @function
*
* @return {Boolean} true if SCE is enabled, false otherwise. If you want to set the value, you
@@ -12672,13 +13588,12 @@ function $SceProvider() {
/**
* @ngdoc method
- * @name ng.$sce#parse
- * @methodOf ng.$sce
+ * @name $sce#parse
*
* @description
* Converts Angular {@link guide/expression expression} into a function. This is like {@link
* ng.$parse $parse} and is identical when the expression is a literal constant. Otherwise, it
- * wraps the expression in a call to {@link ng.$sce#methods_getTrusted $sce.getTrusted(*type*,
+ * wraps the expression in a call to {@link ng.$sce#getTrusted $sce.getTrusted(*type*,
* *result*)}
*
* @param {string} type The kind of SCE context in which this result will be used.
@@ -12703,13 +13618,12 @@ function $SceProvider() {
/**
* @ngdoc method
- * @name ng.$sce#trustAs
- * @methodOf ng.$sce
+ * @name $sce#trustAs
*
* @description
- * Delegates to {@link ng.$sceDelegate#methods_trustAs `$sceDelegate.trustAs`}. As such,
- * returns an objectthat is trusted by angular for use in specified strict contextual
- * escaping contexts (such as ng-html-bind-unsafe, ng-include, any src attribute
+ * Delegates to {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs`}. As such,
+ * returns an object that is trusted by angular for use in specified strict contextual
+ * escaping contexts (such as ng-bind-html, ng-include, any src attribute
* interpolation, any dom event binding attribute interpolation such as for onclick, etc.)
* that uses the provided value. See * {@link ng.$sce $sce} for enabling strict contextual
* escaping.
@@ -12723,95 +13637,89 @@ function $SceProvider() {
/**
* @ngdoc method
- * @name ng.$sce#trustAsHtml
- * @methodOf ng.$sce
+ * @name $sce#trustAsHtml
*
* @description
* Shorthand method. `$sce.trustAsHtml(value)` →
- * {@link ng.$sceDelegate#methods_trustAs `$sceDelegate.trustAs($sce.HTML, value)`}
+ * {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.HTML, value)`}
*
* @param {*} value The value to trustAs.
- * @returns {*} An object that can be passed to {@link ng.$sce#methods_getTrustedHtml
+ * @returns {*} An object that can be passed to {@link ng.$sce#getTrustedHtml
* $sce.getTrustedHtml(value)} to obtain the original value. (privileged directives
* only accept expressions that are either literal constants or are the
- * return value of {@link ng.$sce#methods_trustAs $sce.trustAs}.)
+ * return value of {@link ng.$sce#trustAs $sce.trustAs}.)
*/
/**
* @ngdoc method
- * @name ng.$sce#trustAsUrl
- * @methodOf ng.$sce
+ * @name $sce#trustAsUrl
*
* @description
* Shorthand method. `$sce.trustAsUrl(value)` →
- * {@link ng.$sceDelegate#methods_trustAs `$sceDelegate.trustAs($sce.URL, value)`}
+ * {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.URL, value)`}
*
* @param {*} value The value to trustAs.
- * @returns {*} An object that can be passed to {@link ng.$sce#methods_getTrustedUrl
+ * @returns {*} An object that can be passed to {@link ng.$sce#getTrustedUrl
* $sce.getTrustedUrl(value)} to obtain the original value. (privileged directives
* only accept expressions that are either literal constants or are the
- * return value of {@link ng.$sce#methods_trustAs $sce.trustAs}.)
+ * return value of {@link ng.$sce#trustAs $sce.trustAs}.)
*/
/**
* @ngdoc method
- * @name ng.$sce#trustAsResourceUrl
- * @methodOf ng.$sce
+ * @name $sce#trustAsResourceUrl
*
* @description
* Shorthand method. `$sce.trustAsResourceUrl(value)` →
- * {@link ng.$sceDelegate#methods_trustAs `$sceDelegate.trustAs($sce.RESOURCE_URL, value)`}
+ * {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.RESOURCE_URL, value)`}
*
* @param {*} value The value to trustAs.
- * @returns {*} An object that can be passed to {@link ng.$sce#methods_getTrustedResourceUrl
+ * @returns {*} An object that can be passed to {@link ng.$sce#getTrustedResourceUrl
* $sce.getTrustedResourceUrl(value)} to obtain the original value. (privileged directives
* only accept expressions that are either literal constants or are the return
- * value of {@link ng.$sce#methods_trustAs $sce.trustAs}.)
+ * value of {@link ng.$sce#trustAs $sce.trustAs}.)
*/
/**
* @ngdoc method
- * @name ng.$sce#trustAsJs
- * @methodOf ng.$sce
+ * @name $sce#trustAsJs
*
* @description
* Shorthand method. `$sce.trustAsJs(value)` →
- * {@link ng.$sceDelegate#methods_trustAs `$sceDelegate.trustAs($sce.JS, value)`}
+ * {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.JS, value)`}
*
* @param {*} value The value to trustAs.
- * @returns {*} An object that can be passed to {@link ng.$sce#methods_getTrustedJs
+ * @returns {*} An object that can be passed to {@link ng.$sce#getTrustedJs
* $sce.getTrustedJs(value)} to obtain the original value. (privileged directives
* only accept expressions that are either literal constants or are the
- * return value of {@link ng.$sce#methods_trustAs $sce.trustAs}.)
+ * return value of {@link ng.$sce#trustAs $sce.trustAs}.)
*/
/**
* @ngdoc method
- * @name ng.$sce#getTrusted
- * @methodOf ng.$sce
+ * @name $sce#getTrusted
*
* @description
- * Delegates to {@link ng.$sceDelegate#methods_getTrusted `$sceDelegate.getTrusted`}. As such,
- * takes the result of a {@link ng.$sce#methods_trustAs `$sce.trustAs`}() call and returns the
+ * Delegates to {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted`}. As such,
+ * takes the result of a {@link ng.$sce#trustAs `$sce.trustAs`}() call and returns the
* originally supplied value if the queried context type is a supertype of the created type.
* If this condition isn't satisfied, throws an exception.
*
* @param {string} type The kind of context in which this value is to be used.
- * @param {*} maybeTrusted The result of a prior {@link ng.$sce#methods_trustAs `$sce.trustAs`}
+ * @param {*} maybeTrusted The result of a prior {@link ng.$sce#trustAs `$sce.trustAs`}
* call.
* @returns {*} The value the was originally provided to
- * {@link ng.$sce#methods_trustAs `$sce.trustAs`} if valid in this context.
+ * {@link ng.$sce#trustAs `$sce.trustAs`} if valid in this context.
* Otherwise, throws an exception.
*/
/**
* @ngdoc method
- * @name ng.$sce#getTrustedHtml
- * @methodOf ng.$sce
+ * @name $sce#getTrustedHtml
*
* @description
* Shorthand method. `$sce.getTrustedHtml(value)` →
- * {@link ng.$sceDelegate#methods_getTrusted `$sceDelegate.getTrusted($sce.HTML, value)`}
+ * {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.HTML, value)`}
*
* @param {*} value The value to pass to `$sce.getTrusted`.
* @returns {*} The return value of `$sce.getTrusted($sce.HTML, value)`
@@ -12819,12 +13727,11 @@ function $SceProvider() {
/**
* @ngdoc method
- * @name ng.$sce#getTrustedCss
- * @methodOf ng.$sce
+ * @name $sce#getTrustedCss
*
* @description
* Shorthand method. `$sce.getTrustedCss(value)` →
- * {@link ng.$sceDelegate#methods_getTrusted `$sceDelegate.getTrusted($sce.CSS, value)`}
+ * {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.CSS, value)`}
*
* @param {*} value The value to pass to `$sce.getTrusted`.
* @returns {*} The return value of `$sce.getTrusted($sce.CSS, value)`
@@ -12832,12 +13739,11 @@ function $SceProvider() {
/**
* @ngdoc method
- * @name ng.$sce#getTrustedUrl
- * @methodOf ng.$sce
+ * @name $sce#getTrustedUrl
*
* @description
* Shorthand method. `$sce.getTrustedUrl(value)` →
- * {@link ng.$sceDelegate#methods_getTrusted `$sceDelegate.getTrusted($sce.URL, value)`}
+ * {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.URL, value)`}
*
* @param {*} value The value to pass to `$sce.getTrusted`.
* @returns {*} The return value of `$sce.getTrusted($sce.URL, value)`
@@ -12845,12 +13751,11 @@ function $SceProvider() {
/**
* @ngdoc method
- * @name ng.$sce#getTrustedResourceUrl
- * @methodOf ng.$sce
+ * @name $sce#getTrustedResourceUrl
*
* @description
* Shorthand method. `$sce.getTrustedResourceUrl(value)` →
- * {@link ng.$sceDelegate#methods_getTrusted `$sceDelegate.getTrusted($sce.RESOURCE_URL, value)`}
+ * {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.RESOURCE_URL, value)`}
*
* @param {*} value The value to pass to `$sceDelegate.getTrusted`.
* @returns {*} The return value of `$sce.getTrusted($sce.RESOURCE_URL, value)`
@@ -12858,12 +13763,11 @@ function $SceProvider() {
/**
* @ngdoc method
- * @name ng.$sce#getTrustedJs
- * @methodOf ng.$sce
+ * @name $sce#getTrustedJs
*
* @description
* Shorthand method. `$sce.getTrustedJs(value)` →
- * {@link ng.$sceDelegate#methods_getTrusted `$sceDelegate.getTrusted($sce.JS, value)`}
+ * {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.JS, value)`}
*
* @param {*} value The value to pass to `$sce.getTrusted`.
* @returns {*} The return value of `$sce.getTrusted($sce.JS, value)`
@@ -12871,12 +13775,11 @@ function $SceProvider() {
/**
* @ngdoc method
- * @name ng.$sce#parseAsHtml
- * @methodOf ng.$sce
+ * @name $sce#parseAsHtml
*
* @description
* Shorthand method. `$sce.parseAsHtml(expression string)` →
- * {@link ng.$sce#methods_parse `$sce.parseAs($sce.HTML, value)`}
+ * {@link ng.$sce#parse `$sce.parseAs($sce.HTML, value)`}
*
* @param {string} expression String expression to compile.
* @returns {function(context, locals)} a function which represents the compiled expression:
@@ -12889,12 +13792,11 @@ function $SceProvider() {
/**
* @ngdoc method
- * @name ng.$sce#parseAsCss
- * @methodOf ng.$sce
+ * @name $sce#parseAsCss
*
* @description
* Shorthand method. `$sce.parseAsCss(value)` →
- * {@link ng.$sce#methods_parse `$sce.parseAs($sce.CSS, value)`}
+ * {@link ng.$sce#parse `$sce.parseAs($sce.CSS, value)`}
*
* @param {string} expression String expression to compile.
* @returns {function(context, locals)} a function which represents the compiled expression:
@@ -12907,12 +13809,11 @@ function $SceProvider() {
/**
* @ngdoc method
- * @name ng.$sce#parseAsUrl
- * @methodOf ng.$sce
+ * @name $sce#parseAsUrl
*
* @description
* Shorthand method. `$sce.parseAsUrl(value)` →
- * {@link ng.$sce#methods_parse `$sce.parseAs($sce.URL, value)`}
+ * {@link ng.$sce#parse `$sce.parseAs($sce.URL, value)`}
*
* @param {string} expression String expression to compile.
* @returns {function(context, locals)} a function which represents the compiled expression:
@@ -12925,12 +13826,11 @@ function $SceProvider() {
/**
* @ngdoc method
- * @name ng.$sce#parseAsResourceUrl
- * @methodOf ng.$sce
+ * @name $sce#parseAsResourceUrl
*
* @description
* Shorthand method. `$sce.parseAsResourceUrl(value)` →
- * {@link ng.$sce#methods_parse `$sce.parseAs($sce.RESOURCE_URL, value)`}
+ * {@link ng.$sce#parse `$sce.parseAs($sce.RESOURCE_URL, value)`}
*
* @param {string} expression String expression to compile.
* @returns {function(context, locals)} a function which represents the compiled expression:
@@ -12943,12 +13843,11 @@ function $SceProvider() {
/**
* @ngdoc method
- * @name ng.$sce#parseAsJs
- * @methodOf ng.$sce
+ * @name $sce#parseAsJs
*
* @description
* Shorthand method. `$sce.parseAsJs(value)` →
- * {@link ng.$sce#methods_parse `$sce.parseAs($sce.JS, value)`}
+ * {@link ng.$sce#parse `$sce.parseAs($sce.JS, value)`}
*
* @param {string} expression String expression to compile.
* @returns {function(context, locals)} a function which represents the compiled expression:
@@ -12984,7 +13883,7 @@ function $SceProvider() {
/**
* !!! This is an undocumented "private" service !!!
*
- * @name ng.$sniffer
+ * @name $sniffer
* @requires $window
* @requires $document
*
@@ -13003,6 +13902,7 @@ function $SnifferProvider() {
int((/android (\d+)/.exec(lowercase(($window.navigator || {}).userAgent)) || [])[1]),
boxee = /Boxee/i.test(($window.navigator || {}).userAgent),
document = $document[0] || {},
+ documentMode = document.documentMode,
vendorPrefix,
vendorRegex = /^(Moz|webkit|O|ms)(?=[A-Z])/,
bodyStyle = document.body && document.body.style,
@@ -13039,7 +13939,7 @@ function $SnifferProvider() {
// http://code.google.com/p/android/issues/detail?id=17471
// https://github.com/angular/angular.js/issues/904
- // older webit browser (533.9) on Boxee box has exactly the same problem as Android has
+ // older webkit browser (533.9) on Boxee box has exactly the same problem as Android has
// so let's not use the history API also
// We are purposefully using `!(android < 4)` to cover the case when `android` is undefined
// jshint -W018
@@ -13047,7 +13947,7 @@ function $SnifferProvider() {
// jshint +W018
hashchange: 'onhashchange' in $window &&
// IE8 compatible mode lies
- (!document.documentMode || document.documentMode > 7),
+ (!documentMode || documentMode > 7),
hasEvent: function(event) {
// IE9 implements 'input' event it's so fubared that we rather pretend that it doesn't have
// it. In particular the event is not fired when backspace or delete key are pressed or
@@ -13065,7 +13965,9 @@ function $SnifferProvider() {
vendorPrefix: vendorPrefix,
transitions : transitions,
animations : animations,
- msie : msie
+ android: android,
+ msie : msie,
+ msieDocumentMode: documentMode
};
}];
}
@@ -13077,9 +13979,8 @@ function $TimeoutProvider() {
/**
- * @ngdoc function
- * @name ng.$timeout
- * @requires $browser
+ * @ngdoc service
+ * @name $timeout
*
* @description
* Angular's wrapper for `window.setTimeout`. The `fn` function is wrapped into a try/catch
@@ -13097,97 +13998,10 @@ function $TimeoutProvider() {
* @param {function()} fn A function, whose execution should be delayed.
* @param {number=} [delay=0] Delay in milliseconds.
* @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise
- * will invoke `fn` within the {@link ng.$rootScope.Scope#methods_$apply $apply} block.
+ * will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block.
* @returns {Promise} Promise that will be resolved when the timeout is reached. The value this
* promise will be resolved with is the return value of the `fn` function.
- *
- * @example
- <doc:example module="time">
- <doc:source>
- <script>
- function Ctrl2($scope,$timeout) {
- $scope.format = 'M/d/yy h:mm:ss a';
- $scope.blood_1 = 100;
- $scope.blood_2 = 120;
-
- var stop;
- $scope.fight = function() {
- stop = $timeout(function() {
- if ($scope.blood_1 > 0 && $scope.blood_2 > 0) {
- $scope.blood_1 = $scope.blood_1 - 3;
- $scope.blood_2 = $scope.blood_2 - 4;
- $scope.fight();
- } else {
- $timeout.cancel(stop);
- }
- }, 100);
- };
-
- $scope.stopFight = function() {
- $timeout.cancel(stop);
- };
-
- $scope.resetFight = function() {
- $scope.blood_1 = 100;
- $scope.blood_2 = 120;
- }
- }
-
- angular.module('time', [])
- // Register the 'myCurrentTime' directive factory method.
- // We inject $timeout and dateFilter service since the factory method is DI.
- .directive('myCurrentTime', function($timeout, dateFilter) {
- // return the directive link function. (compile function not needed)
- return function(scope, element, attrs) {
- var format, // date format
- timeoutId; // timeoutId, so that we can cancel the time updates
-
- // used to update the UI
- function updateTime() {
- element.text(dateFilter(new Date(), format));
- }
-
- // watch the expression, and update the UI on change.
- scope.$watch(attrs.myCurrentTime, function(value) {
- format = value;
- updateTime();
- });
-
- // schedule update in one second
- function updateLater() {
- // save the timeoutId for canceling
- timeoutId = $timeout(function() {
- updateTime(); // update DOM
- updateLater(); // schedule another update
- }, 1000);
- }
-
- // listen on DOM destroy (removal) event, and cancel the next UI update
- // to prevent updating time ofter the DOM element was removed.
- element.bind('$destroy', function() {
- $timeout.cancel(timeoutId);
- });
-
- updateLater(); // kick off the UI update process.
- }
- });
- </script>
-
- <div>
- <div ng-controller="Ctrl2">
- Date format: <input ng-model="format"> <hr/>
- Current time is: <span my-current-time="format"></span>
- <hr/>
- Blood 1 : <font color='red'>{{blood_1}}</font>
- Blood 2 : <font color='red'>{{blood_2}}</font>
- <button type="button" data-ng-click="fight()">Fight</button>
- <button type="button" data-ng-click="stopFight()">StopFight</button>
- <button type="button" data-ng-click="resetFight()">resetFight</button>
- </div>
- </div>
-
- </doc:source>
- </doc:example>
+ *
*/
function timeout(fn, delay, invokeApply) {
var deferred = $q.defer(),
@@ -13217,9 +14031,8 @@ function $TimeoutProvider() {
/**
- * @ngdoc function
- * @name ng.$timeout#cancel
- * @methodOf ng.$timeout
+ * @ngdoc method
+ * @name $timeout#cancel
*
* @description
* Cancels a task associated with the `promise`. As a result of this, the promise will be
@@ -13250,11 +14063,6 @@ function $TimeoutProvider() {
// exactly the behavior needed here. There is little value is mocking these out for this
// service.
var urlParsingNode = document.createElement("a");
-/*
-Matches paths for file protocol on windows,
-such as /C:/foo/bar, and captures only /foo/bar.
-*/
-var windowsFilePathExp = /^\/?.*?:(\/.*)/;
var originUrl = urlResolve(window.location.href, true);
@@ -13311,8 +14119,7 @@ var originUrl = urlResolve(window.location.href, true);
*
*/
function urlResolve(url, base) {
- var href = url,
- pathname;
+ var href = url;
if (msie) {
// Normalize before parse. Refer Implementation Notes on why this is
@@ -13323,21 +14130,6 @@ function urlResolve(url, base) {
urlParsingNode.setAttribute('href', href);
- /*
- * In Windows, on an anchor node on documents loaded from
- * the filesystem, the browser will return a pathname
- * prefixed with the drive name ('/C:/path') when a
- * pathname without a drive is set:
- * * a.setAttribute('href', '/foo')
- * * a.pathname === '/C:/foo' //true
- *
- * Inside of Angular, we're always using pathnames that
- * do not include drive names for routing.
- */
-
- pathname = removeWindowsDriveName(urlParsingNode.pathname, url, base);
- pathname = (pathname.charAt(0) === '/') ? pathname : '/' + pathname;
-
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
return {
href: urlParsingNode.href,
@@ -13347,11 +14139,12 @@ function urlResolve(url, base) {
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
hostname: urlParsingNode.hostname,
port: urlParsingNode.port,
- pathname: pathname
+ pathname: (urlParsingNode.pathname.charAt(0) === '/')
+ ? urlParsingNode.pathname
+ : '/' + urlParsingNode.pathname
};
}
-
/**
* Parse a request URL and determine whether this is a same-origin request as the application document.
*
@@ -13365,29 +14158,9 @@ function urlIsSameOrigin(requestUrl) {
parsed.host === originUrl.host);
}
-function removeWindowsDriveName (path, url, base) {
- var firstPathSegmentMatch;
-
- //Get the relative path from the input URL.
- if (url.indexOf(base) === 0) {
- url = url.replace(base, '');
- }
-
- /*
- * The input URL intentionally contains a
- * first path segment that ends with a colon.
- */
- if (windowsFilePathExp.exec(url)) {
- return path;
- }
-
- firstPathSegmentMatch = windowsFilePathExp.exec(path);
- return firstPathSegmentMatch ? firstPathSegmentMatch[1] : path;
-}
-
/**
- * @ngdoc object
- * @name ng.$window
+ * @ngdoc service
+ * @name $window
*
* @description
* A reference to the browser's `window` object. While `window`
@@ -13401,42 +14174,44 @@ function removeWindowsDriveName (path, url, base) {
* expression.
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<script>
function Ctrl($scope, $window) {
- $scope.$window = $window;
$scope.greeting = 'Hello, World!';
+ $scope.doGreeting = function(greeting) {
+ $window.alert(greeting);
+ };
}
</script>
<div ng-controller="Ctrl">
<input type="text" ng-model="greeting" />
- <button ng-click="$window.alert(greeting)">ALERT</button>
+ <button ng-click="doGreeting(greeting)">ALERT</button>
</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should display the greeting in the input box', function() {
- input('greeting').enter('Hello, E2E Tests');
+ element(by.model('greeting')).sendKeys('Hello, E2E Tests');
// If we click the button it will block the test runner
// element(':button').click();
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
function $WindowProvider(){
this.$get = valueFn(window);
}
/**
- * @ngdoc object
- * @name ng.$filterProvider
+ * @ngdoc provider
+ * @name $filterProvider
* @description
*
* Filters are just functions which transform input to an output. However filters need to be
* Dependency Injected. To achieve this a filter definition consists of a factory function which is
* annotated with dependencies and is responsible for creating a filter function.
*
- * <pre>
+ * ```js
* // Filter registration
* function MyModule($provide, $filterProvider) {
* // create a service to demonstrate injection (not always needed)
@@ -13455,12 +14230,12 @@ function $WindowProvider(){
* };
* });
* }
- * </pre>
+ * ```
*
* The filter function is registered with the `$injector` under the filter name suffix with
* `Filter`.
- *
- * <pre>
+ *
+ * ```js
* it('should be the same instance', inject(
* function($filterProvider) {
* $filterProvider.register('reverse', function(){
@@ -13470,7 +14245,7 @@ function $WindowProvider(){
* function($filter, reverseFilter) {
* expect($filter('reverse')).toBe(reverseFilter);
* });
- * </pre>
+ * ```
*
*
* For more information about how angular filters work, and how to create your own filters, see
@@ -13478,19 +14253,18 @@ function $WindowProvider(){
*/
/**
* @ngdoc method
- * @name ng.$filterProvider#register
- * @methodOf ng.$filterProvider
+ * @name $filterProvider#register
* @description
* Register filter factory function.
*
* @param {String} name Name of the filter.
- * @param {function} fn The filter factory function which is injectable.
+ * @param {Function} fn The filter factory function which is injectable.
*/
/**
- * @ngdoc function
- * @name ng.$filter
+ * @ngdoc service
+ * @name $filter
* @function
* @description
* Filters are used for formatting data displayed to the user.
@@ -13507,9 +14281,8 @@ function $FilterProvider($provide) {
var suffix = 'Filter';
/**
- * @ngdoc function
- * @name ng.$controllerProvider#register
- * @methodOf ng.$controllerProvider
+ * @ngdoc method
+ * @name $controllerProvider#register
* @param {string|Object} name Name of the filter function, or an object map of filters where
* the keys are the filter names and the values are the filter factories.
* @returns {Object} Registered filter instance, or if a map of filters was provided then a map
@@ -13535,7 +14308,7 @@ function $FilterProvider($provide) {
}];
////////////////////////////////////////
-
+
/* global
currencyFilter: false,
dateFilter: false,
@@ -13561,7 +14334,7 @@ function $FilterProvider($provide) {
/**
* @ngdoc filter
- * @name ng.filter:filter
+ * @name filter
* @function
*
* @description
@@ -13573,8 +14346,8 @@ function $FilterProvider($provide) {
*
* Can be one of:
*
- * - `string`: Predicate that results in a substring match using the value of `expression`
- * string. All strings or objects with string properties in `array` that contain this string
+ * - `string`: The string is evaluated as an expression and the resulting value is used for substring match against
+ * the contents of the `array`. All strings or objects with string properties in `array` that contain this string
* will be returned. The predicate can be negated by prefixing the string with `!`.
*
* - `Object`: A pattern object can be used to filter specific properties on objects contained
@@ -13584,29 +14357,29 @@ function $FilterProvider($provide) {
* property of the object. That's equivalent to the simple substring match with a `string`
* as described above.
*
- * - `function`: A predicate function can be used to write arbitrary filters. The function is
+ * - `function(value)`: A predicate function can be used to write arbitrary filters. The function is
* called for each element of `array`. The final result is an array of those elements that
* the predicate returned true for.
*
- * @param {function(expected, actual)|true|undefined} comparator Comparator which is used in
+ * @param {function(actual, expected)|true|undefined} comparator Comparator which is used in
* determining if the expected value (from the filter expression) and actual value (from
* the object in the array) should be considered a match.
*
* Can be one of:
*
- * - `function(expected, actual)`:
+ * - `function(actual, expected)`:
* The function will be given the object value and the predicate value to compare and
* should return true if the item should be included in filtered result.
*
- * - `true`: A shorthand for `function(expected, actual) { return angular.equals(expected, actual)}`.
+ * - `true`: A shorthand for `function(actual, expected) { return angular.equals(expected, actual)}`.
* this is essentially strict comparison of expected and actual.
*
* - `false|undefined`: A short hand for a function which will look for a substring match in case
* insensitive way.
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<div ng-init="friends = [{name:'John', phone:'555-1276'},
{name:'Mary', phone:'800-BIG-MARY'},
{name:'Mike', phone:'555-4321'},
@@ -13629,36 +14402,48 @@ function $FilterProvider($provide) {
Equality <input type="checkbox" ng-model="strict"><br>
<table id="searchObjResults">
<tr><th>Name</th><th>Phone</th></tr>
- <tr ng-repeat="friend in friends | filter:search:strict">
- <td>{{friend.name}}</td>
- <td>{{friend.phone}}</td>
+ <tr ng-repeat="friendObj in friends | filter:search:strict">
+ <td>{{friendObj.name}}</td>
+ <td>{{friendObj.phone}}</td>
</tr>
</table>
- </doc:source>
- <doc:scenario>
- it('should search across all fields when filtering with a string', function() {
- input('searchText').enter('m');
- expect(repeater('#searchTextResults tr', 'friend in friends').column('friend.name')).
- toEqual(['Mary', 'Mike', 'Adam']);
+ </file>
+ <file name="protractor.js" type="protractor">
+ var expectFriendNames = function(expectedNames, key) {
+ element.all(by.repeater(key + ' in friends').column(key + '.name')).then(function(arr) {
+ arr.forEach(function(wd, i) {
+ expect(wd.getText()).toMatch(expectedNames[i]);
+ });
+ });
+ };
- input('searchText').enter('76');
- expect(repeater('#searchTextResults tr', 'friend in friends').column('friend.name')).
- toEqual(['John', 'Julie']);
+ it('should search across all fields when filtering with a string', function() {
+ var searchText = element(by.model('searchText'));
+ searchText.clear();
+ searchText.sendKeys('m');
+ expectFriendNames(['Mary', 'Mike', 'Adam'], 'friend');
+
+ searchText.clear();
+ searchText.sendKeys('76');
+ expectFriendNames(['John', 'Julie'], 'friend');
});
it('should search in specific fields when filtering with a predicate object', function() {
- input('search.$').enter('i');
- expect(repeater('#searchObjResults tr', 'friend in friends').column('friend.name')).
- toEqual(['Mary', 'Mike', 'Julie', 'Juliette']);
+ var searchAny = element(by.model('search.$'));
+ searchAny.clear();
+ searchAny.sendKeys('i');
+ expectFriendNames(['Mary', 'Mike', 'Julie', 'Juliette'], 'friendObj');
});
it('should use a equal comparison when comparator is true', function() {
- input('search.name').enter('Julie');
- input('strict').check();
- expect(repeater('#searchObjResults tr', 'friend in friends').column('friend.name')).
- toEqual(['Julie']);
+ var searchName = element(by.model('search.name'));
+ var strict = element(by.model('strict'));
+ searchName.clear();
+ searchName.sendKeys('Julie');
+ strict.click();
+ expectFriendNames(['Julie'], 'friendObj');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
function filterFilter() {
return function(array, expression, comparator) {
@@ -13683,6 +14468,15 @@ function filterFilter() {
};
} else {
comparator = function(obj, text) {
+ if (obj && text && typeof obj === 'object' && typeof text === 'object') {
+ for (var objKey in obj) {
+ if (objKey.charAt(0) !== '$' && hasOwnProperty.call(obj, objKey) &&
+ comparator(obj[objKey], text[objKey])) {
+ return true;
+ }
+ }
+ return false;
+ }
text = (''+text).toLowerCase();
return (''+obj).toLowerCase().indexOf(text) > -1;
};
@@ -13732,23 +14526,12 @@ function filterFilter() {
case "object":
// jshint +W086
for (var key in expression) {
- if (key == '$') {
- (function() {
- if (!expression[key]) return;
- var path = key;
- predicates.push(function(value) {
- return search(value, expression[path]);
- });
- })();
- } else {
- (function() {
- if (typeof(expression[key]) == 'undefined') { return; }
- var path = key;
- predicates.push(function(value) {
- return search(getter(value,path), expression[path]);
- });
- })();
- }
+ (function(path) {
+ if (typeof expression[path] == 'undefined') return;
+ predicates.push(function(value) {
+ return search(path == '$' ? value : (value && value[path]), expression[path]);
+ });
+ })(key);
}
break;
case 'function':
@@ -13770,7 +14553,7 @@ function filterFilter() {
/**
* @ngdoc filter
- * @name ng.filter:currency
+ * @name currency
* @function
*
* @description
@@ -13783,8 +14566,8 @@ function filterFilter() {
*
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.amount = 1234.56;
@@ -13792,22 +14575,28 @@ function filterFilter() {
</script>
<div ng-controller="Ctrl">
<input type="number" ng-model="amount"> <br>
- default currency symbol ($): {{amount | currency}}<br>
- custom currency identifier (USD$): {{amount | currency:"USD$"}}
+ default currency symbol ($): <span id="currency-default">{{amount | currency}}</span><br>
+ custom currency identifier (USD$): <span>{{amount | currency:"USD$"}}</span>
</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should init with 1234.56', function() {
- expect(binding('amount | currency')).toBe('$1,234.56');
- expect(binding('amount | currency:"USD$"')).toBe('USD$1,234.56');
+ expect(element(by.id('currency-default')).getText()).toBe('$1,234.56');
+ expect(element(by.binding('amount | currency:"USD$"')).getText()).toBe('USD$1,234.56');
});
it('should update', function() {
- input('amount').enter('-1234');
- expect(binding('amount | currency')).toBe('($1,234.00)');
- expect(binding('amount | currency:"USD$"')).toBe('(USD$1,234.00)');
+ if (browser.params.browser == 'safari') {
+ // Safari does not understand the minus key. See
+ // https://github.com/angular/protractor/issues/481
+ return;
+ }
+ element(by.model('amount')).clear();
+ element(by.model('amount')).sendKeys('-1234');
+ expect(element(by.id('currency-default')).getText()).toBe('($1,234.00)');
+ expect(element(by.binding('amount | currency:"USD$"')).getText()).toBe('(USD$1,234.00)');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
currencyFilter.$inject = ['$locale'];
function currencyFilter($locale) {
@@ -13821,7 +14610,7 @@ function currencyFilter($locale) {
/**
* @ngdoc filter
- * @name ng.filter:number
+ * @name number
* @function
*
* @description
@@ -13836,8 +14625,8 @@ function currencyFilter($locale) {
* @returns {string} Number rounded to decimalPlaces and places a “,” after each third digit.
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.val = 1234.56789;
@@ -13845,26 +14634,27 @@ function currencyFilter($locale) {
</script>
<div ng-controller="Ctrl">
Enter number: <input ng-model='val'><br>
- Default formatting: {{val | number}}<br>
- No fractions: {{val | number:0}}<br>
- Negative number: {{-val | number:4}}
+ Default formatting: <span id='number-default'>{{val | number}}</span><br>
+ No fractions: <span>{{val | number:0}}</span><br>
+ Negative number: <span>{{-val | number:4}}</span>
</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should format numbers', function() {
- expect(binding('val | number')).toBe('1,234.568');
- expect(binding('val | number:0')).toBe('1,235');
- expect(binding('-val | number:4')).toBe('-1,234.5679');
+ expect(element(by.id('number-default')).getText()).toBe('1,234.568');
+ expect(element(by.binding('val | number:0')).getText()).toBe('1,235');
+ expect(element(by.binding('-val | number:4')).getText()).toBe('-1,234.5679');
});
it('should update', function() {
- input('val').enter('3374.333');
- expect(binding('val | number')).toBe('3,374.333');
- expect(binding('val | number:0')).toBe('3,374');
- expect(binding('-val | number:4')).toBe('-3,374.3330');
- });
- </doc:scenario>
- </doc:example>
+ element(by.model('val')).clear();
+ element(by.model('val')).sendKeys('3374.333');
+ expect(element(by.id('number-default')).getText()).toBe('3,374.333');
+ expect(element(by.binding('val | number:0')).getText()).toBe('3,374');
+ expect(element(by.binding('-val | number:4')).getText()).toBe('-3,374.3330');
+ });
+ </file>
+ </example>
*/
@@ -13879,7 +14669,7 @@ function numberFilter($locale) {
var DECIMAL_SEP = '.';
function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
- if (isNaN(number) || !isFinite(number)) return '';
+ if (number == null || !isFinite(number) || isObject(number)) return '';
var isNegative = number < 0;
number = Math.abs(number);
@@ -14032,7 +14822,7 @@ var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+
/**
* @ngdoc filter
- * @name ng.filter:date
+ * @name date
* @function
*
* @description
@@ -14090,26 +14880,26 @@ var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+
* @returns {string} Formatted string or the input if input is not recognized as date/millis.
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<span ng-non-bindable>{{1288323623006 | date:'medium'}}</span>:
- {{1288323623006 | date:'medium'}}<br>
+ <span>{{1288323623006 | date:'medium'}}</span><br>
<span ng-non-bindable>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span>:
- {{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}<br>
+ <span>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span><br>
<span ng-non-bindable>{{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}</span>:
- {{'1288323623006' | date:'MM/dd/yyyy @ h:mma'}}<br>
- </doc:source>
- <doc:scenario>
+ <span>{{'1288323623006' | date:'MM/dd/yyyy @ h:mma'}}</span><br>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should format date', function() {
- expect(binding("1288323623006 | date:'medium'")).
+ expect(element(by.binding("1288323623006 | date:'medium'")).getText()).
toMatch(/Oct 2\d, 2010 \d{1,2}:\d{2}:\d{2} (AM|PM)/);
- expect(binding("1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'")).
+ expect(element(by.binding("1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'")).getText()).
toMatch(/2010\-10\-2\d \d{2}:\d{2}:\d{2} (\-|\+)?\d{4}/);
- expect(binding("'1288323623006' | date:'MM/dd/yyyy @ h:mma'")).
+ expect(element(by.binding("'1288323623006' | date:'MM/dd/yyyy @ h:mma'")).getText()).
toMatch(/10\/2\d\/2010 @ \d{1,2}:\d{2}(AM|PM)/);
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
dateFilter.$inject = ['$locale'];
function dateFilter($locale) {
@@ -14189,7 +14979,7 @@ function dateFilter($locale) {
/**
* @ngdoc filter
- * @name ng.filter:json
+ * @name json
* @function
*
* @description
@@ -14202,17 +14992,17 @@ function dateFilter($locale) {
* @returns {string} JSON string.
*
*
- * @example:
- <doc:example>
- <doc:source>
+ * @example
+ <example>
+ <file name="index.html">
<pre>{{ {'name':'value'} | json }}</pre>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should jsonify filtered objects', function() {
- expect(binding("{'name':'value'}")).toMatch(/\{\n "name": ?"value"\n}/);
+ expect(element(by.binding("{'name':'value'}")).getText()).toMatch(/\{\n "name": ?"value"\n}/);
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*
*/
function jsonFilter() {
@@ -14224,7 +15014,7 @@ function jsonFilter() {
/**
* @ngdoc filter
- * @name ng.filter:lowercase
+ * @name lowercase
* @function
* @description
* Converts string to lowercase.
@@ -14235,7 +15025,7 @@ var lowercaseFilter = valueFn(lowercase);
/**
* @ngdoc filter
- * @name ng.filter:uppercase
+ * @name uppercase
* @function
* @description
* Converts string to uppercase.
@@ -14244,8 +15034,8 @@ var lowercaseFilter = valueFn(lowercase);
var uppercaseFilter = valueFn(uppercase);
/**
- * @ngdoc function
- * @name ng.filter:limitTo
+ * @ngdoc filter
+ * @name limitTo
* @function
*
* @description
@@ -14254,16 +15044,16 @@ var uppercaseFilter = valueFn(uppercase);
* the value and sign (positive or negative) of `limit`.
*
* @param {Array|string} input Source array or string to be limited.
- * @param {string|number} limit The length of the returned array or string. If the `limit` number
+ * @param {string|number} limit The length of the returned array or string. If the `limit` number
* is positive, `limit` number of items from the beginning of the source array/string are copied.
- * If the number is negative, `limit` number of items from the end of the source array/string
+ * If the number is negative, `limit` number of items from the end of the source array/string
* are copied. The `limit` will be trimmed if it exceeds `array.length`
* @returns {Array|string} A new sub-array or substring of length `limit` or less if input array
* had less than `limit` elements.
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.numbers = [1,2,3,4,5,6,7,8,9];
@@ -14278,35 +15068,44 @@ var uppercaseFilter = valueFn(uppercase);
Limit {{letters}} to: <input type="integer" ng-model="letterLimit">
<p>Output letters: {{ letters | limitTo:letterLimit }}</p>
</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
+ var numLimitInput = element(by.model('numLimit'));
+ var letterLimitInput = element(by.model('letterLimit'));
+ var limitedNumbers = element(by.binding('numbers | limitTo:numLimit'));
+ var limitedLetters = element(by.binding('letters | limitTo:letterLimit'));
+
it('should limit the number array to first three items', function() {
- expect(element('.doc-example-live input[ng-model=numLimit]').val()).toBe('3');
- expect(element('.doc-example-live input[ng-model=letterLimit]').val()).toBe('3');
- expect(binding('numbers | limitTo:numLimit')).toEqual('[1,2,3]');
- expect(binding('letters | limitTo:letterLimit')).toEqual('abc');
+ expect(numLimitInput.getAttribute('value')).toBe('3');
+ expect(letterLimitInput.getAttribute('value')).toBe('3');
+ expect(limitedNumbers.getText()).toEqual('Output numbers: [1,2,3]');
+ expect(limitedLetters.getText()).toEqual('Output letters: abc');
});
it('should update the output when -3 is entered', function() {
- input('numLimit').enter(-3);
- input('letterLimit').enter(-3);
- expect(binding('numbers | limitTo:numLimit')).toEqual('[7,8,9]');
- expect(binding('letters | limitTo:letterLimit')).toEqual('ghi');
+ numLimitInput.clear();
+ numLimitInput.sendKeys('-3');
+ letterLimitInput.clear();
+ letterLimitInput.sendKeys('-3');
+ expect(limitedNumbers.getText()).toEqual('Output numbers: [7,8,9]');
+ expect(limitedLetters.getText()).toEqual('Output letters: ghi');
});
it('should not exceed the maximum size of input array', function() {
- input('numLimit').enter(100);
- input('letterLimit').enter(100);
- expect(binding('numbers | limitTo:numLimit')).toEqual('[1,2,3,4,5,6,7,8,9]');
- expect(binding('letters | limitTo:letterLimit')).toEqual('abcdefghi');
+ numLimitInput.clear();
+ numLimitInput.sendKeys('100');
+ letterLimitInput.clear();
+ letterLimitInput.sendKeys('100');
+ expect(limitedNumbers.getText()).toEqual('Output numbers: [1,2,3,4,5,6,7,8,9]');
+ expect(limitedLetters.getText()).toEqual('Output letters: abcdefghi');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
function limitToFilter(){
return function(input, limit) {
if (!isArray(input) && !isString(input)) return input;
-
+
limit = int(limit);
if (isString(input)) {
@@ -14344,8 +15143,8 @@ function limitToFilter(){
}
/**
- * @ngdoc function
- * @name ng.filter:orderBy
+ * @ngdoc filter
+ * @name orderBy
* @function
*
* @description
@@ -14365,12 +15164,12 @@ function limitToFilter(){
* - `Array`: An array of function or string predicates. The first predicate in the array
* is used for sorting, but when two items are equivalent, the next predicate is used.
*
- * @param {boolean=} reverse Reverse the order the array.
+ * @param {boolean=} reverse Reverse the order of the array.
* @returns {Array} Sorted copy of the source array.
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.friends =
@@ -14400,31 +15199,8 @@ function limitToFilter(){
</tr>
</table>
</div>
- </doc:source>
- <doc:scenario>
- it('should be reverse ordered by aged', function() {
- expect(binding('predicate')).toBe('-age');
- expect(repeater('table.friend', 'friend in friends').column('friend.age')).
- toEqual(['35', '29', '21', '19', '10']);
- expect(repeater('table.friend', 'friend in friends').column('friend.name')).
- toEqual(['Adam', 'Julie', 'Mike', 'Mary', 'John']);
- });
-
- it('should reorder the table when user selects different predicate', function() {
- element('.doc-example-live a:contains("Name")').click();
- expect(repeater('table.friend', 'friend in friends').column('friend.name')).
- toEqual(['Adam', 'John', 'Julie', 'Mary', 'Mike']);
- expect(repeater('table.friend', 'friend in friends').column('friend.age')).
- toEqual(['35', '10', '29', '19', '21']);
-
- element('.doc-example-live a:contains("Phone")').click();
- expect(repeater('table.friend', 'friend in friends').column('friend.phone')).
- toEqual(['555-9876', '555-8765', '555-5678', '555-4321', '555-1212']);
- expect(repeater('table.friend', 'friend in friends').column('friend.name')).
- toEqual(['Mary', 'Julie', 'Adam', 'Mike', 'John']);
- });
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
orderByFilter.$inject = ['$parse'];
function orderByFilter($parse){
@@ -14440,6 +15216,12 @@ function orderByFilter($parse){
predicate = predicate.substring(1);
}
get = $parse(predicate);
+ if (get.constant) {
+ var key = get();
+ return reverseComparator(function(a,b) {
+ return compare(a[key], b[key]);
+ }, descending);
+ }
}
return reverseComparator(function(a,b){
return compare(get(a),get(b));
@@ -14490,7 +15272,7 @@ function ngDirective(directive) {
/**
* @ngdoc directive
- * @name ng.directive:a
+ * @name a
* @restrict E
*
* @description
@@ -14520,21 +15302,27 @@ var htmlAnchorDirective = valueFn({
element.append(document.createComment('IE fix'));
}
- return function(scope, element) {
- element.on('click', function(event){
- // if we have no href url, then don't navigate anywhere.
- if (!element.attr('href')) {
- event.preventDefault();
- }
- });
- };
+ if (!attr.href && !attr.xlinkHref && !attr.name) {
+ return function(scope, element) {
+ // SVGAElement does not use the href attribute, but rather the 'xlinkHref' attribute.
+ var href = toString.call(element.prop('href')) === '[object SVGAnimatedString]' ?
+ 'xlink:href' : 'href';
+ element.on('click', function(event){
+ // if we have no href url, then don't navigate anywhere.
+ if (!element.attr(href)) {
+ event.preventDefault();
+ }
+ });
+ };
+ }
}
});
/**
* @ngdoc directive
- * @name ng.directive:ngHref
+ * @name ngHref
* @restrict A
+ * @priority 99
*
* @description
* Using Angular markup like `{{hash}}` in an href attribute will
@@ -14546,14 +15334,14 @@ var htmlAnchorDirective = valueFn({
* The `ngHref` directive solves this problem.
*
* The wrong way to write it:
- * <pre>
+ * ```html
* <a href="http://www.gravatar.com/avatar/{{hash}}"/>
- * </pre>
+ * ```
*
* The correct way to write it:
- * <pre>
+ * ```html
* <a ng-href="http://www.gravatar.com/avatar/{{hash}}"/>
- * </pre>
+ * ```
*
* @element A
* @param {template} ngHref any string which can contain `{{}}` markup.
@@ -14561,8 +15349,8 @@ var htmlAnchorDirective = valueFn({
* @example
* This example shows various combinations of `href`, `ng-href` and `ng-click` attributes
* in links and their different behaviors:
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<input ng-model="value" /><br />
<a id="link-1" href ng-click="value = 1">link 1</a> (link, don't reload)<br />
<a id="link-2" href="" ng-click="value = 2">link 2</a> (link, don't reload)<br />
@@ -14570,54 +15358,71 @@ var htmlAnchorDirective = valueFn({
<a id="link-4" href="" name="xx" ng-click="value = 4">anchor</a> (link, don't reload)<br />
<a id="link-5" name="xxx" ng-click="value = 5">anchor</a> (no link)<br />
<a id="link-6" ng-href="{{value}}">link</a> (link, change location)
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should execute ng-click but not reload when href without value', function() {
- element('#link-1').click();
- expect(input('value').val()).toEqual('1');
- expect(element('#link-1').attr('href')).toBe("");
+ element(by.id('link-1')).click();
+ expect(element(by.model('value')).getAttribute('value')).toEqual('1');
+ expect(element(by.id('link-1')).getAttribute('href')).toBe('');
});
it('should execute ng-click but not reload when href empty string', function() {
- element('#link-2').click();
- expect(input('value').val()).toEqual('2');
- expect(element('#link-2').attr('href')).toBe("");
+ element(by.id('link-2')).click();
+ expect(element(by.model('value')).getAttribute('value')).toEqual('2');
+ expect(element(by.id('link-2')).getAttribute('href')).toBe('');
});
it('should execute ng-click and change url when ng-href specified', function() {
- expect(element('#link-3').attr('href')).toBe("/123");
+ expect(element(by.id('link-3')).getAttribute('href')).toMatch(/\/123$/);
+
+ element(by.id('link-3')).click();
+
+ // At this point, we navigate away from an Angular page, so we need
+ // to use browser.driver to get the base webdriver.
- element('#link-3').click();
- expect(browser().window().path()).toEqual('/123');
+ browser.wait(function() {
+ return browser.driver.getCurrentUrl().then(function(url) {
+ return url.match(/\/123$/);
+ });
+ }, 1000, 'page should navigate to /123');
});
- it('should execute ng-click but not reload when href empty string and name specified', function() {
- element('#link-4').click();
- expect(input('value').val()).toEqual('4');
- expect(element('#link-4').attr('href')).toBe('');
+ xit('should execute ng-click but not reload when href empty string and name specified', function() {
+ element(by.id('link-4')).click();
+ expect(element(by.model('value')).getAttribute('value')).toEqual('4');
+ expect(element(by.id('link-4')).getAttribute('href')).toBe('');
});
it('should execute ng-click but not reload when no href but name specified', function() {
- element('#link-5').click();
- expect(input('value').val()).toEqual('5');
- expect(element('#link-5').attr('href')).toBe(undefined);
+ element(by.id('link-5')).click();
+ expect(element(by.model('value')).getAttribute('value')).toEqual('5');
+ expect(element(by.id('link-5')).getAttribute('href')).toBe(null);
});
it('should only change url when only ng-href', function() {
- input('value').enter('6');
- expect(element('#link-6').attr('href')).toBe('6');
+ element(by.model('value')).clear();
+ element(by.model('value')).sendKeys('6');
+ expect(element(by.id('link-6')).getAttribute('href')).toMatch(/\/6$/);
+
+ element(by.id('link-6')).click();
- element('#link-6').click();
- expect(browser().location().url()).toEqual('/6');
+ // At this point, we navigate away from an Angular page, so we need
+ // to use browser.driver to get the base webdriver.
+ browser.wait(function() {
+ return browser.driver.getCurrentUrl().then(function(url) {
+ return url.match(/\/6$/);
+ });
+ }, 1000, 'page should navigate to /6');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
/**
* @ngdoc directive
- * @name ng.directive:ngSrc
+ * @name ngSrc
* @restrict A
+ * @priority 99
*
* @description
* Using Angular markup like `{{hash}}` in a `src` attribute doesn't
@@ -14626,14 +15431,14 @@ var htmlAnchorDirective = valueFn({
* `{{hash}}`. The `ngSrc` directive solves this problem.
*
* The buggy way to write it:
- * <pre>
+ * ```html
* <img src="http://www.gravatar.com/avatar/{{hash}}"/>
- * </pre>
+ * ```
*
* The correct way to write it:
- * <pre>
+ * ```html
* <img ng-src="http://www.gravatar.com/avatar/{{hash}}"/>
- * </pre>
+ * ```
*
* @element IMG
* @param {template} ngSrc any string which can contain `{{}}` markup.
@@ -14641,8 +15446,9 @@ var htmlAnchorDirective = valueFn({
/**
* @ngdoc directive
- * @name ng.directive:ngSrcset
+ * @name ngSrcset
* @restrict A
+ * @priority 99
*
* @description
* Using Angular markup like `{{hash}}` in a `srcset` attribute doesn't
@@ -14651,14 +15457,14 @@ var htmlAnchorDirective = valueFn({
* `{{hash}}`. The `ngSrcset` directive solves this problem.
*
* The buggy way to write it:
- * <pre>
+ * ```html
* <img srcset="http://www.gravatar.com/avatar/{{hash}} 2x"/>
- * </pre>
+ * ```
*
* The correct way to write it:
- * <pre>
+ * ```html
* <img ng-srcset="http://www.gravatar.com/avatar/{{hash}} 2x"/>
- * </pre>
+ * ```
*
* @element IMG
* @param {template} ngSrcset any string which can contain `{{}}` markup.
@@ -14666,169 +15472,189 @@ var htmlAnchorDirective = valueFn({
/**
* @ngdoc directive
- * @name ng.directive:ngDisabled
+ * @name ngDisabled
* @restrict A
+ * @priority 100
*
* @description
*
* The following markup will make the button enabled on Chrome/Firefox but not on IE8 and older IEs:
- * <pre>
+ * ```html
* <div ng-init="scope = { isDisabled: false }">
* <button disabled="{{scope.isDisabled}}">Disabled</button>
* </div>
- * </pre>
+ * ```
*
* The HTML specification does not require browsers to preserve the values of boolean attributes
* such as disabled. (Their presence means true and their absence means false.)
- * This prevents the Angular compiler from retrieving the binding expression.
+ * If we put an Angular interpolation expression into such an attribute then the
+ * binding information would be lost when the browser removes the attribute.
* The `ngDisabled` directive solves this problem for the `disabled` attribute.
+ * This complementary directive is not removed by the browser and so provides
+ * a permanent reliable place to store the binding information.
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
Click me to toggle: <input type="checkbox" ng-model="checked"><br/>
<button ng-model="button" ng-disabled="checked">Button</button>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should toggle button', function() {
- expect(element('.doc-example-live :button').prop('disabled')).toBeFalsy();
- input('checked').check();
- expect(element('.doc-example-live :button').prop('disabled')).toBeTruthy();
+ expect(element(by.css('button')).getAttribute('disabled')).toBeFalsy();
+ element(by.model('checked')).click();
+ expect(element(by.css('button')).getAttribute('disabled')).toBeTruthy();
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*
* @element INPUT
- * @param {expression} ngDisabled If the {@link guide/expression expression} is truthy,
+ * @param {expression} ngDisabled If the {@link guide/expression expression} is truthy,
* then special attribute "disabled" will be set on the element
*/
/**
* @ngdoc directive
- * @name ng.directive:ngChecked
+ * @name ngChecked
* @restrict A
+ * @priority 100
*
* @description
* The HTML specification does not require browsers to preserve the values of boolean attributes
* such as checked. (Their presence means true and their absence means false.)
- * This prevents the Angular compiler from retrieving the binding expression.
+ * If we put an Angular interpolation expression into such an attribute then the
+ * binding information would be lost when the browser removes the attribute.
* The `ngChecked` directive solves this problem for the `checked` attribute.
+ * This complementary directive is not removed by the browser and so provides
+ * a permanent reliable place to store the binding information.
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
Check me to check both: <input type="checkbox" ng-model="master"><br/>
<input id="checkSlave" type="checkbox" ng-checked="master">
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should check both checkBoxes', function() {
- expect(element('.doc-example-live #checkSlave').prop('checked')).toBeFalsy();
- input('master').check();
- expect(element('.doc-example-live #checkSlave').prop('checked')).toBeTruthy();
+ expect(element(by.id('checkSlave')).getAttribute('checked')).toBeFalsy();
+ element(by.model('master')).click();
+ expect(element(by.id('checkSlave')).getAttribute('checked')).toBeTruthy();
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*
* @element INPUT
- * @param {expression} ngChecked If the {@link guide/expression expression} is truthy,
+ * @param {expression} ngChecked If the {@link guide/expression expression} is truthy,
* then special attribute "checked" will be set on the element
*/
/**
* @ngdoc directive
- * @name ng.directive:ngReadonly
+ * @name ngReadonly
* @restrict A
+ * @priority 100
*
* @description
* The HTML specification does not require browsers to preserve the values of boolean attributes
* such as readonly. (Their presence means true and their absence means false.)
- * This prevents the Angular compiler from retrieving the binding expression.
+ * If we put an Angular interpolation expression into such an attribute then the
+ * binding information would be lost when the browser removes the attribute.
* The `ngReadonly` directive solves this problem for the `readonly` attribute.
+ * This complementary directive is not removed by the browser and so provides
+ * a permanent reliable place to store the binding information.
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
Check me to make text readonly: <input type="checkbox" ng-model="checked"><br/>
<input type="text" ng-readonly="checked" value="I'm Angular"/>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should toggle readonly attr', function() {
- expect(element('.doc-example-live :text').prop('readonly')).toBeFalsy();
- input('checked').check();
- expect(element('.doc-example-live :text').prop('readonly')).toBeTruthy();
+ expect(element(by.css('[type="text"]')).getAttribute('readonly')).toBeFalsy();
+ element(by.model('checked')).click();
+ expect(element(by.css('[type="text"]')).getAttribute('readonly')).toBeTruthy();
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*
* @element INPUT
- * @param {expression} ngReadonly If the {@link guide/expression expression} is truthy,
+ * @param {expression} ngReadonly If the {@link guide/expression expression} is truthy,
* then special attribute "readonly" will be set on the element
*/
/**
* @ngdoc directive
- * @name ng.directive:ngSelected
+ * @name ngSelected
* @restrict A
+ * @priority 100
*
* @description
* The HTML specification does not require browsers to preserve the values of boolean attributes
* such as selected. (Their presence means true and their absence means false.)
- * This prevents the Angular compiler from retrieving the binding expression.
- * The `ngSelected` directive solves this problem for the `selected` atttribute.
+ * If we put an Angular interpolation expression into such an attribute then the
+ * binding information would be lost when the browser removes the attribute.
+ * The `ngSelected` directive solves this problem for the `selected` attribute.
+ * This complementary directive is not removed by the browser and so provides
+ * a permanent reliable place to store the binding information.
+ *
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
Check me to select: <input type="checkbox" ng-model="selected"><br/>
<select>
<option>Hello!</option>
<option id="greet" ng-selected="selected">Greetings!</option>
</select>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should select Greetings!', function() {
- expect(element('.doc-example-live #greet').prop('selected')).toBeFalsy();
- input('selected').check();
- expect(element('.doc-example-live #greet').prop('selected')).toBeTruthy();
+ expect(element(by.id('greet')).getAttribute('selected')).toBeFalsy();
+ element(by.model('selected')).click();
+ expect(element(by.id('greet')).getAttribute('selected')).toBeTruthy();
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*
* @element OPTION
- * @param {expression} ngSelected If the {@link guide/expression expression} is truthy,
+ * @param {expression} ngSelected If the {@link guide/expression expression} is truthy,
* then special attribute "selected" will be set on the element
*/
/**
* @ngdoc directive
- * @name ng.directive:ngOpen
+ * @name ngOpen
* @restrict A
+ * @priority 100
*
* @description
* The HTML specification does not require browsers to preserve the values of boolean attributes
* such as open. (Their presence means true and their absence means false.)
- * This prevents the Angular compiler from retrieving the binding expression.
+ * If we put an Angular interpolation expression into such an attribute then the
+ * binding information would be lost when the browser removes the attribute.
* The `ngOpen` directive solves this problem for the `open` attribute.
- *
+ * This complementary directive is not removed by the browser and so provides
+ * a permanent reliable place to store the binding information.
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
Check me check multiple: <input type="checkbox" ng-model="open"><br/>
<details id="details" ng-open="open">
<summary>Show/Hide me</summary>
</details>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should toggle open', function() {
- expect(element('#details').prop('open')).toBeFalsy();
- input('open').check();
- expect(element('#details').prop('open')).toBeTruthy();
+ expect(element(by.id('details')).getAttribute('open')).toBeFalsy();
+ element(by.model('open')).click();
+ expect(element(by.id('details')).getAttribute('open')).toBeTruthy();
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*
* @element DETAILS
- * @param {expression} ngOpen If the {@link guide/expression expression} is truthy,
+ * @param {expression} ngOpen If the {@link guide/expression expression} is truthy,
* then special attribute "open" will be set on the element
*/
@@ -14844,12 +15670,10 @@ forEach(BOOLEAN_ATTR, function(propName, attrName) {
ngAttributeAliasDirectives[normalized] = function() {
return {
priority: 100,
- compile: function() {
- return function(scope, element, attr) {
- scope.$watch(attr[normalized], function ngBooleanAttrWatchAction(value) {
- attr.$set(attrName, !!value);
- });
- };
+ link: function(scope, element, attr) {
+ scope.$watch(attr[normalized], function ngBooleanAttrWatchAction(value) {
+ attr.$set(attrName, !!value);
+ });
}
};
};
@@ -14863,17 +15687,27 @@ forEach(['src', 'srcset', 'href'], function(attrName) {
return {
priority: 99, // it needs to run after the attributes are interpolated
link: function(scope, element, attr) {
+ var propName = attrName,
+ name = attrName;
+
+ if (attrName === 'href' &&
+ toString.call(element.prop('href')) === '[object SVGAnimatedString]') {
+ name = 'xlinkHref';
+ attr.$attr[name] = 'xlink:href';
+ propName = null;
+ }
+
attr.$observe(normalized, function(value) {
if (!value)
return;
- attr.$set(attrName, value);
+ attr.$set(name, value);
// on IE, if "ng:src" directive declaration is used and "src" attribute doesn't exist
// then calling element.setAttribute('src', 'foo') doesn't do anything, so we need
// to set the property as well to achieve the desired effect.
// we use attr[attrName] value since $set can sanitize the url.
- if (msie) element.prop(attrName, attr[attrName]);
+ if (msie && propName) element.prop(propName, attr[name]);
});
}
};
@@ -14890,8 +15724,8 @@ var nullFormCtrl = {
};
/**
- * @ngdoc object
- * @name ng.directive:form.FormController
+ * @ngdoc type
+ * @name form.FormController
*
* @property {boolean} $pristine True if user has not interacted with the form yet.
* @property {boolean} $dirty True if user has already interacted with the form.
@@ -14901,8 +15735,21 @@ var nullFormCtrl = {
* @property {Object} $error Is an object hash, containing references to all invalid controls or
* forms, where:
*
- * - keys are validation tokens (error names) — such as `required`, `url` or `email`,
- * - values are arrays of controls or forms that are invalid with given error.
+ * - keys are validation tokens (error names),
+ * - values are arrays of controls or forms that are invalid for given error name.
+ *
+ *
+ * Built-in validation tokens:
+ *
+ * - `email`
+ * - `max`
+ * - `maxlength`
+ * - `min`
+ * - `minlength`
+ * - `number`
+ * - `pattern`
+ * - `required`
+ * - `url`
*
* @description
* `FormController` keeps track of all its controls and nested forms as well as state of them,
@@ -14913,8 +15760,8 @@ var nullFormCtrl = {
*
*/
//asks for $scope to fool the BC controller module
-FormController.$inject = ['$element', '$attrs', '$scope'];
-function FormController(element, attrs) {
+FormController.$inject = ['$element', '$attrs', '$scope', '$animate'];
+function FormController(element, attrs, $scope, $animate) {
var form = this,
parentForm = element.parent().controller('form') || nullFormCtrl,
invalidCount = 0, // used to easily determine if we are valid
@@ -14937,15 +15784,13 @@ function FormController(element, attrs) {
// convenience method for easy toggling of classes
function toggleValidCss(isValid, validationErrorKey) {
validationErrorKey = validationErrorKey ? '-' + snake_case(validationErrorKey, '-') : '';
- element.
- removeClass((isValid ? INVALID_CLASS : VALID_CLASS) + validationErrorKey).
- addClass((isValid ? VALID_CLASS : INVALID_CLASS) + validationErrorKey);
+ $animate.removeClass(element, (isValid ? INVALID_CLASS : VALID_CLASS) + validationErrorKey);
+ $animate.addClass(element, (isValid ? VALID_CLASS : INVALID_CLASS) + validationErrorKey);
}
/**
- * @ngdoc function
- * @name ng.directive:form.FormController#$addControl
- * @methodOf ng.directive:form.FormController
+ * @ngdoc method
+ * @name form.FormController#$addControl
*
* @description
* Register a control with the form.
@@ -14964,9 +15809,8 @@ function FormController(element, attrs) {
};
/**
- * @ngdoc function
- * @name ng.directive:form.FormController#$removeControl
- * @methodOf ng.directive:form.FormController
+ * @ngdoc method
+ * @name form.FormController#$removeControl
*
* @description
* Deregister a control from the form.
@@ -14985,9 +15829,8 @@ function FormController(element, attrs) {
};
/**
- * @ngdoc function
- * @name ng.directive:form.FormController#$setValidity
- * @methodOf ng.directive:form.FormController
+ * @ngdoc method
+ * @name form.FormController#$setValidity
*
* @description
* Sets the validity of a form control.
@@ -15033,9 +15876,8 @@ function FormController(element, attrs) {
};
/**
- * @ngdoc function
- * @name ng.directive:form.FormController#$setDirty
- * @methodOf ng.directive:form.FormController
+ * @ngdoc method
+ * @name form.FormController#$setDirty
*
* @description
* Sets the form to a dirty state.
@@ -15044,16 +15886,16 @@ function FormController(element, attrs) {
* state (ng-dirty class). This method will also propagate to parent forms.
*/
form.$setDirty = function() {
- element.removeClass(PRISTINE_CLASS).addClass(DIRTY_CLASS);
+ $animate.removeClass(element, PRISTINE_CLASS);
+ $animate.addClass(element, DIRTY_CLASS);
form.$dirty = true;
form.$pristine = false;
parentForm.$setDirty();
};
/**
- * @ngdoc function
- * @name ng.directive:form.FormController#$setPristine
- * @methodOf ng.directive:form.FormController
+ * @ngdoc method
+ * @name form.FormController#$setPristine
*
* @description
* Sets the form to its pristine state.
@@ -15066,7 +15908,8 @@ function FormController(element, attrs) {
* saving or resetting it.
*/
form.$setPristine = function () {
- element.removeClass(DIRTY_CLASS).addClass(PRISTINE_CLASS);
+ $animate.removeClass(element, DIRTY_CLASS);
+ $animate.addClass(element, PRISTINE_CLASS);
form.$dirty = false;
form.$pristine = true;
forEach(controls, function(control) {
@@ -15078,7 +15921,7 @@ function FormController(element, attrs) {
/**
* @ngdoc directive
- * @name ng.directive:ngForm
+ * @name ngForm
* @restrict EAC
*
* @description
@@ -15086,6 +15929,10 @@ function FormController(element, attrs) {
* does not allow nesting of form elements. It is useful to nest forms, for example if the validity of a
* sub-group of controls needs to be determined.
*
+ * Note: the purpose of `ngForm` is to group controls,
+ * but not to be a replacement for the `<form>` tag with all of its capabilities
+ * (e.g. posting to the server, ...).
+ *
* @param {string=} ngForm|name Name of the form. If specified, the form controller will be published into
* related scope, under this name.
*
@@ -15093,12 +15940,12 @@ function FormController(element, attrs) {
/**
* @ngdoc directive
- * @name ng.directive:form
+ * @name form
* @restrict E
*
* @description
* Directive that instantiates
- * {@link ng.directive:form.FormController FormController}.
+ * {@link form.FormController FormController}.
*
* If the `name` attribute is specified, the form controller is published onto the current scope under
* this name.
@@ -15116,10 +15963,12 @@ function FormController(element, attrs) {
*
*
* # CSS classes
- * - `ng-valid` Is set if the form is valid.
- * - `ng-invalid` Is set if the form is invalid.
- * - `ng-pristine` Is set if the form is pristine.
- * - `ng-dirty` Is set if the form is dirty.
+ * - `ng-valid` is set if the form is valid.
+ * - `ng-invalid` is set if the form is invalid.
+ * - `ng-pristine` is set if the form is pristine.
+ * - `ng-dirty` is set if the form is dirty.
+ *
+ * Keep in mind that ngAnimate can detect each of these classes when added and removed.
*
*
* # Submitting a form and preventing the default action
@@ -15154,15 +16003,49 @@ function FormController(element, attrs) {
* @param {string=} name Name of the form. If specified, the form controller will be published into
* related scope, under this name.
*
+ * ## Animation Hooks
+ *
+ * Animations in ngForm are triggered when any of the associated CSS classes are added and removed.
+ * These classes are: `.ng-pristine`, `.ng-dirty`, `.ng-invalid` and `.ng-valid` as well as any
+ * other validations that are performed within the form. Animations in ngForm are similar to how
+ * they work in ngClass and animations can be hooked into using CSS transitions, keyframes as well
+ * as JS animations.
+ *
+ * The following example shows a simple way to utilize CSS transitions to style a form element
+ * that has been rendered as invalid after it has been validated:
+ *
+ * <pre>
+ * //be sure to include ngAnimate as a module to hook into more
+ * //advanced animations
+ * .my-form {
+ * transition:0.5s linear all;
+ * background: white;
+ * }
+ * .my-form.ng-invalid {
+ * background: red;
+ * color:white;
+ * }
+ * </pre>
+ *
* @example
- <doc:example>
- <doc:source>
+ <example deps="angular-animate.js" animations="true" fixBase="true">
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.userType = 'guest';
}
</script>
- <form name="myForm" ng-controller="Ctrl">
+ <style>
+ .my-form {
+ -webkit-transition:all linear 0.5s;
+ transition:all linear 0.5s;
+ background: transparent;
+ }
+ .my-form.ng-invalid {
+ background: red;
+ }
+ </style>
+ <form name="myForm" ng-controller="Ctrl" class="my-form">
userType: <input name="input" ng-model="userType" required>
<span class="error" ng-show="myForm.input.$error.required">Required!</span><br>
<tt>userType = {{userType}}</tt><br>
@@ -15171,20 +16054,30 @@ function FormController(element, attrs) {
<tt>myForm.$valid = {{myForm.$valid}}</tt><br>
<tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br>
</form>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should initialize to model', function() {
- expect(binding('userType')).toEqual('guest');
- expect(binding('myForm.input.$valid')).toEqual('true');
+ var userType = element(by.binding('userType'));
+ var valid = element(by.binding('myForm.input.$valid'));
+
+ expect(userType.getText()).toContain('guest');
+ expect(valid.getText()).toContain('true');
});
it('should be invalid if empty', function() {
- input('userType').enter('');
- expect(binding('userType')).toEqual('');
- expect(binding('myForm.input.$valid')).toEqual('false');
+ var userType = element(by.binding('userType'));
+ var valid = element(by.binding('myForm.input.$valid'));
+ var userInput = element(by.model('userType'));
+
+ userInput.clear();
+ userInput.sendKeys('');
+
+ expect(userType.getText()).toEqual('userType =');
+ expect(valid.getText()).toContain('false');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
+ *
*/
var formDirectiveFactory = function(isNgForm) {
return ['$timeout', function($timeout) {
@@ -15255,14 +16148,14 @@ var ngFormDirective = formDirectiveFactory(true);
*/
var URL_REGEXP = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/;
-var EMAIL_REGEXP = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}$/;
+var EMAIL_REGEXP = /^[a-z0-9!#$%&'*+/=?^_`{|}~.-]+@[a-z0-9-]+(\.[a-z0-9-]+)*$/i;
var NUMBER_REGEXP = /^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/;
var inputType = {
/**
- * @ngdoc inputType
- * @name ng.directive:input.text
+ * @ngdoc input
+ * @name input[text]
*
* @description
* Standard HTML text input with angular data binding.
@@ -15285,8 +16178,8 @@ var inputType = {
* @param {boolean=} [ngTrim=true] If set to false Angular will not automatically trim the input.
*
* @example
- <doc:example>
- <doc:source>
+ <example name="text-input-directive">
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.text = 'guest';
@@ -15307,38 +16200,40 @@ var inputType = {
<tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
<tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
</form>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
+ var text = element(by.binding('text'));
+ var valid = element(by.binding('myForm.input.$valid'));
+ var input = element(by.model('text'));
+
it('should initialize to model', function() {
- expect(binding('text')).toEqual('guest');
- expect(binding('myForm.input.$valid')).toEqual('true');
+ expect(text.getText()).toContain('guest');
+ expect(valid.getText()).toContain('true');
});
it('should be invalid if empty', function() {
- input('text').enter('');
- expect(binding('text')).toEqual('');
- expect(binding('myForm.input.$valid')).toEqual('false');
+ input.clear();
+ input.sendKeys('');
+
+ expect(text.getText()).toEqual('text =');
+ expect(valid.getText()).toContain('false');
});
it('should be invalid if multi word', function() {
- input('text').enter('hello world');
- expect(binding('myForm.input.$valid')).toEqual('false');
- });
+ input.clear();
+ input.sendKeys('hello world');
- it('should not be trimmed', function() {
- input('text').enter('untrimmed ');
- expect(binding('text')).toEqual('untrimmed ');
- expect(binding('myForm.input.$valid')).toEqual('true');
+ expect(valid.getText()).toContain('false');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
'text': textInputType,
/**
- * @ngdoc inputType
- * @name ng.directive:input.number
+ * @ngdoc input
+ * @name input[number]
*
* @description
* Text input with number validation and transformation. Sets the `number` validation
@@ -15363,8 +16258,8 @@ var inputType = {
* interaction with the input element.
*
* @example
- <doc:example>
- <doc:source>
+ <example name="number-input-directive">
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.value = 12;
@@ -15383,33 +16278,39 @@ var inputType = {
<tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
<tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
</form>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
+ var value = element(by.binding('value'));
+ var valid = element(by.binding('myForm.input.$valid'));
+ var input = element(by.model('value'));
+
it('should initialize to model', function() {
- expect(binding('value')).toEqual('12');
- expect(binding('myForm.input.$valid')).toEqual('true');
+ expect(value.getText()).toContain('12');
+ expect(valid.getText()).toContain('true');
});
it('should be invalid if empty', function() {
- input('value').enter('');
- expect(binding('value')).toEqual('');
- expect(binding('myForm.input.$valid')).toEqual('false');
+ input.clear();
+ input.sendKeys('');
+ expect(value.getText()).toEqual('value =');
+ expect(valid.getText()).toContain('false');
});
it('should be invalid if over max', function() {
- input('value').enter('123');
- expect(binding('value')).toEqual('');
- expect(binding('myForm.input.$valid')).toEqual('false');
+ input.clear();
+ input.sendKeys('123');
+ expect(value.getText()).toEqual('value =');
+ expect(valid.getText()).toContain('false');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
'number': numberInputType,
/**
- * @ngdoc inputType
- * @name ng.directive:input.url
+ * @ngdoc input
+ * @name input[url]
*
* @description
* Text input with URL validation. Sets the `url` validation error key if the content is not a
@@ -15432,8 +16333,8 @@ var inputType = {
* interaction with the input element.
*
* @example
- <doc:example>
- <doc:source>
+ <example name="url-input-directive">
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.text = 'http://google.com';
@@ -15452,32 +16353,40 @@ var inputType = {
<tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
<tt>myForm.$error.url = {{!!myForm.$error.url}}</tt><br/>
</form>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
+ var text = element(by.binding('text'));
+ var valid = element(by.binding('myForm.input.$valid'));
+ var input = element(by.model('text'));
+
it('should initialize to model', function() {
- expect(binding('text')).toEqual('http://google.com');
- expect(binding('myForm.input.$valid')).toEqual('true');
+ expect(text.getText()).toContain('http://google.com');
+ expect(valid.getText()).toContain('true');
});
it('should be invalid if empty', function() {
- input('text').enter('');
- expect(binding('text')).toEqual('');
- expect(binding('myForm.input.$valid')).toEqual('false');
+ input.clear();
+ input.sendKeys('');
+
+ expect(text.getText()).toEqual('text =');
+ expect(valid.getText()).toContain('false');
});
it('should be invalid if not url', function() {
- input('text').enter('xxx');
- expect(binding('myForm.input.$valid')).toEqual('false');
+ input.clear();
+ input.sendKeys('box');
+
+ expect(valid.getText()).toContain('false');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
'url': urlInputType,
/**
- * @ngdoc inputType
- * @name ng.directive:input.email
+ * @ngdoc input
+ * @name input[email]
*
* @description
* Text input with email validation. Sets the `email` validation error key if not a valid email
@@ -15500,8 +16409,8 @@ var inputType = {
* interaction with the input element.
*
* @example
- <doc:example>
- <doc:source>
+ <example name="email-input-directive">
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.text = 'me@example.com';
@@ -15520,32 +16429,39 @@ var inputType = {
<tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
<tt>myForm.$error.email = {{!!myForm.$error.email}}</tt><br/>
</form>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
+ var text = element(by.binding('text'));
+ var valid = element(by.binding('myForm.input.$valid'));
+ var input = element(by.model('text'));
+
it('should initialize to model', function() {
- expect(binding('text')).toEqual('me@example.com');
- expect(binding('myForm.input.$valid')).toEqual('true');
+ expect(text.getText()).toContain('me@example.com');
+ expect(valid.getText()).toContain('true');
});
it('should be invalid if empty', function() {
- input('text').enter('');
- expect(binding('text')).toEqual('');
- expect(binding('myForm.input.$valid')).toEqual('false');
+ input.clear();
+ input.sendKeys('');
+ expect(text.getText()).toEqual('text =');
+ expect(valid.getText()).toContain('false');
});
it('should be invalid if not email', function() {
- input('text').enter('xxx');
- expect(binding('myForm.input.$valid')).toEqual('false');
+ input.clear();
+ input.sendKeys('xxx');
+
+ expect(valid.getText()).toContain('false');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
'email': emailInputType,
/**
- * @ngdoc inputType
- * @name ng.directive:input.radio
+ * @ngdoc input
+ * @name input[radio]
*
* @description
* HTML radio button.
@@ -15555,38 +16471,48 @@ var inputType = {
* @param {string=} name Property name of the form under which the control is published.
* @param {string=} ngChange Angular expression to be executed when input changes due to user
* interaction with the input element.
+ * @param {string} ngValue Angular expression which sets the value to which the expression should
+ * be set when selected.
*
* @example
- <doc:example>
- <doc:source>
+ <example name="radio-input-directive">
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.color = 'blue';
+ $scope.specialValue = {
+ "id": "12345",
+ "value": "green"
+ };
}
</script>
<form name="myForm" ng-controller="Ctrl">
<input type="radio" ng-model="color" value="red"> Red <br/>
- <input type="radio" ng-model="color" value="green"> Green <br/>
+ <input type="radio" ng-model="color" ng-value="specialValue"> Green <br/>
<input type="radio" ng-model="color" value="blue"> Blue <br/>
- <tt>color = {{color}}</tt><br/>
+ <tt>color = {{color | json}}</tt><br/>
</form>
- </doc:source>
- <doc:scenario>
+ Note that `ng-value="specialValue"` sets radio item's value to be the value of `$scope.specialValue`.
+ </file>
+ <file name="protractor.js" type="protractor">
it('should change state', function() {
- expect(binding('color')).toEqual('blue');
+ var color = element(by.binding('color'));
- input('color').select('red');
- expect(binding('color')).toEqual('red');
+ expect(color.getText()).toContain('blue');
+
+ element.all(by.model('color')).get(0).click();
+
+ expect(color.getText()).toContain('red');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
'radio': radioInputType,
/**
- * @ngdoc inputType
- * @name ng.directive:input.checkbox
+ * @ngdoc input
+ * @name input[checkbox]
*
* @description
* HTML checkbox.
@@ -15599,8 +16525,8 @@ var inputType = {
* interaction with the input element.
*
* @example
- <doc:example>
- <doc:source>
+ <example name="checkbox-input-directive">
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.value1 = true;
@@ -15614,32 +16540,78 @@ var inputType = {
<tt>value1 = {{value1}}</tt><br/>
<tt>value2 = {{value2}}</tt><br/>
</form>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should change state', function() {
- expect(binding('value1')).toEqual('true');
- expect(binding('value2')).toEqual('YES');
+ var value1 = element(by.binding('value1'));
+ var value2 = element(by.binding('value2'));
+
+ expect(value1.getText()).toContain('true');
+ expect(value2.getText()).toContain('YES');
- input('value1').check();
- input('value2').check();
- expect(binding('value1')).toEqual('false');
- expect(binding('value2')).toEqual('NO');
+ element(by.model('value1')).click();
+ element(by.model('value2')).click();
+
+ expect(value1.getText()).toContain('false');
+ expect(value2.getText()).toContain('NO');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
'checkbox': checkboxInputType,
'hidden': noop,
'button': noop,
'submit': noop,
- 'reset': noop
+ 'reset': noop,
+ 'file': noop
};
+// A helper function to call $setValidity and return the value / undefined,
+// a pattern that is repeated a lot in the input validation logic.
+function validate(ctrl, validatorName, validity, value){
+ ctrl.$setValidity(validatorName, validity);
+ return validity ? value : undefined;
+}
+
+
+function addNativeHtml5Validators(ctrl, validatorName, element) {
+ var validity = element.prop('validity');
+ if (isObject(validity)) {
+ var validator = function(value) {
+ // Don't overwrite previous validation, don't consider valueMissing to apply (ng-required can
+ // perform the required validation)
+ if (!ctrl.$error[validatorName] && (validity.badInput || validity.customError ||
+ validity.typeMismatch) && !validity.valueMissing) {
+ ctrl.$setValidity(validatorName, false);
+ return;
+ }
+ return value;
+ };
+ ctrl.$parsers.push(validator);
+ }
+}
function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
+ var validity = element.prop('validity');
+ // In composition mode, users are still inputing intermediate text buffer,
+ // hold the listener until composition is done.
+ // More about composition events: https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent
+ if (!$sniffer.android) {
+ var composing = false;
+
+ element.on('compositionstart', function(data) {
+ composing = true;
+ });
+
+ element.on('compositionend', function() {
+ composing = false;
+ listener();
+ });
+ }
var listener = function() {
+ if (composing) return;
var value = element.val();
// By default we will trim the value
@@ -15649,10 +16621,18 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
value = trim(value);
}
- if (ctrl.$viewValue !== value) {
- scope.$apply(function() {
+ if (ctrl.$viewValue !== value ||
+ // If the value is still empty/falsy, and there is no `required` error, run validators
+ // again. This enables HTML5 constraint validation errors to affect Angular validation
+ // even when the first character entered causes an error.
+ (validity && value === '' && !validity.valueMissing)) {
+ if (scope.$$phase) {
ctrl.$setViewValue(value);
- });
+ } else {
+ scope.$apply(function() {
+ ctrl.$setViewValue(value);
+ });
+ }
}
};
@@ -15682,15 +16662,15 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
deferListener();
});
- // if user paste into input using mouse, we need "change" event to catch it
- element.on('change', listener);
-
// if user modifies input value using context menu in IE, we need "paste" and "cut" events to catch it
if ($sniffer.hasEvent('paste')) {
element.on('paste cut', deferListener);
}
}
+ // if user paste into input using mouse on older browser
+ // or form autocomplete on newer browser, we need "change" event to catch it
+ element.on('change', listener);
ctrl.$render = function() {
element.val(ctrl.$isEmpty(ctrl.$viewValue) ? '' : ctrl.$viewValue);
@@ -15701,22 +16681,15 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
patternValidator,
match;
- var validate = function(regexp, value) {
- if (ctrl.$isEmpty(value) || regexp.test(value)) {
- ctrl.$setValidity('pattern', true);
- return value;
- } else {
- ctrl.$setValidity('pattern', false);
- return undefined;
- }
- };
-
if (pattern) {
+ var validateRegex = function(regexp, value) {
+ return validate(ctrl, 'pattern', ctrl.$isEmpty(value) || regexp.test(value), value);
+ };
match = pattern.match(/^\/(.*)\/([gim]*)$/);
if (match) {
pattern = new RegExp(match[1], match[2]);
patternValidator = function(value) {
- return validate(pattern, value);
+ return validateRegex(pattern, value);
};
} else {
patternValidator = function(value) {
@@ -15727,7 +16700,7 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
'Expected {0} to be a RegExp but was {1}. Element: {2}', pattern,
patternObj, startingTag(element));
}
- return validate(patternObj, value);
+ return validateRegex(patternObj, value);
};
}
@@ -15739,13 +16712,7 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
if (attr.ngMinlength) {
var minlength = int(attr.ngMinlength);
var minLengthValidator = function(value) {
- if (!ctrl.$isEmpty(value) && value.length < minlength) {
- ctrl.$setValidity('minlength', false);
- return undefined;
- } else {
- ctrl.$setValidity('minlength', true);
- return value;
- }
+ return validate(ctrl, 'minlength', ctrl.$isEmpty(value) || value.length >= minlength, value);
};
ctrl.$parsers.push(minLengthValidator);
@@ -15756,13 +16723,7 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
if (attr.ngMaxlength) {
var maxlength = int(attr.ngMaxlength);
var maxLengthValidator = function(value) {
- if (!ctrl.$isEmpty(value) && value.length > maxlength) {
- ctrl.$setValidity('maxlength', false);
- return undefined;
- } else {
- ctrl.$setValidity('maxlength', true);
- return value;
- }
+ return validate(ctrl, 'maxlength', ctrl.$isEmpty(value) || value.length <= maxlength, value);
};
ctrl.$parsers.push(maxLengthValidator);
@@ -15784,6 +16745,8 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
}
});
+ addNativeHtml5Validators(ctrl, 'number', element);
+
ctrl.$formatters.push(function(value) {
return ctrl.$isEmpty(value) ? '' : '' + value;
});
@@ -15791,13 +16754,7 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
if (attr.min) {
var minValidator = function(value) {
var min = parseFloat(attr.min);
- if (!ctrl.$isEmpty(value) && value < min) {
- ctrl.$setValidity('min', false);
- return undefined;
- } else {
- ctrl.$setValidity('min', true);
- return value;
- }
+ return validate(ctrl, 'min', ctrl.$isEmpty(value) || value >= min, value);
};
ctrl.$parsers.push(minValidator);
@@ -15807,13 +16764,7 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
if (attr.max) {
var maxValidator = function(value) {
var max = parseFloat(attr.max);
- if (!ctrl.$isEmpty(value) && value > max) {
- ctrl.$setValidity('max', false);
- return undefined;
- } else {
- ctrl.$setValidity('max', true);
- return value;
- }
+ return validate(ctrl, 'max', ctrl.$isEmpty(value) || value <= max, value);
};
ctrl.$parsers.push(maxValidator);
@@ -15821,14 +16772,7 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
}
ctrl.$formatters.push(function(value) {
-
- if (ctrl.$isEmpty(value) || isNumber(value)) {
- ctrl.$setValidity('number', true);
- return value;
- } else {
- ctrl.$setValidity('number', false);
- return undefined;
- }
+ return validate(ctrl, 'number', ctrl.$isEmpty(value) || isNumber(value), value);
});
}
@@ -15836,13 +16780,7 @@ function urlInputType(scope, element, attr, ctrl, $sniffer, $browser) {
textInputType(scope, element, attr, ctrl, $sniffer, $browser);
var urlValidator = function(value) {
- if (ctrl.$isEmpty(value) || URL_REGEXP.test(value)) {
- ctrl.$setValidity('url', true);
- return value;
- } else {
- ctrl.$setValidity('url', false);
- return undefined;
- }
+ return validate(ctrl, 'url', ctrl.$isEmpty(value) || URL_REGEXP.test(value), value);
};
ctrl.$formatters.push(urlValidator);
@@ -15853,13 +16791,7 @@ function emailInputType(scope, element, attr, ctrl, $sniffer, $browser) {
textInputType(scope, element, attr, ctrl, $sniffer, $browser);
var emailValidator = function(value) {
- if (ctrl.$isEmpty(value) || EMAIL_REGEXP.test(value)) {
- ctrl.$setValidity('email', true);
- return value;
- } else {
- ctrl.$setValidity('email', false);
- return undefined;
- }
+ return validate(ctrl, 'email', ctrl.$isEmpty(value) || EMAIL_REGEXP.test(value), value);
};
ctrl.$formatters.push(emailValidator);
@@ -15922,7 +16854,7 @@ function checkboxInputType(scope, element, attr, ctrl) {
/**
* @ngdoc directive
- * @name ng.directive:textarea
+ * @name textarea
* @restrict E
*
* @description
@@ -15950,7 +16882,7 @@ function checkboxInputType(scope, element, attr, ctrl) {
/**
* @ngdoc directive
- * @name ng.directive:input
+ * @name input
* @restrict E
*
* @description
@@ -15972,8 +16904,8 @@ function checkboxInputType(scope, element, attr, ctrl) {
* interaction with the input element.
*
* @example
- <doc:example>
- <doc:source>
+ <example name="input-directive">
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.user = {name: 'guest', last: 'visitor'};
@@ -16002,46 +16934,61 @@ function checkboxInputType(scope, element, attr, ctrl) {
<tt>myForm.$error.minlength = {{!!myForm.$error.minlength}}</tt><br>
<tt>myForm.$error.maxlength = {{!!myForm.$error.maxlength}}</tt><br>
</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
+ var user = element(by.binding('{{user}}'));
+ var userNameValid = element(by.binding('myForm.userName.$valid'));
+ var lastNameValid = element(by.binding('myForm.lastName.$valid'));
+ var lastNameError = element(by.binding('myForm.lastName.$error'));
+ var formValid = element(by.binding('myForm.$valid'));
+ var userNameInput = element(by.model('user.name'));
+ var userLastInput = element(by.model('user.last'));
+
it('should initialize to model', function() {
- expect(binding('user')).toEqual('{"name":"guest","last":"visitor"}');
- expect(binding('myForm.userName.$valid')).toEqual('true');
- expect(binding('myForm.$valid')).toEqual('true');
+ expect(user.getText()).toContain('{"name":"guest","last":"visitor"}');
+ expect(userNameValid.getText()).toContain('true');
+ expect(formValid.getText()).toContain('true');
});
it('should be invalid if empty when required', function() {
- input('user.name').enter('');
- expect(binding('user')).toEqual('{"last":"visitor"}');
- expect(binding('myForm.userName.$valid')).toEqual('false');
- expect(binding('myForm.$valid')).toEqual('false');
+ userNameInput.clear();
+ userNameInput.sendKeys('');
+
+ expect(user.getText()).toContain('{"last":"visitor"}');
+ expect(userNameValid.getText()).toContain('false');
+ expect(formValid.getText()).toContain('false');
});
it('should be valid if empty when min length is set', function() {
- input('user.last').enter('');
- expect(binding('user')).toEqual('{"name":"guest","last":""}');
- expect(binding('myForm.lastName.$valid')).toEqual('true');
- expect(binding('myForm.$valid')).toEqual('true');
+ userLastInput.clear();
+ userLastInput.sendKeys('');
+
+ expect(user.getText()).toContain('{"name":"guest","last":""}');
+ expect(lastNameValid.getText()).toContain('true');
+ expect(formValid.getText()).toContain('true');
});
it('should be invalid if less than required min length', function() {
- input('user.last').enter('xx');
- expect(binding('user')).toEqual('{"name":"guest"}');
- expect(binding('myForm.lastName.$valid')).toEqual('false');
- expect(binding('myForm.lastName.$error')).toMatch(/minlength/);
- expect(binding('myForm.$valid')).toEqual('false');
+ userLastInput.clear();
+ userLastInput.sendKeys('xx');
+
+ expect(user.getText()).toContain('{"name":"guest"}');
+ expect(lastNameValid.getText()).toContain('false');
+ expect(lastNameError.getText()).toContain('minlength');
+ expect(formValid.getText()).toContain('false');
});
it('should be invalid if longer than max length', function() {
- input('user.last').enter('some ridiculously long name');
- expect(binding('user'))
- .toEqual('{"name":"guest"}');
- expect(binding('myForm.lastName.$valid')).toEqual('false');
- expect(binding('myForm.lastName.$error')).toMatch(/maxlength/);
- expect(binding('myForm.$valid')).toEqual('false');
+ userLastInput.clear();
+ userLastInput.sendKeys('some ridiculously long name');
+
+ expect(user.getText()).toContain('{"name":"guest"}');
+ expect(lastNameValid.getText()).toContain('false');
+ expect(lastNameError.getText()).toContain('maxlength');
+ expect(formValid.getText()).toContain('false');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
var inputDirective = ['$browser', '$sniffer', function($browser, $sniffer) {
return {
@@ -16062,30 +17009,31 @@ var VALID_CLASS = 'ng-valid',
DIRTY_CLASS = 'ng-dirty';
/**
- * @ngdoc object
- * @name ng.directive:ngModel.NgModelController
+ * @ngdoc type
+ * @name ngModel.NgModelController
*
* @property {string} $viewValue Actual string value in the view.
* @property {*} $modelValue The value in the model, that the control is bound to.
* @property {Array.<Function>} $parsers Array of functions to execute, as a pipeline, whenever
the control reads value from the DOM. Each function is called, in turn, passing the value
- through to the next. Used to sanitize / convert the value as well as validation.
- For validation, the parsers should update the validity state using
- {@link ng.directive:ngModel.NgModelController#methods_$setValidity $setValidity()},
+ through to the next. The last return value is used to populate the model.
+ Used to sanitize / convert the value as well as validation. For validation,
+ the parsers should update the validity state using
+ {@link ngModel.NgModelController#$setValidity $setValidity()},
and return `undefined` for invalid values.
*
* @property {Array.<Function>} $formatters Array of functions to execute, as a pipeline, whenever
the model value changes. Each function is called, in turn, passing the value through to the
next. Used to format / convert values for display in the control and validation.
- * <pre>
+ * ```js
* function formatter(value) {
* if (value) {
* return value.toUpperCase();
* }
* }
* ngModel.$formatters.push(formatter);
- * </pre>
+ * ```
*
* @property {Array.<Function>} $viewChangeListeners Array of functions to execute whenever the
* view value has changed. It is called with no arguments, and its return value is ignored.
@@ -16114,7 +17062,7 @@ var VALID_CLASS = 'ng-valid',
* Note that `contenteditable` is an HTML5 attribute, which tells the browser to let the element
* contents be edited in place by the user. This will not work on older browsers.
*
- * <example module="customControl">
+ * <example name="NgModelController" module="customControl">
<file name="style.css">
[contenteditable] {
border: 1px solid black;
@@ -16172,55 +17120,30 @@ var VALID_CLASS = 'ng-valid',
<textarea ng-model="userContent"></textarea>
</form>
</file>
- <file name="scenario.js">
- it('should data-bind and become invalid', function() {
- var contentEditable = element('[contenteditable]');
-
- expect(contentEditable.text()).toEqual('Change me!');
- input('userContent').enter('');
- expect(contentEditable.text()).toEqual('');
- expect(contentEditable.prop('className')).toMatch(/ng-invalid-required/);
- });
- </file>
- * </example>
- *
- * ## Isolated Scope Pitfall
- *
- * Note that if you have a directive with an isolated scope, you cannot require `ngModel`
- * since the model value will be looked up on the isolated scope rather than the outer scope.
- * When the directive updates the model value, calling `ngModel.$setViewValue()` the property
- * on the outer scope will not be updated. However you can get around this by using $parent.
- *
- * Here is an example of this situation. You'll notice that the first div is not updating the input.
- * However the second div can update the input properly.
- *
- * <example module="badIsolatedDirective">
- <file name="script.js">
- angular.module('badIsolatedDirective', []).directive('isolate', function() {
- return {
- require: 'ngModel',
- scope: { },
- template: '<input ng-model="innerModel">',
- link: function(scope, element, attrs, ngModel) {
- scope.$watch('innerModel', function(value) {
- console.log(value);
- ngModel.$setViewValue(value);
- });
- }
- };
- });
- </file>
- <file name="index.html">
- <input ng-model="someModel"/>
- <div isolate ng-model="someModel"></div>
- <div isolate ng-model="$parent.someModel"></div>
+ <file name="protractor.js" type="protractor">
+ it('should data-bind and become invalid', function() {
+ if (browser.params.browser == 'safari' || browser.params.browser == 'firefox') {
+ // SafariDriver can't handle contenteditable
+ // and Firefox driver can't clear contenteditables very well
+ return;
+ }
+ var contentEditable = element(by.css('[contenteditable]'));
+ var content = 'Change me!';
+
+ expect(contentEditable.getText()).toEqual(content);
+
+ contentEditable.clear();
+ contentEditable.sendKeys(protractor.Key.BACK_SPACE);
+ expect(contentEditable.getText()).toEqual('');
+ expect(contentEditable.getAttribute('class')).toMatch(/ng-invalid-required/);
+ });
</file>
* </example>
*
*
*/
-var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$parse',
- function($scope, $exceptionHandler, $attr, $element, $parse) {
+var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$parse', '$animate',
+ function($scope, $exceptionHandler, $attr, $element, $parse, $animate) {
this.$viewValue = Number.NaN;
this.$modelValue = Number.NaN;
this.$parsers = [];
@@ -16241,9 +17164,8 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
}
/**
- * @ngdoc function
- * @name ng.directive:ngModel.NgModelController#$render
- * @methodOf ng.directive:ngModel.NgModelController
+ * @ngdoc method
+ * @name ngModel.NgModelController#$render
*
* @description
* Called when the view needs to be updated. It is expected that the user of the ng-model
@@ -16252,9 +17174,8 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
this.$render = noop;
/**
- * @ngdoc function
- * @name { ng.directive:ngModel.NgModelController#$isEmpty
- * @methodOf ng.directive:ngModel.NgModelController
+ * @ngdoc method
+ * @name ngModel.NgModelController#$isEmpty
*
* @description
* This is called when we need to determine if the value of the input is empty.
@@ -16265,6 +17186,9 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
* You can override this for input directives whose concept of being empty is different to the
* default. The `checkboxInputType` directive does this because in its case a value of `false`
* implies empty.
+ *
+ * @param {*} value Reference to check.
+ * @returns {boolean} True if `value` is empty.
*/
this.$isEmpty = function(value) {
return isUndefined(value) || value === '' || value === null || value !== value;
@@ -16282,15 +17206,13 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
// convenience method for easy toggling of classes
function toggleValidCss(isValid, validationErrorKey) {
validationErrorKey = validationErrorKey ? '-' + snake_case(validationErrorKey, '-') : '';
- $element.
- removeClass((isValid ? INVALID_CLASS : VALID_CLASS) + validationErrorKey).
- addClass((isValid ? VALID_CLASS : INVALID_CLASS) + validationErrorKey);
+ $animate.removeClass($element, (isValid ? INVALID_CLASS : VALID_CLASS) + validationErrorKey);
+ $animate.addClass($element, (isValid ? VALID_CLASS : INVALID_CLASS) + validationErrorKey);
}
/**
- * @ngdoc function
- * @name ng.directive:ngModel.NgModelController#$setValidity
- * @methodOf ng.directive:ngModel.NgModelController
+ * @ngdoc method
+ * @name ngModel.NgModelController#$setValidity
*
* @description
* Change the validity state, and notifies the form when the control changes validity. (i.e. it
@@ -16332,9 +17254,8 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
};
/**
- * @ngdoc function
- * @name ng.directive:ngModel.NgModelController#$setPristine
- * @methodOf ng.directive:ngModel.NgModelController
+ * @ngdoc method
+ * @name ngModel.NgModelController#$setPristine
*
* @description
* Sets the control to its pristine state.
@@ -16345,13 +17266,13 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
this.$setPristine = function () {
this.$dirty = false;
this.$pristine = true;
- $element.removeClass(DIRTY_CLASS).addClass(PRISTINE_CLASS);
+ $animate.removeClass($element, DIRTY_CLASS);
+ $animate.addClass($element, PRISTINE_CLASS);
};
/**
- * @ngdoc function
- * @name ng.directive:ngModel.NgModelController#$setViewValue
- * @methodOf ng.directive:ngModel.NgModelController
+ * @ngdoc method
+ * @name ngModel.NgModelController#$setViewValue
*
* @description
* Update the view value.
@@ -16363,7 +17284,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
* It will update the $viewValue, then pass this value through each of the functions in `$parsers`,
* which includes any validators. The value that comes out of this `$parsers` pipeline, be applied to
* `$modelValue` and the **expression** specified in the `ng-model` attribute.
- *
+ *
* Lastly, all the registered change listeners, in the `$viewChangeListeners` list, are called.
*
* Note that calling this function does not trigger a `$digest`.
@@ -16377,7 +17298,8 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
if (this.$pristine) {
this.$dirty = true;
this.$pristine = false;
- $element.removeClass(PRISTINE_CLASS).addClass(DIRTY_CLASS);
+ $animate.removeClass($element, PRISTINE_CLASS);
+ $animate.addClass($element, DIRTY_CLASS);
parentForm.$setDirty();
}
@@ -16420,19 +17342,21 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
ctrl.$render();
}
}
+
+ return value;
});
}];
/**
* @ngdoc directive
- * @name ng.directive:ngModel
+ * @name ngModel
*
* @element input
*
* @description
* The `ngModel` directive binds an `input`,`select`, `textarea` (or custom form control) to a
- * property on the scope using {@link ng.directive:ngModel.NgModelController NgModelController},
+ * property on the scope using {@link ngModel.NgModelController NgModelController},
* which is created and exposed by this directive.
*
* `ngModel` is responsible for:
@@ -16441,7 +17365,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
* require.
* - Providing validation behavior (i.e. required, number, email, url).
* - Keeping the state of the control (valid/invalid, dirty/pristine, validation errors).
- * - Setting related css classes on the element (`ng-valid`, `ng-invalid`, `ng-dirty`, `ng-pristine`).
+ * - Setting related css classes on the element (`ng-valid`, `ng-invalid`, `ng-dirty`, `ng-pristine`) including animations.
* - Registering the control with its parent {@link ng.directive:form form}.
*
* Note: `ngModel` will try to bind to the property given by evaluating the expression on the
@@ -16450,20 +17374,81 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
*
* For best practices on using `ngModel`, see:
*
- * - {@link https://github.com/angular/angular.js/wiki/Understanding-Scopes}
+ * - [https://github.com/angular/angular.js/wiki/Understanding-Scopes]
*
* For basic examples, how to use `ngModel`, see:
*
* - {@link ng.directive:input input}
- * - {@link ng.directive:input.text text}
- * - {@link ng.directive:input.checkbox checkbox}
- * - {@link ng.directive:input.radio radio}
- * - {@link ng.directive:input.number number}
- * - {@link ng.directive:input.email email}
- * - {@link ng.directive:input.url url}
+ * - {@link input[text] text}
+ * - {@link input[checkbox] checkbox}
+ * - {@link input[radio] radio}
+ * - {@link input[number] number}
+ * - {@link input[email] email}
+ * - {@link input[url] url}
* - {@link ng.directive:select select}
* - {@link ng.directive:textarea textarea}
*
+ * # CSS classes
+ * The following CSS classes are added and removed on the associated input/select/textarea element
+ * depending on the validity of the model.
+ *
+ * - `ng-valid` is set if the model is valid.
+ * - `ng-invalid` is set if the model is invalid.
+ * - `ng-pristine` is set if the model is pristine.
+ * - `ng-dirty` is set if the model is dirty.
+ *
+ * Keep in mind that ngAnimate can detect each of these classes when added and removed.
+ *
+ * ## Animation Hooks
+ *
+ * Animations within models are triggered when any of the associated CSS classes are added and removed
+ * on the input element which is attached to the model. These classes are: `.ng-pristine`, `.ng-dirty`,
+ * `.ng-invalid` and `.ng-valid` as well as any other validations that are performed on the model itself.
+ * The animations that are triggered within ngModel are similar to how they work in ngClass and
+ * animations can be hooked into using CSS transitions, keyframes as well as JS animations.
+ *
+ * The following example shows a simple way to utilize CSS transitions to style an input element
+ * that has been rendered as invalid after it has been validated:
+ *
+ * <pre>
+ * //be sure to include ngAnimate as a module to hook into more
+ * //advanced animations
+ * .my-input {
+ * transition:0.5s linear all;
+ * background: white;
+ * }
+ * .my-input.ng-invalid {
+ * background: red;
+ * color:white;
+ * }
+ * </pre>
+ *
+ * @example
+ * <example deps="angular-animate.js" animations="true" fixBase="true">
+ <file name="index.html">
+ <script>
+ function Ctrl($scope) {
+ $scope.val = '1';
+ }
+ </script>
+ <style>
+ .my-input {
+ -webkit-transition:all linear 0.5s;
+ transition:all linear 0.5s;
+ background: transparent;
+ }
+ .my-input.ng-invalid {
+ color:white;
+ background: red;
+ }
+ </style>
+ Update input to see transitions when valid/invalid.
+ Integer is a valid value.
+ <form name="testForm" ng-controller="Ctrl">
+ <input ng-model="val" ng-pattern="/^\d+$/" name="anim" class="my-input" />
+ </form>
+ </file>
+ * </example>
*/
var ngModelDirective = function() {
return {
@@ -16487,10 +17472,13 @@ var ngModelDirective = function() {
/**
* @ngdoc directive
- * @name ng.directive:ngChange
+ * @name ngChange
*
* @description
- * Evaluate given expression when user changes the input.
+ * Evaluate the given expression when the user changes the input.
+ * The expression is evaluated immediately, unlike the JavaScript onchange event
+ * which only triggers at the end of a change (usually, when the user leaves the
+ * form element or presses the return key).
* The expression is not evaluated when the value change is coming from the model.
*
* Note, this directive requires `ngModel` to be present.
@@ -16500,8 +17488,8 @@ var ngModelDirective = function() {
* in input value.
*
* @example
- * <doc:example>
- * <doc:source>
+ * <example name="ngChange-directive">
+ * <file name="index.html">
* <script>
* function Controller($scope) {
* $scope.counter = 0;
@@ -16514,25 +17502,31 @@ var ngModelDirective = function() {
* <input type="checkbox" ng-model="confirmed" ng-change="change()" id="ng-change-example1" />
* <input type="checkbox" ng-model="confirmed" id="ng-change-example2" />
* <label for="ng-change-example2">Confirmed</label><br />
- * debug = {{confirmed}}<br />
- * counter = {{counter}}
+ * <tt>debug = {{confirmed}}</tt><br/>
+ * <tt>counter = {{counter}}</tt><br/>
* </div>
- * </doc:source>
- * <doc:scenario>
+ * </file>
+ * <file name="protractor.js" type="protractor">
+ * var counter = element(by.binding('counter'));
+ * var debug = element(by.binding('confirmed'));
+ *
* it('should evaluate the expression if changing from view', function() {
- * expect(binding('counter')).toEqual('0');
- * element('#ng-change-example1').click();
- * expect(binding('counter')).toEqual('1');
- * expect(binding('confirmed')).toEqual('true');
+ * expect(counter.getText()).toContain('0');
+ *
+ * element(by.id('ng-change-example1')).click();
+ *
+ * expect(counter.getText()).toContain('1');
+ * expect(debug.getText()).toContain('true');
* });
*
* it('should not evaluate the expression if changing from model', function() {
- * element('#ng-change-example2').click();
- * expect(binding('counter')).toEqual('0');
- * expect(binding('confirmed')).toEqual('true');
+ * element(by.id('ng-change-example2')).click();
+
+ * expect(counter.getText()).toContain('0');
+ * expect(debug.getText()).toContain('true');
* });
- * </doc:scenario>
- * </doc:example>
+ * </file>
+ * </example>
*/
var ngChangeDirective = valueFn({
require: 'ngModel',
@@ -16574,7 +17568,7 @@ var requiredDirective = function() {
/**
* @ngdoc directive
- * @name ng.directive:ngList
+ * @name ngList
*
* @description
* Text input that converts between a delimited string and an array of strings. The delimiter
@@ -16585,8 +17579,8 @@ var requiredDirective = function() {
* specified in form `/something/` then the value will be converted into a regular expression.
*
* @example
- <doc:example>
- <doc:source>
+ <example name="ngList-directive">
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.names = ['igor', 'misko', 'vojta'];
@@ -16603,22 +17597,28 @@ var requiredDirective = function() {
<tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
<tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
</form>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
+ var listInput = element(by.model('names'));
+ var names = element(by.binding('{{names}}'));
+ var valid = element(by.binding('myForm.namesInput.$valid'));
+ var error = element(by.css('span.error'));
+
it('should initialize to model', function() {
- expect(binding('names')).toEqual('["igor","misko","vojta"]');
- expect(binding('myForm.namesInput.$valid')).toEqual('true');
- expect(element('span.error').css('display')).toBe('none');
+ expect(names.getText()).toContain('["igor","misko","vojta"]');
+ expect(valid.getText()).toContain('true');
+ expect(error.getCssValue('display')).toBe('none');
});
it('should be invalid if empty', function() {
- input('names').enter('');
- expect(binding('names')).toEqual('');
- expect(binding('myForm.namesInput.$valid')).toEqual('false');
- expect(element('span.error').css('display')).not().toBe('none');
- });
- </doc:scenario>
- </doc:example>
+ listInput.clear();
+ listInput.sendKeys('');
+
+ expect(names.getText()).toContain('');
+ expect(valid.getText()).toContain('false');
+ expect(error.getCssValue('display')).not.toBe('none'); });
+ </file>
+ </example>
*/
var ngListDirective = function() {
return {
@@ -16663,7 +17663,7 @@ var ngListDirective = function() {
var CONSTANT_VALUE_REGEXP = /^(true|false|\d+)$/;
/**
* @ngdoc directive
- * @name ng.directive:ngValue
+ * @name ngValue
*
* @description
* Binds the given expression to the value of `input[select]` or `input[radio]`, so
@@ -16678,8 +17678,8 @@ var CONSTANT_VALUE_REGEXP = /^(true|false|\d+)$/;
* of the `input` element
*
* @example
- <doc:example>
- <doc:source>
+ <example name="ngValue-directive">
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.names = ['pizza', 'unicorns', 'robots'];
@@ -16696,20 +17696,21 @@ var CONSTANT_VALUE_REGEXP = /^(true|false|\d+)$/;
id="{{name}}"
name="favorite">
</label>
- </span>
<div>You chose {{my.favorite}}</div>
</form>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
+ var favorite = element(by.binding('my.favorite'));
+
it('should initialize to model', function() {
- expect(binding('my.favorite')).toEqual('unicorns');
+ expect(favorite.getText()).toContain('unicorns');
});
it('should bind the values to the inputs', function() {
- input('my.favorite').select('pizza');
- expect(binding('my.favorite')).toEqual('pizza');
+ element.all(by.model('my.favorite')).get(0).click();
+ expect(favorite.getText()).toContain('pizza');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
var ngValueDirective = function() {
return {
@@ -16732,7 +17733,7 @@ var ngValueDirective = function() {
/**
* @ngdoc directive
- * @name ng.directive:ngBind
+ * @name ngBind
* @restrict AC
*
* @description
@@ -16743,7 +17744,7 @@ var ngValueDirective = function() {
* Typically, you don't use `ngBind` directly, but instead you use the double curly markup like
* `{{ expression }}` which is similar but less verbose.
*
- * It is preferrable to use `ngBind` instead of `{{ expression }}` when a template is momentarily
+ * It is preferable to use `ngBind` instead of `{{ expression }}` when a template is momentarily
* displayed by the browser in its raw state before Angular compiles it. Since `ngBind` is an
* element attribute, it makes the bindings invisible to the user while the page is loading.
*
@@ -16756,8 +17757,8 @@ var ngValueDirective = function() {
*
* @example
* Enter a name in the Live Preview text box; the greeting below the text box changes instantly.
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.name = 'Whirled';
@@ -16767,15 +17768,18 @@ var ngValueDirective = function() {
Enter name: <input type="text" ng-model="name"><br>
Hello <span ng-bind="name"></span>!
</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should check ng-bind', function() {
- expect(using('.doc-example-live').binding('name')).toBe('Whirled');
- using('.doc-example-live').input('name').enter('world');
- expect(using('.doc-example-live').binding('name')).toBe('world');
+ var nameInput = element(by.model('name'));
+
+ expect(element(by.binding('name')).getText()).toBe('Whirled');
+ nameInput.clear();
+ nameInput.sendKeys('world');
+ expect(element(by.binding('name')).getText()).toBe('world');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
var ngBindDirective = ngDirective(function(scope, element, attr) {
element.addClass('ng-binding').data('$binding', attr.ngBind);
@@ -16790,7 +17794,7 @@ var ngBindDirective = ngDirective(function(scope, element, attr) {
/**
* @ngdoc directive
- * @name ng.directive:ngBindTemplate
+ * @name ngBindTemplate
*
* @description
* The `ngBindTemplate` directive specifies that the element
@@ -16806,8 +17810,8 @@ var ngBindDirective = ngDirective(function(scope, element, attr) {
*
* @example
* Try it here: enter text in text box and watch the greeting change.
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.salutation = 'Hello';
@@ -16819,22 +17823,24 @@ var ngBindDirective = ngDirective(function(scope, element, attr) {
Name: <input type="text" ng-model="name"><br>
<pre ng-bind-template="{{salutation}} {{name}}!"></pre>
</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should check ng-bind', function() {
- expect(using('.doc-example-live').binding('salutation')).
- toBe('Hello');
- expect(using('.doc-example-live').binding('name')).
- toBe('World');
- using('.doc-example-live').input('salutation').enter('Greetings');
- using('.doc-example-live').input('name').enter('user');
- expect(using('.doc-example-live').binding('salutation')).
- toBe('Greetings');
- expect(using('.doc-example-live').binding('name')).
- toBe('user');
+ var salutationElem = element(by.binding('salutation'));
+ var salutationInput = element(by.model('salutation'));
+ var nameInput = element(by.model('name'));
+
+ expect(salutationElem.getText()).toBe('Hello World!');
+
+ salutationInput.clear();
+ salutationInput.sendKeys('Greetings');
+ nameInput.clear();
+ nameInput.sendKeys('user');
+
+ expect(salutationElem.getText()).toBe('Greetings user!');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
var ngBindTemplateDirective = ['$interpolate', function($interpolate) {
return function(scope, element, attr) {
@@ -16850,7 +17856,7 @@ var ngBindTemplateDirective = ['$interpolate', function($interpolate) {
/**
* @ngdoc directive
- * @name ng.directive:ngBindHtml
+ * @name ngBindHtml
*
* @description
* Creates a binding that will innerHTML the result of evaluating the `expression` into the current
@@ -16858,7 +17864,7 @@ var ngBindTemplateDirective = ['$interpolate', function($interpolate) {
* ngSanitize.$sanitize $sanitize} service. To utilize this functionality, ensure that `$sanitize`
* is available, for example, by including {@link ngSanitize} in your module's dependencies (not in
* core Angular.) You may also bypass sanitization for values you know are safe. To do so, bind to
- * an explicitly trusted value via {@link ng.$sce#methods_trustAsHtml $sce.trustAsHtml}. See the example
+ * an explicitly trusted value via {@link ng.$sce#trustAsHtml $sce.trustAsHtml}. See the example
* under {@link ng.$sce#Example Strict Contextual Escaping (SCE)}.
*
* Note: If a `$sanitize` service is unavailable and the bound value isn't explicitly trusted, you
@@ -16869,14 +17875,14 @@ var ngBindTemplateDirective = ['$interpolate', function($interpolate) {
*
* @example
Try it here: enter text in text box and watch the greeting change.
-
+
<example module="ngBindHtmlExample" deps="angular-sanitize.js">
<file name="index.html">
<div ng-controller="ngBindHtmlCtrl">
<p ng-bind-html="myHTML"></p>
</div>
</file>
-
+
<file name="script.js">
angular.module('ngBindHtmlExample', ['ngSanitize'])
@@ -16886,12 +17892,10 @@ var ngBindTemplateDirective = ['$interpolate', function($interpolate) {
}]);
</file>
- <file name="scenario.js">
+ <file name="protractor.js" type="protractor">
it('should check ng-bind-html', function() {
- expect(using('.doc-example-live').binding('myHTML')).
- toBe(
- 'I am an <code>HTML</code>string with <a href="#">links!</a> and other <em>stuff</em>'
- );
+ expect(element(by.binding('myHTML')).getText()).toBe(
+ 'I am an HTMLstring with links! and other stuff');
});
</file>
</example>
@@ -16911,7 +17915,7 @@ var ngBindHtmlDirective = ['$sce', '$parse', function($sce, $parse) {
function classDirective(name, selector) {
name = 'ngClass' + name;
- return function() {
+ return ['$animate', function($animate) {
return {
restrict: 'AC',
link: function(scope, element, attr) {
@@ -16929,65 +17933,123 @@ function classDirective(name, selector) {
// jshint bitwise: false
var mod = $index & 1;
if (mod !== old$index & 1) {
- if (mod === selector) {
- addClass(scope.$eval(attr[name]));
- } else {
- removeClass(scope.$eval(attr[name]));
+ var classes = arrayClasses(scope.$eval(attr[name]));
+ mod === selector ?
+ addClasses(classes) :
+ removeClasses(classes);
+ }
+ });
+ }
+
+ function addClasses(classes) {
+ var newClasses = digestClassCounts(classes, 1);
+ attr.$addClass(newClasses);
+ }
+
+ function removeClasses(classes) {
+ var newClasses = digestClassCounts(classes, -1);
+ attr.$removeClass(newClasses);
+ }
+
+ function digestClassCounts (classes, count) {
+ var classCounts = element.data('$classCounts') || {};
+ var classesToUpdate = [];
+ forEach(classes, function (className) {
+ if (count > 0 || classCounts[className]) {
+ classCounts[className] = (classCounts[className] || 0) + count;
+ if (classCounts[className] === +(count > 0)) {
+ classesToUpdate.push(className);
}
}
});
+ element.data('$classCounts', classCounts);
+ return classesToUpdate.join(' ');
}
+ function updateClasses (oldClasses, newClasses) {
+ var toAdd = arrayDifference(newClasses, oldClasses);
+ var toRemove = arrayDifference(oldClasses, newClasses);
+ toRemove = digestClassCounts(toRemove, -1);
+ toAdd = digestClassCounts(toAdd, 1);
+
+ if (toAdd.length === 0) {
+ $animate.removeClass(element, toRemove);
+ } else if (toRemove.length === 0) {
+ $animate.addClass(element, toAdd);
+ } else {
+ $animate.setClass(element, toAdd, toRemove);
+ }
+ }
function ngClassWatchAction(newVal) {
if (selector === true || scope.$index % 2 === selector) {
- if (oldVal && !equals(newVal,oldVal)) {
- removeClass(oldVal);
+ var newClasses = arrayClasses(newVal || []);
+ if (!oldVal) {
+ addClasses(newClasses);
+ } else if (!equals(newVal,oldVal)) {
+ var oldClasses = arrayClasses(oldVal);
+ updateClasses(oldClasses, newClasses);
}
- addClass(newVal);
}
oldVal = copy(newVal);
}
+ }
+ };
+ function arrayDifference(tokens1, tokens2) {
+ var values = [];
- function removeClass(classVal) {
- attr.$removeClass(flattenClasses(classVal));
- }
-
-
- function addClass(classVal) {
- attr.$addClass(flattenClasses(classVal));
+ outer:
+ for(var i = 0; i < tokens1.length; i++) {
+ var token = tokens1[i];
+ for(var j = 0; j < tokens2.length; j++) {
+ if(token == tokens2[j]) continue outer;
}
+ values.push(token);
+ }
+ return values;
+ }
- function flattenClasses(classVal) {
- if(isArray(classVal)) {
- return classVal.join(' ');
- } else if (isObject(classVal)) {
- var classes = [], i = 0;
- forEach(classVal, function(v, k) {
- if (v) {
- classes.push(k);
- }
- });
- return classes.join(' ');
+ function arrayClasses (classVal) {
+ if (isArray(classVal)) {
+ return classVal;
+ } else if (isString(classVal)) {
+ return classVal.split(' ');
+ } else if (isObject(classVal)) {
+ var classes = [], i = 0;
+ forEach(classVal, function(v, k) {
+ if (v) {
+ classes.push(k);
}
-
- return classVal;
- }
+ });
+ return classes;
}
- };
- };
+ return classVal;
+ }
+ }];
}
/**
* @ngdoc directive
- * @name ng.directive:ngClass
+ * @name ngClass
* @restrict AC
*
* @description
* The `ngClass` directive allows you to dynamically set CSS classes on an HTML element by databinding
* an expression that represents all classes to be added.
*
+ * The directive operates in three different ways, depending on which of three types the expression
+ * evaluates to:
+ *
+ * 1. If the expression evaluates to a string, the string should be one or more space-delimited class
+ * names.
+ *
+ * 2. If the expression evaluates to an array, each element of the array should be a string that is
+ * one or more space-delimited class names.
+ *
+ * 3. If the expression evaluates to an object, then for each key-value pair of the
+ * object with a truthy value the corresponding key is used as a class name.
+ *
* The directive won't add duplicate classes if a particular class was already set.
*
* When the expression changes, the previously added classes are removed and only then the
@@ -17031,31 +18093,34 @@ function classDirective(name, selector) {
color: red;
}
</file>
- <file name="scenario.js">
+ <file name="protractor.js" type="protractor">
+ var ps = element.all(by.css('p'));
+
it('should let you toggle the class', function() {
- expect(element('.doc-example-live p:first').prop('className')).not().toMatch(/bold/);
- expect(element('.doc-example-live p:first').prop('className')).not().toMatch(/red/);
+ expect(ps.first().getAttribute('class')).not.toMatch(/bold/);
+ expect(ps.first().getAttribute('class')).not.toMatch(/red/);
- input('important').check();
- expect(element('.doc-example-live p:first').prop('className')).toMatch(/bold/);
+ element(by.model('important')).click();
+ expect(ps.first().getAttribute('class')).toMatch(/bold/);
- input('error').check();
- expect(element('.doc-example-live p:first').prop('className')).toMatch(/red/);
+ element(by.model('error')).click();
+ expect(ps.first().getAttribute('class')).toMatch(/red/);
});
it('should let you toggle string example', function() {
- expect(element('.doc-example-live p:nth-of-type(2)').prop('className')).toBe('');
- input('style').enter('red');
- expect(element('.doc-example-live p:nth-of-type(2)').prop('className')).toBe('red');
+ expect(ps.get(1).getAttribute('class')).toBe('');
+ element(by.model('style')).clear();
+ element(by.model('style')).sendKeys('red');
+ expect(ps.get(1).getAttribute('class')).toBe('red');
});
it('array example should have 3 classes', function() {
- expect(element('.doc-example-live p:last').prop('className')).toBe('');
- input('style1').enter('bold');
- input('style2').enter('strike');
- input('style3').enter('red');
- expect(element('.doc-example-live p:last').prop('className')).toBe('bold strike red');
+ expect(ps.last().getAttribute('class')).toBe('');
+ element(by.model('style1')).sendKeys('bold');
+ element(by.model('style2')).sendKeys('strike');
+ element(by.model('style3')).sendKeys('red');
+ expect(ps.last().getAttribute('class')).toBe('bold strike red');
});
</file>
</example>
@@ -17064,10 +18129,10 @@ function classDirective(name, selector) {
The example below demonstrates how to perform animations using ngClass.
- <example animations="true">
+ <example module="ngAnimate" deps="angular-animate.js" animations="true">
<file name="index.html">
- <input type="button" value="set" ng-click="myVar='my-class'">
- <input type="button" value="clear" ng-click="myVar=''">
+ <input id="setbtn" type="button" value="set" ng-click="myVar='my-class'">
+ <input id="clearbtn" type="button" value="clear" ng-click="myVar=''">
<br>
<span class="base-class" ng-class="myVar">Sample Text</span>
</file>
@@ -17082,19 +18147,19 @@ function classDirective(name, selector) {
font-size:3em;
}
</file>
- <file name="scenario.js">
+ <file name="protractor.js" type="protractor">
it('should check ng-class', function() {
- expect(element('.doc-example-live span').prop('className')).not().
+ expect(element(by.css('.base-class')).getAttribute('class')).not.
toMatch(/my-class/);
- using('.doc-example-live').element(':button:first').click();
+ element(by.id('setbtn')).click();
- expect(element('.doc-example-live span').prop('className')).
+ expect(element(by.css('.base-class')).getAttribute('class')).
toMatch(/my-class/);
- using('.doc-example-live').element(':button:last').click();
+ element(by.id('clearbtn')).click();
- expect(element('.doc-example-live span').prop('className')).not().
+ expect(element(by.css('.base-class')).getAttribute('class')).not.
toMatch(/my-class/);
});
</file>
@@ -17105,14 +18170,14 @@ function classDirective(name, selector) {
The ngClass directive still supports CSS3 Transitions/Animations even if they do not follow the ngAnimate CSS naming structure.
Upon animation ngAnimate will apply supplementary CSS classes to track the start and end of an animation, but this will not hinder
any pre-existing CSS transitions already on the element. To get an idea of what happens during a class-based animation, be sure
- to view the step by step details of {@link ngAnimate.$animate#methods_addclass $animate.addClass} and
- {@link ngAnimate.$animate#methods_removeclass $animate.removeClass}.
+ to view the step by step details of {@link ngAnimate.$animate#addclass $animate.addClass} and
+ {@link ngAnimate.$animate#removeclass $animate.removeClass}.
*/
var ngClassDirective = classDirective('', true);
/**
* @ngdoc directive
- * @name ng.directive:ngClassOdd
+ * @name ngClassOdd
* @restrict AC
*
* @description
@@ -17146,11 +18211,11 @@ var ngClassDirective = classDirective('', true);
color: blue;
}
</file>
- <file name="scenario.js">
+ <file name="protractor.js" type="protractor">
it('should check ng-class-odd and ng-class-even', function() {
- expect(element('.doc-example-live li:first span').prop('className')).
+ expect(element(by.repeater('name in names').row(0).column('name')).getAttribute('class')).
toMatch(/odd/);
- expect(element('.doc-example-live li:last span').prop('className')).
+ expect(element(by.repeater('name in names').row(1).column('name')).getAttribute('class')).
toMatch(/even/);
});
</file>
@@ -17160,7 +18225,7 @@ var ngClassOddDirective = classDirective('Odd', 0);
/**
* @ngdoc directive
- * @name ng.directive:ngClassEven
+ * @name ngClassEven
* @restrict AC
*
* @description
@@ -17194,11 +18259,11 @@ var ngClassOddDirective = classDirective('Odd', 0);
color: blue;
}
</file>
- <file name="scenario.js">
+ <file name="protractor.js" type="protractor">
it('should check ng-class-odd and ng-class-even', function() {
- expect(element('.doc-example-live li:first span').prop('className')).
+ expect(element(by.repeater('name in names').row(0).column('name')).getAttribute('class')).
toMatch(/odd/);
- expect(element('.doc-example-live li:last span').prop('className')).
+ expect(element(by.repeater('name in names').row(1).column('name')).getAttribute('class')).
toMatch(/even/);
});
</file>
@@ -17208,7 +18273,7 @@ var ngClassEvenDirective = classDirective('Even', 1);
/**
* @ngdoc directive
- * @name ng.directive:ngCloak
+ * @name ngCloak
* @restrict AC
*
* @description
@@ -17224,11 +18289,11 @@ var ngClassEvenDirective = classDirective('Even', 1);
* `angular.min.js`.
* For CSP mode please add `angular-csp.css` to your html file (see {@link ng.directive:ngCsp ngCsp}).
*
- * <pre>
+ * ```css
* [ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
* display: none !important;
* }
- * </pre>
+ * ```
*
* When this css rule is loaded by the browser, all html elements (including their children) that
* are tagged with the `ngCloak` directive are hidden. When Angular encounters this directive
@@ -17241,25 +18306,25 @@ var ngClassEvenDirective = classDirective('Even', 1);
*
* Legacy browsers, like IE7, do not provide attribute selector support (added in CSS 2.1) so they
* cannot match the `[ng\:cloak]` selector. To work around this limitation, you must add the css
- * class `ngCloak` in addition to the `ngCloak` directive as shown in the example below.
+ * class `ng-cloak` in addition to the `ngCloak` directive as shown in the example below.
*
* @element ANY
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<div id="template1" ng-cloak>{{ 'hello' }}</div>
<div id="template2" ng-cloak class="ng-cloak">{{ 'hello IE7' }}</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should remove the template directive and css class', function() {
- expect(element('.doc-example-live #template1').attr('ng-cloak')).
- not().toBeDefined();
- expect(element('.doc-example-live #template2').attr('ng-cloak')).
- not().toBeDefined();
+ expect($('#template1').getAttribute('ng-cloak')).
+ toBeNull();
+ expect($('#template2').getAttribute('ng-cloak')).
+ toBeNull();
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*
*/
var ngCloakDirective = ngDirective({
@@ -17271,7 +18336,7 @@ var ngCloakDirective = ngDirective({
/**
* @ngdoc directive
- * @name ng.directive:ngController
+ * @name ngController
*
* @description
* The `ngController` directive attaches a controller class to the view. This is a key aspect of how angular
@@ -17305,8 +18370,8 @@ var ngCloakDirective = ngDirective({
* notice that any changes to the data are automatically reflected in the View without the need
* for a manual update. The example is shown in two different declaration styles you may use
* according to preference.
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<script>
function SettingsController1() {
this.name = "John Smith";
@@ -17350,26 +18415,40 @@ var ngCloakDirective = ngDirective({
<li>[ <a href="" ng-click="settings.addContact()">add</a> ]</li>
</ul>
</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should check controller as', function() {
- expect(element('#ctrl-as-exmpl>:input').val()).toBe('John Smith');
- expect(element('#ctrl-as-exmpl li:nth-child(1) input').val())
- .toBe('408 555 1212');
- expect(element('#ctrl-as-exmpl li:nth-child(2) input').val())
- .toBe('john.smith@example.org');
-
- element('#ctrl-as-exmpl li:first a:contains("clear")').click();
- expect(element('#ctrl-as-exmpl li:first input').val()).toBe('');
-
- element('#ctrl-as-exmpl li:last a:contains("add")').click();
- expect(element('#ctrl-as-exmpl li:nth-child(3) input').val())
- .toBe('yourname@example.org');
+ var container = element(by.id('ctrl-as-exmpl'));
+
+ expect(container.findElement(by.model('settings.name'))
+ .getAttribute('value')).toBe('John Smith');
+
+ var firstRepeat =
+ container.findElement(by.repeater('contact in settings.contacts').row(0));
+ var secondRepeat =
+ container.findElement(by.repeater('contact in settings.contacts').row(1));
+
+ expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value'))
+ .toBe('408 555 1212');
+ expect(secondRepeat.findElement(by.model('contact.value')).getAttribute('value'))
+ .toBe('john.smith@example.org');
+
+ firstRepeat.findElement(by.linkText('clear')).click();
+
+ expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value'))
+ .toBe('');
+
+ container.findElement(by.linkText('add')).click();
+
+ expect(container.findElement(by.repeater('contact in settings.contacts').row(2))
+ .findElement(by.model('contact.value'))
+ .getAttribute('value'))
+ .toBe('yourname@example.org');
});
- </doc:scenario>
- </doc:example>
- <doc:example>
- <doc:source>
+ </file>
+ </example>
+ <example>
+ <file name="index.html">
<script>
function SettingsController2($scope) {
$scope.name = "John Smith";
@@ -17413,36 +18492,51 @@ var ngCloakDirective = ngDirective({
<li>[ <a href="" ng-click="addContact()">add</a> ]</li>
</ul>
</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should check controller', function() {
- expect(element('#ctrl-exmpl>:input').val()).toBe('John Smith');
- expect(element('#ctrl-exmpl li:nth-child(1) input').val())
- .toBe('408 555 1212');
- expect(element('#ctrl-exmpl li:nth-child(2) input').val())
- .toBe('john.smith@example.org');
-
- element('#ctrl-exmpl li:first a:contains("clear")').click();
- expect(element('#ctrl-exmpl li:first input').val()).toBe('');
-
- element('#ctrl-exmpl li:last a:contains("add")').click();
- expect(element('#ctrl-exmpl li:nth-child(3) input').val())
- .toBe('yourname@example.org');
+ var container = element(by.id('ctrl-exmpl'));
+
+ expect(container.findElement(by.model('name'))
+ .getAttribute('value')).toBe('John Smith');
+
+ var firstRepeat =
+ container.findElement(by.repeater('contact in contacts').row(0));
+ var secondRepeat =
+ container.findElement(by.repeater('contact in contacts').row(1));
+
+ expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value'))
+ .toBe('408 555 1212');
+ expect(secondRepeat.findElement(by.model('contact.value')).getAttribute('value'))
+ .toBe('john.smith@example.org');
+
+ firstRepeat.findElement(by.linkText('clear')).click();
+
+ expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value'))
+ .toBe('');
+
+ container.findElement(by.linkText('add')).click();
+
+ expect(container.findElement(by.repeater('contact in contacts').row(2))
+ .findElement(by.model('contact.value'))
+ .getAttribute('value'))
+ .toBe('yourname@example.org');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
var ngControllerDirective = [function() {
return {
scope: true,
- controller: '@'
+ controller: '@',
+ priority: 500
};
}];
/**
* @ngdoc directive
- * @name ng.directive:ngCsp
+ * @name ngCsp
*
* @element html
* @description
@@ -17469,13 +18563,13 @@ var ngControllerDirective = [function() {
*
* @example
* This example shows how to apply the `ngCsp` directive to the `html` tag.
- <pre>
+ ```html
<!doctype html>
<html ng-app ng-csp>
...
...
</html>
- </pre>
+ ```
*/
// ngCsp is not implemented as a proper directive any more, because we need it be processed while we bootstrap
@@ -17484,32 +18578,33 @@ var ngControllerDirective = [function() {
/**
* @ngdoc directive
- * @name ng.directive:ngClick
+ * @name ngClick
*
* @description
* The ngClick directive allows you to specify custom behavior when
* an element is clicked.
*
* @element ANY
+ * @priority 0
* @param {expression} ngClick {@link guide/expression Expression} to evaluate upon
- * click. (Event object is available as `$event`)
+ * click. ({@link guide/expression#-event- Event object is available as `$event`})
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<button ng-click="count = count + 1" ng-init="count=0">
Increment
</button>
count: {{count}}
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should check ng-click', function() {
- expect(binding('count')).toBe('0');
- element('.doc-example-live :button').click();
- expect(binding('count')).toBe('1');
+ expect(element(by.binding('count')).getText()).toMatch('0');
+ element(by.css('button')).click();
+ expect(element(by.binding('count')).getText()).toMatch('1');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
/*
* A directive that allows creation of custom onclick handlers that are defined as angular
@@ -17541,188 +18636,264 @@ forEach(
/**
* @ngdoc directive
- * @name ng.directive:ngDblclick
+ * @name ngDblclick
*
* @description
* The `ngDblclick` directive allows you to specify custom behavior on a dblclick event.
*
* @element ANY
+ * @priority 0
* @param {expression} ngDblclick {@link guide/expression Expression} to evaluate upon
* a dblclick. (The Event object is available as `$event`)
*
* @example
- * See {@link ng.directive:ngClick ngClick}
+ <example>
+ <file name="index.html">
+ <button ng-dblclick="count = count + 1" ng-init="count=0">
+ Increment (on double click)
+ </button>
+ count: {{count}}
+ </file>
+ </example>
*/
/**
* @ngdoc directive
- * @name ng.directive:ngMousedown
+ * @name ngMousedown
*
* @description
* The ngMousedown directive allows you to specify custom behavior on mousedown event.
*
* @element ANY
+ * @priority 0
* @param {expression} ngMousedown {@link guide/expression Expression} to evaluate upon
- * mousedown. (Event object is available as `$event`)
+ * mousedown. ({@link guide/expression#-event- Event object is available as `$event`})
*
* @example
- * See {@link ng.directive:ngClick ngClick}
+ <example>
+ <file name="index.html">
+ <button ng-mousedown="count = count + 1" ng-init="count=0">
+ Increment (on mouse down)
+ </button>
+ count: {{count}}
+ </file>
+ </example>
*/
/**
* @ngdoc directive
- * @name ng.directive:ngMouseup
+ * @name ngMouseup
*
* @description
* Specify custom behavior on mouseup event.
*
* @element ANY
+ * @priority 0
* @param {expression} ngMouseup {@link guide/expression Expression} to evaluate upon
- * mouseup. (Event object is available as `$event`)
+ * mouseup. ({@link guide/expression#-event- Event object is available as `$event`})
*
* @example
- * See {@link ng.directive:ngClick ngClick}
+ <example>
+ <file name="index.html">
+ <button ng-mouseup="count = count + 1" ng-init="count=0">
+ Increment (on mouse up)
+ </button>
+ count: {{count}}
+ </file>
+ </example>
*/
/**
* @ngdoc directive
- * @name ng.directive:ngMouseover
+ * @name ngMouseover
*
* @description
* Specify custom behavior on mouseover event.
*
* @element ANY
+ * @priority 0
* @param {expression} ngMouseover {@link guide/expression Expression} to evaluate upon
- * mouseover. (Event object is available as `$event`)
+ * mouseover. ({@link guide/expression#-event- Event object is available as `$event`})
*
* @example
- * See {@link ng.directive:ngClick ngClick}
+ <example>
+ <file name="index.html">
+ <button ng-mouseover="count = count + 1" ng-init="count=0">
+ Increment (when mouse is over)
+ </button>
+ count: {{count}}
+ </file>
+ </example>
*/
/**
* @ngdoc directive
- * @name ng.directive:ngMouseenter
+ * @name ngMouseenter
*
* @description
* Specify custom behavior on mouseenter event.
*
* @element ANY
+ * @priority 0
* @param {expression} ngMouseenter {@link guide/expression Expression} to evaluate upon
- * mouseenter. (Event object is available as `$event`)
+ * mouseenter. ({@link guide/expression#-event- Event object is available as `$event`})
*
* @example
- * See {@link ng.directive:ngClick ngClick}
+ <example>
+ <file name="index.html">
+ <button ng-mouseenter="count = count + 1" ng-init="count=0">
+ Increment (when mouse enters)
+ </button>
+ count: {{count}}
+ </file>
+ </example>
*/
/**
* @ngdoc directive
- * @name ng.directive:ngMouseleave
+ * @name ngMouseleave
*
* @description
* Specify custom behavior on mouseleave event.
*
* @element ANY
+ * @priority 0
* @param {expression} ngMouseleave {@link guide/expression Expression} to evaluate upon
- * mouseleave. (Event object is available as `$event`)
+ * mouseleave. ({@link guide/expression#-event- Event object is available as `$event`})
*
* @example
- * See {@link ng.directive:ngClick ngClick}
+ <example>
+ <file name="index.html">
+ <button ng-mouseleave="count = count + 1" ng-init="count=0">
+ Increment (when mouse leaves)
+ </button>
+ count: {{count}}
+ </file>
+ </example>
*/
/**
* @ngdoc directive
- * @name ng.directive:ngMousemove
+ * @name ngMousemove
*
* @description
* Specify custom behavior on mousemove event.
*
* @element ANY
+ * @priority 0
* @param {expression} ngMousemove {@link guide/expression Expression} to evaluate upon
- * mousemove. (Event object is available as `$event`)
+ * mousemove. ({@link guide/expression#-event- Event object is available as `$event`})
*
* @example
- * See {@link ng.directive:ngClick ngClick}
+ <example>
+ <file name="index.html">
+ <button ng-mousemove="count = count + 1" ng-init="count=0">
+ Increment (when mouse moves)
+ </button>
+ count: {{count}}
+ </file>
+ </example>
*/
/**
* @ngdoc directive
- * @name ng.directive:ngKeydown
+ * @name ngKeydown
*
* @description
* Specify custom behavior on keydown event.
*
* @element ANY
+ * @priority 0
* @param {expression} ngKeydown {@link guide/expression Expression} to evaluate upon
* keydown. (Event object is available as `$event` and can be interrogated for keyCode, altKey, etc.)
*
* @example
- * See {@link ng.directive:ngClick ngClick}
+ <example>
+ <file name="index.html">
+ <input ng-keydown="count = count + 1" ng-init="count=0">
+ key down count: {{count}}
+ </file>
+ </example>
*/
/**
* @ngdoc directive
- * @name ng.directive:ngKeyup
+ * @name ngKeyup
*
* @description
* Specify custom behavior on keyup event.
*
* @element ANY
+ * @priority 0
* @param {expression} ngKeyup {@link guide/expression Expression} to evaluate upon
* keyup. (Event object is available as `$event` and can be interrogated for keyCode, altKey, etc.)
*
* @example
- * See {@link ng.directive:ngClick ngClick}
+ <example>
+ <file name="index.html">
+ <input ng-keyup="count = count + 1" ng-init="count=0">
+ key up count: {{count}}
+ </file>
+ </example>
*/
/**
* @ngdoc directive
- * @name ng.directive:ngKeypress
+ * @name ngKeypress
*
* @description
* Specify custom behavior on keypress event.
*
* @element ANY
* @param {expression} ngKeypress {@link guide/expression Expression} to evaluate upon
- * keypress. (Event object is available as `$event` and can be interrogated for keyCode, altKey, etc.)
+ * keypress. ({@link guide/expression#-event- Event object is available as `$event`}
+ * and can be interrogated for keyCode, altKey, etc.)
*
* @example
- * See {@link ng.directive:ngClick ngClick}
+ <example>
+ <file name="index.html">
+ <input ng-keypress="count = count + 1" ng-init="count=0">
+ key press count: {{count}}
+ </file>
+ </example>
*/
/**
* @ngdoc directive
- * @name ng.directive:ngSubmit
+ * @name ngSubmit
*
* @description
* Enables binding angular expressions to onsubmit events.
*
* Additionally it prevents the default action (which for form means sending the request to the
- * server and reloading the current page) **but only if the form does not contain an `action`
- * attribute**.
+ * server and reloading the current page), but only if the form does not contain `action`,
+ * `data-action`, or `x-action` attributes.
*
* @element form
- * @param {expression} ngSubmit {@link guide/expression Expression} to eval. (Event object is available as `$event`)
+ * @priority 0
+ * @param {expression} ngSubmit {@link guide/expression Expression} to eval.
+ * ({@link guide/expression#-event- Event object is available as `$event`})
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.list = [];
$scope.text = 'hello';
$scope.submit = function() {
- if (this.text) {
- this.list.push(this.text);
- this.text = '';
+ if ($scope.text) {
+ $scope.list.push(this.text);
+ $scope.text = '';
}
};
}
@@ -17733,34 +18904,35 @@ forEach(
<input type="submit" id="submit" value="Submit" />
<pre>list={{list}}</pre>
</form>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should check ng-submit', function() {
- expect(binding('list')).toBe('[]');
- element('.doc-example-live #submit').click();
- expect(binding('list')).toBe('["hello"]');
- expect(input('text').val()).toBe('');
+ expect(element(by.binding('list')).getText()).toBe('list=[]');
+ element(by.css('#submit')).click();
+ expect(element(by.binding('list')).getText()).toContain('hello');
+ expect(element(by.input('text')).getAttribute('value')).toBe('');
});
it('should ignore empty strings', function() {
- expect(binding('list')).toBe('[]');
- element('.doc-example-live #submit').click();
- element('.doc-example-live #submit').click();
- expect(binding('list')).toBe('["hello"]');
- });
- </doc:scenario>
- </doc:example>
+ expect(element(by.binding('list')).getText()).toBe('list=[]');
+ element(by.css('#submit')).click();
+ element(by.css('#submit')).click();
+ expect(element(by.binding('list')).getText()).toContain('hello');
+ });
+ </file>
+ </example>
*/
/**
* @ngdoc directive
- * @name ng.directive:ngFocus
+ * @name ngFocus
*
* @description
* Specify custom behavior on focus event.
*
* @element window, input, select, textarea, a
+ * @priority 0
* @param {expression} ngFocus {@link guide/expression Expression} to evaluate upon
- * focus. (Event object is available as `$event`)
+ * focus. ({@link guide/expression#-event- Event object is available as `$event`})
*
* @example
* See {@link ng.directive:ngClick ngClick}
@@ -17768,14 +18940,15 @@ forEach(
/**
* @ngdoc directive
- * @name ng.directive:ngBlur
+ * @name ngBlur
*
* @description
* Specify custom behavior on blur event.
*
* @element window, input, select, textarea, a
+ * @priority 0
* @param {expression} ngBlur {@link guide/expression Expression} to evaluate upon
- * blur. (Event object is available as `$event`)
+ * blur. ({@link guide/expression#-event- Event object is available as `$event`})
*
* @example
* See {@link ng.directive:ngClick ngClick}
@@ -17783,52 +18956,70 @@ forEach(
/**
* @ngdoc directive
- * @name ng.directive:ngCopy
+ * @name ngCopy
*
* @description
* Specify custom behavior on copy event.
*
* @element window, input, select, textarea, a
+ * @priority 0
* @param {expression} ngCopy {@link guide/expression Expression} to evaluate upon
- * copy. (Event object is available as `$event`)
+ * copy. ({@link guide/expression#-event- Event object is available as `$event`})
*
* @example
- * See {@link ng.directive:ngClick ngClick}
+ <example>
+ <file name="index.html">
+ <input ng-copy="copied=true" ng-init="copied=false; value='copy me'" ng-model="value">
+ copied: {{copied}}
+ </file>
+ </example>
*/
/**
* @ngdoc directive
- * @name ng.directive:ngCut
+ * @name ngCut
*
* @description
* Specify custom behavior on cut event.
*
* @element window, input, select, textarea, a
+ * @priority 0
* @param {expression} ngCut {@link guide/expression Expression} to evaluate upon
- * cut. (Event object is available as `$event`)
+ * cut. ({@link guide/expression#-event- Event object is available as `$event`})
*
* @example
- * See {@link ng.directive:ngClick ngClick}
+ <example>
+ <file name="index.html">
+ <input ng-cut="cut=true" ng-init="cut=false; value='cut me'" ng-model="value">
+ cut: {{cut}}
+ </file>
+ </example>
*/
/**
* @ngdoc directive
- * @name ng.directive:ngPaste
+ * @name ngPaste
*
* @description
* Specify custom behavior on paste event.
*
* @element window, input, select, textarea, a
+ * @priority 0
* @param {expression} ngPaste {@link guide/expression Expression} to evaluate upon
- * paste. (Event object is available as `$event`)
+ * paste. ({@link guide/expression#-event- Event object is available as `$event`})
*
* @example
- * See {@link ng.directive:ngClick ngClick}
+ <example>
+ <file name="index.html">
+ <input ng-paste="paste=true" ng-init="paste=false" placeholder='paste here'>
+ pasted: {{paste}}
+ </file>
+ </example>
*/
/**
* @ngdoc directive
- * @name ng.directive:ngIf
+ * @name ngIf
* @restrict A
*
* @description
@@ -17845,7 +19036,7 @@ forEach(
* Note that when an element is removed using `ngIf` its scope is destroyed and a new scope
* is created when the element is restored. The scope created within `ngIf` inherits from
* its parent scope using
- * {@link https://github.com/angular/angular.js/wiki/The-Nuances-of-Scope-Prototypal-Inheritance prototypal inheritance}.
+ * [prototypal inheritance](https://github.com/angular/angular.js/wiki/The-Nuances-of-Scope-Prototypal-Inheritance).
* An important implication of this is if `ngModel` is used within `ngIf` to bind to
* a javascript primitive defined in the parent scope. In this case any modifications made to the
* variable within the child scope will override (hide) the value in the parent scope.
@@ -17870,7 +19061,7 @@ forEach(
* element is added to the DOM tree.
*
* @example
- <example animations="true">
+ <example module="ngAnimate" deps="angular-animate.js" animations="true">
<file name="index.html">
Click me: <input type="checkbox" ng-model="checked" ng-init="checked=true" /><br/>
Show when checked:
@@ -17885,9 +19076,6 @@ forEach(
padding:10px;
}
- /&#42;
- The transition styles can also be placed on the CSS base class above
- &#42;/
.animate-if.ng-enter, .animate-if.ng-leave {
-webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
@@ -17913,29 +19101,37 @@ var ngIfDirective = ['$animate', function($animate) {
restrict: 'A',
$$tlb: true,
link: function ($scope, $element, $attr, ctrl, $transclude) {
- var block, childScope;
+ var block, childScope, previousElements;
$scope.$watch($attr.ngIf, function ngIfWatchAction(value) {
if (toBoolean(value)) {
if (!childScope) {
childScope = $scope.$new();
$transclude(childScope, function (clone) {
+ clone[clone.length++] = document.createComment(' end ngIf: ' + $attr.ngIf + ' ');
+ // Note: We only need the first/last node of the cloned nodes.
+ // However, we need to keep the reference to the jqlite wrapper as it might be changed later
+ // by a directive with templateUrl when it's template arrives.
block = {
- startNode: clone[0],
- endNode: clone[clone.length++] = document.createComment(' end ngIf: ' + $attr.ngIf + ' ')
+ clone: clone
};
$animate.enter(clone, $element.parent(), $element);
});
}
} else {
-
- if (childScope) {
+ if(previousElements) {
+ previousElements.remove();
+ previousElements = null;
+ }
+ if(childScope) {
childScope.$destroy();
childScope = null;
}
-
- if (block) {
- $animate.leave(getBlockElements(block));
+ if(block) {
+ previousElements = getBlockElements(block.clone);
+ $animate.leave(previousElements, function() {
+ previousElements = null;
+ });
block = null;
}
}
@@ -17946,23 +19142,23 @@ var ngIfDirective = ['$animate', function($animate) {
/**
* @ngdoc directive
- * @name ng.directive:ngInclude
+ * @name ngInclude
* @restrict ECA
*
* @description
* Fetches, compiles and includes an external HTML fragment.
*
* By default, the template URL is restricted to the same domain and protocol as the
- * application document. This is done by calling {@link ng.$sce#methods_getTrustedResourceUrl
+ * application document. This is done by calling {@link ng.$sce#getTrustedResourceUrl
* $sce.getTrustedResourceUrl} on it. To load templates from other domains or protocols
- * you may either {@link ng.$sceDelegateProvider#methods_resourceUrlWhitelist whitelist them} or
- * {@link ng.$sce#methods_trustAsResourceUrl wrap them} as trusted values. Refer to Angular's {@link
+ * you may either {@link ng.$sceDelegateProvider#resourceUrlWhitelist whitelist them} or
+ * [wrap them](ng.$sce#trustAsResourceUrl) as trusted values. Refer to Angular's {@link
* ng.$sce Strict Contextual Escaping}.
*
* In addition, the browser's
- * {@link https://code.google.com/p/browsersec/wiki/Part2#Same-origin_policy_for_XMLHttpRequest
- * Same Origin Policy} and {@link http://www.w3.org/TR/cors/ Cross-Origin Resource Sharing
- * (CORS)} policy may further restrict whether the template is successfully loaded.
+ * [Same Origin Policy](https://code.google.com/p/browsersec/wiki/Part2#Same-origin_policy_for_XMLHttpRequest)
+ * and [Cross-Origin Resource Sharing (CORS)](http://www.w3.org/TR/cors/)
+ * policy may further restrict whether the template is successfully loaded.
* For example, `ngInclude` won't work for cross-domain requests on all browsers and for `file://`
* access on some browsers.
*
@@ -17976,7 +19172,7 @@ var ngIfDirective = ['$animate', function($animate) {
* @priority 400
*
* @param {string} ngInclude|src angular expression evaluating to URL. If the source is a string constant,
- * make sure you wrap it in quotes, e.g. `src="'myPartialTemplate.html'"`.
+ * make sure you wrap it in **single** quotes, e.g. `src="'myPartialTemplate.html'"`.
* @param {string=} onload Expression to evaluate when a new partial is loaded.
*
* @param {string=} autoscroll Whether `ngInclude` should call {@link ng.$anchorScroll
@@ -17987,7 +19183,7 @@ var ngIfDirective = ['$animate', function($animate) {
* - Otherwise enable scrolling only if the expression evaluates to truthy value.
*
* @example
- <example animations="true">
+ <example module="ngAnimate" deps="angular-animate.js" animations="true">
<file name="index.html">
<div ng-controller="Ctrl">
<select ng-model="template" ng-options="t.name for t in templates">
@@ -18003,8 +19199,8 @@ var ngIfDirective = ['$animate', function($animate) {
<file name="script.js">
function Ctrl($scope) {
$scope.templates =
- [ { name: 'template1.html', url: 'template1.html'}
- , { name: 'template2.html', url: 'template2.html'} ];
+ [ { name: 'template1.html', url: 'template1.html'},
+ { name: 'template2.html', url: 'template2.html'} ];
$scope.template = $scope.templates[0];
}
</file>
@@ -18054,19 +19250,33 @@ var ngIfDirective = ['$animate', function($animate) {
top:50px;
}
</file>
- <file name="scenario.js">
+ <file name="protractor.js" type="protractor">
+ var templateSelect = element(by.model('template'));
+ var includeElem = element(by.css('[ng-include]'));
+
it('should load template1.html', function() {
- expect(element('.doc-example-live [ng-include]').text()).
- toMatch(/Content of template1.html/);
+ expect(includeElem.getText()).toMatch(/Content of template1.html/);
});
+
it('should load template2.html', function() {
- select('template').option('1');
- expect(element('.doc-example-live [ng-include]').text()).
- toMatch(/Content of template2.html/);
+ if (browser.params.browser == 'firefox') {
+ // Firefox can't handle using selects
+ // See https://github.com/angular/protractor/issues/480
+ return;
+ }
+ templateSelect.click();
+ templateSelect.element.all(by.css('option')).get(2).click();
+ expect(includeElem.getText()).toMatch(/Content of template2.html/);
});
+
it('should change to blank', function() {
- select('template').option('');
- expect(element('.doc-example-live [ng-include]')).toBe(undefined);
+ if (browser.params.browser == 'firefox') {
+ // Firefox can't handle using selects
+ return;
+ }
+ templateSelect.click();
+ templateSelect.element.all(by.css('option')).get(0).click();
+ expect(includeElem.isPresent()).toBe(false);
});
</file>
</example>
@@ -18075,8 +19285,7 @@ var ngIfDirective = ['$animate', function($animate) {
/**
* @ngdoc event
- * @name ng.directive:ngInclude#$includeContentRequested
- * @eventOf ng.directive:ngInclude
+ * @name ngInclude#$includeContentRequested
* @eventType emit on the scope ngInclude was declared in
* @description
* Emitted every time the ngInclude content is requested.
@@ -18085,19 +19294,19 @@ var ngIfDirective = ['$animate', function($animate) {
/**
* @ngdoc event
- * @name ng.directive:ngInclude#$includeContentLoaded
- * @eventOf ng.directive:ngInclude
+ * @name ngInclude#$includeContentLoaded
* @eventType emit on the current ngInclude scope
* @description
* Emitted every time the ngInclude content is reloaded.
*/
-var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile', '$animate', '$sce',
- function($http, $templateCache, $anchorScroll, $compile, $animate, $sce) {
+var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$animate', '$sce',
+ function($http, $templateCache, $anchorScroll, $animate, $sce) {
return {
restrict: 'ECA',
priority: 400,
terminal: true,
transclude: 'element',
+ controller: angular.noop,
compile: function(element, attr) {
var srcExp = attr.ngInclude || attr.src,
onloadExp = attr.onload || '',
@@ -18106,15 +19315,23 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
return function(scope, $element, $attr, ctrl, $transclude) {
var changeCounter = 0,
currentScope,
+ previousElement,
currentElement;
var cleanupLastIncludeContent = function() {
- if (currentScope) {
+ if(previousElement) {
+ previousElement.remove();
+ previousElement = null;
+ }
+ if(currentScope) {
currentScope.$destroy();
currentScope = null;
}
if(currentElement) {
- $animate.leave(currentElement);
+ $animate.leave(currentElement, function() {
+ previousElement = null;
+ });
+ previousElement = currentElement;
currentElement = null;
}
};
@@ -18131,25 +19348,31 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
$http.get(src, {cache: $templateCache}).success(function(response) {
if (thisChangeId !== changeCounter) return;
var newScope = scope.$new();
-
- $transclude(newScope, function(clone) {
+ ctrl.template = response;
+
+ // Note: This will also link all children of ng-include that were contained in the original
+ // html. If that content contains controllers, ... they could pollute/change the scope.
+ // However, using ng-include on an element with additional content does not make sense...
+ // Note: We can't remove them in the cloneAttchFn of $transclude as that
+ // function is called before linking the content, which would apply child
+ // directives to non existing elements.
+ var clone = $transclude(newScope, function(clone) {
cleanupLastIncludeContent();
+ $animate.enter(clone, null, $element, afterAnimation);
+ });
- currentScope = newScope;
- currentElement = clone;
+ currentScope = newScope;
+ currentElement = clone;
- currentElement.html(response);
- $animate.enter(currentElement, null, $element, afterAnimation);
- $compile(currentElement.contents())(currentScope);
- currentScope.$emit('$includeContentLoaded');
- scope.$eval(onloadExp);
- });
+ currentScope.$emit('$includeContentLoaded');
+ scope.$eval(onloadExp);
}).error(function() {
if (thisChangeId === changeCounter) cleanupLastIncludeContent();
});
scope.$emit('$includeContentRequested');
} else {
cleanupLastIncludeContent();
+ ctrl.template = null;
}
});
};
@@ -18157,9 +19380,27 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
};
}];
+// This directive is called during the $transclude call of the first `ngInclude` directive.
+// It will replace and compile the content of the element with the loaded template.
+// We need this directive so that the element content is already filled when
+// the link function of another directive on the same element as ngInclude
+// is called.
+var ngIncludeFillContentDirective = ['$compile',
+ function($compile) {
+ return {
+ restrict: 'ECA',
+ priority: -400,
+ require: 'ngInclude',
+ link: function(scope, $element, $attr, ctrl) {
+ $element.html(ctrl.template);
+ $compile($element.contents())(scope);
+ }
+ };
+ }];
+
/**
* @ngdoc directive
- * @name ng.directive:ngInit
+ * @name ngInit
* @restrict AC
*
* @description
@@ -18167,18 +19408,27 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
* current scope.
*
* <div class="alert alert-error">
- * The only appropriate use of `ngInit` for aliasing special properties of
- * {@link api/ng.directive:ngRepeat `ngRepeat`}, as seen in the demo below. Besides this case, you
+ * The only appropriate use of `ngInit` is for aliasing special properties of
+ * {@link ng.directive:ngRepeat `ngRepeat`}, as seen in the demo below. Besides this case, you
* should use {@link guide/controller controllers} rather than `ngInit`
* to initialize values on a scope.
* </div>
+ * <div class="alert alert-warning">
+ * **Note**: If you have assignment in `ngInit` along with {@link ng.$filter `$filter`}, make
+ * sure you have parenthesis for correct precedence:
+ * <pre class="prettyprint">
+ * <div ng-init="test1 = (data | orderBy:'name')"></div>
+ * </pre>
+ * </div>
+ *
+ * @priority 450
*
* @element ANY
* @param {expression} ngInit {@link guide/expression Expression} to eval.
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.list = [['a', 'b'], ['c', 'd']];
@@ -18191,19 +19441,20 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
</div>
</div>
</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should alias index positions', function() {
- expect(element('.example-init').text())
- .toBe('list[ 0 ][ 0 ] = a;' +
- 'list[ 0 ][ 1 ] = b;' +
- 'list[ 1 ][ 0 ] = c;' +
- 'list[ 1 ][ 1 ] = d;');
+ var elements = element.all(by.css('.example-init'));
+ expect(elements.get(0).getText()).toBe('list[ 0 ][ 0 ] = a;');
+ expect(elements.get(1).getText()).toBe('list[ 0 ][ 1 ] = b;');
+ expect(elements.get(2).getText()).toBe('list[ 1 ][ 0 ] = c;');
+ expect(elements.get(3).getText()).toBe('list[ 1 ][ 1 ] = d;');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
var ngInitDirective = ngDirective({
+ priority: 450,
compile: function() {
return {
pre: function(scope, element, attrs) {
@@ -18215,7 +19466,7 @@ var ngInitDirective = ngDirective({
/**
* @ngdoc directive
- * @name ng.directive:ngNonBindable
+ * @name ngNonBindable
* @restrict AC
* @priority 1000
*
@@ -18232,40 +19483,38 @@ var ngInitDirective = ngDirective({
* but the one wrapped in `ngNonBindable` is left alone.
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<div>Normal: {{1 + 2}}</div>
<div ng-non-bindable>Ignored: {{1 + 2}}</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should check ng-non-bindable', function() {
- expect(using('.doc-example-live').binding('1 + 2')).toBe('3');
- expect(using('.doc-example-live').element('div:last').text()).
- toMatch(/1 \+ 2/);
+ expect(element(by.binding('1 + 2')).getText()).toContain('3');
+ expect(element.all(by.css('div')).last().getText()).toMatch(/1 \+ 2/);
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
var ngNonBindableDirective = ngDirective({ terminal: true, priority: 1000 });
/**
* @ngdoc directive
- * @name ng.directive:ngPluralize
+ * @name ngPluralize
* @restrict EA
*
* @description
- * # Overview
* `ngPluralize` is a directive that displays messages according to en-US localization rules.
* These rules are bundled with angular.js, but can be overridden
* (see {@link guide/i18n Angular i18n} dev guide). You configure ngPluralize directive
* by specifying the mappings between
- * {@link http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
- * plural categories} and the strings to be displayed.
+ * [plural categories](http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html)
+ * and the strings to be displayed.
*
* # Plural categories and explicit number rules
* There are two
- * {@link http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
- * plural categories} in Angular's default en-US locale: "one" and "other".
+ * [plural categories](http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html)
+ * in Angular's default en-US locale: "one" and "other".
*
* While a plural category may match many numbers (for example, in en-US locale, "other" can match
* any number that is not 1), an explicit number rule can only match one number. For example, the
@@ -18284,13 +19533,13 @@ var ngNonBindableDirective = ngDirective({ terminal: true, priority: 1000 });
*
* The following example shows how to configure ngPluralize:
*
- * <pre>
+ * ```html
* <ng-pluralize count="personCount"
when="{'0': 'Nobody is viewing.',
* 'one': '1 person is viewing.',
* 'other': '{} people are viewing.'}">
* </ng-pluralize>
- *</pre>
+ *```
*
* In the example, `"0: Nobody is viewing."` is an explicit number rule. If you did not
* specify this rule, 0 would be matched to the "other" category and "0 people are viewing"
@@ -18298,7 +19547,7 @@ var ngNonBindableDirective = ngDirective({ terminal: true, priority: 1000 });
* other numbers, for example 12, so that instead of showing "12 people are viewing", you can
* show "a dozen people are viewing".
*
- * You can use a set of closed braces(`{}`) as a placeholder for the number that you want substituted
+ * You can use a set of closed braces (`{}`) as a placeholder for the number that you want substituted
* into pluralized strings. In the previous example, Angular will replace `{}` with
* <span ng-non-bindable>`{{personCount}}`</span>. The closed braces `{}` is a placeholder
* for <span ng-non-bindable>{{numberExpression}}</span>.
@@ -18310,7 +19559,7 @@ var ngNonBindableDirective = ngDirective({ terminal: true, priority: 1000 });
* The offset attribute allows you to offset a number by any desired value.
* Let's take a look at an example:
*
- * <pre>
+ * ```html
* <ng-pluralize count="personCount" offset=2
* when="{'0': 'Nobody is viewing.',
* '1': '{{person1}} is viewing.',
@@ -18318,7 +19567,7 @@ var ngNonBindableDirective = ngDirective({ terminal: true, priority: 1000 });
* 'one': '{{person1}}, {{person2}} and one other person are viewing.',
* 'other': '{{person1}}, {{person2}} and {} other people are viewing.'}">
* </ng-pluralize>
- * </pre>
+ * ```
*
* Notice that we are still using two plural categories(one, other), but we added
* three explicit number rules 0, 1 and 2.
@@ -18333,13 +19582,13 @@ var ngNonBindableDirective = ngDirective({ terminal: true, priority: 1000 });
* you must provide explicit number rules for 0, 1, 2 and 3. You must also provide plural strings for
* plural categories "one" and "other".
*
- * @param {string|expression} count The variable to be bounded to.
+ * @param {string|expression} count The variable to be bound to.
* @param {string} when The mapping between plural category to its corresponding strings.
* @param {number=} offset Offset to deduct from the total number.
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.person1 = 'Igor';
@@ -18370,51 +19619,55 @@ var ngNonBindableDirective = ngDirective({ terminal: true, priority: 1000 });
'other': '{{person1}}, {{person2}} and {} other people are viewing.'}">
</ng-pluralize>
</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should show correct pluralized string', function() {
- expect(element('.doc-example-live ng-pluralize:first').text()).
- toBe('1 person is viewing.');
- expect(element('.doc-example-live ng-pluralize:last').text()).
- toBe('Igor is viewing.');
-
- using('.doc-example-live').input('personCount').enter('0');
- expect(element('.doc-example-live ng-pluralize:first').text()).
- toBe('Nobody is viewing.');
- expect(element('.doc-example-live ng-pluralize:last').text()).
- toBe('Nobody is viewing.');
-
- using('.doc-example-live').input('personCount').enter('2');
- expect(element('.doc-example-live ng-pluralize:first').text()).
- toBe('2 people are viewing.');
- expect(element('.doc-example-live ng-pluralize:last').text()).
- toBe('Igor and Misko are viewing.');
-
- using('.doc-example-live').input('personCount').enter('3');
- expect(element('.doc-example-live ng-pluralize:first').text()).
- toBe('3 people are viewing.');
- expect(element('.doc-example-live ng-pluralize:last').text()).
- toBe('Igor, Misko and one other person are viewing.');
-
- using('.doc-example-live').input('personCount').enter('4');
- expect(element('.doc-example-live ng-pluralize:first').text()).
- toBe('4 people are viewing.');
- expect(element('.doc-example-live ng-pluralize:last').text()).
- toBe('Igor, Misko and 2 other people are viewing.');
- });
+ var withoutOffset = element.all(by.css('ng-pluralize')).get(0);
+ var withOffset = element.all(by.css('ng-pluralize')).get(1);
+ var countInput = element(by.model('personCount'));
+
+ expect(withoutOffset.getText()).toEqual('1 person is viewing.');
+ expect(withOffset.getText()).toEqual('Igor is viewing.');
+
+ countInput.clear();
+ countInput.sendKeys('0');
+
+ expect(withoutOffset.getText()).toEqual('Nobody is viewing.');
+ expect(withOffset.getText()).toEqual('Nobody is viewing.');
+
+ countInput.clear();
+ countInput.sendKeys('2');
+
+ expect(withoutOffset.getText()).toEqual('2 people are viewing.');
+ expect(withOffset.getText()).toEqual('Igor and Misko are viewing.');
+
+ countInput.clear();
+ countInput.sendKeys('3');
- it('should show data-binded names', function() {
- using('.doc-example-live').input('personCount').enter('4');
- expect(element('.doc-example-live ng-pluralize:last').text()).
- toBe('Igor, Misko and 2 other people are viewing.');
+ expect(withoutOffset.getText()).toEqual('3 people are viewing.');
+ expect(withOffset.getText()).toEqual('Igor, Misko and one other person are viewing.');
- using('.doc-example-live').input('person1').enter('Di');
- using('.doc-example-live').input('person2').enter('Vojta');
- expect(element('.doc-example-live ng-pluralize:last').text()).
- toBe('Di, Vojta and 2 other people are viewing.');
+ countInput.clear();
+ countInput.sendKeys('4');
+
+ expect(withoutOffset.getText()).toEqual('4 people are viewing.');
+ expect(withOffset.getText()).toEqual('Igor, Misko and 2 other people are viewing.');
+ });
+ it('should show data-bound names', function() {
+ var withOffset = element.all(by.css('ng-pluralize')).get(1);
+ var personCount = element(by.model('personCount'));
+ var person1 = element(by.model('person1'));
+ var person2 = element(by.model('person2'));
+ personCount.clear();
+ personCount.sendKeys('4');
+ person1.clear();
+ person1.sendKeys('Di');
+ person2.clear();
+ person2.sendKeys('Vojta');
+ expect(withOffset.getText()).toEqual('Di, Vojta and 2 other people are viewing.');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interpolate) {
var BRACE = /{}/g;
@@ -18462,7 +19715,7 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
/**
* @ngdoc directive
- * @name ng.directive:ngRepeat
+ * @name ngRepeat
*
* @description
* The `ngRepeat` directive instantiates a template once per item from a collection. Each template
@@ -18480,6 +19733,8 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
* | `$even` | {@type boolean} | true if the iterator position `$index` is even (otherwise false). |
* | `$odd` | {@type boolean} | true if the iterator position `$index` is odd (otherwise false). |
*
+ * Creating aliases for these properties is possible with {@link ng.directive:ngInit `ngInit`}.
+ * This may be useful when, for instance, nesting ngRepeats.
*
* # Special repeat start and end points
* To repeat a series of elements instead of just one parent element, ngRepeat (as well as other ng directives) supports extending
@@ -18488,7 +19743,7 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
* up to and including the ending HTML tag where **ng-repeat-end** is placed.
*
* The example below makes use of this feature:
- * <pre>
+ * ```html
* <header ng-repeat-start="item in items">
* Header {{ item }}
* </header>
@@ -18498,10 +19753,10 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
* <footer ng-repeat-end>
* Footer {{ item }}
* </footer>
- * </pre>
+ * ```
*
* And with an input of {@type ['A','B']} for the items variable in the example above, the output will evaluate to:
- * <pre>
+ * ```html
* <header>
* Header A
* </header>
@@ -18520,15 +19775,17 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
* <footer>
* Footer B
* </footer>
- * </pre>
+ * ```
*
* The custom start and end points for ngRepeat also support all other HTML directive syntax flavors provided in AngularJS (such
* as **data-ng-repeat-start**, **x-ng-repeat-start** and **ng:repeat-start**).
*
* @animations
- * enter - when a new item is added to the list or when an item is revealed after a filter
- * leave - when an item is removed from the list or when an item is filtered out
- * move - when an adjacent item is filtered out causing a reorder or when the item contents are reordered
+ * **.enter** - when a new item is added to the list or when an item is revealed after a filter
+ *
+ * **.leave** - when an item is removed from the list or when an item is filtered out
+ *
+ * **.move** - when an adjacent item is filtered out causing a reorder or when the item contents are reordered
*
* @element ANY
* @scope
@@ -18559,7 +19816,7 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
* For example: `item in items track by $id(item)`. A built in `$id()` function can be used to assign a unique
* `$$hashKey` property to each item in the array. This property is then used as a key to associated DOM elements
* with the corresponding item in the array by identity. Moving the same object in array would move the DOM
- * element in the same way ian the DOM.
+ * element in the same way in the DOM.
*
* For example: `item in items track by item.id` is a typical pattern when the items come from the database. In this
* case the object identity does not matter. Two objects are considered equivalent as long as their `id`
@@ -18571,7 +19828,7 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
* @example
* This example initializes the scope to a list of names and
* then uses `ngRepeat` to display every person:
- <example animations="true">
+ <example module="ngAnimate" deps="angular-animate.js" animations="true">
<file name="index.html">
<div ng-init="friends = [
{name:'John', age:25, gender:'boy'},
@@ -18630,25 +19887,26 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
max-height:40px;
}
</file>
- <file name="scenario.js">
- it('should render initial data set', function() {
- var r = using('.doc-example-live').repeater('ul li');
- expect(r.count()).toBe(10);
- expect(r.row(0)).toEqual(["1","John","25"]);
- expect(r.row(1)).toEqual(["2","Jessie","30"]);
- expect(r.row(9)).toEqual(["10","Samantha","60"]);
- expect(binding('friends.length')).toBe("10");
- });
+ <file name="protractor.js" type="protractor">
+ var friends = element.all(by.repeater('friend in friends'));
+
+ it('should render initial data set', function() {
+ expect(friends.count()).toBe(10);
+ expect(friends.get(0).getText()).toEqual('[1] John who is 25 years old.');
+ expect(friends.get(1).getText()).toEqual('[2] Jessie who is 30 years old.');
+ expect(friends.last().getText()).toEqual('[10] Samantha who is 60 years old.');
+ expect(element(by.binding('friends.length')).getText())
+ .toMatch("I have 10 friends. They are:");
+ });
it('should update repeater when filter predicate changes', function() {
- var r = using('.doc-example-live').repeater('ul li');
- expect(r.count()).toBe(10);
+ expect(friends.count()).toBe(10);
- input('q').enter('ma');
+ element(by.model('q')).sendKeys('ma');
- expect(r.count()).toBe(2);
- expect(r.row(0)).toEqual(["1","Mary","28"]);
- expect(r.row(1)).toEqual(["2","Samantha","60"]);
+ expect(friends.count()).toBe(2);
+ expect(friends.get(0).getText()).toEqual('[1] Mary who is 28 years old.');
+ expect(friends.last().getText()).toEqual('[2] Samantha who is 60 years old.');
});
</file>
</example>
@@ -18663,7 +19921,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
$$tlb: true,
link: function($scope, $element, $attr, ctrl, $transclude){
var expression = $attr.ngRepeat;
- var match = expression.match(/^\s*(.+)\s+in\s+(.*?)\s*(\s+track\s+by\s+(.+)\s*)?$/),
+ var match = expression.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/),
trackByExp, trackByExpGetter, trackByIdExpFn, trackByIdArrayFn, trackByIdObjFn,
lhs, rhs, valueIdentifier, keyIdentifier,
hashFnLocals = {$id: hashKey};
@@ -18675,7 +19933,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
lhs = match[1];
rhs = match[2];
- trackByExp = match[4];
+ trackByExp = match[3];
if (trackByExp) {
trackByExpGetter = $parse(trackByExp);
@@ -18761,7 +20019,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
} else if (nextBlockMap.hasOwnProperty(trackById)) {
// restore lastBlockMap
forEach(nextBlockOrder, function(block) {
- if (block && block.startNode) lastBlockMap[block.id] = block;
+ if (block && block.scope) lastBlockMap[block.id] = block;
});
// This is a duplicate and we need to throw an error
throw ngRepeatMinErr('dupes', "Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: {0}, Duplicate key: {1}",
@@ -18778,7 +20036,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
// lastBlockMap is our own object so we don't need to use special hasOwnPropertyFn
if (lastBlockMap.hasOwnProperty(key)) {
block = lastBlockMap[key];
- elementsToRemove = getBlockElements(block);
+ elementsToRemove = getBlockElements(block.clone);
$animate.leave(elementsToRemove);
forEach(elementsToRemove, function(element) { element[NG_REMOVED] = true; });
block.scope.$destroy();
@@ -18790,9 +20048,9 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
key = (collection === collectionKeys) ? index : collectionKeys[index];
value = collection[key];
block = nextBlockOrder[index];
- if (nextBlockOrder[index - 1]) previousNode = nextBlockOrder[index - 1].endNode;
+ if (nextBlockOrder[index - 1]) previousNode = getBlockEnd(nextBlockOrder[index - 1]);
- if (block.startNode) {
+ if (block.scope) {
// if we have already seen this object, then we need to reuse the
// associated scope/element
childScope = block.scope;
@@ -18802,11 +20060,11 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
nextNode = nextNode.nextSibling;
} while(nextNode && nextNode[NG_REMOVED]);
- if (block.startNode != nextNode) {
+ if (getBlockStart(block) != nextNode) {
// existing item which got moved
- $animate.move(getBlockElements(block), null, jqLite(previousNode));
+ $animate.move(getBlockElements(block.clone), null, jqLite(previousNode));
}
- previousNode = block.endNode;
+ previousNode = getBlockEnd(block);
} else {
// new item which we don't know about
childScope = $scope.$new();
@@ -18822,14 +20080,16 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
childScope.$odd = !(childScope.$even = (index&1) === 0);
// jshint bitwise: true
- if (!block.startNode) {
+ if (!block.scope) {
$transclude(childScope, function(clone) {
clone[clone.length++] = document.createComment(' end ngRepeat: ' + expression + ' ');
$animate.enter(clone, null, jqLite(previousNode));
previousNode = clone;
block.scope = childScope;
- block.startNode = previousNode && previousNode.endNode ? previousNode.endNode : clone[0];
- block.endNode = clone[clone.length - 1];
+ // Note: We only need the first/last node of the cloned nodes.
+ // However, we need to keep the reference to the jqlite wrapper as it might be changed later
+ // by a directive with templateUrl when it's template arrives.
+ block.clone = clone;
nextBlockMap[block.id] = block;
});
}
@@ -18838,11 +20098,19 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
});
}
};
+
+ function getBlockStart(block) {
+ return block.clone[0];
+ }
+
+ function getBlockEnd(block) {
+ return block.clone[block.clone.length - 1];
+ }
}];
/**
* @ngdoc directive
- * @name ng.directive:ngShow
+ * @name ngShow
*
* @description
* The `ngShow` directive shows or hides the given HTML element based on the expression
@@ -18851,13 +20119,13 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
* in AngularJS and sets the display style to none (using an !important flag).
* For CSP mode please add `angular-csp.css` to your html file (see {@link ng.directive:ngCsp ngCsp}).
*
- * <pre>
+ * ```html
* <!-- when $scope.myValue is truthy (element is visible) -->
* <div ng-show="myValue"></div>
*
* <!-- when $scope.myValue is falsy (element is hidden) -->
* <div ng-show="myValue" class="ng-hide"></div>
- * </pre>
+ * ```
*
* When the ngShow expression evaluates to false then the ng-hide CSS class is added to the class attribute
* on the element causing it to become hidden. When true, the ng-hide CSS class is removed
@@ -18878,7 +20146,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
*
* If you wish to change the hide behavior with ngShow/ngHide then this can be achieved by
* restating the styles for the .ng-hide class in CSS:
- * <pre>
+ * ```css
* .ng-hide {
* //!annotate CSS Specificity|Not to worry, this will override the AngularJS default...
* display:block!important;
@@ -18888,10 +20156,15 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
* top:-9999px;
* left:-9999px;
* }
- * </pre>
+ * ```
*
* Just remember to include the important flag so the CSS override will function.
*
+ * <div class="alert alert-warning">
+ * **Note:** Here is a list of values that ngShow will consider as a falsy value (case insensitive):<br />
+ * "f" / "0" / "false" / "no" / "n" / "[]"
+ * </div>
+ *
* ## A note about animations with ngShow
*
* Animations in ngShow/ngHide work with the show and hide events that are triggered when the directive expression
@@ -18899,7 +20172,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
* you must also include the !important flag to override the display property
* so that you can perform an animation when the element is hidden during the time of the animation.
*
- * <pre>
+ * ```css
* //
* //a working example can be found at the bottom of this page
* //
@@ -18912,7 +20185,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
* .my-element.ng-hide-add.ng-hide-add-active { ... }
* .my-element.ng-hide-remove { ... }
* .my-element.ng-hide-remove.ng-hide-remove-active { ... }
- * </pre>
+ * ```
*
* @animations
* addClass: .ng-hide - happens after the ngShow expression evaluates to a truthy value and the just before contents are set to visible
@@ -18923,22 +20196,25 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
* then the element is shown or hidden respectively.
*
* @example
- <example animations="true">
+ <example module="ngAnimate" deps="angular-animate.js" animations="true">
<file name="index.html">
Click me: <input type="checkbox" ng-model="checked"><br/>
<div>
Show:
<div class="check-element animate-show" ng-show="checked">
- <span class="icon-thumbs-up"></span> I show up when your checkbox is checked.
+ <span class="glyphicon glyphicon-thumbs-up"></span> I show up when your checkbox is checked.
</div>
</div>
<div>
Hide:
<div class="check-element animate-show" ng-hide="checked">
- <span class="icon-thumbs-down"></span> I hide when your checkbox is checked.
+ <span class="glyphicon glyphicon-thumbs-down"></span> I hide when your checkbox is checked.
</div>
</div>
</file>
+ <file name="glyphicons.css">
+ @import url(//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css);
+ </file>
<file name="animations.css">
.animate-show {
-webkit-transition:all linear 0.5s;
@@ -18967,16 +20243,19 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
background:white;
}
</file>
- <file name="scenario.js">
- it('should check ng-show / ng-hide', function() {
- expect(element('.doc-example-live span:first:hidden').count()).toEqual(1);
- expect(element('.doc-example-live span:last:visible').count()).toEqual(1);
+ <file name="protractor.js" type="protractor">
+ var thumbsUp = element(by.css('span.glyphicon-thumbs-up'));
+ var thumbsDown = element(by.css('span.glyphicon-thumbs-down'));
- input('checked').check();
+ it('should check ng-show / ng-hide', function() {
+ expect(thumbsUp.isDisplayed()).toBeFalsy();
+ expect(thumbsDown.isDisplayed()).toBeTruthy();
- expect(element('.doc-example-live span:first:visible').count()).toEqual(1);
- expect(element('.doc-example-live span:last:hidden').count()).toEqual(1);
- });
+ element(by.model('checked')).click();
+
+ expect(thumbsUp.isDisplayed()).toBeTruthy();
+ expect(thumbsDown.isDisplayed()).toBeFalsy();
+ });
</file>
</example>
*/
@@ -18991,7 +20270,7 @@ var ngShowDirective = ['$animate', function($animate) {
/**
* @ngdoc directive
- * @name ng.directive:ngHide
+ * @name ngHide
*
* @description
* The `ngHide` directive shows or hides the given HTML element based on the expression
@@ -19000,13 +20279,13 @@ var ngShowDirective = ['$animate', function($animate) {
* in AngularJS and sets the display style to none (using an !important flag).
* For CSP mode please add `angular-csp.css` to your html file (see {@link ng.directive:ngCsp ngCsp}).
*
- * <pre>
+ * ```html
* <!-- when $scope.myValue is truthy (element is hidden) -->
* <div ng-hide="myValue"></div>
*
* <!-- when $scope.myValue is falsy (element is visible) -->
* <div ng-hide="myValue" class="ng-hide"></div>
- * </pre>
+ * ```
*
* When the ngHide expression evaluates to true then the .ng-hide CSS class is added to the class attribute
* on the element causing it to become hidden. When false, the ng-hide CSS class is removed
@@ -19027,7 +20306,7 @@ var ngShowDirective = ['$animate', function($animate) {
*
* If you wish to change the hide behavior with ngShow/ngHide then this can be achieved by
* restating the styles for the .ng-hide class in CSS:
- * <pre>
+ * ```css
* .ng-hide {
* //!annotate CSS Specificity|Not to worry, this will override the AngularJS default...
* display:block!important;
@@ -19037,10 +20316,15 @@ var ngShowDirective = ['$animate', function($animate) {
* top:-9999px;
* left:-9999px;
* }
- * </pre>
+ * ```
*
* Just remember to include the important flag so the CSS override will function.
*
+ * <div class="alert alert-warning">
+ * **Note:** Here is a list of values that ngHide will consider as a falsy value (case insensitive):<br />
+ * "f" / "0" / "false" / "no" / "n" / "[]"
+ * </div>
+ *
* ## A note about animations with ngHide
*
* Animations in ngShow/ngHide work with the show and hide events that are triggered when the directive expression
@@ -19048,7 +20332,7 @@ var ngShowDirective = ['$animate', function($animate) {
* you must also include the !important flag to override the display property so
* that you can perform an animation when the element is hidden during the time of the animation.
*
- * <pre>
+ * ```css
* //
* //a working example can be found at the bottom of this page
* //
@@ -19061,7 +20345,7 @@ var ngShowDirective = ['$animate', function($animate) {
* .my-element.ng-hide-add.ng-hide-add-active { ... }
* .my-element.ng-hide-remove { ... }
* .my-element.ng-hide-remove.ng-hide-remove-active { ... }
- * </pre>
+ * ```
*
* @animations
* removeClass: .ng-hide - happens after the ngHide expression evaluates to a truthy value and just before the contents are set to hidden
@@ -19072,22 +20356,25 @@ var ngShowDirective = ['$animate', function($animate) {
* the element is shown or hidden respectively.
*
* @example
- <example animations="true">
+ <example module="ngAnimate" deps="angular-animate.js" animations="true">
<file name="index.html">
Click me: <input type="checkbox" ng-model="checked"><br/>
<div>
Show:
<div class="check-element animate-hide" ng-show="checked">
- <span class="icon-thumbs-up"></span> I show up when your checkbox is checked.
+ <span class="glyphicon glyphicon-thumbs-up"></span> I show up when your checkbox is checked.
</div>
</div>
<div>
Hide:
<div class="check-element animate-hide" ng-hide="checked">
- <span class="icon-thumbs-down"></span> I hide when your checkbox is checked.
+ <span class="glyphicon glyphicon-thumbs-down"></span> I hide when your checkbox is checked.
</div>
</div>
</file>
+ <file name="glyphicons.css">
+ @import url(//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css);
+ </file>
<file name="animations.css">
.animate-hide {
-webkit-transition:all linear 0.5s;
@@ -19116,16 +20403,19 @@ var ngShowDirective = ['$animate', function($animate) {
background:white;
}
</file>
- <file name="scenario.js">
- it('should check ng-show / ng-hide', function() {
- expect(element('.doc-example-live .check-element:first:hidden').count()).toEqual(1);
- expect(element('.doc-example-live .check-element:last:visible').count()).toEqual(1);
+ <file name="protractor.js" type="protractor">
+ var thumbsUp = element(by.css('span.glyphicon-thumbs-up'));
+ var thumbsDown = element(by.css('span.glyphicon-thumbs-down'));
- input('checked').check();
+ it('should check ng-show / ng-hide', function() {
+ expect(thumbsUp.isDisplayed()).toBeFalsy();
+ expect(thumbsDown.isDisplayed()).toBeTruthy();
- expect(element('.doc-example-live .check-element:first:visible').count()).toEqual(1);
- expect(element('.doc-example-live .check-element:last:hidden').count()).toEqual(1);
- });
+ element(by.model('checked')).click();
+
+ expect(thumbsUp.isDisplayed()).toBeTruthy();
+ expect(thumbsDown.isDisplayed()).toBeFalsy();
+ });
</file>
</example>
*/
@@ -19139,7 +20429,7 @@ var ngHideDirective = ['$animate', function($animate) {
/**
* @ngdoc directive
- * @name ng.directive:ngStyle
+ * @name ngStyle
* @restrict AC
*
* @description
@@ -19164,13 +20454,15 @@ var ngHideDirective = ['$animate', function($animate) {
color: black;
}
</file>
- <file name="scenario.js">
+ <file name="protractor.js" type="protractor">
+ var colorSpan = element(by.css('span'));
+
it('should check ng-style', function() {
- expect(element('.doc-example-live span').css('color')).toBe('rgb(0, 0, 0)');
- element('.doc-example-live :button[value=set]').click();
- expect(element('.doc-example-live span').css('color')).toBe('rgb(255, 0, 0)');
- element('.doc-example-live :button[value=clear]').click();
- expect(element('.doc-example-live span').css('color')).toBe('rgb(0, 0, 0)');
+ expect(colorSpan.getCssValue('color')).toBe('rgba(0, 0, 0, 1)');
+ element(by.css('input[value=set]')).click();
+ expect(colorSpan.getCssValue('color')).toBe('rgba(255, 0, 0, 1)');
+ element(by.css('input[value=clear]')).click();
+ expect(colorSpan.getCssValue('color')).toBe('rgba(0, 0, 0, 1)');
});
</file>
</example>
@@ -19186,23 +20478,30 @@ var ngStyleDirective = ngDirective(function(scope, element, attr) {
/**
* @ngdoc directive
- * @name ng.directive:ngSwitch
+ * @name ngSwitch
* @restrict EA
*
* @description
- * The ngSwitch directive is used to conditionally swap DOM structure on your template based on a scope expression.
- * Elements within ngSwitch but without ngSwitchWhen or ngSwitchDefault directives will be preserved at the location
+ * The `ngSwitch` directive is used to conditionally swap DOM structure on your template based on a scope expression.
+ * Elements within `ngSwitch` but without `ngSwitchWhen` or `ngSwitchDefault` directives will be preserved at the location
* as specified in the template.
*
* The directive itself works similar to ngInclude, however, instead of downloading template code (or loading it
- * from the template cache), ngSwitch simply choses one of the nested elements and makes it visible based on which element
+ * from the template cache), `ngSwitch` simply chooses one of the nested elements and makes it visible based on which element
* matches the value obtained from the evaluated expression. In other words, you define a container element
- * (where you place the directive), place an expression on the **on="..." attribute**
- * (or the **ng-switch="..." attribute**), define any inner elements inside of the directive and place
+ * (where you place the directive), place an expression on the **`on="..."` attribute**
+ * (or the **`ng-switch="..."` attribute**), define any inner elements inside of the directive and place
* a when attribute per element. The when attribute is used to inform ngSwitch which element to display when the on
* expression is evaluated. If a matching expression is not found via a when attribute then an element with the default
* attribute is displayed.
*
+ * <div class="alert alert-info">
+ * Be aware that the attribute values to match against cannot be expressions. They are interpreted
+ * as literal string values to match against.
+ * For example, **`ng-switch-when="someVal"`** will match against the string `"someVal"` not against the
+ * value of the expression `$scope.someVal`.
+ * </div>
+
* @animations
* enter - happens after the ngSwitch contents change and the matched child element is placed inside the container
* leave - happens just after the ngSwitch contents change and just before the former contents are removed from the DOM
@@ -19214,10 +20513,10 @@ var ngStyleDirective = ngDirective(function(scope, element, attr) {
* <ANY ng-switch-default>...</ANY>
* </ANY>
*
+ *
* @scope
* @priority 800
* @param {*} ngSwitch|on expression to match against <tt>ng-switch-when</tt>.
- * @paramDescription
* On child elements add:
*
* * `ngSwitchWhen`: the case statement to match against. If match then this
@@ -19229,7 +20528,7 @@ var ngStyleDirective = ngDirective(function(scope, element, attr) {
*
*
* @example
- <example animations="true">
+ <example module="ngAnimate" deps="angular-animate.js" animations="true">
<file name="index.html">
<div ng-controller="Ctrl">
<select ng-model="selection" ng-options="item for item in items">
@@ -19283,17 +20582,20 @@ var ngStyleDirective = ngDirective(function(scope, element, attr) {
top:0;
}
</file>
- <file name="scenario.js">
+ <file name="protractor.js" type="protractor">
+ var switchElem = element(by.css('[ng-switch]'));
+ var select = element(by.model('selection'));
+
it('should start in settings', function() {
- expect(element('.doc-example-live [ng-switch]').text()).toMatch(/Settings Div/);
+ expect(switchElem.getText()).toMatch(/Settings Div/);
});
it('should change to home', function() {
- select('selection').option('home');
- expect(element('.doc-example-live [ng-switch]').text()).toMatch(/Home Span/);
+ select.element.all(by.css('option')).get(1).click();
+ expect(switchElem.getText()).toMatch(/Home Span/);
});
it('should select default', function() {
- select('selection').option('other');
- expect(element('.doc-example-live [ng-switch]').text()).toMatch(/default/);
+ select.element.all(by.css('option')).get(2).click();
+ expect(switchElem.getText()).toMatch(/default/);
});
</file>
</example>
@@ -19311,12 +20613,31 @@ var ngSwitchDirective = ['$animate', function($animate) {
var watchExpr = attr.ngSwitch || attr.on,
selectedTranscludes,
selectedElements,
+ previousElements,
selectedScopes = [];
scope.$watch(watchExpr, function ngSwitchWatchAction(value) {
- for (var i= 0, ii=selectedScopes.length; i<ii; i++) {
- selectedScopes[i].$destroy();
- $animate.leave(selectedElements[i]);
+ var i, ii = selectedScopes.length;
+ if(ii > 0) {
+ if(previousElements) {
+ for (i = 0; i < ii; i++) {
+ previousElements[i].remove();
+ }
+ previousElements = null;
+ }
+
+ previousElements = [];
+ for (i= 0; i<ii; i++) {
+ var selected = selectedElements[i];
+ selectedScopes[i].$destroy();
+ previousElements[i] = selected;
+ $animate.leave(selected, function() {
+ previousElements.splice(i, 1);
+ if(previousElements.length === 0) {
+ previousElements = null;
+ }
+ });
+ }
}
selectedElements = [];
@@ -19344,11 +20665,9 @@ var ngSwitchWhenDirective = ngDirective({
transclude: 'element',
priority: 800,
require: '^ngSwitch',
- compile: function(element, attrs) {
- return function(scope, element, attr, ctrl, $transclude) {
- ctrl.cases['!' + attrs.ngSwitchWhen] = (ctrl.cases['!' + attrs.ngSwitchWhen] || []);
- ctrl.cases['!' + attrs.ngSwitchWhen].push({ transclude: $transclude, element: element });
- };
+ link: function(scope, element, attrs, ctrl, $transclude) {
+ ctrl.cases['!' + attrs.ngSwitchWhen] = (ctrl.cases['!' + attrs.ngSwitchWhen] || []);
+ ctrl.cases['!' + attrs.ngSwitchWhen].push({ transclude: $transclude, element: element });
}
});
@@ -19364,7 +20683,7 @@ var ngSwitchDefaultDirective = ngDirective({
/**
* @ngdoc directive
- * @name ng.directive:ngTransclude
+ * @name ngTransclude
* @restrict AC
*
* @description
@@ -19375,8 +20694,8 @@ var ngSwitchDefaultDirective = ngDirective({
* @element ANY
*
* @example
- <doc:example module="transclude">
- <doc:source>
+ <example module="transclude">
+ <file name="index.html">
<script>
function Ctrl($scope) {
$scope.title = 'Lorem Ipsum';
@@ -19401,37 +20720,34 @@ var ngSwitchDefaultDirective = ngDirective({
<textarea ng-model="text"></textarea> <br/>
<pane title="{{title}}">{{text}}</pane>
</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should have transcluded', function() {
- input('title').enter('TITLE');
- input('text').enter('TEXT');
- expect(binding('title')).toEqual('TITLE');
- expect(binding('text')).toEqual('TEXT');
+ var titleElement = element(by.model('title'));
+ titleElement.clear();
+ titleElement.sendKeys('TITLE');
+ var textElement = element(by.model('text'));
+ textElement.clear();
+ textElement.sendKeys('TEXT');
+ expect(element(by.binding('title')).getText()).toEqual('TITLE');
+ expect(element(by.binding('text')).getText()).toEqual('TEXT');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*
*/
var ngTranscludeDirective = ngDirective({
- controller: ['$element', '$transclude', function($element, $transclude) {
+ link: function($scope, $element, $attrs, controller, $transclude) {
if (!$transclude) {
throw minErr('ngTransclude')('orphan',
- 'Illegal use of ngTransclude directive in the template! ' +
- 'No parent directive that requires a transclusion found. ' +
- 'Element: {0}',
- startingTag($element));
+ 'Illegal use of ngTransclude directive in the template! ' +
+ 'No parent directive that requires a transclusion found. ' +
+ 'Element: {0}',
+ startingTag($element));
}
- // remember the transclusion fn but call it during linking so that we don't process transclusion before directives on
- // the parent element even when the transclusion replaces the current element. (we can't use priority here because
- // that applies only to compile fns and not controllers
- this.$transclude = $transclude;
- }],
-
- link: function($scope, $element, $attrs, controller) {
- controller.$transclude(function(clone) {
- $element.html('');
+ $transclude(function(clone) {
+ $element.empty();
$element.append(clone);
});
}
@@ -19439,32 +20755,36 @@ var ngTranscludeDirective = ngDirective({
/**
* @ngdoc directive
- * @name ng.directive:script
+ * @name script
* @restrict E
*
* @description
- * Load content of a script tag, with type `text/ng-template`, into `$templateCache`, so that the
- * template can be used by `ngInclude`, `ngView` or directive templates.
+ * Load the content of a `<script>` element into {@link ng.$templateCache `$templateCache`}, so that the
+ * template can be used by {@link ng.directive:ngInclude `ngInclude`},
+ * {@link ngRoute.directive:ngView `ngView`}, or {@link guide/directive directives}. The type of the
+ * `<script>` element must be specified as `text/ng-template`, and a cache name for the template must be
+ * assigned through the element's `id`, which can then be used as a directive's `templateUrl`.
*
- * @param {'text/ng-template'} type must be set to `'text/ng-template'`
+ * @param {string} type Must be set to `'text/ng-template'`.
+ * @param {string} id Cache name of the template.
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<script type="text/ng-template" id="/tpl.html">
Content of the template.
</script>
<a ng-click="currentTpl='/tpl.html'" id="tpl-link">Load inlined template</a>
<div id="tpl-content" ng-include src="currentTpl"></div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should load template defined inside script tag', function() {
- element('#tpl-link').click();
- expect(element('#tpl-content').text()).toMatch(/Content of the template/);
+ element(by.css('#tpl-link')).click();
+ expect(element(by.css('#tpl-content')).getText()).toMatch(/Content of the template/);
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
var scriptDirective = ['$templateCache', function($templateCache) {
return {
@@ -19485,7 +20805,7 @@ var scriptDirective = ['$templateCache', function($templateCache) {
var ngOptionsMinErr = minErr('ngOptions');
/**
* @ngdoc directive
- * @name ng.directive:select
+ * @name select
* @restrict E
*
* @description
@@ -19501,14 +20821,21 @@ var ngOptionsMinErr = minErr('ngOptions');
* represented by the selected option will be bound to the model identified by the `ngModel`
* directive.
*
+ * <div class="alert alert-warning">
+ * **Note:** `ngModel` compares by reference, not value. This is important when binding to an
+ * array of objects. See an example [in this jsfiddle](http://jsfiddle.net/qWzTb/).
+ * </div>
+ *
* Optionally, a single hard-coded `<option>` element, with the value set to an empty string, can
* be nested into the `<select>` element. This element will then represent the `null` or "not selected"
* option. See example below for demonstration.
*
- * Note: `ngOptions` provides iterator facility for `<option>` element which should be used instead
+ * <div class="alert alert-warning">
+ * **Note:** `ngOptions` provides an iterator facility for the `<option>` element which should be used instead
* of {@link ng.directive:ngRepeat ngRepeat} when you want the
* `select` model to be bound to a non-string value. This is because an option element can only
* be bound to string values at present.
+ * </div>
*
* @param {string} ngModel Assignable angular expression to data-bind to.
* @param {string=} name Property name of the form under which the control is published.
@@ -19547,8 +20874,8 @@ var ngOptionsMinErr = minErr('ngOptions');
* `value` variable (e.g. `value.propertyName`).
*
* @example
- <doc:example>
- <doc:source>
+ <example>
+ <file name="index.html">
<script>
function MyCntrl($scope) {
$scope.colors = [
@@ -19594,24 +20921,26 @@ var ngOptionsMinErr = minErr('ngOptions');
ng-style="{'background-color':color.name}">
</div>
</div>
- </doc:source>
- <doc:scenario>
+ </file>
+ <file name="protractor.js" type="protractor">
it('should check ng-options', function() {
- expect(binding('{selected_color:color}')).toMatch('red');
- select('color').option('0');
- expect(binding('{selected_color:color}')).toMatch('black');
- using('.nullable').select('color').option('');
- expect(binding('{selected_color:color}')).toMatch('null');
+ expect(element(by.binding('{selected_color:color}')).getText()).toMatch('red');
+ element.all(by.select('color')).first().click();
+ element.all(by.css('select[ng-model="color"] option')).first().click();
+ expect(element(by.binding('{selected_color:color}')).getText()).toMatch('black');
+ element(by.css('.nullable select[ng-model="color"]')).click();
+ element.all(by.css('.nullable select[ng-model="color"] option')).first().click();
+ expect(element(by.binding('{selected_color:color}')).getText()).toMatch('null');
});
- </doc:scenario>
- </doc:example>
+ </file>
+ </example>
*/
var ngOptionsDirective = valueFn({ terminal: true });
// jshint maxlen: false
var selectDirective = ['$compile', '$parse', function($compile, $parse) {
- //0000111110000000000022220000000000000000000000333300000000000000444444444444444000000000555555555555555000000066666666666666600000000000000007777000000000000000000088888
- var NG_OPTIONS_REGEXP = /^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(.*?)(?:\s+track\s+by\s+(.*?))?$/,
+ //000011111111110000000000022222222220000000000000000000003333333333000000000000004444444444444440000000005555555555555550000000666666666666666000000000000000777777777700000000000000000008888888888
+ var NG_OPTIONS_REGEXP = /^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?$/,
nullModelCtrl = {$setViewValue: noop};
// jshint maxlen: 100
@@ -19703,18 +21032,10 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
selectCtrl.init(ngModelCtrl, nullOption, unknownOption);
// required validator
- if (multiple && (attr.required || attr.ngRequired)) {
- var requiredValidator = function(value) {
- ngModelCtrl.$setValidity('required', !attr.required || (value && value.length));
- return value;
+ if (multiple) {
+ ngModelCtrl.$isEmpty = function(value) {
+ return !value || value.length === 0;
};
-
- ngModelCtrl.$parsers.push(requiredValidator);
- ngModelCtrl.$formatters.unshift(requiredValidator);
-
- attr.$observe('required', function() {
- requiredValidator(ngModelCtrl.$viewValue);
- });
}
if (optionsExp) setupAsOptions(scope, element, ngModelCtrl);
@@ -19785,7 +21106,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
function setupAsOptions(scope, selectElement, ctrl) {
var match;
- if (! (match = optionsExp.match(NG_OPTIONS_REGEXP))) {
+ if (!(match = optionsExp.match(NG_OPTIONS_REGEXP))) {
throw ngOptionsMinErr('iexp',
"Expected expression in form of " +
"'_select_ (as _label_)? for (_key_,)?_value_ in _collection_'" +
@@ -19815,13 +21136,13 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
// becomes the compilation root
nullOption.removeClass('ng-scope');
- // we need to remove it before calling selectElement.html('') because otherwise IE will
+ // we need to remove it before calling selectElement.empty() because otherwise IE will
// remove the label from the element. wtf?
nullOption.remove();
}
// clear contents, we'll add what's needed based on the model
- selectElement.html('');
+ selectElement.empty();
selectElement.on('change', function() {
scope.$apply(function() {
@@ -19875,6 +21196,12 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
value = valueFn(scope, locals);
}
}
+ // Update the null option's selected property here so $render cleans it up correctly
+ if (optionGroupsCache[0].length > 1) {
+ if (optionGroupsCache[0][1].id !== key) {
+ optionGroupsCache[0][1].selected = false;
+ }
+ }
}
ctrl.$setViewValue(value);
});
@@ -19920,7 +21247,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
// We now build up the list of options we need (we merge later)
for (index = 0; length = keys.length, index < length; index++) {
-
+
key = index;
if (keyName) {
key = keys[index];
@@ -20012,7 +21339,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
lastElement.val(existingOption.id = option.id);
}
// lastElement.prop('selected') provided by jQuery has side-effects
- if (lastElement[0].selected !== option.selected) {
+ if (existingOption.selected !== option.selected) {
lastElement.prop('selected', (existingOption.selected = option.selected));
}
} else {
@@ -20116,6 +21443,12 @@ var styleDirective = valueFn({
terminal: true
});
+ if (window.angular.bootstrap) {
+ //AngularJS is already loaded, so we can return here...
+ console.log('WARNING: Tried to load angular more than once.');
+ return;
+ }
+
//try to bind to jquery now so that one can write angular.element().read()
//but we will rebind on bootstrap again.
bindJQuery();
@@ -20128,4 +21461,4 @@ var styleDirective = valueFn({
})(window, document);
-!angular.$$csp() && angular.element(document).find('head').prepend('<style type="text/css">@charset "UTF-8";[ng\\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak,.ng-hide{display:none !important;}ng\\:form{display:block;}.ng-animate-start{clip:rect(0,auto,auto,0);-ms-zoom:1.0001;}.ng-animate-active{clip:rect(-1px,auto,auto,0);-ms-zoom:1;}</style>');
+!angular.$$csp() && angular.element(document).find('head').prepend('<style type="text/css">@charset "UTF-8";[ng\\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak,.ng-hide{display:none !important;}ng\\:form{display:block;}.ng-animate-block-transitions{transition:0s all!important;-webkit-transition:0s all!important;}</style>'); \ No newline at end of file