Commit 3d8d3dad authored by Pascal Hartig's avatar Pascal Hartig

AngularJS: Update to 1.3

I looked through the changelog and couldn't find any changes that were relevant
to us. If you can think of any, please open a PR!
parent b4d6f564
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
"name": "todomvc-angular", "name": "todomvc-angular",
"version": "0.0.0", "version": "0.0.0",
"dependencies": { "dependencies": {
"angular": "1.2.22", "angular": "1.3.0",
"todomvc-common": "~0.1.4" "todomvc-common": "~0.1.4"
}, },
"devDependencies": { "devDependencies": {
"angular-mocks": "1.2.22", "angular-mocks": "1.3.0",
"angular-route": "1.2.22" "angular-route": "1.3.0"
} }
} }
/** /**
* @license AngularJS v1.2.22 * @license AngularJS v1.3.0
* (c) 2010-2014 Google, Inc. http://angularjs.org * (c) 2010-2014 Google, Inc. http://angularjs.org
* License: MIT * License: MIT
*/ */
...@@ -22,12 +22,12 @@ ...@@ -22,12 +22,12 @@
*/ */
/* global -ngRouteModule */ /* global -ngRouteModule */
var ngRouteModule = angular.module('ngRoute', ['ng']). var ngRouteModule = angular.module('ngRoute', ['ng']).
provider('$route', $RouteProvider); provider('$route', $RouteProvider),
$routeMinErr = angular.$$minErr('ngRoute');
/** /**
* @ngdoc provider * @ngdoc provider
* @name $routeProvider * @name $routeProvider
* @kind function
* *
* @description * @description
* *
...@@ -216,10 +216,14 @@ function $RouteProvider(){ ...@@ -216,10 +216,14 @@ function $RouteProvider(){
* Sets route definition that will be used on route change when no other route definition * Sets route definition that will be used on route change when no other route definition
* is matched. * is matched.
* *
* @param {Object} params Mapping information to be assigned to `$route.current`. * @param {Object|string} params Mapping information to be assigned to `$route.current`.
* If called with a string, the value maps to `redirectTo`.
* @returns {Object} self * @returns {Object} self
*/ */
this.otherwise = function(params) { this.otherwise = function(params) {
if (typeof params === 'string') {
params = {redirectTo: params};
}
this.when(null, params); this.when(null, params);
return this; return this;
}; };
...@@ -230,10 +234,9 @@ function $RouteProvider(){ ...@@ -230,10 +234,9 @@ function $RouteProvider(){
'$routeParams', '$routeParams',
'$q', '$q',
'$injector', '$injector',
'$http', '$templateRequest',
'$templateCache',
'$sce', '$sce',
function($rootScope, $location, $routeParams, $q, $injector, $http, $templateCache, $sce) { function($rootScope, $location, $routeParams, $q, $injector, $templateRequest, $sce) {
/** /**
* @ngdoc service * @ngdoc service
...@@ -270,9 +273,6 @@ function $RouteProvider(){ ...@@ -270,9 +273,6 @@ function $RouteProvider(){
* This example shows how changing the URL hash causes the `$route` to match a route against the * This example shows how changing the URL hash causes the `$route` to match a route against the
* URL, and the `ngView` pulls in the partial. * URL, and the `ngView` pulls in the partial.
* *
* Note that this example is using {@link ng.directive:script inlined templates}
* to get it working on jsfiddle as well.
*
* <example name="$route-service" module="ngRouteExample" * <example name="$route-service" module="ngRouteExample"
* deps="angular-route.js" fixBase="true"> * deps="angular-route.js" fixBase="true">
* <file name="index.html"> * <file name="index.html">
...@@ -380,6 +380,10 @@ function $RouteProvider(){ ...@@ -380,6 +380,10 @@ function $RouteProvider(){
* defined in `resolve` route property. Once all of the dependencies are resolved * defined in `resolve` route property. Once all of the dependencies are resolved
* `$routeChangeSuccess` is fired. * `$routeChangeSuccess` is fired.
* *
* The route change (and the `$location` change that triggered it) can be prevented
* by calling `preventDefault` method of the event. See {@link ng.$rootScope.Scope#$on}
* for more details about event object.
*
* @param {Object} angularEvent Synthetic event object. * @param {Object} angularEvent Synthetic event object.
* @param {Route} next Future route information. * @param {Route} next Future route information.
* @param {Route} current Current route information. * @param {Route} current Current route information.
...@@ -424,6 +428,8 @@ function $RouteProvider(){ ...@@ -424,6 +428,8 @@ function $RouteProvider(){
*/ */
var forceReload = false, var forceReload = false,
preparedRoute,
preparedRouteIsUpdateOnly,
$route = { $route = {
routes: routes, routes: routes,
...@@ -440,11 +446,46 @@ function $RouteProvider(){ ...@@ -440,11 +446,46 @@ function $RouteProvider(){
*/ */
reload: function() { reload: function() {
forceReload = true; forceReload = true;
$rootScope.$evalAsync(updateRoute); $rootScope.$evalAsync(function() {
// Don't support cancellation of a reload for now...
prepareRoute();
commitRoute();
});
},
/**
* @ngdoc method
* @name $route#updateParams
*
* @description
* Causes `$route` service to update the current URL, replacing
* current route parameters with those specified in `newParams`.
* Provided property names that match the route's path segment
* definitions will be interpolated into the location's path, while
* remaining properties will be treated as query params.
*
* @param {Object} newParams mapping of URL parameter names to values
*/
updateParams: function(newParams) {
if (this.current && this.current.$$route) {
var searchParams = {}, self=this;
angular.forEach(Object.keys(newParams), function(key) {
if (!self.current.pathParams[key]) searchParams[key] = newParams[key];
});
newParams = angular.extend({}, this.current.params, newParams);
$location.path(interpolate(this.current.$$route.originalPath, newParams));
$location.search(angular.extend({}, $location.search(), searchParams));
}
else {
throw $routeMinErr('norout', 'Tried updating route when with no current route');
}
} }
}; };
$rootScope.$on('$locationChangeSuccess', updateRoute); $rootScope.$on('$locationChangeStart', prepareRoute);
$rootScope.$on('$locationChangeSuccess', commitRoute);
return $route; return $route;
...@@ -482,56 +523,69 @@ function $RouteProvider(){ ...@@ -482,56 +523,69 @@ function $RouteProvider(){
return params; return params;
} }
function updateRoute() { function prepareRoute($locationEvent) {
var next = parseRoute(), var lastRoute = $route.current;
last = $route.current;
preparedRoute = parseRoute();
preparedRouteIsUpdateOnly = preparedRoute && lastRoute && preparedRoute.$$route === lastRoute.$$route
&& angular.equals(preparedRoute.pathParams, lastRoute.pathParams)
&& !preparedRoute.reloadOnSearch && !forceReload;
if (!preparedRouteIsUpdateOnly && (lastRoute || preparedRoute)) {
if ($rootScope.$broadcast('$routeChangeStart', preparedRoute, lastRoute).defaultPrevented) {
if ($locationEvent) {
$locationEvent.preventDefault();
}
}
}
}
function commitRoute() {
var lastRoute = $route.current;
var nextRoute = preparedRoute;
if (next && last && next.$$route === last.$$route if (preparedRouteIsUpdateOnly) {
&& angular.equals(next.pathParams, last.pathParams) lastRoute.params = nextRoute.params;
&& !next.reloadOnSearch && !forceReload) { angular.copy(lastRoute.params, $routeParams);
last.params = next.params; $rootScope.$broadcast('$routeUpdate', lastRoute);
angular.copy(last.params, $routeParams); } else if (nextRoute || lastRoute) {
$rootScope.$broadcast('$routeUpdate', last);
} else if (next || last) {
forceReload = false; forceReload = false;
$rootScope.$broadcast('$routeChangeStart', next, last); $route.current = nextRoute;
$route.current = next; if (nextRoute) {
if (next) { if (nextRoute.redirectTo) {
if (next.redirectTo) { if (angular.isString(nextRoute.redirectTo)) {
if (angular.isString(next.redirectTo)) { $location.path(interpolate(nextRoute.redirectTo, nextRoute.params)).search(nextRoute.params)
$location.path(interpolate(next.redirectTo, next.params)).search(next.params)
.replace(); .replace();
} else { } else {
$location.url(next.redirectTo(next.pathParams, $location.path(), $location.search())) $location.url(nextRoute.redirectTo(nextRoute.pathParams, $location.path(), $location.search()))
.replace(); .replace();
} }
} }
} }
$q.when(next). $q.when(nextRoute).
then(function() { then(function() {
if (next) { if (nextRoute) {
var locals = angular.extend({}, next.resolve), var locals = angular.extend({}, nextRoute.resolve),
template, templateUrl; template, templateUrl;
angular.forEach(locals, function(value, key) { angular.forEach(locals, function(value, key) {
locals[key] = angular.isString(value) ? locals[key] = angular.isString(value) ?
$injector.get(value) : $injector.invoke(value); $injector.get(value) : $injector.invoke(value, null, null, key);
}); });
if (angular.isDefined(template = next.template)) { if (angular.isDefined(template = nextRoute.template)) {
if (angular.isFunction(template)) { if (angular.isFunction(template)) {
template = template(next.params); template = template(nextRoute.params);
} }
} else if (angular.isDefined(templateUrl = next.templateUrl)) { } else if (angular.isDefined(templateUrl = nextRoute.templateUrl)) {
if (angular.isFunction(templateUrl)) { if (angular.isFunction(templateUrl)) {
templateUrl = templateUrl(next.params); templateUrl = templateUrl(nextRoute.params);
} }
templateUrl = $sce.getTrustedResourceUrl(templateUrl); templateUrl = $sce.getTrustedResourceUrl(templateUrl);
if (angular.isDefined(templateUrl)) { if (angular.isDefined(templateUrl)) {
next.loadedTemplateUrl = templateUrl; nextRoute.loadedTemplateUrl = templateUrl;
template = $http.get(templateUrl, {cache: $templateCache}). template = $templateRequest(templateUrl);
then(function(response) { return response.data; });
} }
} }
if (angular.isDefined(template)) { if (angular.isDefined(template)) {
...@@ -542,16 +596,16 @@ function $RouteProvider(){ ...@@ -542,16 +596,16 @@ function $RouteProvider(){
}). }).
// after route change // after route change
then(function(locals) { then(function(locals) {
if (next == $route.current) { if (nextRoute == $route.current) {
if (next) { if (nextRoute) {
next.locals = locals; nextRoute.locals = locals;
angular.copy(next.params, $routeParams); angular.copy(nextRoute.params, $routeParams);
} }
$rootScope.$broadcast('$routeChangeSuccess', next, last); $rootScope.$broadcast('$routeChangeSuccess', nextRoute, lastRoute);
} }
}, function(error) { }, function(error) {
if (next == $route.current) { if (nextRoute == $route.current) {
$rootScope.$broadcast('$routeChangeError', next, last, error); $rootScope.$broadcast('$routeChangeError', nextRoute, lastRoute, error);
} }
}); });
} }
...@@ -693,7 +747,6 @@ ngRouteModule.directive('ngView', ngViewFillContentFactory); ...@@ -693,7 +747,6 @@ ngRouteModule.directive('ngView', ngViewFillContentFactory);
<pre>$location.path() = {{main.$location.path()}}</pre> <pre>$location.path() = {{main.$location.path()}}</pre>
<pre>$route.current.templateUrl = {{main.$route.current.templateUrl}}</pre> <pre>$route.current.templateUrl = {{main.$route.current.templateUrl}}</pre>
<pre>$route.current.params = {{main.$route.current.params}}</pre> <pre>$route.current.params = {{main.$route.current.params}}</pre>
<pre>$route.current.scope.name = {{main.$route.current.scope.name}}</pre>
<pre>$routeParams = {{main.$routeParams}}</pre> <pre>$routeParams = {{main.$routeParams}}</pre>
</div> </div>
</file> </file>
...@@ -771,7 +824,6 @@ ngRouteModule.directive('ngView', ngViewFillContentFactory); ...@@ -771,7 +824,6 @@ ngRouteModule.directive('ngView', ngViewFillContentFactory);
controllerAs: 'chapter' controllerAs: 'chapter'
}); });
// configure html5 to get links working on jsfiddle
$locationProvider.html5Mode(true); $locationProvider.html5Mode(true);
}]) }])
.controller('MainCtrl', ['$route', '$routeParams', '$location', .controller('MainCtrl', ['$route', '$routeParams', '$location',
...@@ -827,7 +879,7 @@ function ngViewFactory( $route, $anchorScroll, $animate) { ...@@ -827,7 +879,7 @@ function ngViewFactory( $route, $anchorScroll, $animate) {
link: function(scope, $element, attr, ctrl, $transclude) { link: function(scope, $element, attr, ctrl, $transclude) {
var currentScope, var currentScope,
currentElement, currentElement,
previousElement, previousLeaveAnimation,
autoScrollExp = attr.autoscroll, autoScrollExp = attr.autoscroll,
onloadExp = attr.onload || ''; onloadExp = attr.onload || '';
...@@ -835,19 +887,20 @@ function ngViewFactory( $route, $anchorScroll, $animate) { ...@@ -835,19 +887,20 @@ function ngViewFactory( $route, $anchorScroll, $animate) {
update(); update();
function cleanupLastView() { function cleanupLastView() {
if(previousElement) { if(previousLeaveAnimation) {
previousElement.remove(); $animate.cancel(previousLeaveAnimation);
previousElement = null; previousLeaveAnimation = null;
} }
if(currentScope) { if(currentScope) {
currentScope.$destroy(); currentScope.$destroy();
currentScope = null; currentScope = null;
} }
if(currentElement) { if(currentElement) {
$animate.leave(currentElement, function() { previousLeaveAnimation = $animate.leave(currentElement);
previousElement = null; previousLeaveAnimation.then(function() {
previousLeaveAnimation = null;
}); });
previousElement = currentElement;
currentElement = null; currentElement = null;
} }
} }
...@@ -867,7 +920,7 @@ function ngViewFactory( $route, $anchorScroll, $animate) { ...@@ -867,7 +920,7 @@ function ngViewFactory( $route, $anchorScroll, $animate) {
// function is called before linking the content, which would apply child // function is called before linking the content, which would apply child
// directives to non existing elements. // directives to non existing elements.
var clone = $transclude(newScope, function(clone) { var clone = $transclude(newScope, function(clone) {
$animate.enter(clone, null, currentElement || $element, function onNgViewEnter () { $animate.enter(clone, null, currentElement || $element).then(function onNgViewEnter () {
if (angular.isDefined(autoScrollExp) if (angular.isDefined(autoScrollExp)
&& (!autoScrollExp || scope.$eval(autoScrollExp))) { && (!autoScrollExp || scope.$eval(autoScrollExp))) {
$anchorScroll(); $anchorScroll();
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment