angular-gem 1.3.1 → 1.3.2

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