summaryrefslogtreecommitdiff
path: root/xstatic/pkg/angular/data/angular-messages.js
diff options
context:
space:
mode:
Diffstat (limited to 'xstatic/pkg/angular/data/angular-messages.js')
-rw-r--r--xstatic/pkg/angular/data/angular-messages.js777
1 files changed, 405 insertions, 372 deletions
diff --git a/xstatic/pkg/angular/data/angular-messages.js b/xstatic/pkg/angular/data/angular-messages.js
index ad55265..9322b53 100644
--- a/xstatic/pkg/angular/data/angular-messages.js
+++ b/xstatic/pkg/angular/data/angular-messages.js
@@ -1,17 +1,14 @@
/**
- * @license AngularJS v1.4.10
- * (c) 2010-2015 Google, Inc. http://angularjs.org
+ * @license AngularJS v1.5.8
+ * (c) 2010-2016 Google, Inc. http://angularjs.org
* License: MIT
*/
-(function(window, angular, undefined) {'use strict';
+(function(window, angular) {'use strict';
-/* jshint ignore:start */
-// this code is in the core, but not in angular-messages.js
-var isArray = angular.isArray;
-var forEach = angular.forEach;
-var isString = angular.isString;
-var jqLite = angular.element;
-/* jshint ignore:end */
+var forEach;
+var isArray;
+var isString;
+var jqLite;
/**
* @ngdoc module
@@ -267,369 +264,404 @@ var jqLite = angular.element;
*
* {@link ngAnimate Click here} to learn how to use JavaScript animations or to learn more about ngAnimate.
*/
-angular.module('ngMessages', [])
-
- /**
- * @ngdoc directive
- * @module ngMessages
- * @name ngMessages
- * @restrict AE
- *
- * @description
- * `ngMessages` is a directive that is designed to show and hide messages based on the state
- * of a key/value object that it listens on. The directive itself complements error message
- * reporting with the `ngModel` $error object (which stores a key/value state of validation errors).
- *
- * `ngMessages` manages the state of internal messages within its container element. The internal
- * messages use the `ngMessage` directive and will be inserted/removed from the page depending
- * on if they're present within the key/value object. By default, only one message will be displayed
- * at a time and this depends on the prioritization of the messages within the template. (This can
- * be changed by using the `ng-messages-multiple` or `multiple` attribute on the directive container.)
- *
- * A remote template can also be used to promote message reusability and messages can also be
- * overridden.
- *
- * {@link module:ngMessages Click here} to learn more about `ngMessages` and `ngMessage`.
- *
- * @usage
- * ```html
- * <!-- using attribute directives -->
- * <ANY ng-messages="expression" role="alert">
- * <ANY ng-message="stringValue">...</ANY>
- * <ANY ng-message="stringValue1, stringValue2, ...">...</ANY>
- * <ANY ng-message-exp="expressionValue">...</ANY>
- * </ANY>
- *
- * <!-- or by using element directives -->
- * <ng-messages for="expression" role="alert">
- * <ng-message when="stringValue">...</ng-message>
- * <ng-message when="stringValue1, stringValue2, ...">...</ng-message>
- * <ng-message when-exp="expressionValue">...</ng-message>
- * </ng-messages>
- * ```
- *
- * @param {string} ngMessages an angular expression evaluating to a key/value object
- * (this is typically the $error object on an ngModel instance).
- * @param {string=} ngMessagesMultiple|multiple when set, all messages will be displayed with true
- *
- * @example
- * <example name="ngMessages-directive" module="ngMessagesExample"
- * deps="angular-messages.js"
- * animations="true" fixBase="true">
- * <file name="index.html">
- * <form name="myForm">
- * <label>
- * Enter your name:
- * <input type="text"
- * name="myName"
- * ng-model="name"
- * ng-minlength="5"
- * ng-maxlength="20"
- * required />
- * </label>
- * <pre>myForm.myName.$error = {{ myForm.myName.$error | json }}</pre>
- *
- * <div ng-messages="myForm.myName.$error" style="color:maroon" role="alert">
- * <div ng-message="required">You did not enter a field</div>
- * <div ng-message="minlength">Your field is too short</div>
- * <div ng-message="maxlength">Your field is too long</div>
- * </div>
- * </form>
- * </file>
- * <file name="script.js">
- * angular.module('ngMessagesExample', ['ngMessages']);
- * </file>
- * </example>
- */
- .directive('ngMessages', ['$animate', function($animate) {
- var ACTIVE_CLASS = 'ng-active';
- var INACTIVE_CLASS = 'ng-inactive';
-
- return {
- require: 'ngMessages',
- restrict: 'AE',
- controller: ['$element', '$scope', '$attrs', function($element, $scope, $attrs) {
- var ctrl = this;
- var latestKey = 0;
- var nextAttachId = 0;
-
- this.getAttachId = function getAttachId() { return nextAttachId++; };
-
- var messages = this.messages = {};
- var renderLater, cachedCollection;
-
- this.render = function(collection) {
- collection = collection || {};
-
- renderLater = false;
- cachedCollection = collection;
-
- // this is true if the attribute is empty or if the attribute value is truthy
- var multiple = isAttrTruthy($scope, $attrs.ngMessagesMultiple) ||
- isAttrTruthy($scope, $attrs.multiple);
-
- var unmatchedMessages = [];
- var matchedKeys = {};
- var messageItem = ctrl.head;
- var messageFound = false;
- var totalMessages = 0;
-
- // we use != instead of !== to allow for both undefined and null values
- while (messageItem != null) {
- totalMessages++;
- var messageCtrl = messageItem.message;
-
- var messageUsed = false;
- if (!messageFound) {
- forEach(collection, function(value, key) {
- if (!messageUsed && truthy(value) && messageCtrl.test(key)) {
- // this is to prevent the same error name from showing up twice
- if (matchedKeys[key]) return;
- matchedKeys[key] = true;
-
- messageUsed = true;
- messageCtrl.attach();
- }
- });
- }
-
- if (messageUsed) {
- // unless we want to display multiple messages then we should
- // set a flag here to avoid displaying the next message in the list
- messageFound = !multiple;
- } else {
- unmatchedMessages.push(messageCtrl);
- }
-
- messageItem = messageItem.next;
- }
-
- forEach(unmatchedMessages, function(messageCtrl) {
- messageCtrl.detach();
- });
-
- unmatchedMessages.length !== totalMessages
+angular.module('ngMessages', [], function initAngularHelpers() {
+ // Access helpers from angular core.
+ // Do it inside a `config` block to ensure `window.angular` is available.
+ forEach = angular.forEach;
+ isArray = angular.isArray;
+ isString = angular.isString;
+ jqLite = angular.element;
+})
+
+ /**
+ * @ngdoc directive
+ * @module ngMessages
+ * @name ngMessages
+ * @restrict AE
+ *
+ * @description
+ * `ngMessages` is a directive that is designed to show and hide messages based on the state
+ * of a key/value object that it listens on. The directive itself complements error message
+ * reporting with the `ngModel` $error object (which stores a key/value state of validation errors).
+ *
+ * `ngMessages` manages the state of internal messages within its container element. The internal
+ * messages use the `ngMessage` directive and will be inserted/removed from the page depending
+ * on if they're present within the key/value object. By default, only one message will be displayed
+ * at a time and this depends on the prioritization of the messages within the template. (This can
+ * be changed by using the `ng-messages-multiple` or `multiple` attribute on the directive container.)
+ *
+ * A remote template can also be used to promote message reusability and messages can also be
+ * overridden.
+ *
+ * {@link module:ngMessages Click here} to learn more about `ngMessages` and `ngMessage`.
+ *
+ * @usage
+ * ```html
+ * <!-- using attribute directives -->
+ * <ANY ng-messages="expression" role="alert">
+ * <ANY ng-message="stringValue">...</ANY>
+ * <ANY ng-message="stringValue1, stringValue2, ...">...</ANY>
+ * <ANY ng-message-exp="expressionValue">...</ANY>
+ * </ANY>
+ *
+ * <!-- or by using element directives -->
+ * <ng-messages for="expression" role="alert">
+ * <ng-message when="stringValue">...</ng-message>
+ * <ng-message when="stringValue1, stringValue2, ...">...</ng-message>
+ * <ng-message when-exp="expressionValue">...</ng-message>
+ * </ng-messages>
+ * ```
+ *
+ * @param {string} ngMessages an angular expression evaluating to a key/value object
+ * (this is typically the $error object on an ngModel instance).
+ * @param {string=} ngMessagesMultiple|multiple when set, all messages will be displayed with true
+ *
+ * @example
+ * <example name="ngMessages-directive" module="ngMessagesExample"
+ * deps="angular-messages.js"
+ * animations="true" fixBase="true">
+ * <file name="index.html">
+ * <form name="myForm">
+ * <label>
+ * Enter your name:
+ * <input type="text"
+ * name="myName"
+ * ng-model="name"
+ * ng-minlength="5"
+ * ng-maxlength="20"
+ * required />
+ * </label>
+ * <pre>myForm.myName.$error = {{ myForm.myName.$error | json }}</pre>
+ *
+ * <div ng-messages="myForm.myName.$error" style="color:maroon" role="alert">
+ * <div ng-message="required">You did not enter a field</div>
+ * <div ng-message="minlength">Your field is too short</div>
+ * <div ng-message="maxlength">Your field is too long</div>
+ * </div>
+ * </form>
+ * </file>
+ * <file name="script.js">
+ * angular.module('ngMessagesExample', ['ngMessages']);
+ * </file>
+ * </example>
+ */
+ .directive('ngMessages', ['$animate', function($animate) {
+ var ACTIVE_CLASS = 'ng-active';
+ var INACTIVE_CLASS = 'ng-inactive';
+
+ return {
+ require: 'ngMessages',
+ restrict: 'AE',
+ controller: ['$element', '$scope', '$attrs', function($element, $scope, $attrs) {
+ var ctrl = this;
+ var latestKey = 0;
+ var nextAttachId = 0;
+
+ this.getAttachId = function getAttachId() { return nextAttachId++; };
+
+ var messages = this.messages = {};
+ var renderLater, cachedCollection;
+
+ this.render = function(collection) {
+ collection = collection || {};
+
+ renderLater = false;
+ cachedCollection = collection;
+
+ // this is true if the attribute is empty or if the attribute value is truthy
+ var multiple = isAttrTruthy($scope, $attrs.ngMessagesMultiple) ||
+ isAttrTruthy($scope, $attrs.multiple);
+
+ var unmatchedMessages = [];
+ var matchedKeys = {};
+ var messageItem = ctrl.head;
+ var messageFound = false;
+ var totalMessages = 0;
+
+ // we use != instead of !== to allow for both undefined and null values
+ while (messageItem != null) {
+ totalMessages++;
+ var messageCtrl = messageItem.message;
+
+ var messageUsed = false;
+ if (!messageFound) {
+ forEach(collection, function(value, key) {
+ if (!messageUsed && truthy(value) && messageCtrl.test(key)) {
+ // this is to prevent the same error name from showing up twice
+ if (matchedKeys[key]) return;
+ matchedKeys[key] = true;
+
+ messageUsed = true;
+ messageCtrl.attach();
+ }
+ });
+ }
+
+ if (messageUsed) {
+ // unless we want to display multiple messages then we should
+ // set a flag here to avoid displaying the next message in the list
+ messageFound = !multiple;
+ } else {
+ unmatchedMessages.push(messageCtrl);
+ }
+
+ messageItem = messageItem.next;
+ }
+
+ forEach(unmatchedMessages, function(messageCtrl) {
+ messageCtrl.detach();
+ });
+
+ unmatchedMessages.length !== totalMessages
? $animate.setClass($element, ACTIVE_CLASS, INACTIVE_CLASS)
: $animate.setClass($element, INACTIVE_CLASS, ACTIVE_CLASS);
- };
-
- $scope.$watchCollection($attrs.ngMessages || $attrs['for'], ctrl.render);
-
- this.reRender = function() {
- if (!renderLater) {
- renderLater = true;
- $scope.$evalAsync(function() {
- if (renderLater) {
- cachedCollection && ctrl.render(cachedCollection);
- }
- });
- }
- };
-
- this.register = function(comment, messageCtrl) {
- var nextKey = latestKey.toString();
- messages[nextKey] = {
- message: messageCtrl
- };
- insertMessageNode($element[0], comment, nextKey);
- comment.$$ngMessageNode = nextKey;
- latestKey++;
-
- ctrl.reRender();
- };
-
- this.deregister = function(comment) {
- var key = comment.$$ngMessageNode;
- delete comment.$$ngMessageNode;
- removeMessageNode($element[0], comment, key);
- delete messages[key];
- ctrl.reRender();
- };
-
- function findPreviousMessage(parent, comment) {
- var prevNode = comment;
- var parentLookup = [];
- while (prevNode && prevNode !== parent) {
- var prevKey = prevNode.$$ngMessageNode;
- if (prevKey && prevKey.length) {
- return messages[prevKey];
- }
-
- // dive deeper into the DOM and examine its children for any ngMessage
- // comments that may be in an element that appears deeper in the list
- if (prevNode.childNodes.length && parentLookup.indexOf(prevNode) == -1) {
- parentLookup.push(prevNode);
- prevNode = prevNode.childNodes[prevNode.childNodes.length - 1];
- } else {
- prevNode = prevNode.previousSibling || prevNode.parentNode;
- }
- }
- }
-
- function insertMessageNode(parent, comment, key) {
- var messageNode = messages[key];
- if (!ctrl.head) {
- ctrl.head = messageNode;
- } else {
- var match = findPreviousMessage(parent, comment);
- if (match) {
- messageNode.next = match.next;
- match.next = messageNode;
- } else {
- messageNode.next = ctrl.head;
- ctrl.head = messageNode;
- }
- }
- }
-
- function removeMessageNode(parent, comment, key) {
- var messageNode = messages[key];
-
- var match = findPreviousMessage(parent, comment);
- if (match) {
- match.next = messageNode.next;
- } else {
- ctrl.head = messageNode.next;
- }
- }
- }]
- };
-
- function isAttrTruthy(scope, attr) {
- return (isString(attr) && attr.length === 0) || //empty attribute
- truthy(scope.$eval(attr));
- }
-
- function truthy(val) {
- return isString(val) ? val.length : !!val;
- }
- }])
-
- /**
- * @ngdoc directive
- * @name ngMessagesInclude
- * @restrict AE
- * @scope
- *
- * @description
- * `ngMessagesInclude` is a directive with the purpose to import existing ngMessage template
- * code from a remote template and place the downloaded template code into the exact spot
- * that the ngMessagesInclude directive is placed within the ngMessages container. This allows
- * for a series of pre-defined messages to be reused and also allows for the developer to
- * determine what messages are overridden due to the placement of the ngMessagesInclude directive.
- *
- * @usage
- * ```html
- * <!-- using attribute directives -->
- * <ANY ng-messages="expression" role="alert">
- * <ANY ng-messages-include="remoteTplString">...</ANY>
- * </ANY>
- *
- * <!-- or by using element directives -->
- * <ng-messages for="expression" role="alert">
- * <ng-messages-include src="expressionValue1">...</ng-messages-include>
- * </ng-messages>
- * ```
- *
- * {@link module:ngMessages Click here} to learn more about `ngMessages` and `ngMessage`.
- *
- * @param {string} ngMessagesInclude|src a string value corresponding to the remote template.
- */
- .directive('ngMessagesInclude',
- ['$templateRequest', '$document', '$compile', function($templateRequest, $document, $compile) {
-
- return {
- restrict: 'AE',
- require: '^^ngMessages', // we only require this for validation sake
- link: function($scope, element, attrs) {
- var src = attrs.ngMessagesInclude || attrs.src;
- $templateRequest(src).then(function(html) {
- $compile(html)($scope, function(contents) {
- element.after(contents);
-
- // the anchor is placed for debugging purposes
- var anchor = jqLite($document[0].createComment(' ngMessagesInclude: ' + src + ' '));
- element.after(anchor);
-
- // we don't want to pollute the DOM anymore by keeping an empty directive element
- element.remove();
- });
- });
- }
- };
- }])
-
- /**
- * @ngdoc directive
- * @name ngMessage
- * @restrict AE
- * @scope
- *
- * @description
- * `ngMessage` is a directive with the purpose to show and hide a particular message.
- * For `ngMessage` to operate, a parent `ngMessages` directive on a parent DOM element
- * must be situated since it determines which messages are visible based on the state
- * of the provided key/value map that `ngMessages` listens on.
- *
- * More information about using `ngMessage` can be found in the
- * {@link module:ngMessages `ngMessages` module documentation}.
- *
- * @usage
- * ```html
- * <!-- using attribute directives -->
- * <ANY ng-messages="expression" role="alert">
- * <ANY ng-message="stringValue">...</ANY>
- * <ANY ng-message="stringValue1, stringValue2, ...">...</ANY>
- * </ANY>
- *
- * <!-- or by using element directives -->
- * <ng-messages for="expression" role="alert">
- * <ng-message when="stringValue">...</ng-message>
- * <ng-message when="stringValue1, stringValue2, ...">...</ng-message>
- * </ng-messages>
- * ```
- *
- * @param {expression} ngMessage|when a string value corresponding to the message key.
- */
- .directive('ngMessage', ngMessageDirectiveFactory('AE'))
-
-
- /**
- * @ngdoc directive
- * @name ngMessageExp
- * @restrict AE
- * @scope
- *
- * @description
- * `ngMessageExp` is a directive with the purpose to show and hide a particular message.
- * For `ngMessageExp` to operate, a parent `ngMessages` directive on a parent DOM element
- * must be situated since it determines which messages are visible based on the state
- * of the provided key/value map that `ngMessages` listens on.
- *
- * @usage
- * ```html
- * <!-- using attribute directives -->
- * <ANY ng-messages="expression">
- * <ANY ng-message-exp="expressionValue">...</ANY>
- * </ANY>
- *
- * <!-- or by using element directives -->
- * <ng-messages for="expression">
- * <ng-message when-exp="expressionValue">...</ng-message>
- * </ng-messages>
- * ```
- *
- * {@link module:ngMessages Click here} to learn more about `ngMessages` and `ngMessage`.
- *
- * @param {expression} ngMessageExp|whenExp an expression value corresponding to the message key.
- */
- .directive('ngMessageExp', ngMessageDirectiveFactory('A'));
-
-function ngMessageDirectiveFactory(restrict) {
+ };
+
+ $scope.$watchCollection($attrs.ngMessages || $attrs['for'], ctrl.render);
+
+ // If the element is destroyed, proactively destroy all the currently visible messages
+ $element.on('$destroy', function() {
+ forEach(messages, function(item) {
+ item.message.detach();
+ });
+ });
+
+ this.reRender = function() {
+ if (!renderLater) {
+ renderLater = true;
+ $scope.$evalAsync(function() {
+ if (renderLater) {
+ cachedCollection && ctrl.render(cachedCollection);
+ }
+ });
+ }
+ };
+
+ this.register = function(comment, messageCtrl) {
+ var nextKey = latestKey.toString();
+ messages[nextKey] = {
+ message: messageCtrl
+ };
+ insertMessageNode($element[0], comment, nextKey);
+ comment.$$ngMessageNode = nextKey;
+ latestKey++;
+
+ ctrl.reRender();
+ };
+
+ this.deregister = function(comment) {
+ var key = comment.$$ngMessageNode;
+ delete comment.$$ngMessageNode;
+ removeMessageNode($element[0], comment, key);
+ delete messages[key];
+ ctrl.reRender();
+ };
+
+ function findPreviousMessage(parent, comment) {
+ var prevNode = comment;
+ var parentLookup = [];
+
+ while (prevNode && prevNode !== parent) {
+ var prevKey = prevNode.$$ngMessageNode;
+ if (prevKey && prevKey.length) {
+ return messages[prevKey];
+ }
+
+ // dive deeper into the DOM and examine its children for any ngMessage
+ // comments that may be in an element that appears deeper in the list
+ if (prevNode.childNodes.length && parentLookup.indexOf(prevNode) === -1) {
+ parentLookup.push(prevNode);
+ prevNode = prevNode.childNodes[prevNode.childNodes.length - 1];
+ } else if (prevNode.previousSibling) {
+ prevNode = prevNode.previousSibling;
+ } else {
+ prevNode = prevNode.parentNode;
+ parentLookup.push(prevNode);
+ }
+ }
+ }
+
+ function insertMessageNode(parent, comment, key) {
+ var messageNode = messages[key];
+ if (!ctrl.head) {
+ ctrl.head = messageNode;
+ } else {
+ var match = findPreviousMessage(parent, comment);
+ if (match) {
+ messageNode.next = match.next;
+ match.next = messageNode;
+ } else {
+ messageNode.next = ctrl.head;
+ ctrl.head = messageNode;
+ }
+ }
+ }
+
+ function removeMessageNode(parent, comment, key) {
+ var messageNode = messages[key];
+
+ var match = findPreviousMessage(parent, comment);
+ if (match) {
+ match.next = messageNode.next;
+ } else {
+ ctrl.head = messageNode.next;
+ }
+ }
+ }]
+ };
+
+ function isAttrTruthy(scope, attr) {
+ return (isString(attr) && attr.length === 0) || //empty attribute
+ truthy(scope.$eval(attr));
+ }
+
+ function truthy(val) {
+ return isString(val) ? val.length : !!val;
+ }
+ }])
+
+ /**
+ * @ngdoc directive
+ * @name ngMessagesInclude
+ * @restrict AE
+ * @scope
+ *
+ * @description
+ * `ngMessagesInclude` is a directive with the purpose to import existing ngMessage template
+ * code from a remote template and place the downloaded template code into the exact spot
+ * that the ngMessagesInclude directive is placed within the ngMessages container. This allows
+ * for a series of pre-defined messages to be reused and also allows for the developer to
+ * determine what messages are overridden due to the placement of the ngMessagesInclude directive.
+ *
+ * @usage
+ * ```html
+ * <!-- using attribute directives -->
+ * <ANY ng-messages="expression" role="alert">
+ * <ANY ng-messages-include="remoteTplString">...</ANY>
+ * </ANY>
+ *
+ * <!-- or by using element directives -->
+ * <ng-messages for="expression" role="alert">
+ * <ng-messages-include src="expressionValue1">...</ng-messages-include>
+ * </ng-messages>
+ * ```
+ *
+ * {@link module:ngMessages Click here} to learn more about `ngMessages` and `ngMessage`.
+ *
+ * @param {string} ngMessagesInclude|src a string value corresponding to the remote template.
+ */
+ .directive('ngMessagesInclude',
+ ['$templateRequest', '$document', '$compile', function($templateRequest, $document, $compile) {
+
+ return {
+ restrict: 'AE',
+ require: '^^ngMessages', // we only require this for validation sake
+ link: function($scope, element, attrs) {
+ var src = attrs.ngMessagesInclude || attrs.src;
+ $templateRequest(src).then(function(html) {
+ if ($scope.$$destroyed) return;
+
+ if (isString(html) && !html.trim()) {
+ // Empty template - nothing to compile
+ replaceElementWithMarker(element, src);
+ } else {
+ // Non-empty template - compile and link
+ $compile(html)($scope, function(contents) {
+ element.after(contents);
+ replaceElementWithMarker(element, src);
+ });
+ }
+ });
+ }
+ };
+
+ // Helpers
+ function replaceElementWithMarker(element, src) {
+ // A comment marker is placed for debugging purposes
+ var comment = $compile.$$createComment ?
+ $compile.$$createComment('ngMessagesInclude', src) :
+ $document[0].createComment(' ngMessagesInclude: ' + src + ' ');
+ var marker = jqLite(comment);
+ element.after(marker);
+
+ // Don't pollute the DOM anymore by keeping an empty directive element
+ element.remove();
+ }
+ }])
+
+ /**
+ * @ngdoc directive
+ * @name ngMessage
+ * @restrict AE
+ * @scope
+ *
+ * @description
+ * `ngMessage` is a directive with the purpose to show and hide a particular message.
+ * For `ngMessage` to operate, a parent `ngMessages` directive on a parent DOM element
+ * must be situated since it determines which messages are visible based on the state
+ * of the provided key/value map that `ngMessages` listens on.
+ *
+ * More information about using `ngMessage` can be found in the
+ * {@link module:ngMessages `ngMessages` module documentation}.
+ *
+ * @usage
+ * ```html
+ * <!-- using attribute directives -->
+ * <ANY ng-messages="expression" role="alert">
+ * <ANY ng-message="stringValue">...</ANY>
+ * <ANY ng-message="stringValue1, stringValue2, ...">...</ANY>
+ * </ANY>
+ *
+ * <!-- or by using element directives -->
+ * <ng-messages for="expression" role="alert">
+ * <ng-message when="stringValue">...</ng-message>
+ * <ng-message when="stringValue1, stringValue2, ...">...</ng-message>
+ * </ng-messages>
+ * ```
+ *
+ * @param {expression} ngMessage|when a string value corresponding to the message key.
+ */
+ .directive('ngMessage', ngMessageDirectiveFactory())
+
+
+ /**
+ * @ngdoc directive
+ * @name ngMessageExp
+ * @restrict AE
+ * @priority 1
+ * @scope
+ *
+ * @description
+ * `ngMessageExp` is a directive with the purpose to show and hide a particular message.
+ * For `ngMessageExp` to operate, a parent `ngMessages` directive on a parent DOM element
+ * must be situated since it determines which messages are visible based on the state
+ * of the provided key/value map that `ngMessages` listens on.
+ *
+ * @usage
+ * ```html
+ * <!-- using attribute directives -->
+ * <ANY ng-messages="expression">
+ * <ANY ng-message-exp="expressionValue">...</ANY>
+ * </ANY>
+ *
+ * <!-- or by using element directives -->
+ * <ng-messages for="expression">
+ * <ng-message when-exp="expressionValue">...</ng-message>
+ * </ng-messages>
+ * ```
+ *
+ * {@link module:ngMessages Click here} to learn more about `ngMessages` and `ngMessage`.
+ *
+ * @param {expression} ngMessageExp|whenExp an expression value corresponding to the message key.
+ */
+ .directive('ngMessageExp', ngMessageDirectiveFactory());
+
+function ngMessageDirectiveFactory() {
return ['$animate', function($animate) {
return {
restrict: 'AE',
transclude: 'element',
+ priority: 1, // must run before ngBind, otherwise the text is set on the comment
terminal: true,
require: '^^ngMessages',
link: function(scope, element, attrs, ngMessagesCtrl, $transclude) {
@@ -641,8 +673,8 @@ function ngMessageDirectiveFactory(restrict) {
var assignRecords = function(items) {
records = items
? (isArray(items)
- ? items
- : items.split(/[\s,]+/))
+ ? items
+ : items.split(/[\s,]+/))
: null;
ngMessagesCtrl.reRender();
};
@@ -661,7 +693,7 @@ function ngMessageDirectiveFactory(restrict) {
},
attach: function() {
if (!currentElement) {
- $transclude(scope, function(elm) {
+ $transclude(function(elm, newScope) {
$animate.enter(elm, null, element);
currentElement = elm;
@@ -669,14 +701,15 @@ function ngMessageDirectiveFactory(restrict) {
// when we are destroying the node later.
var $$attachId = currentElement.$$attachId = ngMessagesCtrl.getAttachId();
- // in the event that the parent element is destroyed
- // by any other structural directive then it's time
+ // in the event that the element or a parent element is destroyed
+ // by another structural directive then it's time
// to deregister the message from the controller
currentElement.on('$destroy', function() {
if (currentElement && currentElement.$$attachId === $$attachId) {
ngMessagesCtrl.deregister(commentNode);
messageCtrl.detach();
}
+ newScope.$destroy();
});
});
}