summaryrefslogtreecommitdiffstats
path: root/js/vendor/angular-route/angular-route.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/vendor/angular-route/angular-route.js')
-rw-r--r--js/vendor/angular-route/angular-route.js97
1 files changed, 61 insertions, 36 deletions
diff --git a/js/vendor/angular-route/angular-route.js b/js/vendor/angular-route/angular-route.js
index 3d95eb529..1adbc961d 100644
--- a/js/vendor/angular-route/angular-route.js
+++ b/js/vendor/angular-route/angular-route.js
@@ -1,5 +1,5 @@
/**
- * @license AngularJS v1.3.0-rc.4
+ * @license AngularJS v1.3.0
* (c) 2010-2014 Google, Inc. http://angularjs.org
* License: MIT
*/
@@ -380,6 +380,10 @@ function $RouteProvider(){
* defined in `resolve` route property. Once all of the dependencies are resolved
* `$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 {Route} next Future route information.
* @param {Route} current Current route information.
@@ -424,6 +428,8 @@ function $RouteProvider(){
*/
var forceReload = false,
+ preparedRoute,
+ preparedRouteIsUpdateOnly,
$route = {
routes: routes,
@@ -440,7 +446,11 @@ function $RouteProvider(){
*/
reload: function() {
forceReload = true;
- $rootScope.$evalAsync(updateRoute);
+ $rootScope.$evalAsync(function() {
+ // Don't support cancellation of a reload for now...
+ prepareRoute();
+ commitRoute();
+ });
},
/**
@@ -474,7 +484,8 @@ function $RouteProvider(){
}
};
- $rootScope.$on('$locationChangeSuccess', updateRoute);
+ $rootScope.$on('$locationChangeStart', prepareRoute);
+ $rootScope.$on('$locationChangeSuccess', commitRoute);
return $route;
@@ -512,36 +523,50 @@ function $RouteProvider(){
return params;
}
- function updateRoute() {
- var next = parseRoute(),
- last = $route.current;
-
- if (next && last && next.$$route === last.$$route
- && angular.equals(next.pathParams, last.pathParams)
- && !next.reloadOnSearch && !forceReload) {
- last.params = next.params;
- angular.copy(last.params, $routeParams);
- $rootScope.$broadcast('$routeUpdate', last);
- } else if (next || last) {
+ function prepareRoute($locationEvent) {
+ var lastRoute = $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 (preparedRouteIsUpdateOnly) {
+ lastRoute.params = nextRoute.params;
+ angular.copy(lastRoute.params, $routeParams);
+ $rootScope.$broadcast('$routeUpdate', lastRoute);
+ } else if (nextRoute || lastRoute) {
forceReload = false;
- $rootScope.$broadcast('$routeChangeStart', next, last);
- $route.current = next;
- if (next) {
- if (next.redirectTo) {
- if (angular.isString(next.redirectTo)) {
- $location.path(interpolate(next.redirectTo, next.params)).search(next.params)
+ $route.current = nextRoute;
+ if (nextRoute) {
+ if (nextRoute.redirectTo) {
+ if (angular.isString(nextRoute.redirectTo)) {
+ $location.path(interpolate(nextRoute.redirectTo, nextRoute.params)).search(nextRoute.params)
.replace();
} else {
- $location.url(next.redirectTo(next.pathParams, $location.path(), $location.search()))
+ $location.url(nextRoute.redirectTo(nextRoute.pathParams, $location.path(), $location.search()))
.replace();
}
}
}
- $q.when(next).
+ $q.when(nextRoute).
then(function() {
- if (next) {
- var locals = angular.extend({}, next.resolve),
+ if (nextRoute) {
+ var locals = angular.extend({}, nextRoute.resolve),
template, templateUrl;
angular.forEach(locals, function(value, key) {
@@ -549,17 +574,17 @@ function $RouteProvider(){
$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)) {
- 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)) {
- templateUrl = templateUrl(next.params);
+ templateUrl = templateUrl(nextRoute.params);
}
templateUrl = $sce.getTrustedResourceUrl(templateUrl);
if (angular.isDefined(templateUrl)) {
- next.loadedTemplateUrl = templateUrl;
+ nextRoute.loadedTemplateUrl = templateUrl;
template = $templateRequest(templateUrl);
}
}
@@ -571,16 +596,16 @@ function $RouteProvider(){
}).
// after route change
then(function(locals) {
- if (next == $route.current) {
- if (next) {
- next.locals = locals;
- angular.copy(next.params, $routeParams);
+ if (nextRoute == $route.current) {
+ if (nextRoute) {
+ nextRoute.locals = locals;
+ angular.copy(nextRoute.params, $routeParams);
}
- $rootScope.$broadcast('$routeChangeSuccess', next, last);
+ $rootScope.$broadcast('$routeChangeSuccess', nextRoute, lastRoute);
}
}, function(error) {
- if (next == $route.current) {
- $rootScope.$broadcast('$routeChangeError', next, last, error);
+ if (nextRoute == $route.current) {
+ $rootScope.$broadcast('$routeChangeError', nextRoute, lastRoute, error);
}
});
}