From 5599b55b04788c2e327d7551a4a699d75516dd21 Mon Sep 17 00:00:00 2001
From: Igor Minar
Date: Wed, 5 Jun 2013 15:30:31 -0700
Subject: refactor($route): pull $route and friends into angular-route.js
$route, $routeParams and ngView have been pulled from core angular.js
to angular-route.js/ngRoute module.
This is was done to in order keep the core focused on most commonly
used functionality and allow community routers to be freely used
instead of $route service.
There is no need to panic, angular-route will keep on being supported
by the angular team.
Note: I'm intentionally not fixing tutorial links. Tutorial will need
bigger changes and those should be done when we update tutorial to
1.2.
BREAKING CHANGE: applications that use $route will now need to load
angular-route.js file and define dependency on ngRoute module.
Before:
```
...
...
var myApp = angular.module('myApp', ['someOtherModule']);
...
```
After:
```
...
...
var myApp = angular.module('myApp', ['ngRoute', 'someOtherModule']);
...
```
Closes #2804
---
src/ng/animator.js | 32 +--
src/ng/compile.js | 2 +-
src/ng/directive/ngController.js | 2 +-
src/ng/directive/ngView.js | 226 -----------------
src/ng/route.js | 509 ---------------------------------------
src/ng/routeParams.js | 30 ---
6 files changed, 18 insertions(+), 783 deletions(-)
delete mode 100644 src/ng/directive/ngView.js
delete mode 100644 src/ng/route.js
delete mode 100644 src/ng/routeParams.js
(limited to 'src/ng')
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
-
-
-
').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.