angular-gem 1.3.0 → 1.3.1

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