rails-angularjs 1.3.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +22 -0
  3. data/README.md +37 -0
  4. data/lib/rails-angularjs.rb +9 -0
  5. data/lib/rails-angularjs/engine.rb +4 -0
  6. data/lib/rails-angularjs/sprockets.rb +3 -0
  7. data/lib/rails-angularjs/version.rb +4 -0
  8. data/vendor/assets/javascripts/angularjs/angular-animate.js +2137 -0
  9. data/vendor/assets/javascripts/angularjs/angular-animate.min.js +33 -0
  10. data/vendor/assets/javascripts/angularjs/angular-aria.js +339 -0
  11. data/vendor/assets/javascripts/angularjs/angular-aria.min.js +12 -0
  12. data/vendor/assets/javascripts/angularjs/angular-cookies.js +206 -0
  13. data/vendor/assets/javascripts/angularjs/angular-cookies.min.js +8 -0
  14. data/vendor/assets/javascripts/angularjs/angular-loader.js +405 -0
  15. data/vendor/assets/javascripts/angularjs/angular-loader.min.js +9 -0
  16. data/vendor/assets/javascripts/angularjs/angular-messages.js +400 -0
  17. data/vendor/assets/javascripts/angularjs/angular-messages.min.js +10 -0
  18. data/vendor/assets/javascripts/angularjs/angular-mocks.js +2396 -0
  19. data/vendor/assets/javascripts/angularjs/angular-resource.js +667 -0
  20. data/vendor/assets/javascripts/angularjs/angular-resource.min.js +13 -0
  21. data/vendor/assets/javascripts/angularjs/angular-route.js +989 -0
  22. data/vendor/assets/javascripts/angularjs/angular-route.min.js +15 -0
  23. data/vendor/assets/javascripts/angularjs/angular-sanitize.js +680 -0
  24. data/vendor/assets/javascripts/angularjs/angular-sanitize.min.js +16 -0
  25. data/vendor/assets/javascripts/angularjs/angular-scenario.js +37499 -0
  26. data/vendor/assets/javascripts/angularjs/angular-touch.js +622 -0
  27. data/vendor/assets/javascripts/angularjs/angular-touch.min.js +13 -0
  28. data/vendor/assets/javascripts/angularjs/angular.js +26130 -0
  29. data/vendor/assets/javascripts/angularjs/angular.min.js +250 -0
  30. data/vendor/assets/javascripts/angularjs/unstable/angular-animate.js +2137 -0
  31. data/vendor/assets/javascripts/angularjs/unstable/angular-animate.min.js +33 -0
  32. data/vendor/assets/javascripts/angularjs/unstable/angular-aria.js +339 -0
  33. data/vendor/assets/javascripts/angularjs/unstable/angular-aria.min.js +12 -0
  34. data/vendor/assets/javascripts/angularjs/unstable/angular-cookies.js +206 -0
  35. data/vendor/assets/javascripts/angularjs/unstable/angular-cookies.min.js +8 -0
  36. data/vendor/assets/javascripts/angularjs/unstable/angular-loader.js +410 -0
  37. data/vendor/assets/javascripts/angularjs/unstable/angular-loader.min.js +9 -0
  38. data/vendor/assets/javascripts/angularjs/unstable/angular-messages.js +400 -0
  39. data/vendor/assets/javascripts/angularjs/unstable/angular-messages.min.js +10 -0
  40. data/vendor/assets/javascripts/angularjs/unstable/angular-mocks.js +2400 -0
  41. data/vendor/assets/javascripts/angularjs/unstable/angular-resource.js +667 -0
  42. data/vendor/assets/javascripts/angularjs/unstable/angular-resource.min.js +13 -0
  43. data/vendor/assets/javascripts/angularjs/unstable/angular-route.js +989 -0
  44. data/vendor/assets/javascripts/angularjs/unstable/angular-route.min.js +15 -0
  45. data/vendor/assets/javascripts/angularjs/unstable/angular-sanitize.js +682 -0
  46. data/vendor/assets/javascripts/angularjs/unstable/angular-sanitize.min.js +16 -0
  47. data/vendor/assets/javascripts/angularjs/unstable/angular-scenario.js +38463 -0
  48. data/vendor/assets/javascripts/angularjs/unstable/angular-touch.js +622 -0
  49. data/vendor/assets/javascripts/angularjs/unstable/angular-touch.min.js +13 -0
  50. data/vendor/assets/javascripts/angularjs/unstable/angular.js +27088 -0
  51. data/vendor/assets/javascripts/angularjs/unstable/angular.min.js +281 -0
  52. metadata +140 -0
@@ -0,0 +1,13 @@
1
+ /*
2
+ AngularJS v1.3.12
3
+ (c) 2010-2014 Google, Inc. http://angularjs.org
4
+ License: MIT
5
+ */
6
+ (function(I,d,B){'use strict';function D(f,q){q=q||{};d.forEach(q,function(d,h){delete q[h]});for(var h in f)!f.hasOwnProperty(h)||"$"===h.charAt(0)&&"$"===h.charAt(1)||(q[h]=f[h]);return q}var w=d.$$minErr("$resource"),C=/^(\.[a-zA-Z_$][0-9a-zA-Z_$]*)+$/;d.module("ngResource",["ng"]).provider("$resource",function(){var f=this;this.defaults={stripTrailingSlashes:!0,actions:{get:{method:"GET"},save:{method:"POST"},query:{method:"GET",isArray:!0},remove:{method:"DELETE"},"delete":{method:"DELETE"}}};
7
+ this.$get=["$http","$q",function(q,h){function t(d,g){this.template=d;this.defaults=s({},f.defaults,g);this.urlParams={}}function v(x,g,l,m){function c(b,k){var c={};k=s({},g,k);r(k,function(a,k){u(a)&&(a=a());var d;if(a&&a.charAt&&"@"==a.charAt(0)){d=b;var e=a.substr(1);if(null==e||""===e||"hasOwnProperty"===e||!C.test("."+e))throw w("badmember",e);for(var e=e.split("."),n=0,g=e.length;n<g&&d!==B;n++){var h=e[n];d=null!==d?d[h]:B}}else d=a;c[k]=d});return c}function F(b){return b.resource}function e(b){D(b||
8
+ {},this)}var G=new t(x,m);l=s({},f.defaults.actions,l);e.prototype.toJSON=function(){var b=s({},this);delete b.$promise;delete b.$resolved;return b};r(l,function(b,k){var g=/^(POST|PUT|PATCH)$/i.test(b.method);e[k]=function(a,y,m,x){var n={},f,l,z;switch(arguments.length){case 4:z=x,l=m;case 3:case 2:if(u(y)){if(u(a)){l=a;z=y;break}l=y;z=m}else{n=a;f=y;l=m;break}case 1:u(a)?l=a:g?f=a:n=a;break;case 0:break;default:throw w("badargs",arguments.length);}var t=this instanceof e,p=t?f:b.isArray?[]:new e(f),
9
+ A={},v=b.interceptor&&b.interceptor.response||F,C=b.interceptor&&b.interceptor.responseError||B;r(b,function(b,a){"params"!=a&&"isArray"!=a&&"interceptor"!=a&&(A[a]=H(b))});g&&(A.data=f);G.setUrlParams(A,s({},c(f,b.params||{}),n),b.url);n=q(A).then(function(a){var c=a.data,g=p.$promise;if(c){if(d.isArray(c)!==!!b.isArray)throw w("badcfg",k,b.isArray?"array":"object",d.isArray(c)?"array":"object");b.isArray?(p.length=0,r(c,function(a){"object"===typeof a?p.push(new e(a)):p.push(a)})):(D(c,p),p.$promise=
10
+ g)}p.$resolved=!0;a.resource=p;return a},function(a){p.$resolved=!0;(z||E)(a);return h.reject(a)});n=n.then(function(a){var b=v(a);(l||E)(b,a.headers);return b},C);return t?n:(p.$promise=n,p.$resolved=!1,p)};e.prototype["$"+k]=function(a,b,c){u(a)&&(c=b,b=a,a={});a=e[k].call(this,a,this,b,c);return a.$promise||a}});e.bind=function(b){return v(x,s({},g,b),l)};return e}var E=d.noop,r=d.forEach,s=d.extend,H=d.copy,u=d.isFunction;t.prototype={setUrlParams:function(f,g,l){var m=this,c=l||m.template,h,
11
+ e,q=m.urlParams={};r(c.split(/\W/),function(b){if("hasOwnProperty"===b)throw w("badname");!/^\d+$/.test(b)&&b&&(new RegExp("(^|[^\\\\]):"+b+"(\\W|$)")).test(c)&&(q[b]=!0)});c=c.replace(/\\:/g,":");g=g||{};r(m.urlParams,function(b,k){h=g.hasOwnProperty(k)?g[k]:m.defaults[k];d.isDefined(h)&&null!==h?(e=encodeURIComponent(h).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"%20").replace(/%26/gi,"&").replace(/%3D/gi,"=").replace(/%2B/gi,"+"),c=c.replace(new RegExp(":"+
12
+ k+"(\\W|$)","g"),function(b,a){return e+a})):c=c.replace(new RegExp("(/?):"+k+"(\\W|$)","g"),function(b,a,c){return"/"==c.charAt(0)?c:a+c})});m.defaults.stripTrailingSlashes&&(c=c.replace(/\/+$/,"")||"/");c=c.replace(/\/\.(?=\w+($|\?))/,".");f.url=c.replace(/\/\\\./,"/.");r(g,function(b,c){m.urlParams[c]||(f.params=f.params||{},f.params[c]=b)})}};return v}]})})(window,window.angular);
13
+ //# sourceMappingURL=angular-resource.min.js.map
@@ -0,0 +1,989 @@
1
+ /**
2
+ * @license AngularJS v1.3.12
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);