aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng
diff options
context:
space:
mode:
Diffstat (limited to 'src/ng')
-rw-r--r--src/ng/animator.js32
-rw-r--r--src/ng/compile.js2
-rw-r--r--src/ng/directive/ngController.js2
-rw-r--r--src/ng/directive/ngView.js226
-rw-r--r--src/ng/route.js509
-rw-r--r--src/ng/routeParams.js30
6 files changed, 18 insertions, 783 deletions
diff --git a/src/ng/animator.js b/src/ng/animator.js
index a9ec1616..d8495f2d 100644
--- a/src/ng/animator.js
+++ b/src/ng/animator.js
@@ -18,7 +18,7 @@
* | Directive | Supported Animations |
* |========================================================== |====================================================|
* | {@link ng.directive:ngRepeat#animations ngRepeat} | enter, leave and move |
- * | {@link ng.directive:ngView#animations ngView} | enter and leave |
+ * | {@link ngRoute.directive:ngView#animations ngView} | enter and leave |
* | {@link ng.directive:ngInclude#animations ngInclude} | enter and leave |
* | {@link ng.directive:ngSwitch#animations ngSwitch} | enter and leave |
* | {@link ng.directive:ngIf#animations ngIf} | enter and leave |
@@ -183,7 +183,7 @@ var $AnimatorProvider = function() {
*/
var AnimatorService = function(scope, attrs) {
var animator = {};
-
+
/**
* @ngdoc function
* @name ng.animator#enter
@@ -198,7 +198,7 @@ var $AnimatorProvider = function() {
* @param {jQuery/jqLite element} after the sibling element (which is the previous element) of the element that will be the focus of the enter animation
*/
animator.enter = animateActionFactory('enter', insert, noop);
-
+
/**
* @ngdoc function
* @name ng.animator#leave
@@ -212,7 +212,7 @@ var $AnimatorProvider = function() {
* @param {jQuery/jqLite element} parent the parent element of the element that will be the focus of the leave animation
*/
animator.leave = animateActionFactory('leave', noop, remove);
-
+
/**
* @ngdoc function
* @name ng.animator#move
@@ -228,7 +228,7 @@ var $AnimatorProvider = function() {
* @param {jQuery/jqLite element} after the sibling element (which is the previous element) of the element that will be the focus of the move animation
*/
animator.move = animateActionFactory('move', move, noop);
-
+
/**
* @ngdoc function
* @name ng.animator#show
@@ -241,7 +241,7 @@ var $AnimatorProvider = function() {
* @param {jQuery/jqLite element} element the element that will be rendered visible or hidden
*/
animator.show = animateActionFactory('show', show, noop);
-
+
/**
* @ngdoc function
* @name ng.animator#hide
@@ -262,14 +262,14 @@ var $AnimatorProvider = function() {
* @description
* Triggers a custom animation event to be executed on the given element
*
- * @param {string} event the name of the custom event
+ * @param {string} event the name of the custom event
* @param {jQuery/jqLite element} element the element that will be animated
*/
animator.animate = function(event, element) {
animateActionFactory(event, noop, noop)(element);
}
return animator;
-
+
function animateActionFactory(type, beforeFn, afterFn) {
return function(element, parent, after) {
var ngAnimateValue = scope.$eval(attrs.ngAnimate);
@@ -329,10 +329,10 @@ var $AnimatorProvider = function() {
polyfillStart(element, done, memento);
} else if (isFunction($window.getComputedStyle)) {
//one day all browsers will have these properties
- var w3cAnimationProp = 'animation';
+ var w3cAnimationProp = 'animation';
var w3cTransitionProp = 'transition';
- //but some still use vendor-prefixed styles
+ //but some still use vendor-prefixed styles
var vendorAnimationProp = $sniffer.vendorPrefix + 'Animation';
var vendorTransitionProp = $sniffer.vendorPrefix + 'Transition';
@@ -340,7 +340,7 @@ var $AnimatorProvider = function() {
delayKey = 'Delay',
animationIterationCountKey = 'IterationCount',
duration = 0;
-
+
//we want all the styles defined before and after
var ELEMENT_NODE = 1;
forEach(element, function(element) {
@@ -387,15 +387,15 @@ var $AnimatorProvider = function() {
}
};
}
-
+
function show(element) {
element.css('display', '');
}
-
+
function hide(element) {
element.css('display', 'none');
}
-
+
function insert(element, parent, after) {
var afterNode = after && after[after.length - 1];
var parentNode = parent && parent[0] || afterNode && afterNode.parentNode;
@@ -408,11 +408,11 @@ var $AnimatorProvider = function() {
}
});
}
-
+
function remove(element) {
element.remove();
}
-
+
function move(element, parent, after) {
// Do not remove element before insert. Removing will cause data associated with the
// element to be dropped. Insert will implicitly do the remove.
diff --git a/src/ng/compile.js b/src/ng/compile.js
index 2dddf82d..d231fb40 100644
--- a/src/ng/compile.js
+++ b/src/ng/compile.js
@@ -172,7 +172,7 @@ function $CompileProvider($provide) {
*/
this.directive = function registerDirective(name, directiveFactory) {
if (isString(name)) {
- assertArg(directiveFactory, 'directive');
+ assertArg(directiveFactory, 'directiveFactory');
if (!hasDirectives.hasOwnProperty(name)) {
hasDirectives[name] = [];
$provide.factory(name + Suffix, ['$injector', '$exceptionHandler',
diff --git a/src/ng/directive/ngController.js b/src/ng/directive/ngController.js
index 289ee034..47b233f9 100644
--- a/src/ng/directive/ngController.js
+++ b/src/ng/directive/ngController.js
@@ -15,7 +15,7 @@
* * Controller — The `ngController` directive specifies a Controller class; the class has
* methods that typically express the business logic behind the application.
*
- * Note that an alternative way to define controllers is via the {@link ng.$route $route} service.
+ * Note that an alternative way to define controllers is via the {@link ngRoute.$route $route} service.
*
* @element ANY
* @scope
diff --git a/src/ng/directive/ngView.js b/src/ng/directive/ngView.js
deleted file mode 100644
index 9b5694dd..00000000
--- a/src/ng/directive/ngView.js
+++ /dev/null
@@ -1,226 +0,0 @@
-'use strict';
-
-/**
- * @ngdoc directive
- * @name ng.directive:ngView
- * @restrict ECA
- *
- * @description
- * # Overview
- * `ngView` is a directive that complements the {@link ng.$route $route} service by
- * including the rendered template of the current route into the main layout (`index.html`) file.
- * Every time the current route changes, the included view changes with it according to the
- * configuration of the `$route` service.
- *
- * Additionally, you can also provide animations via the ngAnimate attribute to animate the **enter**
- * and **leave** effects.
- *
- * @animations
- * enter - happens just after the ngView contents are changed (when the new view DOM element is inserted into the DOM)
- * leave - happens just after the current ngView contents change and just before the former contents are removed from the DOM
- *
- * @scope
- * @example
- <example module="ngView" animations="true">
- <file name="index.html">
- <div ng-controller="MainCntl as main">
- Choose:
- <a href="Book/Moby">Moby</a> |
- <a href="Book/Moby/ch/1">Moby: Ch1</a> |
- <a href="Book/Gatsby">Gatsby</a> |
- <a href="Book/Gatsby/ch/4?key=value">Gatsby: Ch4</a> |
- <a href="Book/Scarlet">Scarlet Letter</a><br/>
-
- <div
- ng-view
- class="example-animate-container"
- ng-animate="{enter: 'example-enter', leave: 'example-leave'}"></div>
- <hr />
-
- <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>
-
- <file name="book.html">
- <div>
- controller: {{book.name}}<br />
- Book Id: {{book.params.bookId}}<br />
- </div>
- </file>
-
- <file name="chapter.html">
- <div>
- controller: {{chapter.name}}<br />
- Book Id: {{chapter.params.bookId}}<br />
- Chapter Id: {{chapter.params.chapterId}}
- </div>
- </file>
-
- <file name="animations.css">
- .example-leave, .example-enter {
- -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
- -moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
- -ms-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
- -o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
- transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
- }
-
- .example-animate-container {
- position:relative;
- height:100px;
- }
-
- .example-animate-container > * {
- display:block;
- width:100%;
- border-left:1px solid black;
-
- position:absolute;
- top:0;
- left:0;
- right:0;
- bottom:0;
- padding:10px;
- }
-
- .example-enter {
- left:100%;
- }
- .example-enter.example-enter-active {
- left:0;
- }
-
- .example-leave { }
- .example-leave.example-leave-active {
- left:-100%;
- }
- </file>
-
- <file name="script.js">
- angular.module('ngView', [], function($routeProvider, $locationProvider) {
- $routeProvider.when('/Book/:bookId', {
- templateUrl: 'book.html',
- controller: BookCntl,
- controllerAs: 'book'
- });
- $routeProvider.when('/Book/:bookId/ch/:chapterId', {
- templateUrl: 'chapter.html',
- controller: ChapterCntl,
- controllerAs: 'chapter'
- });
-
- // configure html5 to get links working on jsfiddle
- $locationProvider.html5Mode(true);
- });
-
- function MainCntl($route, $routeParams, $location) {
- this.$route = $route;
- this.$location = $location;
- this.$routeParams = $routeParams;
- }
-
- function BookCntl($routeParams) {
- this.name = "BookCntl";
- this.params = $routeParams;
- }
-
- function ChapterCntl($routeParams) {
- this.name = "ChapterCntl";
- this.params = $routeParams;
- }
- </file>
-
- <file name="scenario.js">
- it('should load and compile correct template', function() {
- element('a:contains("Moby: Ch1")').click();
- var content = element('.doc-example-live [ng-view]').text();
- expect(content).toMatch(/controller\: ChapterCntl/);
- expect(content).toMatch(/Book Id\: Moby/);
- expect(content).toMatch(/Chapter Id\: 1/);
-
- element('a:contains("Scarlet")').click();
- content = element('.doc-example-live [ng-view]').text();
- expect(content).toMatch(/controller\: BookCntl/);
- expect(content).toMatch(/Book Id\: Scarlet/);
- });
- </file>
- </example>
- */
-
-
-/**
- * @ngdoc event
- * @name ng.directive:ngView#$viewContentLoaded
- * @eventOf ng.directive:ngView
- * @eventType emit on the current ngView scope
- * @description
- * Emitted every time the ngView content is reloaded.
- */
-var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$compile',
- '$controller', '$animator',
- function($http, $templateCache, $route, $anchorScroll, $compile,
- $controller, $animator) {
- return {
- restrict: 'ECA',
- terminal: true,
- link: function(scope, element, attr) {
- var lastScope,
- onloadExp = attr.onload || '',
- animate = $animator(scope, attr);
-
- scope.$on('$routeChangeSuccess', update);
- update();
-
-
- function destroyLastScope() {
- if (lastScope) {
- lastScope.$destroy();
- lastScope = null;
- }
- }
-
- function clearContent() {
- animate.leave(element.contents(), element);
- destroyLastScope();
- }
-
- function update() {
- var locals = $route.current && $route.current.locals,
- template = locals && locals.$template;
-
- if (template) {
- clearContent();
- var enterElements = jqLite('<div></div>').html(template).contents();
- animate.enter(enterElements, element);
-
- var link = $compile(enterElements),
- current = $route.current,
- controller;
-
- lastScope = current.scope = scope.$new();
- if (current.controller) {
- locals.$scope = lastScope;
- controller = $controller(current.controller, locals);
- if (current.controllerAs) {
- lastScope[current.controllerAs] = controller;
- }
- element.children().data('$ngControllerController', controller);
- }
-
- link(lastScope);
- lastScope.$emit('$viewContentLoaded');
- lastScope.$eval(onloadExp);
-
- // $anchorScroll might listen on event...
- $anchorScroll();
- } else {
- clearContent();
- }
- }
- }
- };
-}];
diff --git a/src/ng/route.js b/src/ng/route.js
deleted file mode 100644
index 12e560c7..00000000
--- a/src/ng/route.js
+++ /dev/null
@@ -1,509 +0,0 @@
-'use strict';
-
-
-/**
- * @ngdoc object
- * @name ng.$routeProvider
- * @function
- *
- * @description
- *
- * Used for configuring routes. See {@link ng.$route $route} for an example.
- */
-function $RouteProvider(){
- var routes = {};
-
- /**
- * @ngdoc method
- * @name ng.$routeProvider#when
- * @methodOf ng.$routeProvider
- *
- * @param {string} path Route path (matched against `$location.path`). If `$location.path`
- * contains redundant trailing slash or is missing one, the route will still match and the
- * `$location.path` will be updated to add or drop the trailing slash to exactly match the
- * route definition.
- *
- * * `path` can contain named groups starting with a colon (`:name`). All characters up
- * to the next slash are matched and stored in `$routeParams` under the given `name`
- * when the route matches.
- * * `path` can contain named groups starting with a star (`*name`). All characters are
- * eagerly stored in `$routeParams` under the given `name` when the route matches.
- *
- * For example, routes like `/color/:color/largecode/*largecode/edit` will match
- * `/color/brown/largecode/code/with/slashs/edit` and extract:
- *
- * * `color: brown`
- * * `largecode: code/with/slashs`.
- *
- *
- * @param {Object} route Mapping information to be assigned to `$route.current` on route
- * match.
- *
- * Object properties:
- *
- * - `controller` – `{(string|function()=}` – Controller fn that should be associated with newly
- * created scope or the name of a {@link angular.Module#controller registered controller}
- * if passed as a string.
- * - `controllerAs` – `{string=}` – A controller alias name. If present the controller will be
- * published to scope under the `controllerAs` name.
- * - `template` – `{string=|function()=}` – html template as a string or function that returns
- * an html template as a string which should be used by {@link ng.directive:ngView ngView} or
- * {@link ng.directive:ngInclude ngInclude} directives.
- * This property takes precedence over `templateUrl`.
- *
- * If `template` is a function, it will be called with the following parameters:
- *
- * - `{Array.<Object>}` - route parameters extracted from the current
- * `$location.path()` by applying the current route
- *
- * - `templateUrl` – `{string=|function()=}` – path or function that returns a path to an html
- * template that should be used by {@link ng.directive:ngView ngView}.
- *
- * If `templateUrl` is a function, it will be called with the following parameters:
- *
- * - `{Array.<Object>}` - route parameters extracted from the current
- * `$location.path()` by applying the current route
- *
- * - `resolve` - `{Object.<string, function>=}` - An optional map of dependencies which should
- * be injected into the controller. If any of these dependencies are promises, they will be
- * resolved and converted to a value before the controller is instantiated and the
- * `$routeChangeSuccess` event is fired. The map object is:
- *
- * - `key` – `{string}`: a name of a dependency to be injected into the controller.
- * - `factory` - `{string|function}`: If `string` then it is an alias for a service.
- * Otherwise if function, then it is {@link api/AUTO.$injector#invoke injected}
- * and the return value is treated as the dependency. If the result is a promise, it is resolved
- * before its value is injected into the controller.
- *
- * - `redirectTo` – {(string|function())=} – value to update
- * {@link ng.$location $location} path with and trigger route redirection.
- *
- * If `redirectTo` is a function, it will be called with the following parameters:
- *
- * - `{Object.<string>}` - route parameters extracted from the current
- * `$location.path()` by applying the current route templateUrl.
- * - `{string}` - current `$location.path()`
- * - `{Object}` - current `$location.search()`
- *
- * The custom `redirectTo` function is expected to return a string which will be used
- * to update `$location.path()` and `$location.search()`.
- *
- * - `[reloadOnSearch=true]` - {boolean=} - reload route when only $location.search()
- * changes.
- *
- * If the option is set to `false` and url in the browser changes, then
- * `$routeUpdate` event is broadcasted on the root scope.
- *
- * - `[caseInsensitiveMatch=false]` - {boolean=} - match routes without being case sensitive
- *
- * If the option is set to `true`, then the particular route can be matched without being
- * case sensitive
- *
- * @returns {Object} self
- *
- * @description
- * Adds a new route definition to the `$route` service.
- */
- this.when = function(path, route) {
- routes[path] = extend({reloadOnSearch: true, caseInsensitiveMatch: false}, route);
-
- // create redirection for trailing slashes
- if (path) {
- var redirectPath = (path[path.length-1] == '/')
- ? path.substr(0, path.length-1)
- : path +'/';
-
- routes[redirectPath] = {redirectTo: path};
- }
-
- return this;
- };
-
- /**
- * @ngdoc method
- * @name ng.$routeProvider#otherwise
- * @methodOf ng.$routeProvider
- *
- * @description
- * 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`.
- * @returns {Object} self
- */
- this.otherwise = function(params) {
- this.when(null, params);
- return this;
- };
-
-
- this.$get = ['$rootScope', '$location', '$routeParams', '$q', '$injector', '$http', '$templateCache',
- function( $rootScope, $location, $routeParams, $q, $injector, $http, $templateCache) {
-
- /**
- * @ngdoc object
- * @name ng.$route
- * @requires $location
- * @requires $routeParams
- *
- * @property {Object} current Reference to the current route definition.
- * The route definition contains:
- *
- * - `controller`: The controller constructor as define in route definition.
- * - `locals`: A map of locals which is used by {@link ng.$controller $controller} service for
- * controller instantiation. The `locals` contain
- * the resolved values of the `resolve` map. Additionally the `locals` also contain:
- *
- * - `$scope` - The current route scope.
- * - `$template` - The current route template HTML.
- *
- * @property {Array.<Object>} routes Array of all configured routes.
- *
- * @description
- * Is used for deep-linking URLs to controllers and views (HTML partials).
- * It watches `$location.url()` and tries to map the path to an existing route definition.
- *
- * You can define routes through {@link ng.$routeProvider $routeProvider}'s API.
- *
- * The `$route` service is typically used in conjunction with {@link ng.directive:ngView ngView}
- * directive and the {@link ng.$routeParams $routeParams} service.
- *
- * @example
- 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 module="ngView">
- <file name="index.html">
- <div ng-controller="MainCntl">
- Choose:
- <a href="Book/Moby">Moby</a> |
- <a href="Book/Moby/ch/1">Moby: Ch1</a> |
- <a href="Book/Gatsby">Gatsby</a> |
- <a href="Book/Gatsby/ch/4?key=value">Gatsby: Ch4</a> |
- <a href="Book/Scarlet">Scarlet Letter</a><br/>
-
- <div ng-view></div>
- <hr />
-
- <pre>$location.path() = {{$location.path()}}</pre>
- <pre>$route.current.templateUrl = {{$route.current.templateUrl}}</pre>
- <pre>$route.current.params = {{$route.current.params}}</pre>
- <pre>$route.current.scope.name = {{$route.current.scope.name}}</pre>
- <pre>$routeParams = {{$routeParams}}</pre>
- </div>
- </file>
-
- <file name="book.html">
- controller: {{name}}<br />
- Book Id: {{params.bookId}}<br />
- </file>
-
- <file name="chapter.html">
- controller: {{name}}<br />
- Book Id: {{params.bookId}}<br />
- Chapter Id: {{params.chapterId}}
- </file>
-
- <file name="script.js">
- angular.module('ngView', [], function($routeProvider, $locationProvider) {
- $routeProvider.when('/Book/:bookId', {
- templateUrl: 'book.html',
- controller: BookCntl,
- resolve: {
- // I will cause a 1 second delay
- delay: function($q, $timeout) {
- var delay = $q.defer();
- $timeout(delay.resolve, 1000);
- return delay.promise;
- }
- }
- });
- $routeProvider.when('/Book/:bookId/ch/:chapterId', {
- templateUrl: 'chapter.html',
- controller: ChapterCntl
- });
-
- // configure html5 to get links working on jsfiddle
- $locationProvider.html5Mode(true);
- });
-
- function MainCntl($scope, $route, $routeParams, $location) {
- $scope.$route = $route;
- $scope.$location = $location;
- $scope.$routeParams = $routeParams;
- }
-
- function BookCntl($scope, $routeParams) {
- $scope.name = "BookCntl";
- $scope.params = $routeParams;
- }
-
- function ChapterCntl($scope, $routeParams) {
- $scope.name = "ChapterCntl";
- $scope.params = $routeParams;
- }
- </file>
-
- <file name="scenario.js">
- it('should load and compile correct template', function() {
- element('a:contains("Moby: Ch1")').click();
- var content = element('.doc-example-live [ng-view]').text();
- expect(content).toMatch(/controller\: ChapterCntl/);
- expect(content).toMatch(/Book Id\: Moby/);
- expect(content).toMatch(/Chapter Id\: 1/);
-
- element('a:contains("Scarlet")').click();
- sleep(2); // promises are not part of scenario waiting
- content = element('.doc-example-live [ng-view]').text();
- expect(content).toMatch(/controller\: BookCntl/);
- expect(content).toMatch(/Book Id\: Scarlet/);
- });
- </file>
- </example>
- */
-
- /**
- * @ngdoc event
- * @name ng.$route#$routeChangeStart
- * @eventOf ng.$route
- * @eventType broadcast on root scope
- * @description
- * Broadcasted before a route change. At this point the route services starts
- * resolving all of the dependencies needed for the route change to occurs.
- * Typically this involves fetching the view template as well as any dependencies
- * defined in `resolve` route property. Once all of the dependencies are resolved
- * `$routeChangeSuccess` is fired.
- *
- * @param {Route} next Future route information.
- * @param {Route} current Current route information.
- */
-
- /**
- * @ngdoc event
- * @name ng.$route#$routeChangeSuccess
- * @eventOf ng.$route
- * @eventType broadcast on root scope
- * @description
- * Broadcasted after a route dependencies are resolved.
- * {@link ng.directive:ngView ngView} listens for the directive
- * to instantiate the controller and render the view.
- *
- * @param {Object} angularEvent Synthetic event object.
- * @param {Route} current Current route information.
- * @param {Route|Undefined} previous Previous route information, or undefined if current is first route entered.
- */
-
- /**
- * @ngdoc event
- * @name ng.$route#$routeChangeError
- * @eventOf ng.$route
- * @eventType broadcast on root scope
- * @description
- * Broadcasted if any of the resolve promises are rejected.
- *
- * @param {Route} current Current route information.
- * @param {Route} previous Previous route information.
- * @param {Route} rejection Rejection of the promise. Usually the error of the failed promise.
- */
-
- /**
- * @ngdoc event
- * @name ng.$route#$routeUpdate
- * @eventOf ng.$route
- * @eventType broadcast on root scope
- * @description
- *
- * The `reloadOnSearch` property has been set to false, and we are reusing the same
- * instance of the Controller.
- */
-
- var forceReload = false,
- $route = {
- routes: routes,
-
- /**
- * @ngdoc method
- * @name ng.$route#reload
- * @methodOf ng.$route
- *
- * @description
- * Causes `$route` service to reload the current route even if
- * {@link ng.$location $location} hasn't changed.
- *
- * As a result of that, {@link ng.directive:ngView ngView}
- * creates new scope, reinstantiates the controller.
- */
- reload: function() {
- forceReload = true;
- $rootScope.$evalAsync(updateRoute);
- }
- };
-
- $rootScope.$on('$locationChangeSuccess', updateRoute);
-
- return $route;
-
- /////////////////////////////////////////////////////
-
- /**
- * @param on {string} current url
- * @param when {string} route when template to match the url against
- * @param whenProperties {Object} properties to define when's matching behavior
- * @return {?Object}
- */
- function switchRouteMatcher(on, when, whenProperties) {
- // TODO(i): this code is convoluted and inefficient, we should construct the route matching
- // regex only once and then reuse it
-
- // Escape regexp special characters.
- when = '^' + when.replace(/[-\/\\^$:*+?.()|[\]{}]/g, "\\$&") + '$';
-
- var regex = '',
- params = [],
- dst = {};
-
- var re = /\\([:*])(\w+)/g,
- paramMatch,
- lastMatchedIndex = 0;
-
- while ((paramMatch = re.exec(when)) !== null) {
- // Find each :param in `when` and replace it with a capturing group.
- // Append all other sections of when unchanged.
- regex += when.slice(lastMatchedIndex, paramMatch.index);
- switch(paramMatch[1]) {
- case ':':
- regex += '([^\\/]*)';
- break;
- case '*':
- regex += '(.*)';
- break;
- }
- params.push(paramMatch[2]);
- lastMatchedIndex = re.lastIndex;
- }
- // Append trailing path part.
- regex += when.substr(lastMatchedIndex);
-
- var match = on.match(new RegExp(regex, whenProperties.caseInsensitiveMatch ? 'i' : ''));
- if (match) {
- forEach(params, function(name, index) {
- dst[name] = match[index + 1];
- });
- }
- return match ? dst : null;
- }
-
- function updateRoute() {
- var next = parseRoute(),
- last = $route.current;
-
- if (next && last && next.$$route === last.$$route
- && equals(next.pathParams, last.pathParams) && !next.reloadOnSearch && !forceReload) {
- last.params = next.params;
- copy(last.params, $routeParams);
- $rootScope.$broadcast('$routeUpdate', last);
- } else if (next || last) {
- forceReload = false;
- $rootScope.$broadcast('$routeChangeStart', next, last);
- $route.current = next;
- if (next) {
- if (next.redirectTo) {
- if (isString(next.redirectTo)) {
- $location.path(interpolate(next.redirectTo, next.params)).search(next.params)
- .replace();
- } else {
- $location.url(next.redirectTo(next.pathParams, $location.path(), $location.search()))
- .replace();
- }
- }
- }
-
- $q.when(next).
- then(function() {
- if (next) {
- var locals = extend({}, next.resolve),
- template;
-
- forEach(locals, function(value, key) {
- locals[key] = isString(value) ? $injector.get(value) : $injector.invoke(value);
- });
-
- if (isDefined(template = next.template)) {
- if (isFunction(template)) {
- template = template(next.params);
- }
- } else if (isDefined(template = next.templateUrl)) {
- if (isFunction(template)) {
- template = template(next.params);
- }
- if (isDefined(template)) {
- next.loadedTemplateUrl = template;
- template = $http.get(template, {cache: $templateCache}).
- then(function(response) { return response.data; });
- }
- }
- if (isDefined(template)) {
- locals['$template'] = template;
- }
- return $q.all(locals);
- }
- }).
- // after route change
- then(function(locals) {
- if (next == $route.current) {
- if (next) {
- next.locals = locals;
- copy(next.params, $routeParams);
- }
- $rootScope.$broadcast('$routeChangeSuccess', next, last);
- }
- }, function(error) {
- if (next == $route.current) {
- $rootScope.$broadcast('$routeChangeError', next, last, error);
- }
- });
- }
- }
-
-
- /**
- * @returns the current active route, by matching it against the URL
- */
- function parseRoute() {
- // Match a route
- var params, match;
- forEach(routes, function(route, path) {
- if (!match && (params = switchRouteMatcher($location.path(), path, route))) {
- match = inherit(route, {
- params: extend({}, $location.search(), params),
- pathParams: params});
- match.$$route = route;
- }
- });
- // No route matched; fallback to "otherwise" route
- return match || routes[null] && inherit(routes[null], {params: {}, pathParams:{}});
- }
-
- /**
- * @returns interpolation of the redirect path with the parameters
- */
- function interpolate(string, params) {
- var result = [];
- forEach((string||'').split(':'), function(segment, i) {
- if (i == 0) {
- result.push(segment);
- } else {
- var segmentMatch = segment.match(/(\w+)(.*)/);
- var key = segmentMatch[1];
- result.push(params[key]);
- result.push(segmentMatch[2] || '');
- delete params[key];
- }
- });
- return result.join('');
- }
- }];
-}
diff --git a/src/ng/routeParams.js b/src/ng/routeParams.js
deleted file mode 100644
index 0202f8e5..00000000
--- a/src/ng/routeParams.js
+++ /dev/null
@@ -1,30 +0,0 @@
-'use strict';
-
-/**
- * @ngdoc object
- * @name ng.$routeParams
- * @requires $route
- *
- * @description
- * Current set of route parameters. The route parameters are a combination of the
- * {@link ng.$location $location} `search()`, and `path()`. The `path` parameters
- * are extracted when the {@link ng.$route $route} path is matched.
- *
- * In case of parameter name collision, `path` params take precedence over `search` params.
- *
- * The service guarantees that the identity of the `$routeParams` object will remain unchanged
- * (but its properties will likely change) even when a route change occurs.
- *
- * @example
- * <pre>
- * // Given:
- * // URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby
- * // Route: /Chapter/:chapterId/Section/:sectionId
- * //
- * // Then
- * $routeParams ==> {chapterId:1, sectionId:2, search:'moby'}
- * </pre>
- */
-function $RouteParamsProvider() {
- this.$get = valueFn({});
-}