aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng
diff options
context:
space:
mode:
authorVojta Jina2013-10-22 14:41:21 -0700
committerVojta Jina2013-10-22 15:32:41 -0700
commitf2fab498303e00d199cb3d19a008670e214d5c10 (patch)
tree3aa88fdb1f63bbed45c7541232a0fdfac226c126 /src/ng
parent934a95d3ef3f72dfc37b0b564624cb4a1286d4f4 (diff)
downloadangular.js-f2fab498303e00d199cb3d19a008670e214d5c10.tar.bz2
style: make jshint happy
Diffstat (limited to 'src/ng')
-rw-r--r--src/ng/anchorScroll.js2
-rw-r--r--src/ng/animate.js118
-rw-r--r--src/ng/browser.js28
-rw-r--r--src/ng/cacheFactory.js20
-rw-r--r--src/ng/compile.js179
-rw-r--r--src/ng/controller.js6
-rw-r--r--src/ng/directive/a.js2
-rw-r--r--src/ng/directive/directives.js2
-rw-r--r--src/ng/directive/form.js2
-rw-r--r--src/ng/directive/input.js39
-rw-r--r--src/ng/directive/ngBind.js5
-rw-r--r--src/ng/directive/ngClass.js5
-rw-r--r--[-rwxr-xr-x]src/ng/directive/ngIf.js4
-rw-r--r--src/ng/directive/ngInit.js2
-rw-r--r--src/ng/directive/ngRepeat.js14
-rw-r--r--src/ng/directive/ngSwitch.js2
-rw-r--r--src/ng/directive/select.js43
-rw-r--r--src/ng/filter.js22
-rw-r--r--src/ng/filter/filter.js41
-rw-r--r--src/ng/filter/filters.js6
-rw-r--r--src/ng/filter/limitTo.js2
-rw-r--r--src/ng/filter/orderBy.js2
-rw-r--r--src/ng/http.js225
-rw-r--r--src/ng/httpBackend.js5
-rw-r--r--src/ng/interpolate.js75
-rw-r--r--src/ng/interval.js8
-rw-r--r--src/ng/locale.js5
-rw-r--r--src/ng/location.js40
-rw-r--r--src/ng/log.js28
-rw-r--r--src/ng/parse.js125
-rw-r--r--src/ng/q.js19
-rw-r--r--src/ng/rootScope.js182
-rw-r--r--src/ng/sce.js255
-rw-r--r--src/ng/sniffer.js6
-rw-r--r--src/ng/urlUtils.js3
35 files changed, 863 insertions, 659 deletions
diff --git a/src/ng/anchorScroll.js b/src/ng/anchorScroll.js
index 263562bf..4cef2bdf 100644
--- a/src/ng/anchorScroll.js
+++ b/src/ng/anchorScroll.js
@@ -1,3 +1,5 @@
+'use strict';
+
/**
* @ngdoc function
* @name ng.$anchorScroll
diff --git a/src/ng/animate.js b/src/ng/animate.js
index 1756e7d1..bb08410c 100644
--- a/src/ng/animate.js
+++ b/src/ng/animate.js
@@ -7,7 +7,8 @@ var $animateMinErr = minErr('$animate');
* @name ng.$animateProvider
*
* @description
- * Default implementation of $animate that doesn't perform any animations, instead just synchronously performs DOM
+ * Default implementation of $animate that doesn't perform any animations, instead just
+ * synchronously performs DOM
* updates and calls done() callbacks.
*
* In order to enable animations the ngAnimate module has to be loaded.
@@ -16,6 +17,7 @@ var $animateMinErr = minErr('$animate');
*/
var $AnimateProvider = ['$provide', function($provide) {
+
this.$$selectors = {};
@@ -25,12 +27,14 @@ var $AnimateProvider = ['$provide', function($provide) {
* @methodOf ng.$animateProvider
*
* @description
- * Registers a new injectable animation factory function. The factory function produces the animation object which
- * contains callback functions for each event that is expected to be animated.
+ * Registers a new injectable animation factory function. The factory function produces the
+ * animation object which contains callback functions for each event that is expected to be
+ * animated.
*
- * * `eventFn`: `function(Element, doneFunction)` The element to animate, the `doneFunction` must be called once the
- * element animation is complete. If a function is returned then the animation service will use this function to
- * cancel the animation whenever a cancel event is triggered.
+ * * `eventFn`: `function(Element, doneFunction)` The element to animate, the `doneFunction`
+ * must be called once the element animation is complete. If a function is returned then the
+ * animation service will use this function to cancel the animation whenever a cancel event is
+ * triggered.
*
*
*<pre>
@@ -46,7 +50,8 @@ 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 object.
+ * @param {function} factory The factory function that will be executed to return the animation
+ * object.
*/
this.register = function(name, factory) {
var key = name + '-animation';
@@ -59,36 +64,39 @@ var $AnimateProvider = ['$provide', function($provide) {
this.$get = ['$timeout', function($timeout) {
/**
+ *
* @ngdoc object
* @name ng.$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
+ * high-level animation hooks for CSS and JavaScript.
*
- * @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 high-level animation hooks for CSS and JavaScript.
- *
- * $animate is available in the AngularJS core, however, the ngAnimate module must be included to enable full out
- * animation support. Otherwise, $animate will only perform simple DOM manipulation operations.
+ * $animate is available in the AngularJS core, however, the ngAnimate module must be included
+ * to enable full out animation support. Otherwise, $animate will only perform simple DOM
+ * manipulation operations.
*
- * To learn more about enabling animation support, click here to visit the {@link ngAnimate ngAnimate module page}
- * as well as the {@link ngAnimate.$animate ngAnimate $animate service page}.
+ * To learn more about enabling animation support, click here to visit the {@link ngAnimate
+ * ngAnimate module page} as well as the {@link ngAnimate.$animate ngAnimate $animate service
+ * page}.
*/
return {
/**
+ *
* @ngdoc function
* @name ng.$animate#enter
* @methodOf ng.$animate
* @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).
- *
+ * @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 a child (if the after element is not present)
- * @param {jQuery/jqLite element} 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 inserted into the DOM
+ * @param {jQuery/jqLite element} 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
+ * after itself
+ * @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];
@@ -102,16 +110,16 @@ var $AnimateProvider = ['$provide', function($provide) {
},
/**
+ *
* @ngdoc function
* @name ng.$animate#leave
* @methodOf ng.$animate
* @function
- *
- * @description
- * Removes the element from the DOM. Once complete, the done() callback will be fired (if provided).
- *
+ * @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 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();
@@ -119,19 +127,23 @@ var $AnimateProvider = ['$provide', function($provide) {
},
/**
+ *
* @ngdoc function
* @name ng.$animate#move
* @methodOf ng.$animate
* @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 DOM
- * @param {jQuery/jqLite element} 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 positioned next to
- * @param {function=} done the callback function (if provided) that will be fired after the element has been moved to its new position
+ * @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
+ * DOM
+ * @param {jQuery/jqLite element} 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
+ * positioned next to
+ * @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) {
// Do not remove element before insert. Removing will cause data associated with the
@@ -140,47 +152,49 @@ var $AnimateProvider = ['$provide', function($provide) {
},
/**
+ *
* @ngdoc function
* @name ng.$animate#addClass
* @methodOf ng.$animate
* @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 added to it
+ * @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
+ * 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 className value has been added to the element
+ * @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) {
className = isString(className) ?
className :
isArray(className) ? className.join(' ') : '';
forEach(element, function (element) {
- JQLiteAddClass(element, className);
+ jqLiteAddClass(element, className);
});
done && $timeout(done, 0, false);
},
/**
+ *
* @ngdoc function
* @name ng.$animate#removeClass
* @methodOf ng.$animate
* @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 removed from it
+ * @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
+ * 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 className value has been removed from the element
+ * @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) {
className = isString(className) ?
className :
isArray(className) ? className.join(' ') : '';
forEach(element, function (element) {
- JQLiteRemoveClass(element, className);
+ jqLiteRemoveClass(element, className);
});
done && $timeout(done, 0, false);
},
diff --git a/src/ng/browser.js b/src/ng/browser.js
index 7a0e3fec..5e52b828 100644
--- a/src/ng/browser.js
+++ b/src/ng/browser.js
@@ -274,30 +274,35 @@ 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:
- * <ul>
- * <li>cookies() -> hash of all cookies, this is NOT a copy of the internal state, so do not modify it</li>
- * <li>cookies(name, value) -> set name to value, if value is undefined delete the cookie</li>
- * <li>cookies(name) -> the same as (name, undefined) == DELETES (no one calls it right now that way)</li>
- * </ul>
- *
+ *
+ * - 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) {
+ /* global escape: false, unescape: false */
var cookieLength, cookieArray, cookie, i, index;
if (name) {
if (value === undefined) {
- rawDocument.cookie = escape(name) + "=;path=" + cookiePath + ";expires=Thu, 01 Jan 1970 00:00:00 GMT";
+ rawDocument.cookie = escape(name) + "=;path=" + cookiePath +
+ ";expires=Thu, 01 Jan 1970 00:00:00 GMT";
} else {
if (isString(value)) {
- cookieLength = (rawDocument.cookie = escape(name) + '=' + escape(value) + ';path=' + cookiePath).length + 1;
+ cookieLength = (rawDocument.cookie = escape(name) + '=' + escape(value) +
+ ';path=' + cookiePath).length + 1;
// per http://www.ietf.org/rfc/rfc2109.txt browser must allow at minimum:
// - 300 cookies
// - 20 cookies per unique domain
// - 4096 bytes per cookie
if (cookieLength > 4096) {
- $log.warn("Cookie '"+ name +"' possibly not set or overflowed because it was too large ("+
+ $log.warn("Cookie '"+ name +
+ "' possibly not set or overflowed because it was too large ("+
cookieLength + " > 4096 bytes)!");
}
}
@@ -312,7 +317,7 @@ function Browser(window, document, $log, $sniffer) {
cookie = cookieArray[i];
index = cookie.indexOf('=');
if (index > 0) { //ignore nameless cookies
- var name = unescape(cookie.substring(0, index));
+ name = unescape(cookie.substring(0, index));
// the first value that is seen for a cookie is the most
// specific one. values for the same cookie name that
// follow are for less specific paths.
@@ -362,7 +367,8 @@ function Browser(window, document, $log, $sniffer) {
* Cancels a deferred task identified with `deferId`.
*
* @param {*} deferId Token returned by the `$browser.defer` function.
- * @returns {boolean} Returns `true` if the task hasn't executed yet and was successfully canceled.
+ * @returns {boolean} Returns `true` if the task hasn't executed yet and was successfully
+ * canceled.
*/
self.defer.cancel = function(deferId) {
if (pendingDeferIds[deferId]) {
diff --git a/src/ng/cacheFactory.js b/src/ng/cacheFactory.js
index 1a0cb549..0e887c81 100644
--- a/src/ng/cacheFactory.js
+++ b/src/ng/cacheFactory.js
@@ -1,3 +1,5 @@
+'use strict';
+
/**
* @ngdoc object
* @name ng.$cacheFactory
@@ -13,8 +15,9 @@
*
* cache.put("key", "value");
* cache.put("another key", "another value");
- *
- * expect(cache.info()).toEqual({id: 'cacheId', size: 2}); // Since we've specified no options on creation
+ *
+ * // We've specified no options on creation
+ * expect(cache.info()).toEqual({id: 'cacheId', size: 2});
*
* </pre>
*
@@ -27,7 +30,8 @@
* @returns {object} Newly created cache object with the following set of methods:
*
* - `{object}` `info()` — Returns id, size, and options of cache.
- * - `{{*}}` `put({string} key, {*} value)` — Puts a new key-value pair into the cache and returns it.
+ * - `{{*}}` `put({string} key, {*} value)` — Puts a new key-value pair into the cache and returns
+ * it.
* - `{{*}}` `get({string} key)` — Returns cached value for `key` or undefined for cache miss.
* - `{void}` `remove({string} key)` — Removes a key-value pair from the cache.
* - `{void}` `removeAll()` — Removes all cached values.
@@ -194,9 +198,9 @@ function $CacheFactoryProvider() {
* @name ng.$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.
+ * 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>
@@ -210,8 +214,8 @@ function $CacheFactoryProvider() {
* </html>
* </pre>
*
- * **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.
+ * **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:
*
diff --git a/src/ng/compile.js b/src/ng/compile.js
index 84546f39..7476b46b 100644
--- a/src/ng/compile.js
+++ b/src/ng/compile.js
@@ -97,16 +97,16 @@
* (a DOM element/tree) to a scope. Where:
*
* * `scope` - A {@link ng.$rootScope.Scope Scope} to bind to.
- * * `cloneAttachFn` - If `cloneAttachFn` is provided, then the link function will clone the `template`
- * and call the `cloneAttachFn` function allowing the caller to attach the
+ * * `cloneAttachFn` - If `cloneAttachFn` is provided, then the link function will clone the
+ * `template` and call the `cloneAttachFn` function allowing the caller to attach the
* cloned elements to the DOM document at the appropriate place. The `cloneAttachFn` is
* called as: <br> `cloneAttachFn(clonedElement, scope)` where:
*
* * `clonedElement` - is a clone of the original `element` passed into the compiler.
* * `scope` - is the current scope with which the linking function is working with.
*
- * Calling the linking function returns the element of the template. It is either the original element
- * passed in, or the clone of the element if the `cloneAttachFn` is provided.
+ * Calling the linking function returns the element of the template. It is either the original
+ * element passed in, or the clone of the element if the `cloneAttachFn` is provided.
*
* After linking the view is not updated until after a call to $digest which typically is done by
* Angular automatically.
@@ -257,10 +257,10 @@ function $CompileProvider($provide) {
*
* 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.
+ * 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
@@ -315,8 +315,8 @@ function $CompileProvider($provide) {
* @function
*
* @description
- * Removes the CSS class value specified by the classVal parameter from the element. If animations
- * are enabled then an animation will be triggered for the class removal.
+ * Removes the CSS class value specified by the classVal parameter from the element. If
+ * animations are enabled then an animation will be triggered for the class removal.
*
* @param {string} classVal The className value that will be removed from the element
*/
@@ -416,7 +416,7 @@ function $CompileProvider($provide) {
values.push(token);
}
return values;
- };
+ }
},
@@ -469,9 +469,11 @@ function $CompileProvider($provide) {
//================================
- function compile($compileNodes, transcludeFn, maxPriority, ignoreDirective, previousCompileContext) {
+ function compile($compileNodes, transcludeFn, maxPriority, ignoreDirective,
+ previousCompileContext) {
if (!($compileNodes instanceof jqLite)) {
- // jquery always rewraps, whereas we need to preserve the original selector so that we can modify it.
+ // jquery always rewraps, whereas we need to preserve the original selector so that we can
+ // modify it.
$compileNodes = jqLite($compileNodes);
}
// We can not compile top level text elements since text nodes can be merged and we will
@@ -481,7 +483,9 @@ function $CompileProvider($provide) {
$compileNodes[index] = node = jqLite(node).wrap('<span></span>').parent()[0];
}
});
- var compositeLinkFn = compileNodes($compileNodes, transcludeFn, $compileNodes, maxPriority, ignoreDirective, previousCompileContext);
+ var compositeLinkFn =
+ compileNodes($compileNodes, transcludeFn, $compileNodes,
+ maxPriority, ignoreDirective, previousCompileContext);
return function publicLinkFn(scope, cloneConnectFn){
assertArg(scope, 'scope');
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
@@ -522,13 +526,14 @@ function $CompileProvider($provide) {
* @param {NodeList} nodeList an array of nodes or NodeList to compile
* @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
+ * @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.
*/
- function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective, previousCompileContext) {
+ function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective,
+ previousCompileContext) {
var linkFns = [],
nodeLinkFn, childLinkFn, directives, attrs, linkFnFound;
@@ -536,13 +541,17 @@ function $CompileProvider($provide) {
attrs = new Attributes();
// we must always refer to nodeList[i] since the nodes can be replaced underneath us.
- directives = collectDirectives(nodeList[i], [], attrs, i == 0 ? maxPriority : undefined, ignoreDirective);
+ directives = collectDirectives(nodeList[i], [], attrs, i === 0 ? maxPriority : undefined,
+ ignoreDirective);
nodeLinkFn = (directives.length)
- ? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement, null, [], [], previousCompileContext)
+ ? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement,
+ null, [], [], previousCompileContext)
: null;
- childLinkFn = (nodeLinkFn && nodeLinkFn.terminal || !nodeList[i].childNodes || !nodeList[i].childNodes.length)
+ childLinkFn = (nodeLinkFn && nodeLinkFn.terminal ||
+ !nodeList[i].childNodes ||
+ !nodeList[i].childNodes.length)
? null
: compileNodes(nodeList[i].childNodes,
nodeLinkFn ? nodeLinkFn.transclude : transcludeFn);
@@ -550,7 +559,8 @@ function $CompileProvider($provide) {
linkFns.push(nodeLinkFn);
linkFns.push(childLinkFn);
linkFnFound = (linkFnFound || nodeLinkFn || childLinkFn);
- previousCompileContext = null; //use the previous context only for the first element in the virtual group
+ //use the previous context only for the first element in the virtual group
+ previousCompileContext = null;
}
// return a linking function if we have found anything, null otherwise
@@ -654,7 +664,8 @@ function $CompileProvider($provide) {
attrs[nName] = true; // presence means true
}
addAttrInterpolateDirective(node, directives, value, nName);
- addDirective(directives, nName, 'A', maxPriority, ignoreDirective, attrStartName, attrEndName);
+ addDirective(directives, nName, 'A', maxPriority, ignoreDirective, attrStartName,
+ attrEndName);
}
}
@@ -683,7 +694,8 @@ function $CompileProvider($provide) {
}
}
} catch (e) {
- // turns out that under some circumstances IE9 throws errors when one attempts to read comment's node value.
+ // turns out that under some circumstances IE9 throws errors when one attempts to read
+ // comment's node value.
// Just ignore it and continue. (Can't seem to reproduce in test case.)
}
break;
@@ -694,7 +706,8 @@ function $CompileProvider($provide) {
}
/**
- * Given a node with an directive-start it collects all of the siblings until it find directive-end.
+ * Given a node with an directive-start it collects all of the siblings until it finds
+ * directive-end.
* @param node
* @param attrStart
* @param attrEnd
@@ -707,7 +720,9 @@ function $CompileProvider($provide) {
var startNode = node;
do {
if (!node) {
- throw $compileMinErr('uterdir', "Unterminated attribute, found '{0}' but no matching '{1}' found.", attrStart, attrEnd);
+ throw $compileMinErr('uterdir',
+ "Unterminated attribute, found '{0}' but no matching '{1}' found.",
+ attrStart, attrEnd);
}
if (node.nodeType == 1 /** Element **/) {
if (node.hasAttribute(attrStart)) depth++;
@@ -735,7 +750,7 @@ function $CompileProvider($provide) {
return function(scope, element, attrs, controllers) {
element = groupScan(element[0], attrStart, attrEnd);
return linkFn(scope, element, attrs, controllers);
- }
+ };
}
/**
@@ -748,18 +763,22 @@ function $CompileProvider($provide) {
* @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
- * scope argument is auto-generated to the new child of the transcluded parent scope.
+ * 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
- * argument has the root jqLite array so that we can replace nodes on it.
- * @param {Object=} originalReplaceDirective An optional directive that will be ignored when compiling
- * the transclusion.
+ * argument has the root jqLite array so that we can replace nodes
+ * on it.
+ * @param {Object=} originalReplaceDirective An optional directive that will be ignored when
+ * compiling the transclusion.
* @param {Array.<Function>} preLinkFns
* @param {Array.<Function>} postLinkFns
- * @param {Object} previousCompileContext Context used for previous compilation of the current node
+ * @param {Object} previousCompileContext Context used for previous compilation of the current
+ * node
* @returns linkFn
*/
- function applyDirectivesToNode(directives, compileNode, templateAttrs, transcludeFn, jqCollection,
- originalReplaceDirective, preLinkFns, postLinkFns, previousCompileContext) {
+ function applyDirectivesToNode(directives, compileNode, templateAttrs, transcludeFn,
+ jqCollection, originalReplaceDirective, preLinkFns, postLinkFns,
+ previousCompileContext) {
previousCompileContext = previousCompileContext || {};
var terminalPriority = -Number.MAX_VALUE,
@@ -785,7 +804,7 @@ function $CompileProvider($provide) {
// collect multiblock sections
if (attrStart) {
- $compileNode = groupScan(compileNode, attrStart, attrEnd)
+ $compileNode = groupScan(compileNode, attrStart, attrEnd);
}
$template = undefined;
@@ -796,10 +815,11 @@ function $CompileProvider($provide) {
if (directiveValue = directive.scope) {
newScopeDirective = newScopeDirective || directive;
- // skip the check for directives with async templates, we'll check the derived sync directive when
- // the template arrives
+ // skip the check for directives with async templates, we'll check the derived sync
+ // directive when the template arrives
if (!directive.templateUrl) {
- assertNoDuplicate('new/isolated scope', newIsolateScopeDirective, directive, $compileNode);
+ assertNoDuplicate('new/isolated scope', newIsolateScopeDirective, directive,
+ $compileNode);
if (isObject(directiveValue)) {
safeAddClass($compileNode, 'ng-isolate-scope');
newIsolateScopeDirective = directive;
@@ -819,8 +839,8 @@ function $CompileProvider($provide) {
}
if (directiveValue = directive.transclude) {
- // Special case ngRepeat so that we don't complain about duplicate transclusion, ngRepeat knows how to handle
- // this on its own.
+ // Special case ngRepeat so that we don't complain about duplicate transclusion, ngRepeat
+ // knows how to handle this on its own.
if (directiveName !== 'ngRepeat') {
assertNoDuplicate('transclusion', transcludeDirective, directive, $compileNode);
transcludeDirective = directive;
@@ -830,7 +850,8 @@ function $CompileProvider($provide) {
terminalPriority = directive.priority;
$template = groupScan(compileNode, attrStart, attrEnd);
$compileNode = templateAttrs.$$element =
- jqLite(document.createComment(' ' + directiveName + ': ' + templateAttrs[directiveName] + ' '));
+ jqLite(document.createComment(' ' + directiveName + ': ' +
+ templateAttrs[directiveName] + ' '));
compileNode = $compileNode[0];
replaceWith(jqCollection, jqLite(sliceArgs($template)), compileNode);
@@ -841,7 +862,7 @@ function $CompileProvider($provide) {
templateDirective: templateDirective
});
} else {
- $template = jqLite(JQLiteClone(compileNode)).contents();
+ $template = jqLite(jqLiteClone(compileNode)).contents();
$compileNode.html(''); // clear contents
childTranscludeFn = compile($template, transcludeFn);
}
@@ -865,7 +886,9 @@ function $CompileProvider($provide) {
compileNode = $template[0];
if ($template.length != 1 || compileNode.nodeType !== 1) {
- throw $compileMinErr('tplrt', "Template for directive '{0}' must have exactly one root element. {1}", directiveName, '');
+ throw $compileMinErr('tplrt',
+ "Template for directive '{0}' must have exactly one root element. {1}",
+ directiveName, '');
}
replaceWith(jqCollection, $compileNode, compileNode);
@@ -968,7 +991,9 @@ function $CompileProvider($provide) {
}
if (!value && !optional) {
- throw $compileMinErr('ctreq', "Controller '{0}', required by directive '{1}', can't be found!", require, directiveName);
+ throw $compileMinErr('ctreq',
+ "Controller '{0}', required by directive '{1}', can't be found!",
+ require, directiveName);
}
return value;
} else if (isArray(require)) {
@@ -1008,19 +1033,19 @@ function $CompileProvider($provide) {
switch (mode) {
- case '@': {
+ case '@':
attrs.$observe(attrName, function(value) {
scope[scopeName] = value;
});
attrs.$$observers[attrName].$$scope = parentScope;
if( attrs[attrName] ) {
- // If the attribute has been provided then we trigger an interpolation to ensure the value is there for use in the link fn
+ // If the attribute has been provided then we trigger an interpolation to ensure
+ // the value is there for use in the link fn
scope[scopeName] = $interpolate(attrs[attrName])(parentScope);
}
break;
- }
- case '=': {
+ case '=':
if (optional && !attrs[attrName]) {
return;
}
@@ -1028,7 +1053,8 @@ function $CompileProvider($provide) {
parentSet = parentGet.assign || function() {
// reset the change, or we will throw this exception on every $digest
lastValue = scope[scopeName] = parentGet(parentScope);
- throw $compileMinErr('nonassign', "Expression '{0}' used with directive '{1}' is non-assignable!",
+ throw $compileMinErr('nonassign',
+ "Expression '{0}' used with directive '{1}' is non-assignable!",
attrs[attrName], newIsolateScopeDirective.name);
};
lastValue = scope[scopeName] = parentGet(parentScope);
@@ -1048,20 +1074,19 @@ function $CompileProvider($provide) {
return parentValue;
});
break;
- }
- case '&': {
+ case '&':
parentGet = $parse(attrs[attrName]);
scope[scopeName] = function(locals) {
return parentGet(parentScope, locals);
};
break;
- }
-
- default: {
- throw $compileMinErr('iscp', "Invalid isolate scope definition for directive '{0}'. Definition: {... {1}: '{2}' ...}",
+
+ default:
+ throw $compileMinErr('iscp',
+ "Invalid isolate scope definition for directive '{0}'." +
+ " Definition: {... {1}: '{2}' ...}",
newIsolateScopeDirective.name, scopeName, definition);
- }
}
});
}
@@ -1139,7 +1164,8 @@ function $CompileProvider($provide) {
* * `M`: comment
* @returns true if directive was added.
*/
- function addDirective(tDirectives, name, location, maxPriority, ignoreDirective, startAttrName, endAttrName) {
+ function addDirective(tDirectives, name, location, maxPriority, ignoreDirective, startAttrName,
+ endAttrName) {
if (name === ignoreDirective) return null;
var match = null;
if (hasDirectives.hasOwnProperty(name)) {
@@ -1231,7 +1257,8 @@ function $CompileProvider($provide) {
compileNode = $template[0];
if ($template.length != 1 || compileNode.nodeType !== 1) {
- throw $compileMinErr('tplrt', "Template for directive '{0}' must have exactly one root element. {1}",
+ throw $compileMinErr('tplrt',
+ "Template for directive '{0}' must have exactly one root element. {1}",
origAsyncDirective.name, templateUrl);
}
@@ -1247,7 +1274,8 @@ function $CompileProvider($provide) {
directives.unshift(derivedSyncDirective);
afterTemplateNodeLinkFn = applyDirectivesToNode(directives, compileNode, tAttrs,
- childTranscludeFn, $compileNode, origAsyncDirective, preLinkFns, postLinkFns, previousCompileContext);
+ childTranscludeFn, $compileNode, origAsyncDirective, preLinkFns, postLinkFns,
+ previousCompileContext);
forEach($rootElement, function(node, i) {
if (node == compileNode) {
$rootElement[i] = $compileNode[0];
@@ -1265,11 +1293,12 @@ function $CompileProvider($provide) {
if (beforeTemplateLinkNode !== beforeTemplateCompileNode) {
// it was cloned therefore we have to clone as well.
- linkNode = JQLiteClone(compileNode);
+ linkNode = jqLiteClone(compileNode);
replaceWith(linkRootElement, jqLite(beforeTemplateLinkNode), linkNode);
}
- afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, linkNode, $rootElement, controller);
+ afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, linkNode, $rootElement,
+ controller);
}
linkQueue = null;
}).
@@ -1346,7 +1375,8 @@ function $CompileProvider($provide) {
if (name === "multiple" && nodeName_(node) === "SELECT") {
- throw $compileMinErr("selmulti", "Binding to the 'multiple' attribute is not supported. Element: {0}",
+ throw $compileMinErr("selmulti",
+ "Binding to the 'multiple' attribute is not supported. Element: {0}",
startingTag(node));
}
@@ -1357,8 +1387,8 @@ function $CompileProvider($provide) {
if (EVENT_HANDLER_ATTR_REGEXP.test(name)) {
throw $compileMinErr('nodomevents',
- "Interpolations for HTML DOM event attributes are disallowed. Please use the ng- " +
- "versions (such as ng-click instead of onclick) instead.");
+ "Interpolations for HTML DOM event attributes are disallowed. Please use the " +
+ "ng- versions (such as ng-click instead of onclick) instead.");
}
// we need to interpolate again, in case the attribute value has been updated
@@ -1369,7 +1399,8 @@ function $CompileProvider($provide) {
// register any observers
if (!interpolateFn) return;
- // TODO(i): this should likely be attr.$set(name, iterpolateFn(scope) so that we reset the actual attr value
+ // TODO(i): this should likely be attr.$set(name, iterpolateFn(scope) so that we reset the
+ // actual attr value
attr[name] = interpolateFn(scope);
($$observers[name] || ($$observers[name] = [])).$$inter = true;
(attr.$$observers && attr.$$observers[name].$$scope || scope).
@@ -1386,9 +1417,9 @@ function $CompileProvider($provide) {
* have no parents, provided that the containing jqLite collection is provided.
*
* @param {JqLite=} $rootElement The root of the compile tree. Used so that we can replace nodes
- * in the root of the tree.
- * @param {JqLite} elementsToRemove The jqLite element which we are going to replace. We keep the shell,
- * but replace its DOM node reference.
+ * in the root of the tree.
+ * @param {JqLite} elementsToRemove The jqLite element which we are going to replace. We keep
+ * the shell, but replace its DOM node reference.
* @param {Node} newNode The new DOM node.
*/
function replaceWith($rootElement, elementsToRemove, newNode) {
@@ -1430,7 +1461,7 @@ function $CompileProvider($provide) {
}
elementsToRemove[0] = newNode;
- elementsToRemove.length = 1
+ elementsToRemove.length = 1;
}
}];
}
@@ -1454,13 +1485,13 @@ function directiveNormalize(name) {
/**
* @ngdoc object
* @name ng.$compile.directive.Attributes
+ *
* @description
+ * A shared object between directive compile / linking functions which contains normalized DOM
+ * element attributes. The the values reflect current binding state `{{ }}`. The normalization is
+ * needed since all of these are treated as equivalent in Angular:
*
- * A shared object between directive compile / linking functions which contains normalized DOM element
- * attributes. The the values reflect current binding state `{{ }}`. The normalization is needed
- * since all of these are treated as equivalent in Angular:
- *
- * <span ng:bind="a" ng-bind="a" data-ng-bind="a" x-ng-bind="a">
+ * <span ng:bind="a" ng-bind="a" data-ng-bind="a" x-ng-bind="a">
*/
/**
@@ -1468,7 +1499,7 @@ function directiveNormalize(name) {
* @name ng.$compile.directive.Attributes#$attr
* @propertyOf ng.$compile.directive.Attributes
* @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.
+ * needed to do reverse lookup from normalized name back to actual name.
*/
diff --git a/src/ng/controller.js b/src/ng/controller.js
index 827d807b..938fbfbe 100644
--- a/src/ng/controller.js
+++ b/src/ng/controller.js
@@ -27,7 +27,7 @@ function $ControllerProvider() {
this.register = function(name, constructor) {
assertNotHasOwnProperty(name, 'controller');
if (isObject(name)) {
- extend(controllers, name)
+ extend(controllers, name);
} else {
controllers[name] = constructor;
}
@@ -77,7 +77,9 @@ function $ControllerProvider() {
if (identifier) {
if (!(locals && typeof locals.$scope == 'object')) {
- throw minErr('$controller')('noscp', "Cannot export controller '{0}' as '{1}'! No $scope object provided via `locals`.", constructor || expression.name, identifier);
+ throw minErr('$controller')('noscp',
+ "Cannot export controller '{0}' as '{1}'! No $scope object provided via `locals`.",
+ constructor || expression.name, identifier);
}
locals.$scope[identifier] = instance;
diff --git a/src/ng/directive/a.js b/src/ng/directive/a.js
index 25cd9105..b3e9ad6d 100644
--- a/src/ng/directive/a.js
+++ b/src/ng/directive/a.js
@@ -39,6 +39,6 @@ var htmlAnchorDirective = valueFn({
event.preventDefault();
}
});
- }
+ };
}
});
diff --git a/src/ng/directive/directives.js b/src/ng/directive/directives.js
index aa316533..b97408e6 100644
--- a/src/ng/directive/directives.js
+++ b/src/ng/directive/directives.js
@@ -4,7 +4,7 @@ function ngDirective(directive) {
if (isFunction(directive)) {
directive = {
link: directive
- }
+ };
}
directive.restrict = directive.restrict || 'AC';
return valueFn(directive);
diff --git a/src/ng/directive/form.js b/src/ng/directive/form.js
index 455ad15f..6b5c52f4 100644
--- a/src/ng/directive/form.js
+++ b/src/ng/directive/form.js
@@ -1,6 +1,6 @@
'use strict';
-
+/* global -nullFormCtrl */
var nullFormCtrl = {
$addControl: noop,
$removeControl: noop,
diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js
index 87afc328..07b5f997 100644
--- a/src/ng/directive/input.js
+++ b/src/ng/directive/input.js
@@ -1,5 +1,13 @@
'use strict';
+/* global
+
+ -VALID_CLASS,
+ -INVALID_CLASS,
+ -PRISTINE_CLASS,
+ -DIRTY_CLASS
+*/
+
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 NUMBER_REGEXP = /^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/;
@@ -939,22 +947,22 @@ var VALID_CLASS = 'ng-valid',
* <example module="badIsolatedDirective">
<file name="script.js">
angular.module('badIsolatedDirective', []).directive('bad', 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);
- });
- }
- };
+ 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 bad ng-model="someModel"></div>
+ <input ng-model="someModel">
+ <div bad ng-model="someModel"></div>
</file>
* </example>
*
@@ -1047,7 +1055,10 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
* @param {boolean} isValid Whether the current state is valid (true) or invalid (false).
*/
this.$setValidity = function(validationErrorKey, isValid) {
+ // Purposeful use of ! here to cast isValid to boolean in case it is undefined
+ // jshint -W018
if ($error[validationErrorKey] === !isValid) return;
+ // jshint +W018
if (isValid) {
if ($error[validationErrorKey]) invalidCount--;
@@ -1127,7 +1138,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
} catch(e) {
$exceptionHandler(e);
}
- })
+ });
}
};
diff --git a/src/ng/directive/ngBind.js b/src/ng/directive/ngBind.js
index c55ab076..82ff505a 100644
--- a/src/ng/directive/ngBind.js
+++ b/src/ng/directive/ngBind.js
@@ -50,6 +50,9 @@
var ngBindDirective = ngDirective(function(scope, element, attr) {
element.addClass('ng-binding').data('$binding', attr.ngBind);
scope.$watch(attr.ngBind, function ngBindWatchAction(value) {
+ // We are purposefully using == here rather than === because we want to
+ // catch when value is "null or undefined"
+ // jshint -W041
element.text(value == undefined ? '' : value);
});
});
@@ -111,7 +114,7 @@ var ngBindTemplateDirective = ['$interpolate', function($interpolate) {
attr.$observe('ngBindTemplate', function(value) {
element.text(value);
});
- }
+ };
}];
diff --git a/src/ng/directive/ngClass.js b/src/ng/directive/ngClass.js
index 7fcdcfec..39568f6a 100644
--- a/src/ng/directive/ngClass.js
+++ b/src/ng/directive/ngClass.js
@@ -6,7 +6,7 @@ function classDirective(name, selector) {
return {
restrict: 'AC',
link: function(scope, element, attr) {
- var oldVal = undefined;
+ var oldVal;
scope.$watch(attr[name], ngClassWatchAction, true);
@@ -17,6 +17,7 @@ function classDirective(name, selector) {
if (name !== 'ngClass') {
scope.$watch('$index', function($index, old$index) {
+ // jshint bitwise: false
var mod = $index & 1;
if (mod !== old$index & 1) {
if (mod === selector) {
@@ -63,7 +64,7 @@ function classDirective(name, selector) {
}
return classVal;
- };
+ }
}
};
};
diff --git a/src/ng/directive/ngIf.js b/src/ng/directive/ngIf.js
index dc95d170..00556539 100755..100644
--- a/src/ng/directive/ngIf.js
+++ b/src/ng/directive/ngIf.js
@@ -104,7 +104,7 @@ var ngIfDirective = ['$animate', function($animate) {
});
}
});
- }
+ };
}
- }
+ };
}];
diff --git a/src/ng/directive/ngInit.js b/src/ng/directive/ngInit.js
index 854f5c35..36f130c7 100644
--- a/src/ng/directive/ngInit.js
+++ b/src/ng/directive/ngInit.js
@@ -52,6 +52,6 @@ var ngInitDirective = ngDirective({
pre: function(scope, element, attrs) {
scope.$eval(attrs.ngInit);
}
- }
+ };
}
});
diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js
index bce76411..e3ff1b8e 100644
--- a/src/ng/directive/ngRepeat.js
+++ b/src/ng/directive/ngRepeat.js
@@ -243,10 +243,10 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
} else {
trackByIdArrayFn = function(key, value) {
return hashKey(value);
- }
+ };
trackByIdObjFn = function(key) {
return key;
- }
+ };
}
match = lhs.match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/);
@@ -308,7 +308,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
trackById = trackByIdFn(key, value, index);
assertNotHasOwnProperty(trackById, '`track by` id');
if(lastBlockMap.hasOwnProperty(trackById)) {
- block = lastBlockMap[trackById]
+ block = lastBlockMap[trackById];
delete lastBlockMap[trackById];
nextBlockMap[trackById] = block;
nextBlockOrder[index] = block;
@@ -356,9 +356,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
nextNode = nextNode.nextSibling;
} while(nextNode && nextNode[NG_REMOVED]);
- if (block.startNode == nextNode) {
- // do nothing
- } else {
+ if (block.startNode != nextNode) {
// existing item which got moved
$animate.move(getBlockElements(block), null, jqLite(previousNode));
}
@@ -374,7 +372,9 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
childScope.$first = (index === 0);
childScope.$last = (index === (arrayLength - 1));
childScope.$middle = !(childScope.$first || childScope.$last);
- childScope.$odd = !(childScope.$even = index%2==0);
+ // jshint bitwise: false
+ childScope.$odd = !(childScope.$even = (index&1) === 0);
+ // jshint bitwise: true
if (!block.startNode) {
linker(childScope, function(clone) {
diff --git a/src/ng/directive/ngSwitch.js b/src/ng/directive/ngSwitch.js
index 320400d9..b67aa904 100644
--- a/src/ng/directive/ngSwitch.js
+++ b/src/ng/directive/ngSwitch.js
@@ -161,7 +161,7 @@ var ngSwitchDirective = ['$animate', function($animate) {
}
});
}
- }
+ };
}];
var ngSwitchWhenDirective = ngDirective({
diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js
index fb03e0ca..83148e22 100644
--- a/src/ng/directive/select.js
+++ b/src/ng/directive/select.js
@@ -126,10 +126,12 @@ var ngOptionsMinErr = minErr('ngOptions');
*/
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+(.*?))?$/,
nullModelCtrl = {$setViewValue: noop};
+// jshint maxlen: 100
return {
restrict: 'E',
@@ -210,7 +212,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
// find "null" option
for(var i = 0, children = element.children(), ii = children.length; i < ii; i++) {
- if (children[i].value == '') {
+ if (children[i].value === '') {
emptyOption = nullOption = children.eq(i);
break;
}
@@ -233,16 +235,16 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
});
}
- if (optionsExp) Options(scope, element, ngModelCtrl);
- else if (multiple) Multiple(scope, element, ngModelCtrl);
- else Single(scope, element, ngModelCtrl, selectCtrl);
+ if (optionsExp) setupAsOptions(scope, element, ngModelCtrl);
+ else if (multiple) setupAsMultiple(scope, element, ngModelCtrl);
+ else setupAsSingle(scope, element, ngModelCtrl, selectCtrl);
////////////////////////////
- function Single(scope, selectElement, ngModelCtrl, selectCtrl) {
+ function setupAsSingle(scope, selectElement, ngModelCtrl, selectCtrl) {
ngModelCtrl.$render = function() {
var viewValue = ngModelCtrl.$viewValue;
@@ -267,7 +269,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
});
}
- function Multiple(scope, selectElement, ctrl) {
+ function setupAsMultiple(scope, selectElement, ctrl) {
var lastView;
ctrl.$render = function() {
var items = new HashMap(ctrl.$viewValue);
@@ -298,12 +300,14 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
});
}
- function Options(scope, selectElement, ctrl) {
+ function setupAsOptions(scope, selectElement, ctrl) {
var match;
if (! (match = optionsExp.match(NG_OPTIONS_REGEXP))) {
throw ngOptionsMinErr('iexp',
- "Expected expression in form of '_select_ (as _label_)? for (_key_,)?_value_ in _collection_' but got '{0}'. Element: {1}",
+ "Expected expression in form of " +
+ "'_select_ (as _label_)? for (_key_,)?_value_ in _collection_'" +
+ " but got '{0}'. Element: {1}",
optionsExp, startingTag(selectElement));
}
@@ -315,9 +319,10 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
valuesFn = $parse(match[7]),
track = match[8],
trackFn = track ? $parse(match[8]) : null,
- // This is an array of array of existing option groups in DOM. We try to reuse these if possible
- // optionGroupsCache[0] is the options with no option group
- // optionGroupsCache[?][0] is the parent: either the SELECT or OPTGROUP element
+ // This is an array of array of existing option groups in DOM.
+ // We try to reuse these if possible
+ // - optionGroupsCache[0] is the options with no option group
+ // - optionGroupsCache[?][0] is the parent: either the SELECT or OPTGROUP element
optionGroupsCache = [[{element: selectElement, label:''}]];
if (nullOption) {
@@ -371,7 +376,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
key = selectElement.val();
if (key == '?') {
value = undefined;
- } else if (key == ''){
+ } else if (key === ''){
value = null;
} else {
if (trackFn) {
@@ -399,7 +404,8 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
scope.$watch(render);
function render() {
- var optionGroups = {'':[]}, // Temporary location for the option groups before we render them
+ // Temporary location for the option groups before we render them
+ var optionGroups = {'':[]},
optionGroupNames = [''],
optionGroupName,
optionGroup,
@@ -448,7 +454,9 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
optionGroupNames.push(optionGroupName);
}
if (multiple) {
- selected = selectedSet.remove(trackFn ? trackFn(scope, locals) : valueFn(scope, locals)) !== undefined;
+ selected = isDefined(
+ selectedSet.remove(trackFn ? trackFn(scope, locals) : valueFn(scope, locals))
+ );
} else {
if (trackFn) {
var modelCast = {};
@@ -460,9 +468,12 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
selectedSet = selectedSet || selected; // see if at least one item is selected
}
label = displayFn(scope, locals); // what will be seen by the user
- label = label === undefined ? '' : label; // doing displayFn(scope, locals) || '' overwrites zero values
+
+ // doing displayFn(scope, locals) || '' overwrites zero values
+ label = isDefined(label) ? label : '';
optionGroup.push({
- id: trackFn ? trackFn(scope, locals) : (keyName ? keys[index] : index), // either the index into array or key from object
+ // either the index into array or key from object
+ id: trackFn ? trackFn(scope, locals) : (keyName ? keys[index] : index),
label: label,
selected: selected // determine if we should be selected
});
diff --git a/src/ng/filter.js b/src/ng/filter.js
index f41efbd9..11607abc 100644
--- a/src/ng/filter.js
+++ b/src/ng/filter.js
@@ -5,9 +5,9 @@
* @name ng.$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.
+ * 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>
* // Filter registration
@@ -30,7 +30,9 @@
* }
* </pre>
*
- * The filter function is registered with the `$injector` under the filter name suffix with `Filter`.
+ * The filter function is registered with the `$injector` under the filter name suffix with
+ * `Filter`.
+ *
* <pre>
* it('should be the same instance', inject(
* function($filterProvider) {
@@ -107,6 +109,18 @@ function $FilterProvider($provide) {
}];
////////////////////////////////////////
+
+ /* global
+ currencyFilter: false,
+ dateFilter: false,
+ filterFilter: false,
+ jsonFilter: false,
+ limitToFilter: false,
+ lowercaseFilter: false,
+ numberFilter: false,
+ orderByFilter: false,
+ uppercaseFilter: false,
+ */
register('currency', currencyFilter);
register('date', dateFilter);
diff --git a/src/ng/filter/filter.js b/src/ng/filter/filter.js
index b55e11f4..24c0e444 100644
--- a/src/ng/filter/filter.js
+++ b/src/ng/filter/filter.js
@@ -105,9 +105,12 @@
</doc:example>
*/
function filterFilter() {
- return function(array, expression, comperator) {
+ return function(array, expression, comparator) {
if (!isArray(array)) return array;
- var predicates = [];
+
+ var comparatorType = typeof(comparator),
+ predicates = [];
+
predicates.check = function(value) {
for (var j = 0; j < predicates.length; j++) {
if(!predicates[j](value)) {
@@ -116,22 +119,20 @@ function filterFilter() {
}
return true;
};
- switch(typeof comperator) {
- case "function":
- break;
- case "boolean":
- if(comperator == true) {
- comperator = function(obj, text) {
- return angular.equals(obj, text);
- }
- break;
- }
- default:
- comperator = function(obj, text) {
+
+ if (comparatorType !== 'function') {
+ if (comparatorType === 'boolean' && comparator) {
+ comparator = function(obj, text) {
+ return angular.equals(obj, text);
+ };
+ } else {
+ comparator = function(obj, text) {
text = (''+text).toLowerCase();
return (''+obj).toLowerCase().indexOf(text) > -1;
};
+ }
}
+
var search = function(obj, text){
if (typeof text == 'string' && text.charAt(0) === '!') {
return !search(obj, text.substr(1));
@@ -140,12 +141,11 @@ function filterFilter() {
case "boolean":
case "number":
case "string":
- return comperator(obj, text);
+ return comparator(obj, text);
case "object":
switch (typeof text) {
case "object":
- return comperator(obj, text);
- break;
+ return comparator(obj, text);
default:
for ( var objKey in obj) {
if (objKey.charAt(0) !== '$' && search(obj[objKey], text)) {
@@ -170,13 +170,16 @@ function filterFilter() {
case "boolean":
case "number":
case "string":
+ // Set up expression object and fall through
expression = {$:expression};
+ // jshint -W086
case "object":
+ // jshint +W086
for (var key in expression) {
if (key == '$') {
(function() {
if (!expression[key]) return;
- var path = key
+ var path = key;
predicates.push(function(value) {
return search(value, expression[path]);
});
@@ -206,5 +209,5 @@ function filterFilter() {
}
}
return filtered;
- }
+ };
}
diff --git a/src/ng/filter/filters.js b/src/ng/filter/filters.js
index d387f668..c92ed384 100644
--- a/src/ng/filter/filters.js
+++ b/src/ng/filter/filters.js
@@ -144,13 +144,13 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
var whole = fraction[0];
fraction = fraction[1] || '';
- var pos = 0,
+ var i, pos = 0,
lgroup = pattern.lgSize,
group = pattern.gSize;
if (whole.length >= (lgroup + group)) {
pos = whole.length - lgroup;
- for (var i = 0; i < pos; i++) {
+ for (i = 0; i < pos; i++) {
if ((pos - i)%group === 0 && i !== 0) {
formatedText += groupSep;
}
@@ -364,7 +364,7 @@ function dateFilter($locale) {
}
dateSetter.call(date, int(match[1]), int(match[2]) - 1, int(match[3]));
var h = int(match[4]||0) - tzHour;
- var m = int(match[5]||0) - tzMin
+ var m = int(match[5]||0) - tzMin;
var s = int(match[6]||0);
var ms = Math.round(parseFloat('0.' + (match[7]||0)) * 1000);
timeSetter.call(date, h, m, s, ms);
diff --git a/src/ng/filter/limitTo.js b/src/ng/filter/limitTo.js
index bbbeb83c..3c88e470 100644
--- a/src/ng/filter/limitTo.js
+++ b/src/ng/filter/limitTo.js
@@ -100,5 +100,5 @@ function limitToFilter(){
}
return out;
- }
+ };
}
diff --git a/src/ng/filter/orderBy.js b/src/ng/filter/orderBy.js
index 65fbdde0..7ef41c8b 100644
--- a/src/ng/filter/orderBy.js
+++ b/src/ng/filter/orderBy.js
@@ -135,5 +135,5 @@ function orderByFilter($parse){
return t1 < t2 ? -1 : 1;
}
}
- }
+ };
}
diff --git a/src/ng/http.js b/src/ng/http.js
index a09691e7..814694cd 100644
--- a/src/ng/http.js
+++ b/src/ng/http.js
@@ -224,11 +224,11 @@ function $HttpProvider() {
* 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.
+ * 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() {
@@ -237,10 +237,11 @@ function $HttpProvider() {
* ```
*
* # 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 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.
*
* ```
* $httpBackend.expectGET(...);
@@ -300,22 +301,24 @@ function $HttpProvider() {
*
* Request transformations:
*
- * - If the `data` property of the request configuration object contains an object, serialize it into
- * JSON format.
+ * - If the `data` property of the request configuration object contains an object, serialize it
+ * into JSON format.
*
* Response transformations:
*
* - If XSRF prefix is detected, strip it (see Security Considerations section below).
* - If JSON response is detected, deserialize it using a JSON parser.
*
- * To globally augment or override the default transforms, modify the `$httpProvider.defaults.transformRequest` and
- * `$httpProvider.defaults.transformResponse` 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
+ * To globally augment or override the default transforms, modify the
+ * `$httpProvider.defaults.transformRequest` and `$httpProvider.defaults.transformResponse`
+ * 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.
*
- * Similarly, to locally override the request/response transforms, augment the `transformRequest` and/or
- * `transformResponse` properties of the configuration object passed into `$http`.
+ * Similarly, to locally override the request/response transforms, augment the
+ * `transformRequest` and/or `transformResponse` properties of the configuration object passed
+ * into `$http`.
*
*
* # Caching
@@ -353,16 +356,16 @@ function $HttpProvider() {
*
* There are two kinds of interceptors (and two kinds of rejection interceptors):
*
- * * `request`: interceptors get called with http `config` object. The function is free to modify
- * the `config` or create a new one. The function needs to return the `config` directly or as a
- * promise.
- * * `requestError`: interceptor gets called when a previous interceptor threw an error or resolved
- * with a rejection.
- * * `response`: interceptors get called with http `response` object. The function is free to modify
- * the `response` or create a new one. The function needs to return the `response` directly or as a
- * promise.
- * * `responseError`: interceptor gets called when a previous interceptor threw an error or resolved
- * with a rejection.
+ * * `request`: interceptors get called with http `config` object. The function is free to
+ * modify the `config` or create a new one. The function needs to return the `config`
+ * directly or as a promise.
+ * * `requestError`: interceptor gets called when a previous interceptor threw an error or
+ * resolved with a rejection.
+ * * `response`: interceptors get called with http `response` object. The function is free to
+ * modify the `response` or create a new one. The function needs to return the `response`
+ * directly or as a promise.
+ * * `responseError`: interceptor gets called when a previous interceptor threw an error or
+ * resolved with a rejection.
*
*
* <pre>
@@ -511,9 +514,10 @@ function $HttpProvider() {
* cookie called `XSRF-TOKEN` on the first HTTP GET request. On subsequent XHR requests the
* server can verify that the cookie matches `X-XSRF-TOKEN` HTTP header, and therefore be sure
* 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} for added security.
+ * 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}
+ * 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.
@@ -524,18 +528,21 @@ function $HttpProvider() {
*
* - **method** – `{string}` – HTTP method (e.g. 'GET', 'POST', etc)
* - **url** – `{string}` – Absolute or relative URL of the resource that is being requested.
- * - **params** – `{Object.<string|Object>}` – Map of strings or objects which will be turned to
- * `?key1=value1&key2=value2` after the url. If the value is not a string, it will be JSONified.
+ * - **params** – `{Object.<string|Object>}` – Map of strings or objects which will be turned
+ * to `?key1=value1&key2=value2` after the url. If the value is not a string, it will be
+ * JSONified.
* - **data** – `{string|Object}` – Data to be sent as the request message data.
* - **headers** – `{Object}` – Map of strings or functions which return strings representing
- * HTTP headers to send to the server. If the return value of a function is null, the header will
- * not be sent.
+ * HTTP headers to send to the server. If the return value of a function is null, the
+ * header will not be sent.
* - **xsrfHeaderName** – `{string}` – Name of HTTP header to populate with the XSRF token.
* - **xsrfCookieName** – `{string}` – Name of cookie containing the XSRF token.
- * - **transformRequest** – `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
+ * - **transformRequest** –
+ * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
* transform function or an array of such functions. The transform function takes the http
* request body and headers and returns its transformed (typically serialized) version.
- * - **transformResponse** – `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
+ * - **transformResponse** –
+ * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
* transform function or an array of such functions. The transform function takes the http
* response body and headers and returns its transformed (typically deserialized) version.
* - **cache** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the
@@ -558,7 +565,8 @@ function $HttpProvider() {
* these functions are destructured representation of the response object passed into the
* `then` method. The response object has these properties:
*
- * - **data** – `{string|Object}` – The response body transformed with the transform functions.
+ * - **data** – `{string|Object}` – The response body transformed with the transform
+ * functions.
* - **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.
@@ -568,75 +576,82 @@ function $HttpProvider() {
*
*
* @example
- <example>
- <file name="index.html">
- <div ng-controller="FetchCtrl">
- <select ng-model="method">
- <option>GET</option>
- <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 ng-click="updateModel('JSONP', 'http://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero')">Sample JSONP</button>
- <button ng-click="updateModel('JSONP', 'http://angularjs.org/doesntexist&callback=JSON_CALLBACK')">Invalid JSONP</button>
- <pre>http status code: {{status}}</pre>
- <pre>http response data: {{data}}</pre>
- </div>
- </file>
- <file name="script.js">
- function FetchCtrl($scope, $http, $templateCache) {
- $scope.method = 'GET';
- $scope.url = 'http-hello.html';
-
- $scope.fetch = function() {
- $scope.code = null;
- $scope.response = null;
-
- $http({method: $scope.method, url: $scope.url, cache: $templateCache}).
- success(function(data, status) {
- $scope.status = status;
- $scope.data = data;
- }).
- error(function(data, status) {
- $scope.data = data || "Request failed";
- $scope.status = status;
- });
- };
-
- $scope.updateModel = function(method, url) {
- $scope.method = method;
- $scope.url = url;
- };
- }
- </file>
- <file name="http-hello.html">
- Hello, $http!
- </file>
- <file name="scenario.js">
- 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!/);
- });
+<example>
+<file name="index.html">
+ <div ng-controller="FetchCtrl">
+ <select ng-model="method">
+ <option>GET</option>
+ <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
+ ng-click="updateModel('JSONP',
+ 'http://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero')">
+ Sample JSONP
+ </button>
+ <button
+ ng-click="updateModel('JSONP', 'http://angularjs.org/doesntexist&callback=JSON_CALLBACK')">
+ Invalid JSONP
+ </button>
+ <pre>http status code: {{status}}</pre>
+ <pre>http response data: {{data}}</pre>
+ </div>
+</file>
+<file name="script.js">
+ function FetchCtrl($scope, $http, $templateCache) {
+ $scope.method = 'GET';
+ $scope.url = 'http-hello.html';
+
+ $scope.fetch = function() {
+ $scope.code = null;
+ $scope.response = null;
+
+ $http({method: $scope.method, url: $scope.url, cache: $templateCache}).
+ success(function(data, status) {
+ $scope.status = status;
+ $scope.data = data;
+ }).
+ error(function(data, status) {
+ $scope.data = data || "Request failed";
+ $scope.status = status;
+ });
+ };
+
+ $scope.updateModel = function(method, url) {
+ $scope.method = method;
+ $scope.url = url;
+ };
+ }
+</file>
+<file name="http-hello.html">
+ Hello, $http!
+</file>
+<file name="scenario.js">
+ 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!/);
+ });
- 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!/);
- });
+ 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!/);
+ });
- 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');
- });
- </file>
- </example>
+ 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');
+ });
+</file>
+</example>
*/
function $http(requestConfig) {
var config = {
@@ -996,7 +1011,7 @@ function $HttpProvider() {
if (!params) return url;
var parts = [];
forEachSorted(params, function(value, key) {
- if (value == null || value == undefined) return;
+ if (value === null || isUndefined(value)) return;
if (!isArray(value)) value = [value];
forEach(value, function(v) {
diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js
index 55ea5607..dcb15f77 100644
--- a/src/ng/httpBackend.js
+++ b/src/ng/httpBackend.js
@@ -1,4 +1,7 @@
+'use strict';
+
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) {}
@@ -69,7 +72,7 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
var responseHeaders = xhr.getAllResponseHeaders();
// responseText is the old-school way of retrieving response (supported by IE8 & 9)
- // response and responseType properties were introduced in XHR Level2 spec (supported by IE10)
+ // response/responseType properties were introduced in XHR Level2 spec (supported by IE10)
completeRequest(callback,
status || xhr.status,
(xhr.responseType ? xhr.response : xhr.responseText),
diff --git a/src/ng/interpolate.js b/src/ng/interpolate.js
index d02a6a07..43593f91 100644
--- a/src/ng/interpolate.js
+++ b/src/ng/interpolate.js
@@ -12,31 +12,31 @@ var $interpolateMinErr = minErr('$interpolate');
* Used for configuring the interpolation markup. Defaults to `{{` and `}}`.
*
* @example
- <doc:example module="customInterpolationApp">
- <doc:source>
- <script>
- var customInterpolationApp = angular.module('customInterpolationApp', []);
-
- customInterpolationApp.config(function($interpolateProvider) {
- $interpolateProvider.startSymbol('//');
- $interpolateProvider.endSymbol('//');
- });
-
-
- customInterpolationApp.controller('DemoController', function DemoController() {
- this.label = "This bindings is brought you you by // interpolation symbols.";
- });
- </script>
- <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 bindings is brought you you by // interpolation symbols.');
- });
- </doc:scenario>
- </doc:example>
+<doc:example module="customInterpolationApp">
+<doc:source>
+<script>
+ var customInterpolationApp = angular.module('customInterpolationApp', []);
+
+ customInterpolationApp.config(function($interpolateProvider) {
+ $interpolateProvider.startSymbol('//');
+ $interpolateProvider.endSymbol('//');
+ });
+
+
+ customInterpolationApp.controller('DemoController', function DemoController() {
+ this.label = "This binding is brought you by // interpolation symbols.";
+ });
+</script>
+<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>
*/
function $InterpolateProvider() {
var startSymbol = '{{';
@@ -116,8 +116,8 @@ function $InterpolateProvider() {
* result through {@link ng.$sce#methods_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 interpolated
- * string. The function has these parameters:
+ * @returns {function(context)} an interpolation function which is used to compute the
+ * interpolated string. The function has these parameters:
*
* * `context`: an object against which any expressions embedded in the strings are evaluated
* against.
@@ -155,12 +155,12 @@ function $InterpolateProvider() {
length = 1;
}
- // Concatenating expressions makes it hard to reason about whether some combination of concatenated
- // values are unsafe to use and could easily lead to XSS. By requiring that a single
- // expression be used for iframe[src], object[src], etc., we ensure that the value that's used
- // is assigned or constructed by some JS code somewhere that is more testable or make it
- // obvious that you bound the value to some user controlled value. This helps reduce the load
- // when auditing for XSS issues.
+ // Concatenating expressions makes it hard to reason about whether some combination of
+ // concatenated values are unsafe to use and could easily lead to XSS. By requiring that a
+ // single expression be used for iframe[src], object[src], etc., we ensure that the value
+ // that's used is assigned or constructed by some JS code somewhere that is more testable or
+ // make it obvious that you bound the value to some user controlled value. This helps reduce
+ // the load when auditing for XSS issues.
if (trustedContext && parts.length > 1) {
throw $interpolateMinErr('noconcat',
"Error while interpolating: {0}\nStrict Contextual Escaping disallows " +
@@ -180,7 +180,7 @@ function $InterpolateProvider() {
} else {
part = $sce.valueOf(part);
}
- if (part == null || part == undefined) {
+ if (part === null || isUndefined(part)) {
part = '';
} else if (typeof part != 'string') {
part = toJson(part);
@@ -191,7 +191,8 @@ function $InterpolateProvider() {
return concat.join('');
}
catch(err) {
- var newErr = $interpolateMinErr('interr', "Can't interpolate: {0}\n{1}", text, err.toString());
+ var newErr = $interpolateMinErr('interr', "Can't interpolate: {0}\n{1}", text,
+ err.toString());
$exceptionHandler(newErr);
}
};
@@ -216,7 +217,7 @@ function $InterpolateProvider() {
*/
$interpolate.startSymbol = function() {
return startSymbol;
- }
+ };
/**
@@ -233,7 +234,7 @@ function $InterpolateProvider() {
*/
$interpolate.endSymbol = function() {
return endSymbol;
- }
+ };
return $interpolate;
}];
diff --git a/src/ng/interval.js b/src/ng/interval.js
index 04493b11..2ad3a7f1 100644
--- a/src/ng/interval.js
+++ b/src/ng/interval.js
@@ -35,13 +35,13 @@ function $IntervalProvider() {
*/
function interval(fn, delay, count, invokeApply) {
var setInterval = $window.setInterval,
- clearInterval = $window.clearInterval;
-
- var deferred = $q.defer(),
+ clearInterval = $window.clearInterval,
+ deferred = $q.defer(),
promise = deferred.promise,
- count = (isDefined(count)) ? count : 0,
iteration = 0,
skipApply = (isDefined(invokeApply) && !invokeApply);
+
+ count = isDefined(count) ? count : 0,
promise.then(null, null, fn);
diff --git a/src/ng/locale.js b/src/ng/locale.js
index 06d2dd07..23df4275 100644
--- a/src/ng/locale.js
+++ b/src/ng/locale.js
@@ -45,8 +45,9 @@ function $LocaleProvider(){
},
DATETIME_FORMATS: {
- MONTH: 'January,February,March,April,May,June,July,August,September,October,November,December'
- .split(','),
+ MONTH:
+ 'January,February,March,April,May,June,July,August,September,October,November,December'
+ .split(','),
SHORTMONTH: 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(','),
DAY: 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday'.split(','),
SHORTDAY: 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'.split(','),
diff --git a/src/ng/location.js b/src/ng/location.js
index 5268bc04..abb6135a 100644
--- a/src/ng/location.js
+++ b/src/ng/location.js
@@ -37,12 +37,15 @@ function parseAppUrl(relativeUrl, locationObj) {
relativeUrl = '/' + relativeUrl;
}
var match = urlResolve(relativeUrl);
- locationObj.$$path = decodeURIComponent(prefixed && match.pathname.charAt(0) === '/' ? match.pathname.substring(1) : match.pathname);
+ locationObj.$$path = decodeURIComponent(prefixed && match.pathname.charAt(0) === '/' ?
+ match.pathname.substring(1) : match.pathname);
locationObj.$$search = parseKeyValue(match.search);
locationObj.$$hash = decodeURIComponent(match.hash);
// make sure path starts with '/';
- if (locationObj.$$path && locationObj.$$path.charAt(0) != '/') locationObj.$$path = '/' + locationObj.$$path;
+ if (locationObj.$$path && locationObj.$$path.charAt(0) != '/') {
+ locationObj.$$path = '/' + locationObj.$$path;
+ }
}
@@ -50,10 +53,11 @@ function parseAppUrl(relativeUrl, locationObj) {
*
* @param {string} begin
* @param {string} whole
- * @returns {string} returns text from whole after begin or undefined if it does not begin with expected string.
+ * @returns {string} returns text from whole after begin or undefined if it does not begin with
+ * expected string.
*/
function beginsWith(begin, whole) {
- if (whole.indexOf(begin) == 0) {
+ if (whole.indexOf(begin) === 0) {
return whole.substr(begin.length);
}
}
@@ -98,7 +102,8 @@ function LocationHtml5Url(appBase, basePrefix) {
this.$$parse = function(url) {
var pathUrl = beginsWith(appBaseNoFile, url);
if (!isString(pathUrl)) {
- throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url, appBaseNoFile);
+ throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url,
+ appBaseNoFile);
}
parseAppUrl(pathUrl, this);
@@ -137,7 +142,7 @@ function LocationHtml5Url(appBase, basePrefix) {
} else if (appBaseNoFile == url + '/') {
return appBaseNoFile;
}
- }
+ };
}
@@ -170,7 +175,8 @@ function LocationHashbangUrl(appBase, hashPrefix) {
: '';
if (!isString(withoutHashUrl)) {
- throw $locationMinErr('ihshprfx', 'Invalid url "{0}", missing hash prefix "{1}".', url, hashPrefix);
+ throw $locationMinErr('ihshprfx', 'Invalid url "{0}", missing hash prefix "{1}".', url,
+ hashPrefix);
}
parseAppUrl(withoutHashUrl, this);
this.$$compose();
@@ -192,7 +198,7 @@ function LocationHashbangUrl(appBase, hashPrefix) {
if(stripHash(appBase) == stripHash(url)) {
return url;
}
- }
+ };
}
@@ -221,7 +227,7 @@ function LocationHashbangInHtml5Url(appBase, hashPrefix) {
} else if ( appBaseNoFile === url + '/') {
return appBaseNoFile;
}
- }
+ };
}
@@ -360,10 +366,12 @@ LocationHashbangInHtml5Url.prototype =
*
* Change search part when called with parameter and return `$location`.
*
- * @param {string|Object.<string>|Object.<Array.<string>>} search New search params - string or hash object. Hash object
- * may contain an array of values, which will be decoded as duplicates in the url.
+ * @param {string|Object.<string>|Object.<Array.<string>>} search New search params - string or
+ * hash object. Hash object may contain an array of values, which will be decoded as duplicates in
+ * the url.
+ *
* @param {string=} paramValue If `search` is a string, then `paramValue` will override only a
- * single search parameter. If the value is `null`, the parameter will be deleted.
+ * single search parameter. If the value is `null`, the parameter will be deleted.
*
* @return {string} search
*/
@@ -377,11 +385,12 @@ LocationHashbangInHtml5Url.prototype =
} else if (isObject(search)) {
this.$$search = search;
} else {
- throw $locationMinErr('isrcharg', 'The first argument of the `$location#search()` call must be a string or an object.');
+ throw $locationMinErr('isrcharg',
+ 'The first argument of the `$location#search()` call must be a string or an object.');
}
break;
default:
- if (paramValue == undefined || paramValue == null) {
+ if (isUndefined(paramValue) || paramValue === null) {
delete this.$$search[search];
} else {
this.$$search[search] = paramValue;
@@ -573,7 +582,8 @@ function $LocationProvider(){
// update $location when $browser url changes
$browser.onUrlChange(function(newUrl) {
if ($location.absUrl() != newUrl) {
- if ($rootScope.$broadcast('$locationChangeStart', newUrl, $location.absUrl()).defaultPrevented) {
+ if ($rootScope.$broadcast('$locationChangeStart', newUrl,
+ $location.absUrl()).defaultPrevented) {
$browser.url($location.absUrl());
return;
}
diff --git a/src/ng/log.js b/src/ng/log.js
index 70911fdf..cedf0264 100644
--- a/src/ng/log.js
+++ b/src/ng/log.js
@@ -55,12 +55,12 @@ function $LogProvider(){
* @returns {*} current value if used as getter or itself (chaining) if used as setter
*/
this.debugEnabled = function(flag) {
- if (isDefined(flag)) {
- debug = flag;
- return this;
- } else {
- return debug;
- }
+ if (isDefined(flag)) {
+ debug = flag;
+ return this;
+ } else {
+ return debug;
+ }
};
this.$get = ['$window', function($window){
@@ -114,13 +114,13 @@ function $LogProvider(){
* Write a debug message
*/
debug: (function () {
- var fn = consoleLog('debug');
-
- return function() {
- if (debug) {
- fn.apply(self, arguments);
- }
- }
+ var fn = consoleLog('debug');
+
+ return function() {
+ if (debug) {
+ fn.apply(self, arguments);
+ }
+ };
}())
};
@@ -155,7 +155,7 @@ function $LogProvider(){
// or we are IE where console.log doesn't have apply so we log at least first 2 args
return function(arg1, arg2) {
logFn(arg1, arg2 == null ? '' : arg2);
- }
+ };
}
}];
}
diff --git a/src/ng/parse.js b/src/ng/parse.js
index f6c85358..c93d07de 100644
--- a/src/ng/parse.js
+++ b/src/ng/parse.js
@@ -6,58 +6,65 @@ var promiseWarning;
// Sandboxing Angular Expressions
// ------------------------------
-// Angular expressions are generally considered safe because these expressions only have direct access to $scope and
-// locals. However, one can obtain the ability to execute arbitrary JS code by obtaining a reference to native JS
-// functions such as the Function constructor.
+// Angular expressions are generally considered safe because these expressions only have direct
+// access to $scope and locals. However, one can obtain the ability to execute arbitrary JS code by
+// obtaining a reference to native JS functions such as the Function constructor.
//
// As an example, consider the following Angular expression:
//
// {}.toString.constructor(alert("evil JS code"))
//
-// We want to prevent this type of access. For the sake of performance, during the lexing phase we disallow any "dotted"
-// access to any member named "constructor".
+// We want to prevent this type of access. For the sake of performance, during the lexing phase we
+// disallow any "dotted" access to any member named "constructor".
//
-// For reflective calls (a[b]) we check that the value of the lookup is not the Function constructor while evaluating
-// the expression, which is a stronger but more expensive test. Since reflective calls are expensive anyway, this is not
-// such a big deal compared to static dereferencing.
+// For reflective calls (a[b]) we check that the value of the lookup is not the Function constructor
+// while evaluating the expression, which is a stronger but more expensive test. Since reflective
+// calls are expensive anyway, this is not such a big deal compared to static dereferencing.
//
-// This sandboxing technique is not perfect and doesn't aim to be. The goal is to prevent exploits against the
-// expression language, but not to prevent exploits that were enabled by exposing sensitive JavaScript or browser apis
-// on Scope. Exposing such objects on a Scope is never a good practice and therefore we are not even trying to protect
-// against interaction with an object explicitly exposed in this way.
+// This sandboxing technique is not perfect and doesn't aim to be. The goal is to prevent exploits
+// against the expression language, but not to prevent exploits that were enabled by exposing
+// sensitive JavaScript or browser apis on Scope. Exposing such objects on a Scope is never a good
+// practice and therefore we are not even trying to protect against interaction with an object
+// explicitly exposed in this way.
//
-// A developer could foil the name check by aliasing the Function constructor under a different name on the scope.
+// A developer could foil the name check by aliasing the Function constructor under a different
+// name on the scope.
//
-// In general, it is not possible to access a Window object from an angular expression unless a window or some DOM
-// object that has a reference to window is published onto a Scope.
+// In general, it is not possible to access a Window object from an angular expression unless a
+// window or some DOM object that has a reference to window is published onto a Scope.
function ensureSafeMemberName(name, fullExpression) {
if (name === "constructor") {
throw $parseMinErr('isecfld',
- 'Referencing "constructor" field in Angular expressions is disallowed! Expression: {0}', fullExpression);
+ 'Referencing "constructor" field in Angular expressions is disallowed! Expression: {0}',
+ fullExpression);
}
return name;
-};
+}
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);
+ '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);
+ '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);
+ 'Referencing DOM nodes in Angular expressions is disallowed! Expression: {0}',
+ fullExpression);
} else {
return obj;
}
}
var OPERATORS = {
+ /* jshint bitwise : false */
'null':function(){return null;},
'true':function(){return true;},
'false':function(){return false;},
@@ -71,7 +78,10 @@ var OPERATORS = {
return a;
}
return isDefined(b)?b:undefined;},
- '-':function(self, locals, a,b){a=a(self, locals); b=b(self, locals); return (isDefined(a)?a:0)-(isDefined(b)?b:0);},
+ '-':function(self, locals, a,b){
+ a=a(self, locals); b=b(self, locals);
+ return (isDefined(a)?a:0)-(isDefined(b)?b:0);
+ },
'*':function(self, locals, a,b){return a(self, locals)*b(self, locals);},
'/':function(self, locals, a,b){return a(self, locals)/b(self, locals);},
'%':function(self, locals, a,b){return a(self, locals)%b(self, locals);},
@@ -92,6 +102,7 @@ var OPERATORS = {
'|':function(self, locals, a,b){return b(self, locals)(self, locals, a(self, locals));},
'!':function(self, locals, a){return !a(self, locals);}
};
+/* jshint bitwise: true */
var ESCAPE = {"n":"\n", "f":"\f", "r":"\r", "t":"\t", "v":"\v", "'":"'", '"':'"'};
@@ -192,8 +203,9 @@ Lexer.prototype = {
},
isWhitespace: function(ch) {
+ // IE treats non-breaking space as \u00A0
return (ch === ' ' || ch === '\r' || ch === '\t' ||
- ch === '\n' || ch === '\v' || ch === '\u00A0'); // IE treats non-breaking space as \u00A0
+ ch === '\n' || ch === '\v' || ch === '\u00A0');
},
isIdent: function(ch) {
@@ -960,7 +972,7 @@ function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) {
pathVal = pathVal.$$v;
}
return pathVal;
- }
+ };
}
function getterFn(path, options, fullExp) {
@@ -976,20 +988,22 @@ function getterFn(path, options, fullExp) {
fn;
if (options.csp) {
- fn = (pathKeysLength < 6)
- ? cspSafeGetterFn(pathKeys[0], pathKeys[1], pathKeys[2], pathKeys[3], pathKeys[4], fullExp, options)
- : function(scope, locals) {
- var i = 0, val;
- do {
- val = cspSafeGetterFn(
- pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++], fullExp, options
- )(scope, locals);
-
- locals = undefined; // clear after first iteration
- scope = val;
- } while (i < pathKeysLength);
- return val;
- }
+ if (pathKeysLength < 6) {
+ fn = cspSafeGetterFn(pathKeys[0], pathKeys[1], pathKeys[2], pathKeys[3], pathKeys[4], fullExp,
+ options);
+ } else {
+ fn = function(scope, locals) {
+ var i = 0, val;
+ do {
+ val = cspSafeGetterFn(pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++],
+ pathKeys[i++], fullExp, options)(scope, locals);
+
+ locals = undefined; // clear after first iteration
+ scope = val;
+ } while (i < pathKeysLength);
+ return val;
+ };
+ }
} else {
var code = 'var l, fn, p;\n';
forEach(pathKeys, function(key, index) {
@@ -1015,7 +1029,9 @@ function getterFn(path, options, fullExp) {
});
code += 'return s;';
- var evaledFnGetter = Function('s', 'k', 'pw', code); // s=scope, k=locals, pw=promiseWarning
+ /* 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) {
return evaledFnGetter(scope, locals, promiseWarning);
@@ -1079,7 +1095,8 @@ function getterFn(path, options, fullExp) {
* @function
*
* @description
- * `$parseProvider` can be used for configuring the default behavior of the {@link ng.$parse $parse} service.
+ * `$parseProvider` can be used for configuring the default behavior of the {@link ng.$parse $parse}
+ * service.
*/
function $ParseProvider() {
var cache = {};
@@ -1101,35 +1118,40 @@ function $ParseProvider() {
*
* **This feature is deprecated, see deprecation notes below for more info**
*
- * If set to true (default is false), $parse will unwrap promises automatically when a promise is found at any part of
- * the expression. In other words, if set to true, the expression will always result in a non-promise value.
+ * If set to true (default is false), $parse will unwrap promises automatically when a promise is
+ * found at any part of the expression. In other words, if set to true, the expression will always
+ * result in a non-promise value.
*
- * While the promise is unresolved, it's treated as undefined, but once resolved and fulfilled, the fulfillment value
- * is used in place of the promise while evaluating the expression.
+ * While the promise is unresolved, it's treated as undefined, but once resolved and fulfilled,
+ * the fulfillment value is used in place of the promise while evaluating the expression.
*
* **Deprecation notice**
*
- * This is a feature that didn't prove to be wildly useful or popular, primarily because of the dichotomy between data
- * access in templates (accessed as raw values) and controller code (accessed as promises).
+ * This is a feature that didn't prove to be wildly useful or popular, primarily because of the
+ * dichotomy between data access in templates (accessed as raw values) and controller code
+ * (accessed as promises).
*
- * In most code we ended up resolving promises manually in controllers anyway and thus unifying the model access there.
+ * In most code we ended up resolving promises manually in controllers anyway and thus unifying
+ * the model access there.
*
* Other downsides of automatic promise unwrapping:
*
* - when building components it's often desirable to receive the raw promises
* - adds complexity and slows down expression evaluation
- * - makes expression code pre-generation unattractive due to the amount of code that needs to be generated
+ * - makes expression code pre-generation unattractive due to the amount of code that needs to be
+ * generated
* - makes IDE auto-completion and tool support hard
*
* **Warning Logs**
*
- * If the unwrapping is enabled, Angular will log a warning about each expression that unwraps a promise (to reduce
- * the noise, each expression is logged only once). To disable this logging use
+ * If the unwrapping is enabled, Angular will log a warning about each expression that unwraps a
+ * promise (to reduce the noise, each expression is logged only once). To disable this logging use
* `$parseProvider.logPromiseWarnings(false)` api.
*
*
* @param {boolean=} value New value.
- * @returns {boolean|self} Returns the current setting when used as getter and self if used as setter.
+ * @returns {boolean|self} Returns the current setting when used as getter and self if used as
+ * setter.
*/
this.unwrapPromises = function(value) {
if (isDefined(value)) {
@@ -1156,7 +1178,8 @@ function $ParseProvider() {
* This setting applies only if `$parseProvider.unwrapPromises` setting is set to true as well.
*
* @param {boolean=} value New value.
- * @returns {boolean|self} Returns the current setting when used as getter and self if used as setter.
+ * @returns {boolean|self} Returns the current setting when used as getter and self if used as
+ * setter.
*/
this.logPromiseWarnings = function(value) {
if (isDefined(value)) {
diff --git a/src/ng/q.js b/src/ng/q.js
index be5bd6f4..c363fdf1 100644
--- a/src/ng/q.js
+++ b/src/ng/q.js
@@ -50,8 +50,8 @@
* </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](https://github.com/kriskowal/uncommonjs/blob/master/promises/specification.md).
+ * comes in the way of guarantees that promise and deferred APIs make, see
+ * https://github.com/kriskowal/uncommonjs/blob/master/promises/specification.md.
*
* Additionally the promise api allows for composition that is very hard to do with the
* traditional callback ([CPS](http://en.wikipedia.org/wiki/Continuation-passing_style)) approach.
@@ -98,8 +98,9 @@
* provide a progress indication, before the promise is resolved or rejected.
*
* This method *returns a new promise* which is resolved or rejected via the return value of the
- * `successCallback`, `errorCallback`. It also notifies via the return value of the `notifyCallback`
- * method. The promise can not be resolved or rejected from the notifyCallback method.
+ * `successCallback`, `errorCallback`. It also notifies via the return value of the
+ * `notifyCallback` method. The promise can not be resolved or rejected from the notifyCallback
+ * method.
*
* - `catch(errorCallback)` – shorthand for `promise.then(null, errorCallback)`
*
@@ -115,8 +116,8 @@
*
* # 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:
+ * Because calling the `then` method of a promise returns a new derived promise, it is easily
+ * possible to create a chain of promises:
*
* <pre>
* promiseB = promiseA.then(function(result) {
@@ -479,9 +480,9 @@ function qFactory(nextTick, exceptionHandler) {
*
* @param {Array.<Promise>|Object.<Promise>} promises An array or hash of promises.
* @returns {Promise} Returns a single promise that will be resolved with an array/hash of values,
- * each value corresponding to the promise at the same index/key in the `promises` array/hash. If any of
- * the promises is resolved with a rejection, this resulting promise will be rejected with the
- * same rejection value.
+ * each value corresponding to the promise at the same index/key in the `promises` array/hash.
+ * If any of the promises is resolved with a rejection, this resulting promise will be rejected
+ * with the same rejection value.
*/
function all(promises) {
var deferred = defer(),
diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js
index da4e30c2..58aedd05 100644
--- a/src/ng/rootScope.js
+++ b/src/ng/rootScope.js
@@ -40,14 +40,18 @@
* @methodOf ng.$rootScopeProvider
* @description
*
- * Sets the number of `$digest` iterations the scope should attempt to execute before giving up and assuming that the model is unstable.
+ * Sets the number of `$digest` iterations the scope should attempt to execute before giving up and
+ * assuming that the model is unstable.
*
* The current default is 10 iterations.
*
- * In complex applications it's possible that the dependencies between `$watch`s will result in several digest iterations.
- * However if an application needs more than the default 10 digest iterations for its model to stabilize then you should investigate what is causing the model to continuously change during the digest.
+ * In complex applications it's possible that the dependencies between `$watch`s will result in
+ * several digest iterations. However if an application needs more than the default 10 digest
+ * iterations for its model to stabilize then you should investigate what is causing the model to
+ * continuously change during the digest.
*
- * Increasing the TTL could have performance implications, so you should not change it without proper justification.
+ * Increasing the TTL could have performance implications, so you should not change it without
+ * proper justification.
*
* @param {number} limit The number of digest iterations.
*/
@@ -109,11 +113,12 @@ function $RootScopeProvider(){
* </pre>
*
*
- * @param {Object.<string, function()>=} providers Map of service factory which need to be provided
- * for the current scope. Defaults to {@link ng}.
+ * @param {Object.<string, function()>=} providers Map of service factory which need to be
+ * provided for the current scope. Defaults to {@link ng}.
* @param {Object.<string, *>=} instanceCache Provides pre-instantiated services which should
- * append/override services provided by `providers`. This is handy when unit-testing and having
- * the need to override a default service.
+ * append/override services provided by `providers`. This is handy
+ * when unit-testing and having the need to override a default
+ * service.
* @returns {Object} Newly created scope.
*
*/
@@ -151,12 +156,12 @@ function $RootScopeProvider(){
* Creates a new child {@link ng.$rootScope.Scope scope}.
*
* The parent scope will propagate the {@link ng.$rootScope.Scope#$digest $digest()} and
- * {@link ng.$rootScope.Scope#$digest $digest()} events. The scope can be removed from the scope
- * hierarchy using {@link ng.$rootScope.Scope#$destroy $destroy()}.
+ * {@link ng.$rootScope.Scope#$digest $digest()} events. The scope can be removed from the
+ * scope hierarchy using {@link ng.$rootScope.Scope#$destroy $destroy()}.
*
- * {@link ng.$rootScope.Scope#$destroy $destroy()} must be called on a scope when it is desired for
- * the scope and its child scopes to be permanently detached from the parent and thus stop
- * participating in model change detection and listener notification by invoking.
+ * {@link ng.$rootScope.Scope#$destroy $destroy()} must be called on a scope when it is
+ * desired for the scope and its child scopes to be permanently detached from the parent and
+ * thus stop participating in model change detection and listener notification by invoking.
*
* @param {boolean} isolate If true, then the scope does not prototypically inherit from the
* parent scope. The scope is isolated, as it can not see parent scope properties.
@@ -207,25 +212,26 @@ function $RootScopeProvider(){
* @description
* Registers a `listener` callback to be executed whenever the `watchExpression` changes.
*
- * - The `watchExpression` is called on every call to {@link ng.$rootScope.Scope#$digest $digest()} and
- * should return the value that will be watched. (Since {@link ng.$rootScope.Scope#$digest $digest()}
- * reruns when it detects changes the `watchExpression` can execute multiple times per
+ * - The `watchExpression` is called on every call to {@link ng.$rootScope.Scope#$digest
+ * $digest()} and should return the value that will be watched. (Since
+ * {@link ng.$rootScope.Scope#$digest $digest()} reruns when it detects changes the
+ * `watchExpression` can execute multiple times per
* {@link ng.$rootScope.Scope#$digest $digest()} and should be idempotent.)
* - The `listener` is called only when the value from the current `watchExpression` and the
* previous call to `watchExpression` are not equal (with the exception of the initial run,
* see below). The inequality is determined according to
- * {@link angular.equals} function. To save the value of the object for later comparison, the
- * {@link angular.copy} function is used. It also means that watching complex options will
- * have adverse memory and performance implications.
- * - The watch `listener` may change the model, which may trigger other `listener`s to fire. This
- * is achieved by rerunning the watchers until no changes are detected. The rerun iteration
- * limit is 10 to prevent an infinite loop deadlock.
+ * {@link angular.equals} function. To save the value of the object for later comparison,
+ * the {@link angular.copy} function is used. It also means that watching complex options
+ * will have adverse memory and performance implications.
+ * - The watch `listener` may change the model, which may trigger other `listener`s to fire.
+ * This is achieved by rerunning the watchers until no changes are detected. The rerun
+ * iteration limit is 10 to prevent an infinite loop deadlock.
*
*
* If you want to be notified whenever {@link ng.$rootScope.Scope#$digest $digest} is called,
* you can register a `watchExpression` function with no `listener`. (Since `watchExpression`
- * can execute multiple times per {@link ng.$rootScope.Scope#$digest $digest} cycle when a change is
- * detected, be prepared for multiple calls to your listener.)
+ * can execute multiple times per {@link ng.$rootScope.Scope#$digest $digest} cycle when a
+ * change is detected, be prepared for multiple calls to your listener.)
*
* After a watcher is registered with the scope, the `listener` fn is called asynchronously
* (via {@link ng.$rootScope.Scope#$evalAsync $evalAsync}) to initialize the
@@ -243,7 +249,9 @@ function $RootScopeProvider(){
scope.counter = 0;
expect(scope.counter).toEqual(0);
- scope.$watch('name', function(newValue, oldValue) { scope.counter = scope.counter + 1; });
+ scope.$watch('name', function(newValue, oldValue) {
+ scope.counter = scope.counter + 1;
+ });
expect(scope.counter).toEqual(0);
scope.$digest();
@@ -258,8 +266,8 @@ function $RootScopeProvider(){
*
*
* @param {(function()|string)} watchExpression Expression that is evaluated on each
- * {@link ng.$rootScope.Scope#$digest $digest} cycle. A change in the return value triggers a
- * call to the `listener`.
+ * {@link ng.$rootScope.Scope#$digest $digest} cycle. A change in the return value triggers
+ * a call to the `listener`.
*
* - `string`: Evaluated as {@link guide/expression expression}
* - `function(scope)`: called with current `scope` as a parameter.
@@ -267,7 +275,8 @@ function $RootScopeProvider(){
* the `watchExpression` changes.
*
* - `string`: Evaluated as {@link guide/expression expression}
- * - `function(newValue, oldValue, scope)`: called with current and previous values as parameters.
+ * - `function(newValue, oldValue, scope)`: called with current and previous values as
+ * parameters.
*
* @param {boolean=} objectEquality Compare object for equality rather than for reference.
* @returns {function()} Returns a deregistration function for this listener.
@@ -319,13 +328,13 @@ function $RootScopeProvider(){
*
* @description
* Shallow watches the properties of an object and fires whenever any of the properties change
- * (for arrays, this implies watching the array items; for object maps, this implies watching the properties).
- * If a change is detected, the `listener` callback is fired.
+ * (for arrays, this implies watching the array items; for object maps, this implies watching
+ * the properties). If a change is detected, the `listener` callback is fired.
*
- * - The `obj` collection is observed via standard $watch operation and is examined on every call to $digest() to
- * see if any items have been added, removed, or moved.
- * - The `listener` is called whenever anything within the `obj` has changed. Examples include adding, removing,
- * and moving items belonging to an object or array.
+ * - The `obj` collection is observed via standard $watch operation and is examined on every
+ * call to $digest() to see if any items have been added, removed, or moved.
+ * - The `listener` is called whenever anything within the `obj` has changed. Examples include
+ * adding, removing, and moving items belonging to an object or array.
*
*
* # Example
@@ -351,19 +360,19 @@ function $RootScopeProvider(){
* </pre>
*
*
- * @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 {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.
+ * @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.
*
- * @returns {function()} Returns a de-registration function for this listener. When the de-registration function
- * is executed, the internal watch operation is terminated.
+ * @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;
@@ -458,21 +467,22 @@ function $RootScopeProvider(){
* @function
*
* @description
- * Processes all of the {@link ng.$rootScope.Scope#$watch watchers} of the current scope and its children.
- * Because a {@link ng.$rootScope.Scope#$watch watcher}'s listener can change the model, the
- * `$digest()` keeps calling the {@link ng.$rootScope.Scope#$watch watchers} until no more listeners are
- * firing. This means that it is possible to get into an infinite loop. This function will throw
- * `'Maximum iteration limit exceeded.'` if the number of iterations exceeds 10.
+ * Processes all of the {@link ng.$rootScope.Scope#$watch watchers} of the current scope and
+ * its children. Because a {@link ng.$rootScope.Scope#$watch watcher}'s listener can change
+ * the model, the `$digest()` keeps calling the {@link ng.$rootScope.Scope#$watch watchers}
+ * until no more listeners are firing. This means that it is possible to get into an infinite
+ * loop. This function will throw `'Maximum iteration limit exceeded.'` if the number of
+ * iterations exceeds 10.
*
* Usually, you don't call `$digest()` directly in
* {@link ng.directive:ngController controllers} or in
* {@link ng.$compileProvider#methods_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()`.
+ * 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()`.
*
* If you want to be notified whenever `$digest()` is called,
- * you can register a `watchExpression` function with {@link ng.$rootScope.Scope#$watch $watch()}
- * with no `listener`.
+ * you can register a `watchExpression` function with
+ * {@link ng.$rootScope.Scope#$watch $watch()} with no `listener`.
*
* In unit tests, you may need to call `$digest()` to simulate the scope life cycle.
*
@@ -570,7 +580,8 @@ function $RootScopeProvider(){
if(dirty && !(ttl--)) {
clearPhase();
throw $rootScopeMinErr('infdig',
- '{0} $digest() iterations reached. Aborting!\nWatchers fired in the last 5 iterations: {1}',
+ '{0} $digest() iterations reached. Aborting!\n' +
+ 'Watchers fired in the last 5 iterations: {1}',
TTL, toJson(watchLog));
}
} while (dirty || asyncQueue.length);
@@ -649,8 +660,9 @@ function $RootScopeProvider(){
* @function
*
* @description
- * Executes the `expression` on the current scope and returns the result. Any exceptions in the
- * expression are propagated (uncaught). This is useful when evaluating Angular expressions.
+ * Executes the `expression` on the current scope and returns the result. Any exceptions in
+ * the expression are propagated (uncaught). This is useful when evaluating Angular
+ * expressions.
*
* # Example
* <pre>
@@ -682,17 +694,20 @@ function $RootScopeProvider(){
* @description
* Executes the expression on the current scope at a later point in time.
*
- * The `$evalAsync` makes no guarantees as to when the `expression` will be executed, only that:
+ * The `$evalAsync` makes no guarantees as to when the `expression` will be executed, only
+ * that:
*
- * - it will execute after the function that scheduled the evaluation (preferably before DOM rendering).
- * - at least one {@link ng.$rootScope.Scope#$digest $digest cycle} will be performed after `expression` execution.
+ * - it will execute after the function that scheduled the evaluation (preferably before DOM
+ * rendering).
+ * - at least one {@link ng.$rootScope.Scope#$digest $digest cycle} will be performed after
+ * `expression` execution.
*
* Any exceptions from the execution of the expression are forwarded to the
* {@link ng.$exceptionHandler $exceptionHandler} service.
*
- * __Note:__ if this function is called outside of a `$digest` cycle, a new `$digest` cycle will be scheduled.
- * However, it is encouraged to always call code that changes the model from within an `$apply` call.
- * That includes code evaluated via `$evalAsync`.
+ * __Note:__ if this function is called outside of a `$digest` cycle, a new `$digest` cycle
+ * will be scheduled. However, it is encouraged to always call code that changes the model
+ * from within an `$apply` call. That includes code evaluated via `$evalAsync`.
*
* @param {(string|function())=} expression An angular expression to be executed.
*
@@ -701,8 +716,8 @@ function $RootScopeProvider(){
*
*/
$evalAsync: function(expr) {
- // if we are outside of an $digest loop and this is the first time we are scheduling async task also schedule
- // async auto-flush
+ // if we are outside of an $digest loop and this is the first time we are scheduling async
+ // task also schedule async auto-flush
if (!$rootScope.$$phase && !$rootScope.$$asyncQueue.length) {
$browser.defer(function() {
if ($rootScope.$$asyncQueue.length) {
@@ -725,10 +740,10 @@ function $RootScopeProvider(){
* @function
*
* @description
- * `$apply()` is used to execute an expression in angular from outside of the angular framework.
- * (For example from browser DOM events, setTimeout, XHR or third party libraries).
- * Because we are calling into the angular framework we need to perform proper scope life cycle
- * of {@link ng.$exceptionHandler exception handling},
+ * `$apply()` is used to execute an expression in angular from outside of the angular
+ * framework. (For example from browser DOM events, setTimeout, XHR or third party libraries).
+ * Because we are calling into the angular framework we need to perform proper scope life
+ * cycle of {@link ng.$exceptionHandler exception handling},
* {@link ng.$rootScope.Scope#$digest executing watches}.
*
* ## Life cycle
@@ -753,8 +768,8 @@ function $RootScopeProvider(){
* {@link ng.$rootScope.Scope#$eval $eval()} method.
* 2. Any exceptions from the execution of the expression are forwarded to the
* {@link ng.$exceptionHandler $exceptionHandler} service.
- * 3. The {@link ng.$rootScope.Scope#$watch watch} listeners are fired immediately after the expression
- * was executed using the {@link ng.$rootScope.Scope#$digest $digest()} method.
+ * 3. The {@link ng.$rootScope.Scope#$watch watch} listeners are fired immediately after the
+ * expression was executed using the {@link ng.$rootScope.Scope#$digest $digest()} method.
*
*
* @param {(string|function())=} exp An angular expression to be executed.
@@ -788,18 +803,20 @@ function $RootScopeProvider(){
* @function
*
* @description
- * Listens on events of a given type. See {@link ng.$rootScope.Scope#$emit $emit} for discussion of
- * event life cycle.
+ * Listens on events of a given type. See {@link ng.$rootScope.Scope#$emit $emit} for
+ * discussion of event life cycle.
*
* The event listener function format is: `function(event, args...)`. The `event` object
* passed into the listener has the following attributes:
*
- * - `targetScope` - `{Scope}`: the scope on which the event was `$emit`-ed or `$broadcast`-ed.
+ * - `targetScope` - `{Scope}`: the scope on which the event was `$emit`-ed or
+ * `$broadcast`-ed.
* - `currentScope` - `{Scope}`: the current scope which is handling the event.
* - `name` - `{string}`: name of the event.
- * - `stopPropagation` - `{function=}`: calling `stopPropagation` function will cancel further event
- * propagation (available only for events that were `$emit`-ed).
- * - `preventDefault` - `{function}`: calling `preventDefault` sets `defaultPrevented` flag to true.
+ * - `stopPropagation` - `{function=}`: calling `stopPropagation` function will cancel
+ * further event propagation (available only for events that were `$emit`-ed).
+ * - `preventDefault` - `{function}`: calling `preventDefault` sets `defaultPrevented` flag
+ * to true.
* - `defaultPrevented` - `{boolean}`: true if `preventDefault` was called.
*
* @param {string} name Event name to listen on.
@@ -830,9 +847,10 @@ function $RootScopeProvider(){
* registered {@link ng.$rootScope.Scope#$on} listeners.
*
* The event life cycle starts at the scope on which `$emit` was called. All
- * {@link ng.$rootScope.Scope#$on listeners} listening for `name` event on this scope get notified.
- * Afterwards, the event traverses upwards toward the root scope and calls all registered
- * listeners along the way. The event will stop propagating if one of the listeners cancels it.
+ * {@link ng.$rootScope.Scope#$on listeners} listening for `name` event on this scope get
+ * notified. Afterwards, the event traverses upwards toward the root scope and calls all
+ * registered listeners along the way. The event will stop propagating if one of the listeners
+ * cancels it.
*
* Any exception emitted from the {@link ng.$rootScope.Scope#$on listeners} will be passed
* onto the {@link ng.$exceptionHandler $exceptionHandler} service.
@@ -898,9 +916,9 @@ function $RootScopeProvider(){
* registered {@link ng.$rootScope.Scope#$on} listeners.
*
* The event life cycle starts at the scope on which `$broadcast` was called. All
- * {@link ng.$rootScope.Scope#$on listeners} listening for `name` event on this scope get notified.
- * Afterwards, the event propagates to all direct and indirect scopes of the current scope and
- * calls all registered listeners along the way. The event cannot be canceled.
+ * {@link ng.$rootScope.Scope#$on listeners} listening for `name` event on this scope get
+ * notified. Afterwards, the event propagates to all direct and indirect scopes of the current
+ * scope and calls all registered listeners along the way. The event cannot be canceled.
*
* Any exception emitted from the {@link ng.$rootScope.Scope#$on listeners} will be passed
* onto the {@link ng.$exceptionHandler $exceptionHandler} service.
diff --git a/src/ng/sce.js b/src/ng/sce.js
index 8c4fde17..8f231031 100644
--- a/src/ng/sce.js
+++ b/src/ng/sce.js
@@ -20,7 +20,7 @@ var SCE_CONTEXTS = {
function escapeForRegexp(s) {
return s.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g, '\\$1').
replace(/\x08/g, '\\x08');
-};
+}
function adjustMatcher(matcher) {
@@ -144,8 +144,8 @@ function $SceDelegateProvider() {
* provided. This must be an array or null. A snapshot of this array is used so further
* changes to the array are ignored.
*
- * Follow {@link ng.$sce#resourceUrlPatternItem this link} for a description of the items allowed in
- * this array.
+ * Follow {@link ng.$sce#resourceUrlPatternItem this link} for a description of the items
+ * allowed in this array.
*
* Note: **an empty whitelist array will block all URLs**!
*
@@ -174,19 +174,19 @@ function $SceDelegateProvider() {
* provided. This must be an array or null. A snapshot of this array is used so further
* changes to the array are ignored.
*
- * Follow {@link ng.$sce#resourceUrlPatternItem this link} for a description of the items allowed in
- * this array.
+ * Follow {@link ng.$sce#resourceUrlPatternItem this link} for a description of the items
+ * allowed in this array.
*
- * The typical usage for the blacklist is to **block [open redirects](http://cwe.mitre.org/data/definitions/601.html)**
- * served by your domain as these would otherwise be trusted but actually return content from the redirected
- * domain.
+ * The typical usage for the blacklist is to **block
+ * [open redirects](http://cwe.mitre.org/data/definitions/601.html)** served by your domain as
+ * these would otherwise be trusted but actually return content from the redirected domain.
*
* Finally, **the blacklist overrides the whitelist** and has the final say.
*
* @return {Array} the currently set blacklist array.
*
- * The **default value** when no whitelist has been explicitly set is the empty array (i.e. there is
- * no blacklist.)
+ * The **default value** when no whitelist has been explicitly set is the empty array (i.e. there
+ * is no blacklist.)
*
* @description
* Sets/Gets the blacklist of trusted resource URLs.
@@ -242,21 +242,21 @@ function $SceDelegateProvider() {
return allowed;
}
- function generateHolderType(base) {
+ function generateHolderType(Base) {
var holderType = function TrustedValueHolderType(trustedValue) {
this.$$unwrapTrustedValue = function() {
return trustedValue;
};
};
- if (base) {
- holderType.prototype = new base();
+ if (Base) {
+ holderType.prototype = new Base();
}
holderType.prototype.valueOf = function sceValueOf() {
return this.$$unwrapTrustedValue();
- }
+ };
holderType.prototype.toString = function sceToString() {
return this.$$unwrapTrustedValue().toString();
- }
+ };
return holderType;
}
@@ -288,9 +288,10 @@ function $SceDelegateProvider() {
* where Angular expects a $sce.trustAs() return value.
*/
function trustAs(type, trustedValue) {
- var constructor = (byType.hasOwnProperty(type) ? byType[type] : null);
- if (!constructor) {
- throw $sceMinErr('icontext', 'Attempted to trust a value in invalid context. Context: {0}; Value: {1}',
+ var Constructor = (byType.hasOwnProperty(type) ? byType[type] : null);
+ if (!Constructor) {
+ throw $sceMinErr('icontext',
+ 'Attempted to trust a value in invalid context. Context: {0}; Value: {1}',
type, trustedValue);
}
if (trustedValue === null || trustedValue === undefined || trustedValue === '') {
@@ -303,7 +304,7 @@ function $SceDelegateProvider() {
'Attempted to trust a non-string value in a content requiring a string: Context: {0}',
type);
}
- return new constructor(trustedValue);
+ return new Constructor(trustedValue);
}
/**
@@ -322,8 +323,8 @@ function $SceDelegateProvider() {
* @param {*} value The result of a prior {@link ng.$sceDelegate#methods_trustAs `$sceDelegate.trustAs`}
* call or anything else.
* @returns {*} The value the was originally provided to {@link ng.$sceDelegate#methods_trustAs
- * `$sceDelegate.trustAs`} if `value` is the result of such a call. Otherwise, returns `value`
- * unchanged.
+ * `$sceDelegate.trustAs`} if `value` is the result of such a call. Otherwise, returns
+ * `value` unchanged.
*/
function valueOf(maybeTrusted) {
if (maybeTrusted instanceof trustedValueHolderBase) {
@@ -339,13 +340,13 @@ function $SceDelegateProvider() {
* @methodOf ng.$sceDelegate
*
* @description
- * Takes the result of a {@link ng.$sceDelegate#methods_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.
+ * Takes the result of a {@link ng.$sceDelegate#methods_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
- * `$sceDelegate.trustAs`} call.
+ * `$sceDelegate.trustAs`} call.
* @returns {*} The value the was originally provided to {@link ng.$sceDelegate#methods_trustAs
* `$sceDelegate.trustAs`} if valid in this context. Otherwise, throws an exception.
*/
@@ -365,7 +366,8 @@ function $SceDelegateProvider() {
return maybeTrusted;
} else {
throw $sceMinErr('insecurl',
- 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: {0}', maybeTrusted.toString());
+ 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: {0}',
+ maybeTrusted.toString());
}
} else if (type === SCE_CONTEXTS.HTML) {
return htmlSanitizer(maybeTrusted);
@@ -392,6 +394,8 @@ function $SceDelegateProvider() {
* Read more about {@link ng.$sce Strict Contextual Escaping (SCE)}.
*/
+/* jshint maxlen: false*/
+
/**
* @ngdoc service
* @name ng.$sce
@@ -448,9 +452,9 @@ 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 obtain values that will be
- * accepted by SCE / privileged contexts.
+ * 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
+ * obtain values that will be accepted by SCE / privileged contexts.
*
*
* ## How does it work?
@@ -577,60 +581,63 @@ function $SceDelegateProvider() {
* ## Show me an example using SCE.
*
* @example
- <example module="mySceApp">
- <file name="index.html">
- <div ng-controller="myAppController as myCtrl">
- <i ng-bind-html="myCtrl.explicitlyTrustedHtml" id="explicitlyTrustedHtml"></i><br><br>
- <b>User comments</b><br>
- By default, HTML that isn't explicitly trusted (e.g. Alice's comment) is sanitized when $sanitize is available. If $sanitize isn't available, this results in an error instead of an exploit.
- <div class="well">
- <div ng-repeat="userComment in myCtrl.userComments">
- <b>{{userComment.name}}</b>:
- <span ng-bind-html="userComment.htmlComment" class="htmlComment"></span>
- <br>
- </div>
+<example module="mySceApp">
+<file name="index.html">
+ <div ng-controller="myAppController as myCtrl">
+ <i ng-bind-html="myCtrl.explicitlyTrustedHtml" id="explicitlyTrustedHtml"></i><br><br>
+ <b>User comments</b><br>
+ By default, HTML that isn't explicitly trusted (e.g. Alice's comment) is sanitized when
+ $sanitize is available. If $sanitize isn't available, this results in an error instead of an
+ exploit.
+ <div class="well">
+ <div ng-repeat="userComment in myCtrl.userComments">
+ <b>{{userComment.name}}</b>:
+ <span ng-bind-html="userComment.htmlComment" class="htmlComment"></span>
+ <br>
</div>
</div>
- </file>
+ </div>
+</file>
+
+<file name="script.js">
+ var mySceApp = angular.module('mySceApp', ['ngSanitize']);
- <file name="script.js">
- var mySceApp = angular.module('mySceApp', ['ngSanitize']);
+ mySceApp.controller("myAppController", function myAppController($http, $templateCache, $sce) {
+ var self = this;
+ $http.get("test_data.json", {cache: $templateCache}).success(function(userComments) {
+ self.userComments = userComments;
+ });
+ self.explicitlyTrustedHtml = $sce.trustAsHtml(
+ '<span onmouseover="this.textContent=&quot;Explicitly trusted HTML bypasses ' +
+ 'sanitization.&quot;">Hover over this text.</span>');
+ });
+</file>
+
+<file name="test_data.json">
+[
+ { "name": "Alice",
+ "htmlComment":
+ "<span onmouseover='this.textContent=\"PWN3D!\"'>Is <i>anyone</i> reading this?</span>"
+ },
+ { "name": "Bob",
+ "htmlComment": "<i>Yes!</i> Am I the only other one?"
+ }
+]
+</file>
- mySceApp.controller("myAppController", function myAppController($http, $templateCache, $sce) {
- var self = this;
- $http.get("test_data.json", {cache: $templateCache}).success(function(userComments) {
- self.userComments = userComments;
- });
- self.explicitlyTrustedHtml = $sce.trustAsHtml(
+<file name="scenario.js">
+ describe('SCE doc demo', function() {
+ it('should sanitize untrusted values', function() {
+ expect(element('.htmlComment').html()).toBe('<span>Is <i>anyone</i> reading this?</span>');
+ });
+ it('should NOT sanitize explicitly trusted values', function() {
+ expect(element('#explicitlyTrustedHtml').html()).toBe(
'<span onmouseover="this.textContent=&quot;Explicitly trusted HTML bypasses ' +
'sanitization.&quot;">Hover over this text.</span>');
});
- </file>
-
- <file name="test_data.json">
- [
- { "name": "Alice",
- "htmlComment": "<span onmouseover='this.textContent=\"PWN3D!\"'>Is <i>anyone</i> reading this?</span>"
- },
- { "name": "Bob",
- "htmlComment": "<i>Yes!</i> Am I the only other one?"
- }
- ]
- </file>
-
- <file name="scenario.js">
- describe('SCE doc demo', function() {
- it('should sanitize untrusted values', function() {
- expect(element('.htmlComment').html()).toBe('<span>Is <i>anyone</i> reading this?</span>');
- });
- it('should NOT sanitize explicitly trusted values', function() {
- expect(element('#explicitlyTrustedHtml').html()).toBe(
- '<span onmouseover="this.textContent=&quot;Explicitly trusted HTML bypasses ' +
- 'sanitization.&quot;">Hover over this text.</span>');
- });
- });
- </file>
- </example>
+ });
+</file>
+</example>
*
*
*
@@ -653,6 +660,7 @@ function $SceDelegateProvider() {
* </pre>
*
*/
+/* jshint maxlen: 100 */
function $SceProvider() {
var enabled = true;
@@ -698,13 +706,13 @@ function $SceProvider() {
* This function should return the a value that is safe to use in the context specified by
* contextEnum or throw and exception otherwise.
*
- * NOTE: This contract deliberately does NOT state that values returned by trustAs() must be opaque
- * or wrapped in some holder object. That happens to be an implementation detail. For instance,
- * an implementation could maintain a registry of all trusted objects by context. In such a case,
- * trustAs() would return the same object that was passed in. getTrusted() would return the same
- * object passed in if it was found in the registry under a compatible context or throw an
- * exception otherwise. An implementation might only wrap values some of the time based on
- * some criteria. getTrusted() might return a value and not throw an exception for special
+ * NOTE: This contract deliberately does NOT state that values returned by trustAs() must be
+ * opaque or wrapped in some holder object. That happens to be an implementation detail. For
+ * instance, an implementation could maintain a registry of all trusted objects by context. In
+ * such a case, trustAs() would return the same object that was passed in. getTrusted() would
+ * return the same object passed in if it was found in the registry under a compatible context or
+ * throw an exception otherwise. An implementation might only wrap values some of the time based
+ * on some criteria. getTrusted() might return a value and not throw an exception for special
* constants or objects even if not wrapped. All such implementations fulfill this contract.
*
*
@@ -759,8 +767,8 @@ function $SceProvider() {
sce.valueOf = $sceDelegate.valueOf;
if (!enabled) {
- sce.trustAs = sce.getTrusted = function(type, value) { return value; },
- sce.valueOf = identity
+ sce.trustAs = sce.getTrusted = function(type, value) { return value; };
+ sce.valueOf = identity;
}
/**
@@ -790,7 +798,7 @@ function $SceProvider() {
} else {
return function sceParseAsTrusted(self, locals) {
return sce.getTrusted(type, parsed(self, locals));
- }
+ };
}
};
@@ -800,11 +808,12 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @description
- * Delegates to {@link ng.$sceDelegate#methods_trustAs `$sceDelegate.trustAs`}. As such, 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 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.
+ * 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
+ * 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.
*
* @param {string} type The kind of context in which this value is safe for use. e.g. url,
* resource_url, html, js and css.
@@ -819,7 +828,8 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @description
- * Shorthand method. `$sce.trustAsHtml(value)` → {@link ng.$sceDelegate#methods_trustAs `$sceDelegate.trustAs($sce.HTML, value)`}
+ * Shorthand method. `$sce.trustAsHtml(value)` →
+ * {@link ng.$sceDelegate#methods_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
@@ -834,7 +844,8 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @description
- * Shorthand method. `$sce.trustAsUrl(value)` → {@link ng.$sceDelegate#methods_trustAs `$sceDelegate.trustAs($sce.URL, value)`}
+ * Shorthand method. `$sce.trustAsUrl(value)` →
+ * {@link ng.$sceDelegate#methods_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
@@ -849,7 +860,8 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @description
- * Shorthand method. `$sce.trustAsResourceUrl(value)` → {@link ng.$sceDelegate#methods_trustAs `$sceDelegate.trustAs($sce.RESOURCE_URL, value)`}
+ * Shorthand method. `$sce.trustAsResourceUrl(value)` →
+ * {@link ng.$sceDelegate#methods_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
@@ -864,7 +876,8 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @description
- * Shorthand method. `$sce.trustAsJs(value)` → {@link ng.$sceDelegate#methods_trustAs `$sceDelegate.trustAs($sce.JS, value)`}
+ * Shorthand method. `$sce.trustAsJs(value)` →
+ * {@link ng.$sceDelegate#methods_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
@@ -879,15 +892,17 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @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 originally supplied
- * value if the queried context type is a supertype of the created type. If this condition
- * isn't satisfied, throws an exception.
+ * 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
+ * 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`} call.
- * @returns {*} The value the was originally provided to {@link ng.$sce#methods_trustAs `$sce.trustAs`} if
- * valid in this context. Otherwise, throws an exception.
+ * @param {*} maybeTrusted The result of a prior {@link ng.$sce#methods_trustAs `$sce.trustAs`}
+ * call.
+ * @returns {*} The value the was originally provided to
+ * {@link ng.$sce#methods_trustAs `$sce.trustAs`} if valid in this context.
+ * Otherwise, throws an exception.
*/
/**
@@ -896,7 +911,8 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @description
- * Shorthand method. `$sce.getTrustedHtml(value)` → {@link ng.$sceDelegate#methods_getTrusted `$sceDelegate.getTrusted($sce.HTML, value)`}
+ * Shorthand method. `$sce.getTrustedHtml(value)` →
+ * {@link ng.$sceDelegate#methods_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)`
@@ -908,7 +924,8 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @description
- * Shorthand method. `$sce.getTrustedCss(value)` → {@link ng.$sceDelegate#methods_getTrusted `$sceDelegate.getTrusted($sce.CSS, value)`}
+ * Shorthand method. `$sce.getTrustedCss(value)` →
+ * {@link ng.$sceDelegate#methods_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)`
@@ -920,7 +937,8 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @description
- * Shorthand method. `$sce.getTrustedUrl(value)` → {@link ng.$sceDelegate#methods_getTrusted `$sceDelegate.getTrusted($sce.URL, value)`}
+ * Shorthand method. `$sce.getTrustedUrl(value)` →
+ * {@link ng.$sceDelegate#methods_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)`
@@ -932,7 +950,8 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @description
- * Shorthand method. `$sce.getTrustedResourceUrl(value)` → {@link ng.$sceDelegate#methods_getTrusted `$sceDelegate.getTrusted($sce.RESOURCE_URL, value)`}
+ * Shorthand method. `$sce.getTrustedResourceUrl(value)` →
+ * {@link ng.$sceDelegate#methods_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)`
@@ -944,7 +963,8 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @description
- * Shorthand method. `$sce.getTrustedJs(value)` → {@link ng.$sceDelegate#methods_getTrusted `$sceDelegate.getTrusted($sce.JS, value)`}
+ * Shorthand method. `$sce.getTrustedJs(value)` →
+ * {@link ng.$sceDelegate#methods_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)`
@@ -956,7 +976,8 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @description
- * Shorthand method. `$sce.parseAsHtml(expression string)` → {@link ng.$sce#methods_parse `$sce.parseAs($sce.HTML, value)`}
+ * Shorthand method. `$sce.parseAsHtml(expression string)` →
+ * {@link ng.$sce#methods_parse `$sce.parseAs($sce.HTML, value)`}
*
* @param {string} expression String expression to compile.
* @returns {function(context, locals)} a function which represents the compiled expression:
@@ -973,7 +994,8 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @description
- * Shorthand method. `$sce.parseAsCss(value)` → {@link ng.$sce#methods_parse `$sce.parseAs($sce.CSS, value)`}
+ * Shorthand method. `$sce.parseAsCss(value)` →
+ * {@link ng.$sce#methods_parse `$sce.parseAs($sce.CSS, value)`}
*
* @param {string} expression String expression to compile.
* @returns {function(context, locals)} a function which represents the compiled expression:
@@ -990,7 +1012,8 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @description
- * Shorthand method. `$sce.parseAsUrl(value)` → {@link ng.$sce#methods_parse `$sce.parseAs($sce.URL, value)`}
+ * Shorthand method. `$sce.parseAsUrl(value)` →
+ * {@link ng.$sce#methods_parse `$sce.parseAs($sce.URL, value)`}
*
* @param {string} expression String expression to compile.
* @returns {function(context, locals)} a function which represents the compiled expression:
@@ -1007,7 +1030,8 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @description
- * Shorthand method. `$sce.parseAsResourceUrl(value)` → {@link ng.$sce#methods_parse `$sce.parseAs($sce.RESOURCE_URL, value)`}
+ * Shorthand method. `$sce.parseAsResourceUrl(value)` →
+ * {@link ng.$sce#methods_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:
@@ -1024,7 +1048,8 @@ function $SceProvider() {
* @methodOf ng.$sce
*
* @description
- * Shorthand method. `$sce.parseAsJs(value)` → {@link ng.$sce#methods_parse `$sce.parseAs($sce.JS, value)`}
+ * Shorthand method. `$sce.parseAsJs(value)` →
+ * {@link ng.$sce#methods_parse `$sce.parseAs($sce.JS, value)`}
*
* @param {string} expression String expression to compile.
* @returns {function(context, locals)} a function which represents the compiled expression:
@@ -1044,13 +1069,13 @@ function $SceProvider() {
var lName = lowercase(name);
sce[camelCase("parse_as_" + lName)] = function (expr) {
return parse(enumValue, expr);
- }
+ };
sce[camelCase("get_trusted_" + lName)] = function (value) {
return getTrusted(enumValue, value);
- }
+ };
sce[camelCase("trust_as_" + lName)] = function (value) {
return trustAs(enumValue, value);
- }
+ };
});
return sce;
diff --git a/src/ng/sniffer.js b/src/ng/sniffer.js
index 9a7447cb..8dcfcd7d 100644
--- a/src/ng/sniffer.js
+++ b/src/ng/sniffer.js
@@ -18,7 +18,8 @@
function $SnifferProvider() {
this.$get = ['$window', '$document', function($window, $document) {
var eventSupport = {},
- android = int((/android (\d+)/.exec(lowercase(($window.navigator || {}).userAgent)) || [])[1]),
+ android =
+ int((/android (\d+)/.exec(lowercase(($window.navigator || {}).userAgent)) || [])[1]),
boxee = /Boxee/i.test(($window.navigator || {}).userAgent),
document = $document[0] || {},
vendorPrefix,
@@ -59,7 +60,10 @@ function $SnifferProvider() {
// older webit 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
history: !!($window.history && $window.history.pushState && !(android < 4) && !boxee),
+ // jshint +W018
hashchange: 'onhashchange' in $window &&
// IE8 compatible mode lies
(!document.documentMode || document.documentMode > 7),
diff --git a/src/ng/urlUtils.js b/src/ng/urlUtils.js
index 50156e6b..e821c08a 100644
--- a/src/ng/urlUtils.js
+++ b/src/ng/urlUtils.js
@@ -81,7 +81,8 @@ function urlResolve(url) {
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
hostname: urlParsingNode.hostname,
port: urlParsingNode.port,
- pathname: urlParsingNode.pathname && urlParsingNode.pathname.charAt(0) === '/' ? urlParsingNode.pathname : '/' + urlParsingNode.pathname
+ pathname: urlParsingNode.pathname && urlParsingNode.pathname.charAt(0) === '/' ?
+ urlParsingNode.pathname : '/' + urlParsingNode.pathname
};
}