summaryrefslogtreecommitdiff
path: root/xstatic/pkg/angular/data/angular-route.js
diff options
context:
space:
mode:
Diffstat (limited to 'xstatic/pkg/angular/data/angular-route.js')
-rw-r--r--xstatic/pkg/angular/data/angular-route.js226
1 files changed, 147 insertions, 79 deletions
diff --git a/xstatic/pkg/angular/data/angular-route.js b/xstatic/pkg/angular/data/angular-route.js
index f7ebda8..834429b 100644
--- a/xstatic/pkg/angular/data/angular-route.js
+++ b/xstatic/pkg/angular/data/angular-route.js
@@ -1,5 +1,5 @@
/**
- * @license AngularJS v1.2.16
+ * @license AngularJS v1.3.7
* (c) 2010-2014 Google, Inc. http://angularjs.org
* License: MIT
*/
@@ -22,12 +22,12 @@
*/
/* global -ngRouteModule */
var ngRouteModule = angular.module('ngRoute', ['ng']).
- provider('$route', $RouteProvider);
+ provider('$route', $RouteProvider),
+ $routeMinErr = angular.$$minErr('ngRoute');
/**
* @ngdoc provider
* @name $routeProvider
- * @function
*
* @description
*
@@ -39,9 +39,9 @@ var ngRouteModule = angular.module('ngRoute', ['ng']).
* ## Dependencies
* Requires the {@link ngRoute `ngRoute`} module to be installed.
*/
-function $RouteProvider(){
+function $RouteProvider() {
function inherit(parent, extra) {
- return angular.extend(new (angular.extend(function() {}, {prototype:parent}))(), extra);
+ return angular.extend(Object.create(parent), extra);
}
var routes = {};
@@ -146,27 +146,45 @@ function $RouteProvider(){
* Adds a new route definition to the `$route` service.
*/
this.when = function(path, route) {
+ //copy original route object to preserve params inherited from proto chain
+ var routeCopy = angular.copy(route);
+ if (angular.isUndefined(routeCopy.reloadOnSearch)) {
+ routeCopy.reloadOnSearch = true;
+ }
+ if (angular.isUndefined(routeCopy.caseInsensitiveMatch)) {
+ routeCopy.caseInsensitiveMatch = this.caseInsensitiveMatch;
+ }
routes[path] = angular.extend(
- {reloadOnSearch: true},
- route,
- path && pathRegExp(path, route)
+ routeCopy,
+ path && pathRegExp(path, routeCopy)
);
// create redirection for trailing slashes
if (path) {
- var redirectPath = (path[path.length-1] == '/')
- ? path.substr(0, path.length-1)
- : path +'/';
+ var redirectPath = (path[path.length - 1] == '/')
+ ? path.substr(0, path.length - 1)
+ : path + '/';
routes[redirectPath] = angular.extend(
{redirectTo: path},
- pathRegExp(redirectPath, route)
+ pathRegExp(redirectPath, routeCopy)
);
}
return this;
};
+ /**
+ * @ngdoc property
+ * @name $routeProvider#caseInsensitiveMatch
+ * @description
+ *
+ * A boolean property indicating if routes defined
+ * using this provider should be matched using a case insensitive
+ * algorithm. Defaults to `false`.
+ */
+ this.caseInsensitiveMatch = false;
+
/**
* @param path {string} path
* @param opts {Object} options
@@ -188,7 +206,7 @@ function $RouteProvider(){
path = path
.replace(/([().])/g, '\\$1')
- .replace(/(\/)?:(\w+)([\?\*])?/g, function(_, slash, key, option){
+ .replace(/(\/)?:(\w+)([\?\*])?/g, function(_, slash, key, option) {
var optional = option === '?' ? option : null;
var star = option === '*' ? option : null;
keys.push({ name: key, optional: !!optional });
@@ -216,10 +234,14 @@ function $RouteProvider(){
* Sets route definition that will be used on route change when no other route definition
* 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
*/
this.otherwise = function(params) {
+ if (typeof params === 'string') {
+ params = {redirectTo: params};
+ }
this.when(null, params);
return this;
};
@@ -230,10 +252,9 @@ function $RouteProvider(){
'$routeParams',
'$q',
'$injector',
- '$http',
- '$templateCache',
+ '$templateRequest',
'$sce',
- function($rootScope, $location, $routeParams, $q, $injector, $http, $templateCache, $sce) {
+ function($rootScope, $location, $routeParams, $q, $injector, $templateRequest, $sce) {
/**
* @ngdoc service
@@ -270,9 +291,6 @@ function $RouteProvider(){
* 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.
*
- * 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"
* deps="angular-route.js" fixBase="true">
* <file name="index.html">
@@ -380,6 +398,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 +446,8 @@ function $RouteProvider(){
*/
var forceReload = false,
+ preparedRoute,
+ preparedRouteIsUpdateOnly,
$route = {
routes: routes,
@@ -436,15 +460,50 @@ function $RouteProvider(){
* {@link ng.$location $location} hasn't changed.
*
* As a result of that, {@link ngRoute.directive:ngView ngView}
- * creates new scope, reinstantiates the controller.
+ * creates new scope and reinstantiates the controller.
*/
reload: function() {
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;
@@ -473,9 +532,7 @@ function $RouteProvider(){
for (var i = 1, len = m.length; i < len; ++i) {
var key = keys[i - 1];
- var val = 'string' == typeof m[i]
- ? decodeURIComponent(m[i])
- : m[i];
+ var val = m[i];
if (key && val) {
params[key.name] = val;
@@ -484,56 +541,69 @@ 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) {
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)) {
- 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;
- template = $http.get(templateUrl, {cache: $templateCache}).
- then(function(response) { return response.data; });
+ nextRoute.loadedTemplateUrl = templateUrl;
+ template = $templateRequest(templateUrl);
}
}
if (angular.isDefined(template)) {
@@ -544,16 +614,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);
}
});
}
@@ -583,11 +653,11 @@ function $RouteProvider(){
*/
function interpolate(string, params) {
var result = [];
- angular.forEach((string||'').split(':'), function(segment, i) {
+ angular.forEach((string || '').split(':'), function(segment, i) {
if (i === 0) {
result.push(segment);
} else {
- var segmentMatch = segment.match(/(\w+)(.*)/);
+ var segmentMatch = segment.match(/(\w+)(?:[?*])?(.*)/);
var key = segmentMatch[1];
result.push(params[key]);
result.push(segmentMatch[2] || '');
@@ -632,7 +702,7 @@ ngRouteModule.provider('$routeParams', $RouteParamsProvider);
* // Route: /Chapter/:chapterId/Section/:sectionId
* //
* // Then
- * $routeParams ==> {chapterId:1, sectionId:2, search:'moby'}
+ * $routeParams ==> {chapterId:'1', sectionId:'2', search:'moby'}
* ```
*/
function $RouteParamsProvider() {
@@ -695,7 +765,6 @@ ngRouteModule.directive('ngView', ngViewFillContentFactory);
<pre>$location.path() = {{main.$location.path()}}</pre>
<pre>$route.current.templateUrl = {{main.$route.current.templateUrl}}</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>
</div>
</file>
@@ -719,7 +788,6 @@ ngRouteModule.directive('ngView', ngViewFillContentFactory);
.view-animate-container {
position:relative;
height:100px!important;
- position:relative;
background:white;
border:1px solid black;
height:40px;
@@ -773,7 +841,6 @@ ngRouteModule.directive('ngView', ngViewFillContentFactory);
controllerAs: 'chapter'
});
- // configure html5 to get links working on jsfiddle
$locationProvider.html5Mode(true);
}])
.controller('MainCtrl', ['$route', '$routeParams', '$location',
@@ -820,7 +887,7 @@ ngRouteModule.directive('ngView', ngViewFillContentFactory);
* Emitted every time the ngView content is reloaded.
*/
ngViewFactory.$inject = ['$route', '$anchorScroll', '$animate'];
-function ngViewFactory( $route, $anchorScroll, $animate) {
+function ngViewFactory($route, $anchorScroll, $animate) {
return {
restrict: 'ECA',
terminal: true,
@@ -829,7 +896,7 @@ function ngViewFactory( $route, $anchorScroll, $animate) {
link: function(scope, $element, attr, ctrl, $transclude) {
var currentScope,
currentElement,
- previousElement,
+ previousLeaveAnimation,
autoScrollExp = attr.autoscroll,
onloadExp = attr.onload || '';
@@ -837,19 +904,20 @@ function ngViewFactory( $route, $anchorScroll, $animate) {
update();
function cleanupLastView() {
- if(previousElement) {
- previousElement.remove();
- previousElement = null;
+ if (previousLeaveAnimation) {
+ $animate.cancel(previousLeaveAnimation);
+ previousLeaveAnimation = null;
}
- if(currentScope) {
+
+ if (currentScope) {
currentScope.$destroy();
currentScope = null;
}
- if(currentElement) {
- $animate.leave(currentElement, function() {
- previousElement = null;
+ if (currentElement) {
+ previousLeaveAnimation = $animate.leave(currentElement);
+ previousLeaveAnimation.then(function() {
+ previousLeaveAnimation = null;
});
- previousElement = currentElement;
currentElement = null;
}
}
@@ -869,7 +937,7 @@ function ngViewFactory( $route, $anchorScroll, $animate) {
// function is called before linking the content, which would apply child
// directives to non existing elements.
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)
&& (!autoScrollExp || scope.$eval(autoScrollExp))) {
$anchorScroll();