angularjs-rails 1.3.15 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/lib/angularjs-rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/angular-animate.js +3443 -1872
  4. data/vendor/assets/javascripts/angular-aria.js +89 -75
  5. data/vendor/assets/javascripts/angular-cookies.js +255 -141
  6. data/vendor/assets/javascripts/angular-loader.js +41 -17
  7. data/vendor/assets/javascripts/angular-message-format.js +980 -0
  8. data/vendor/assets/javascripts/angular-messages.js +430 -153
  9. data/vendor/assets/javascripts/angular-mocks.js +76 -92
  10. data/vendor/assets/javascripts/angular-resource.js +6 -6
  11. data/vendor/assets/javascripts/angular-route.js +8 -6
  12. data/vendor/assets/javascripts/angular-sanitize.js +32 -28
  13. data/vendor/assets/javascripts/angular-scenario.js +4315 -2452
  14. data/vendor/assets/javascripts/angular-touch.js +26 -21
  15. data/vendor/assets/javascripts/angular.js +4314 -2490
  16. data/vendor/assets/javascripts/unstable/angular2.js +24024 -0
  17. metadata +4 -14
  18. data/vendor/assets/javascripts/unstable/angular-animate.js +0 -2137
  19. data/vendor/assets/javascripts/unstable/angular-aria.js +0 -364
  20. data/vendor/assets/javascripts/unstable/angular-cookies.js +0 -206
  21. data/vendor/assets/javascripts/unstable/angular-loader.js +0 -405
  22. data/vendor/assets/javascripts/unstable/angular-messages.js +0 -401
  23. data/vendor/assets/javascripts/unstable/angular-mocks.js +0 -2468
  24. data/vendor/assets/javascripts/unstable/angular-resource.js +0 -668
  25. data/vendor/assets/javascripts/unstable/angular-route.js +0 -989
  26. data/vendor/assets/javascripts/unstable/angular-sanitize.js +0 -679
  27. data/vendor/assets/javascripts/unstable/angular-scenario.js +0 -37678
  28. data/vendor/assets/javascripts/unstable/angular-touch.js +0 -622
  29. data/vendor/assets/javascripts/unstable/angular.js +0 -26309
@@ -1,989 +0,0 @@
1
- /**
2
- * @license AngularJS v1.3.15
3
- * (c) 2010-2014 Google, Inc. http://angularjs.org
4
- * License: MIT
5
- */
6
- (function(window, angular, undefined) {'use strict';
7
-
8
- /**
9
- * @ngdoc module
10
- * @name ngRoute
11
- * @description
12
- *
13
- * # ngRoute
14
- *
15
- * The `ngRoute` module provides routing and deeplinking services and directives for angular apps.
16
- *
17
- * ## Example
18
- * See {@link ngRoute.$route#example $route} for an example of configuring and using `ngRoute`.
19
- *
20
- *
21
- * <div doc-module-components="ngRoute"></div>
22
- */
23
- /* global -ngRouteModule */
24
- var ngRouteModule = angular.module('ngRoute', ['ng']).
25
- provider('$route', $RouteProvider),
26
- $routeMinErr = angular.$$minErr('ngRoute');
27
-
28
- /**
29
- * @ngdoc provider
30
- * @name $routeProvider
31
- *
32
- * @description
33
- *
34
- * Used for configuring routes.
35
- *
36
- * ## Example
37
- * See {@link ngRoute.$route#example $route} for an example of configuring and using `ngRoute`.
38
- *
39
- * ## Dependencies
40
- * Requires the {@link ngRoute `ngRoute`} module to be installed.
41
- */
42
- function $RouteProvider() {
43
- function inherit(parent, extra) {
44
- return angular.extend(Object.create(parent), extra);
45
- }
46
-
47
- var routes = {};
48
-
49
- /**
50
- * @ngdoc method
51
- * @name $routeProvider#when
52
- *
53
- * @param {string} path Route path (matched against `$location.path`). If `$location.path`
54
- * contains redundant trailing slash or is missing one, the route will still match and the
55
- * `$location.path` will be updated to add or drop the trailing slash to exactly match the
56
- * route definition.
57
- *
58
- * * `path` can contain named groups starting with a colon: e.g. `:name`. All characters up
59
- * to the next slash are matched and stored in `$routeParams` under the given `name`
60
- * when the route matches.
61
- * * `path` can contain named groups starting with a colon and ending with a star:
62
- * e.g.`:name*`. All characters are eagerly stored in `$routeParams` under the given `name`
63
- * when the route matches.
64
- * * `path` can contain optional named groups with a question mark: e.g.`:name?`.
65
- *
66
- * For example, routes like `/color/:color/largecode/:largecode*\/edit` will match
67
- * `/color/brown/largecode/code/with/slashes/edit` and extract:
68
- *
69
- * * `color: brown`
70
- * * `largecode: code/with/slashes`.
71
- *
72
- *
73
- * @param {Object} route Mapping information to be assigned to `$route.current` on route
74
- * match.
75
- *
76
- * Object properties:
77
- *
78
- * - `controller` – `{(string|function()=}` – Controller fn that should be associated with
79
- * newly created scope or the name of a {@link angular.Module#controller registered
80
- * controller} if passed as a string.
81
- * - `controllerAs` – `{string=}` – A controller alias name. If present the controller will be
82
- * published to scope under the `controllerAs` name.
83
- * - `template` – `{string=|function()=}` – html template as a string or a function that
84
- * returns an html template as a string which should be used by {@link
85
- * ngRoute.directive:ngView ngView} or {@link ng.directive:ngInclude ngInclude} directives.
86
- * This property takes precedence over `templateUrl`.
87
- *
88
- * If `template` is a function, it will be called with the following parameters:
89
- *
90
- * - `{Array.<Object>}` - route parameters extracted from the current
91
- * `$location.path()` by applying the current route
92
- *
93
- * - `templateUrl` – `{string=|function()=}` – path or function that returns a path to an html
94
- * template that should be used by {@link ngRoute.directive:ngView ngView}.
95
- *
96
- * If `templateUrl` is a function, it will be called with the following parameters:
97
- *
98
- * - `{Array.<Object>}` - route parameters extracted from the current
99
- * `$location.path()` by applying the current route
100
- *
101
- * - `resolve` - `{Object.<string, function>=}` - An optional map of dependencies which should
102
- * be injected into the controller. If any of these dependencies are promises, the router
103
- * will wait for them all to be resolved or one to be rejected before the controller is
104
- * instantiated.
105
- * If all the promises are resolved successfully, the values of the resolved promises are
106
- * injected and {@link ngRoute.$route#$routeChangeSuccess $routeChangeSuccess} event is
107
- * fired. If any of the promises are rejected the
108
- * {@link ngRoute.$route#$routeChangeError $routeChangeError} event is fired. The map object
109
- * is:
110
- *
111
- * - `key` – `{string}`: a name of a dependency to be injected into the controller.
112
- * - `factory` - `{string|function}`: If `string` then it is an alias for a service.
113
- * Otherwise if function, then it is {@link auto.$injector#invoke injected}
114
- * and the return value is treated as the dependency. If the result is a promise, it is
115
- * resolved before its value is injected into the controller. Be aware that
116
- * `ngRoute.$routeParams` will still refer to the previous route within these resolve
117
- * functions. Use `$route.current.params` to access the new route parameters, instead.
118
- *
119
- * - `redirectTo` – {(string|function())=} – value to update
120
- * {@link ng.$location $location} path with and trigger route redirection.
121
- *
122
- * If `redirectTo` is a function, it will be called with the following parameters:
123
- *
124
- * - `{Object.<string>}` - route parameters extracted from the current
125
- * `$location.path()` by applying the current route templateUrl.
126
- * - `{string}` - current `$location.path()`
127
- * - `{Object}` - current `$location.search()`
128
- *
129
- * The custom `redirectTo` function is expected to return a string which will be used
130
- * to update `$location.path()` and `$location.search()`.
131
- *
132
- * - `[reloadOnSearch=true]` - {boolean=} - reload route when only `$location.search()`
133
- * or `$location.hash()` changes.
134
- *
135
- * If the option is set to `false` and url in the browser changes, then
136
- * `$routeUpdate` event is broadcasted on the root scope.
137
- *
138
- * - `[caseInsensitiveMatch=false]` - {boolean=} - match routes without being case sensitive
139
- *
140
- * If the option is set to `true`, then the particular route can be matched without being
141
- * case sensitive
142
- *
143
- * @returns {Object} self
144
- *
145
- * @description
146
- * Adds a new route definition to the `$route` service.
147
- */
148
- this.when = function(path, route) {
149
- //copy original route object to preserve params inherited from proto chain
150
- var routeCopy = angular.copy(route);
151
- if (angular.isUndefined(routeCopy.reloadOnSearch)) {
152
- routeCopy.reloadOnSearch = true;
153
- }
154
- if (angular.isUndefined(routeCopy.caseInsensitiveMatch)) {
155
- routeCopy.caseInsensitiveMatch = this.caseInsensitiveMatch;
156
- }
157
- routes[path] = angular.extend(
158
- routeCopy,
159
- path && pathRegExp(path, routeCopy)
160
- );
161
-
162
- // create redirection for trailing slashes
163
- if (path) {
164
- var redirectPath = (path[path.length - 1] == '/')
165
- ? path.substr(0, path.length - 1)
166
- : path + '/';
167
-
168
- routes[redirectPath] = angular.extend(
169
- {redirectTo: path},
170
- pathRegExp(redirectPath, routeCopy)
171
- );
172
- }
173
-
174
- return this;
175
- };
176
-
177
- /**
178
- * @ngdoc property
179
- * @name $routeProvider#caseInsensitiveMatch
180
- * @description
181
- *
182
- * A boolean property indicating if routes defined
183
- * using this provider should be matched using a case insensitive
184
- * algorithm. Defaults to `false`.
185
- */
186
- this.caseInsensitiveMatch = false;
187
-
188
- /**
189
- * @param path {string} path
190
- * @param opts {Object} options
191
- * @return {?Object}
192
- *
193
- * @description
194
- * Normalizes the given path, returning a regular expression
195
- * and the original path.
196
- *
197
- * Inspired by pathRexp in visionmedia/express/lib/utils.js.
198
- */
199
- function pathRegExp(path, opts) {
200
- var insensitive = opts.caseInsensitiveMatch,
201
- ret = {
202
- originalPath: path,
203
- regexp: path
204
- },
205
- keys = ret.keys = [];
206
-
207
- path = path
208
- .replace(/([().])/g, '\\$1')
209
- .replace(/(\/)?:(\w+)([\?\*])?/g, function(_, slash, key, option) {
210
- var optional = option === '?' ? option : null;
211
- var star = option === '*' ? option : null;
212
- keys.push({ name: key, optional: !!optional });
213
- slash = slash || '';
214
- return ''
215
- + (optional ? '' : slash)
216
- + '(?:'
217
- + (optional ? slash : '')
218
- + (star && '(.+?)' || '([^/]+)')
219
- + (optional || '')
220
- + ')'
221
- + (optional || '');
222
- })
223
- .replace(/([\/$\*])/g, '\\$1');
224
-
225
- ret.regexp = new RegExp('^' + path + '$', insensitive ? 'i' : '');
226
- return ret;
227
- }
228
-
229
- /**
230
- * @ngdoc method
231
- * @name $routeProvider#otherwise
232
- *
233
- * @description
234
- * Sets route definition that will be used on route change when no other route definition
235
- * is matched.
236
- *
237
- * @param {Object|string} params Mapping information to be assigned to `$route.current`.
238
- * If called with a string, the value maps to `redirectTo`.
239
- * @returns {Object} self
240
- */
241
- this.otherwise = function(params) {
242
- if (typeof params === 'string') {
243
- params = {redirectTo: params};
244
- }
245
- this.when(null, params);
246
- return this;
247
- };
248
-
249
-
250
- this.$get = ['$rootScope',
251
- '$location',
252
- '$routeParams',
253
- '$q',
254
- '$injector',
255
- '$templateRequest',
256
- '$sce',
257
- function($rootScope, $location, $routeParams, $q, $injector, $templateRequest, $sce) {
258
-
259
- /**
260
- * @ngdoc service
261
- * @name $route
262
- * @requires $location
263
- * @requires $routeParams
264
- *
265
- * @property {Object} current Reference to the current route definition.
266
- * The route definition contains:
267
- *
268
- * - `controller`: The controller constructor as define in route definition.
269
- * - `locals`: A map of locals which is used by {@link ng.$controller $controller} service for
270
- * controller instantiation. The `locals` contain
271
- * the resolved values of the `resolve` map. Additionally the `locals` also contain:
272
- *
273
- * - `$scope` - The current route scope.
274
- * - `$template` - The current route template HTML.
275
- *
276
- * @property {Object} routes Object with all route configuration Objects as its properties.
277
- *
278
- * @description
279
- * `$route` is used for deep-linking URLs to controllers and views (HTML partials).
280
- * It watches `$location.url()` and tries to map the path to an existing route definition.
281
- *
282
- * Requires the {@link ngRoute `ngRoute`} module to be installed.
283
- *
284
- * You can define routes through {@link ngRoute.$routeProvider $routeProvider}'s API.
285
- *
286
- * The `$route` service is typically used in conjunction with the
287
- * {@link ngRoute.directive:ngView `ngView`} directive and the
288
- * {@link ngRoute.$routeParams `$routeParams`} service.
289
- *
290
- * @example
291
- * This example shows how changing the URL hash causes the `$route` to match a route against the
292
- * URL, and the `ngView` pulls in the partial.
293
- *
294
- * <example name="$route-service" module="ngRouteExample"
295
- * deps="angular-route.js" fixBase="true">
296
- * <file name="index.html">
297
- * <div ng-controller="MainController">
298
- * Choose:
299
- * <a href="Book/Moby">Moby</a> |
300
- * <a href="Book/Moby/ch/1">Moby: Ch1</a> |
301
- * <a href="Book/Gatsby">Gatsby</a> |
302
- * <a href="Book/Gatsby/ch/4?key=value">Gatsby: Ch4</a> |
303
- * <a href="Book/Scarlet">Scarlet Letter</a><br/>
304
- *
305
- * <div ng-view></div>
306
- *
307
- * <hr />
308
- *
309
- * <pre>$location.path() = {{$location.path()}}</pre>
310
- * <pre>$route.current.templateUrl = {{$route.current.templateUrl}}</pre>
311
- * <pre>$route.current.params = {{$route.current.params}}</pre>
312
- * <pre>$route.current.scope.name = {{$route.current.scope.name}}</pre>
313
- * <pre>$routeParams = {{$routeParams}}</pre>
314
- * </div>
315
- * </file>
316
- *
317
- * <file name="book.html">
318
- * controller: {{name}}<br />
319
- * Book Id: {{params.bookId}}<br />
320
- * </file>
321
- *
322
- * <file name="chapter.html">
323
- * controller: {{name}}<br />
324
- * Book Id: {{params.bookId}}<br />
325
- * Chapter Id: {{params.chapterId}}
326
- * </file>
327
- *
328
- * <file name="script.js">
329
- * angular.module('ngRouteExample', ['ngRoute'])
330
- *
331
- * .controller('MainController', function($scope, $route, $routeParams, $location) {
332
- * $scope.$route = $route;
333
- * $scope.$location = $location;
334
- * $scope.$routeParams = $routeParams;
335
- * })
336
- *
337
- * .controller('BookController', function($scope, $routeParams) {
338
- * $scope.name = "BookController";
339
- * $scope.params = $routeParams;
340
- * })
341
- *
342
- * .controller('ChapterController', function($scope, $routeParams) {
343
- * $scope.name = "ChapterController";
344
- * $scope.params = $routeParams;
345
- * })
346
- *
347
- * .config(function($routeProvider, $locationProvider) {
348
- * $routeProvider
349
- * .when('/Book/:bookId', {
350
- * templateUrl: 'book.html',
351
- * controller: 'BookController',
352
- * resolve: {
353
- * // I will cause a 1 second delay
354
- * delay: function($q, $timeout) {
355
- * var delay = $q.defer();
356
- * $timeout(delay.resolve, 1000);
357
- * return delay.promise;
358
- * }
359
- * }
360
- * })
361
- * .when('/Book/:bookId/ch/:chapterId', {
362
- * templateUrl: 'chapter.html',
363
- * controller: 'ChapterController'
364
- * });
365
- *
366
- * // configure html5 to get links working on jsfiddle
367
- * $locationProvider.html5Mode(true);
368
- * });
369
- *
370
- * </file>
371
- *
372
- * <file name="protractor.js" type="protractor">
373
- * it('should load and compile correct template', function() {
374
- * element(by.linkText('Moby: Ch1')).click();
375
- * var content = element(by.css('[ng-view]')).getText();
376
- * expect(content).toMatch(/controller\: ChapterController/);
377
- * expect(content).toMatch(/Book Id\: Moby/);
378
- * expect(content).toMatch(/Chapter Id\: 1/);
379
- *
380
- * element(by.partialLinkText('Scarlet')).click();
381
- *
382
- * content = element(by.css('[ng-view]')).getText();
383
- * expect(content).toMatch(/controller\: BookController/);
384
- * expect(content).toMatch(/Book Id\: Scarlet/);
385
- * });
386
- * </file>
387
- * </example>
388
- */
389
-
390
- /**
391
- * @ngdoc event
392
- * @name $route#$routeChangeStart
393
- * @eventType broadcast on root scope
394
- * @description
395
- * Broadcasted before a route change. At this point the route services starts
396
- * resolving all of the dependencies needed for the route change to occur.
397
- * Typically this involves fetching the view template as well as any dependencies
398
- * defined in `resolve` route property. Once all of the dependencies are resolved
399
- * `$routeChangeSuccess` is fired.
400
- *
401
- * The route change (and the `$location` change that triggered it) can be prevented
402
- * by calling `preventDefault` method of the event. See {@link ng.$rootScope.Scope#$on}
403
- * for more details about event object.
404
- *
405
- * @param {Object} angularEvent Synthetic event object.
406
- * @param {Route} next Future route information.
407
- * @param {Route} current Current route information.
408
- */
409
-
410
- /**
411
- * @ngdoc event
412
- * @name $route#$routeChangeSuccess
413
- * @eventType broadcast on root scope
414
- * @description
415
- * Broadcasted after a route dependencies are resolved.
416
- * {@link ngRoute.directive:ngView ngView} listens for the directive
417
- * to instantiate the controller and render the view.
418
- *
419
- * @param {Object} angularEvent Synthetic event object.
420
- * @param {Route} current Current route information.
421
- * @param {Route|Undefined} previous Previous route information, or undefined if current is
422
- * first route entered.
423
- */
424
-
425
- /**
426
- * @ngdoc event
427
- * @name $route#$routeChangeError
428
- * @eventType broadcast on root scope
429
- * @description
430
- * Broadcasted if any of the resolve promises are rejected.
431
- *
432
- * @param {Object} angularEvent Synthetic event object
433
- * @param {Route} current Current route information.
434
- * @param {Route} previous Previous route information.
435
- * @param {Route} rejection Rejection of the promise. Usually the error of the failed promise.
436
- */
437
-
438
- /**
439
- * @ngdoc event
440
- * @name $route#$routeUpdate
441
- * @eventType broadcast on root scope
442
- * @description
443
- *
444
- * The `reloadOnSearch` property has been set to false, and we are reusing the same
445
- * instance of the Controller.
446
- */
447
-
448
- var forceReload = false,
449
- preparedRoute,
450
- preparedRouteIsUpdateOnly,
451
- $route = {
452
- routes: routes,
453
-
454
- /**
455
- * @ngdoc method
456
- * @name $route#reload
457
- *
458
- * @description
459
- * Causes `$route` service to reload the current route even if
460
- * {@link ng.$location $location} hasn't changed.
461
- *
462
- * As a result of that, {@link ngRoute.directive:ngView ngView}
463
- * creates new scope and reinstantiates the controller.
464
- */
465
- reload: function() {
466
- forceReload = true;
467
- $rootScope.$evalAsync(function() {
468
- // Don't support cancellation of a reload for now...
469
- prepareRoute();
470
- commitRoute();
471
- });
472
- },
473
-
474
- /**
475
- * @ngdoc method
476
- * @name $route#updateParams
477
- *
478
- * @description
479
- * Causes `$route` service to update the current URL, replacing
480
- * current route parameters with those specified in `newParams`.
481
- * Provided property names that match the route's path segment
482
- * definitions will be interpolated into the location's path, while
483
- * remaining properties will be treated as query params.
484
- *
485
- * @param {!Object<string, string>} newParams mapping of URL parameter names to values
486
- */
487
- updateParams: function(newParams) {
488
- if (this.current && this.current.$$route) {
489
- newParams = angular.extend({}, this.current.params, newParams);
490
- $location.path(interpolate(this.current.$$route.originalPath, newParams));
491
- // interpolate modifies newParams, only query params are left
492
- $location.search(newParams);
493
- } else {
494
- throw $routeMinErr('norout', 'Tried updating route when with no current route');
495
- }
496
- }
497
- };
498
-
499
- $rootScope.$on('$locationChangeStart', prepareRoute);
500
- $rootScope.$on('$locationChangeSuccess', commitRoute);
501
-
502
- return $route;
503
-
504
- /////////////////////////////////////////////////////
505
-
506
- /**
507
- * @param on {string} current url
508
- * @param route {Object} route regexp to match the url against
509
- * @return {?Object}
510
- *
511
- * @description
512
- * Check if the route matches the current url.
513
- *
514
- * Inspired by match in
515
- * visionmedia/express/lib/router/router.js.
516
- */
517
- function switchRouteMatcher(on, route) {
518
- var keys = route.keys,
519
- params = {};
520
-
521
- if (!route.regexp) return null;
522
-
523
- var m = route.regexp.exec(on);
524
- if (!m) return null;
525
-
526
- for (var i = 1, len = m.length; i < len; ++i) {
527
- var key = keys[i - 1];
528
-
529
- var val = m[i];
530
-
531
- if (key && val) {
532
- params[key.name] = val;
533
- }
534
- }
535
- return params;
536
- }
537
-
538
- function prepareRoute($locationEvent) {
539
- var lastRoute = $route.current;
540
-
541
- preparedRoute = parseRoute();
542
- preparedRouteIsUpdateOnly = preparedRoute && lastRoute && preparedRoute.$$route === lastRoute.$$route
543
- && angular.equals(preparedRoute.pathParams, lastRoute.pathParams)
544
- && !preparedRoute.reloadOnSearch && !forceReload;
545
-
546
- if (!preparedRouteIsUpdateOnly && (lastRoute || preparedRoute)) {
547
- if ($rootScope.$broadcast('$routeChangeStart', preparedRoute, lastRoute).defaultPrevented) {
548
- if ($locationEvent) {
549
- $locationEvent.preventDefault();
550
- }
551
- }
552
- }
553
- }
554
-
555
- function commitRoute() {
556
- var lastRoute = $route.current;
557
- var nextRoute = preparedRoute;
558
-
559
- if (preparedRouteIsUpdateOnly) {
560
- lastRoute.params = nextRoute.params;
561
- angular.copy(lastRoute.params, $routeParams);
562
- $rootScope.$broadcast('$routeUpdate', lastRoute);
563
- } else if (nextRoute || lastRoute) {
564
- forceReload = false;
565
- $route.current = nextRoute;
566
- if (nextRoute) {
567
- if (nextRoute.redirectTo) {
568
- if (angular.isString(nextRoute.redirectTo)) {
569
- $location.path(interpolate(nextRoute.redirectTo, nextRoute.params)).search(nextRoute.params)
570
- .replace();
571
- } else {
572
- $location.url(nextRoute.redirectTo(nextRoute.pathParams, $location.path(), $location.search()))
573
- .replace();
574
- }
575
- }
576
- }
577
-
578
- $q.when(nextRoute).
579
- then(function() {
580
- if (nextRoute) {
581
- var locals = angular.extend({}, nextRoute.resolve),
582
- template, templateUrl;
583
-
584
- angular.forEach(locals, function(value, key) {
585
- locals[key] = angular.isString(value) ?
586
- $injector.get(value) : $injector.invoke(value, null, null, key);
587
- });
588
-
589
- if (angular.isDefined(template = nextRoute.template)) {
590
- if (angular.isFunction(template)) {
591
- template = template(nextRoute.params);
592
- }
593
- } else if (angular.isDefined(templateUrl = nextRoute.templateUrl)) {
594
- if (angular.isFunction(templateUrl)) {
595
- templateUrl = templateUrl(nextRoute.params);
596
- }
597
- templateUrl = $sce.getTrustedResourceUrl(templateUrl);
598
- if (angular.isDefined(templateUrl)) {
599
- nextRoute.loadedTemplateUrl = templateUrl;
600
- template = $templateRequest(templateUrl);
601
- }
602
- }
603
- if (angular.isDefined(template)) {
604
- locals['$template'] = template;
605
- }
606
- return $q.all(locals);
607
- }
608
- }).
609
- // after route change
610
- then(function(locals) {
611
- if (nextRoute == $route.current) {
612
- if (nextRoute) {
613
- nextRoute.locals = locals;
614
- angular.copy(nextRoute.params, $routeParams);
615
- }
616
- $rootScope.$broadcast('$routeChangeSuccess', nextRoute, lastRoute);
617
- }
618
- }, function(error) {
619
- if (nextRoute == $route.current) {
620
- $rootScope.$broadcast('$routeChangeError', nextRoute, lastRoute, error);
621
- }
622
- });
623
- }
624
- }
625
-
626
-
627
- /**
628
- * @returns {Object} the current active route, by matching it against the URL
629
- */
630
- function parseRoute() {
631
- // Match a route
632
- var params, match;
633
- angular.forEach(routes, function(route, path) {
634
- if (!match && (params = switchRouteMatcher($location.path(), route))) {
635
- match = inherit(route, {
636
- params: angular.extend({}, $location.search(), params),
637
- pathParams: params});
638
- match.$$route = route;
639
- }
640
- });
641
- // No route matched; fallback to "otherwise" route
642
- return match || routes[null] && inherit(routes[null], {params: {}, pathParams:{}});
643
- }
644
-
645
- /**
646
- * @returns {string} interpolation of the redirect path with the parameters
647
- */
648
- function interpolate(string, params) {
649
- var result = [];
650
- angular.forEach((string || '').split(':'), function(segment, i) {
651
- if (i === 0) {
652
- result.push(segment);
653
- } else {
654
- var segmentMatch = segment.match(/(\w+)(?:[?*])?(.*)/);
655
- var key = segmentMatch[1];
656
- result.push(params[key]);
657
- result.push(segmentMatch[2] || '');
658
- delete params[key];
659
- }
660
- });
661
- return result.join('');
662
- }
663
- }];
664
- }
665
-
666
- ngRouteModule.provider('$routeParams', $RouteParamsProvider);
667
-
668
-
669
- /**
670
- * @ngdoc service
671
- * @name $routeParams
672
- * @requires $route
673
- *
674
- * @description
675
- * The `$routeParams` service allows you to retrieve the current set of route parameters.
676
- *
677
- * Requires the {@link ngRoute `ngRoute`} module to be installed.
678
- *
679
- * The route parameters are a combination of {@link ng.$location `$location`}'s
680
- * {@link ng.$location#search `search()`} and {@link ng.$location#path `path()`}.
681
- * The `path` parameters are extracted when the {@link ngRoute.$route `$route`} path is matched.
682
- *
683
- * In case of parameter name collision, `path` params take precedence over `search` params.
684
- *
685
- * The service guarantees that the identity of the `$routeParams` object will remain unchanged
686
- * (but its properties will likely change) even when a route change occurs.
687
- *
688
- * Note that the `$routeParams` are only updated *after* a route change completes successfully.
689
- * This means that you cannot rely on `$routeParams` being correct in route resolve functions.
690
- * Instead you can use `$route.current.params` to access the new route's parameters.
691
- *
692
- * @example
693
- * ```js
694
- * // Given:
695
- * // URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby
696
- * // Route: /Chapter/:chapterId/Section/:sectionId
697
- * //
698
- * // Then
699
- * $routeParams ==> {chapterId:'1', sectionId:'2', search:'moby'}
700
- * ```
701
- */
702
- function $RouteParamsProvider() {
703
- this.$get = function() { return {}; };
704
- }
705
-
706
- ngRouteModule.directive('ngView', ngViewFactory);
707
- ngRouteModule.directive('ngView', ngViewFillContentFactory);
708
-
709
-
710
- /**
711
- * @ngdoc directive
712
- * @name ngView
713
- * @restrict ECA
714
- *
715
- * @description
716
- * # Overview
717
- * `ngView` is a directive that complements the {@link ngRoute.$route $route} service by
718
- * including the rendered template of the current route into the main layout (`index.html`) file.
719
- * Every time the current route changes, the included view changes with it according to the
720
- * configuration of the `$route` service.
721
- *
722
- * Requires the {@link ngRoute `ngRoute`} module to be installed.
723
- *
724
- * @animations
725
- * enter - animation is used to bring new content into the browser.
726
- * leave - animation is used to animate existing content away.
727
- *
728
- * The enter and leave animation occur concurrently.
729
- *
730
- * @scope
731
- * @priority 400
732
- * @param {string=} onload Expression to evaluate whenever the view updates.
733
- *
734
- * @param {string=} autoscroll Whether `ngView` should call {@link ng.$anchorScroll
735
- * $anchorScroll} to scroll the viewport after the view is updated.
736
- *
737
- * - If the attribute is not set, disable scrolling.
738
- * - If the attribute is set without value, enable scrolling.
739
- * - Otherwise enable scrolling only if the `autoscroll` attribute value evaluated
740
- * as an expression yields a truthy value.
741
- * @example
742
- <example name="ngView-directive" module="ngViewExample"
743
- deps="angular-route.js;angular-animate.js"
744
- animations="true" fixBase="true">
745
- <file name="index.html">
746
- <div ng-controller="MainCtrl as main">
747
- Choose:
748
- <a href="Book/Moby">Moby</a> |
749
- <a href="Book/Moby/ch/1">Moby: Ch1</a> |
750
- <a href="Book/Gatsby">Gatsby</a> |
751
- <a href="Book/Gatsby/ch/4?key=value">Gatsby: Ch4</a> |
752
- <a href="Book/Scarlet">Scarlet Letter</a><br/>
753
-
754
- <div class="view-animate-container">
755
- <div ng-view class="view-animate"></div>
756
- </div>
757
- <hr />
758
-
759
- <pre>$location.path() = {{main.$location.path()}}</pre>
760
- <pre>$route.current.templateUrl = {{main.$route.current.templateUrl}}</pre>
761
- <pre>$route.current.params = {{main.$route.current.params}}</pre>
762
- <pre>$routeParams = {{main.$routeParams}}</pre>
763
- </div>
764
- </file>
765
-
766
- <file name="book.html">
767
- <div>
768
- controller: {{book.name}}<br />
769
- Book Id: {{book.params.bookId}}<br />
770
- </div>
771
- </file>
772
-
773
- <file name="chapter.html">
774
- <div>
775
- controller: {{chapter.name}}<br />
776
- Book Id: {{chapter.params.bookId}}<br />
777
- Chapter Id: {{chapter.params.chapterId}}
778
- </div>
779
- </file>
780
-
781
- <file name="animations.css">
782
- .view-animate-container {
783
- position:relative;
784
- height:100px!important;
785
- background:white;
786
- border:1px solid black;
787
- height:40px;
788
- overflow:hidden;
789
- }
790
-
791
- .view-animate {
792
- padding:10px;
793
- }
794
-
795
- .view-animate.ng-enter, .view-animate.ng-leave {
796
- -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
797
- transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
798
-
799
- display:block;
800
- width:100%;
801
- border-left:1px solid black;
802
-
803
- position:absolute;
804
- top:0;
805
- left:0;
806
- right:0;
807
- bottom:0;
808
- padding:10px;
809
- }
810
-
811
- .view-animate.ng-enter {
812
- left:100%;
813
- }
814
- .view-animate.ng-enter.ng-enter-active {
815
- left:0;
816
- }
817
- .view-animate.ng-leave.ng-leave-active {
818
- left:-100%;
819
- }
820
- </file>
821
-
822
- <file name="script.js">
823
- angular.module('ngViewExample', ['ngRoute', 'ngAnimate'])
824
- .config(['$routeProvider', '$locationProvider',
825
- function($routeProvider, $locationProvider) {
826
- $routeProvider
827
- .when('/Book/:bookId', {
828
- templateUrl: 'book.html',
829
- controller: 'BookCtrl',
830
- controllerAs: 'book'
831
- })
832
- .when('/Book/:bookId/ch/:chapterId', {
833
- templateUrl: 'chapter.html',
834
- controller: 'ChapterCtrl',
835
- controllerAs: 'chapter'
836
- });
837
-
838
- $locationProvider.html5Mode(true);
839
- }])
840
- .controller('MainCtrl', ['$route', '$routeParams', '$location',
841
- function($route, $routeParams, $location) {
842
- this.$route = $route;
843
- this.$location = $location;
844
- this.$routeParams = $routeParams;
845
- }])
846
- .controller('BookCtrl', ['$routeParams', function($routeParams) {
847
- this.name = "BookCtrl";
848
- this.params = $routeParams;
849
- }])
850
- .controller('ChapterCtrl', ['$routeParams', function($routeParams) {
851
- this.name = "ChapterCtrl";
852
- this.params = $routeParams;
853
- }]);
854
-
855
- </file>
856
-
857
- <file name="protractor.js" type="protractor">
858
- it('should load and compile correct template', function() {
859
- element(by.linkText('Moby: Ch1')).click();
860
- var content = element(by.css('[ng-view]')).getText();
861
- expect(content).toMatch(/controller\: ChapterCtrl/);
862
- expect(content).toMatch(/Book Id\: Moby/);
863
- expect(content).toMatch(/Chapter Id\: 1/);
864
-
865
- element(by.partialLinkText('Scarlet')).click();
866
-
867
- content = element(by.css('[ng-view]')).getText();
868
- expect(content).toMatch(/controller\: BookCtrl/);
869
- expect(content).toMatch(/Book Id\: Scarlet/);
870
- });
871
- </file>
872
- </example>
873
- */
874
-
875
-
876
- /**
877
- * @ngdoc event
878
- * @name ngView#$viewContentLoaded
879
- * @eventType emit on the current ngView scope
880
- * @description
881
- * Emitted every time the ngView content is reloaded.
882
- */
883
- ngViewFactory.$inject = ['$route', '$anchorScroll', '$animate'];
884
- function ngViewFactory($route, $anchorScroll, $animate) {
885
- return {
886
- restrict: 'ECA',
887
- terminal: true,
888
- priority: 400,
889
- transclude: 'element',
890
- link: function(scope, $element, attr, ctrl, $transclude) {
891
- var currentScope,
892
- currentElement,
893
- previousLeaveAnimation,
894
- autoScrollExp = attr.autoscroll,
895
- onloadExp = attr.onload || '';
896
-
897
- scope.$on('$routeChangeSuccess', update);
898
- update();
899
-
900
- function cleanupLastView() {
901
- if (previousLeaveAnimation) {
902
- $animate.cancel(previousLeaveAnimation);
903
- previousLeaveAnimation = null;
904
- }
905
-
906
- if (currentScope) {
907
- currentScope.$destroy();
908
- currentScope = null;
909
- }
910
- if (currentElement) {
911
- previousLeaveAnimation = $animate.leave(currentElement);
912
- previousLeaveAnimation.then(function() {
913
- previousLeaveAnimation = null;
914
- });
915
- currentElement = null;
916
- }
917
- }
918
-
919
- function update() {
920
- var locals = $route.current && $route.current.locals,
921
- template = locals && locals.$template;
922
-
923
- if (angular.isDefined(template)) {
924
- var newScope = scope.$new();
925
- var current = $route.current;
926
-
927
- // Note: This will also link all children of ng-view that were contained in the original
928
- // html. If that content contains controllers, ... they could pollute/change the scope.
929
- // However, using ng-view on an element with additional content does not make sense...
930
- // Note: We can't remove them in the cloneAttchFn of $transclude as that
931
- // function is called before linking the content, which would apply child
932
- // directives to non existing elements.
933
- var clone = $transclude(newScope, function(clone) {
934
- $animate.enter(clone, null, currentElement || $element).then(function onNgViewEnter() {
935
- if (angular.isDefined(autoScrollExp)
936
- && (!autoScrollExp || scope.$eval(autoScrollExp))) {
937
- $anchorScroll();
938
- }
939
- });
940
- cleanupLastView();
941
- });
942
-
943
- currentElement = clone;
944
- currentScope = current.scope = newScope;
945
- currentScope.$emit('$viewContentLoaded');
946
- currentScope.$eval(onloadExp);
947
- } else {
948
- cleanupLastView();
949
- }
950
- }
951
- }
952
- };
953
- }
954
-
955
- // This directive is called during the $transclude call of the first `ngView` directive.
956
- // It will replace and compile the content of the element with the loaded template.
957
- // We need this directive so that the element content is already filled when
958
- // the link function of another directive on the same element as ngView
959
- // is called.
960
- ngViewFillContentFactory.$inject = ['$compile', '$controller', '$route'];
961
- function ngViewFillContentFactory($compile, $controller, $route) {
962
- return {
963
- restrict: 'ECA',
964
- priority: -400,
965
- link: function(scope, $element) {
966
- var current = $route.current,
967
- locals = current.locals;
968
-
969
- $element.html(locals.$template);
970
-
971
- var link = $compile($element.contents());
972
-
973
- if (current.controller) {
974
- locals.$scope = scope;
975
- var controller = $controller(current.controller, locals);
976
- if (current.controllerAs) {
977
- scope[current.controllerAs] = controller;
978
- }
979
- $element.data('$ngControllerController', controller);
980
- $element.children().data('$ngControllerController', controller);
981
- }
982
-
983
- link(scope);
984
- }
985
- };
986
- }
987
-
988
-
989
- })(window, window.angular);