angularjs-rails 1.2.0.rc3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license AngularJS v1.2.0-rc.3
2
+ * @license AngularJS v1.2.0
3
3
  * (c) 2010-2012 Google, Inc. http://angularjs.org
4
4
  * License: MIT
5
5
  */
@@ -14,12 +14,13 @@ var $resourceMinErr = angular.$$minErr('$resource');
14
14
  *
15
15
  * # ngResource
16
16
  *
17
- * `ngResource` is the name of the optional Angular module that adds support for interacting with
18
- * [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) server-side data sources.
19
- * `ngResource` provides the {@link ngResource.$resource `$resource`} service.
17
+ * The `ngResource` module provides interaction support with RESTful services
18
+ * via the $resource service.
20
19
  *
21
20
  * {@installModule resource}
22
21
  *
22
+ * <div doc-module-components="ngResource"></div>
23
+ *
23
24
  * See {@link ngResource.$resource `$resource`} for usage.
24
25
  */
25
26
 
@@ -63,7 +64,7 @@ var $resourceMinErr = angular.$$minErr('$resource');
63
64
  *
64
65
  * @param {Object.<Object>=} actions Hash with declaration of custom action that should extend the
65
66
  * default set of resource actions. The declaration should be created in the format of {@link
66
- * ng.$http#Parameters $http.config}:
67
+ * ng.$http#usage_parameters $http.config}:
67
68
  *
68
69
  * {action1: {method:?, params:?, isArray:?, headers:?, ...},
69
70
  * action2: {method:?, params:?, isArray:?, headers:?, ...},
@@ -71,21 +72,23 @@ var $resourceMinErr = angular.$$minErr('$resource');
71
72
  *
72
73
  * Where:
73
74
  *
74
- * - **`action`** – {string} – The name of action. This name becomes the name of the method on your
75
- * resource object.
76
- * - **`method`** – {string} – HTTP request method. Valid methods are: `GET`, `POST`, `PUT`, `DELETE`,
77
- * and `JSONP`.
78
- * - **`params`** – {Object=} – Optional set of pre-bound parameters for this action. If any of the
79
- * parameter value is a function, it will be executed every time when a param value needs to be
80
- * obtained for a request (unless the param was overridden).
81
- * - **`url`** – {string} – action specific `url` override. The url templating is supported just like
82
- * for the resource-level urls.
83
- * - **`isArray`** – {boolean=} – If true then the returned object for this action is an array, see
84
- * `returns` section.
85
- * - **`transformRequest`** – `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
75
+ * - **`action`** – {string} – The name of action. This name becomes the name of the method on
76
+ * your resource object.
77
+ * - **`method`** – {string} – HTTP request method. Valid methods are: `GET`, `POST`, `PUT`,
78
+ * `DELETE`, and `JSONP`.
79
+ * - **`params`** – {Object=} – Optional set of pre-bound parameters for this action. If any of
80
+ * the parameter value is a function, it will be executed every time when a param value needs to
81
+ * be obtained for a request (unless the param was overridden).
82
+ * - **`url`** – {string} – action specific `url` override. The url templating is supported just
83
+ * like for the resource-level urls.
84
+ * - **`isArray`** – {boolean=} – If true then the returned object for this action is an array,
85
+ * see `returns` section.
86
+ * - **`transformRequest`** –
87
+ * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
86
88
  * transform function or an array of such functions. The transform function takes the http
87
89
  * request body and headers and returns its transformed (typically serialized) version.
88
- * - **`transformResponse`** – `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
90
+ * - **`transformResponse`** –
91
+ * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
89
92
  * transform function or an array of such functions. The transform function takes the http
90
93
  * response body and headers and returns its transformed (typically deserialized) version.
91
94
  * - **`cache`** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the
@@ -153,14 +156,15 @@ var $resourceMinErr = angular.$$minErr('$resource');
153
156
  *
154
157
  * On success, the promise is resolved with the same resource instance or collection object,
155
158
  * updated with data from server. This makes it easy to use in
156
- * {@link ngRoute.$routeProvider resolve section of $routeProvider.when()} to defer view rendering
157
- * until the resource(s) are loaded.
159
+ * {@link ngRoute.$routeProvider resolve section of $routeProvider.when()} to defer view
160
+ * rendering until the resource(s) are loaded.
158
161
  *
159
- * On failure, the promise is resolved with the {@link ng.$http http response} object,
160
- * without the `resource` property.
162
+ * On failure, the promise is resolved with the {@link ng.$http http response} object, without
163
+ * the `resource` property.
161
164
  *
162
- * - `$resolved`: `true` after first server interaction is completed (either with success or rejection),
163
- * `false` before that. Knowing if the Resource has been resolved is useful in data-binding.
165
+ * - `$resolved`: `true` after first server interaction is completed (either with success or
166
+ * rejection), `false` before that. Knowing if the Resource has been resolved is useful in
167
+ * data-binding.
164
168
  *
165
169
  * @example
166
170
  *
@@ -204,7 +208,8 @@ var $resourceMinErr = angular.$$minErr('$resource');
204
208
  * The object returned from this function execution is a resource "class" which has "static" method
205
209
  * for each action in the definition.
206
210
  *
207
- * Calling these methods invoke `$http` on the `url` template with the given `method`, `params` and `headers`.
211
+ * Calling these methods invoke `$http` on the `url` template with the given `method`, `params` and
212
+ * `headers`.
208
213
  * When the data is returned from the server then the object is an instance of the resource type and
209
214
  * all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD
210
215
  * operations (create, read, update, delete) on server-side data.
@@ -217,7 +222,7 @@ var $resourceMinErr = angular.$$minErr('$resource');
217
222
  });
218
223
  </pre>
219
224
  *
220
- * It's worth noting that the success callback for `get`, `query` and other method gets passed
225
+ * It's worth noting that the success callback for `get`, `query` and other methods gets passed
221
226
  * in the response that came from the server as well as $http header getter function, so one
222
227
  * could rewrite the above example and get access to http headers as:
223
228
  *
@@ -236,48 +241,52 @@ var $resourceMinErr = angular.$$minErr('$resource');
236
241
 
237
242
  Let's look at what a buzz client created with the `$resource` service looks like:
238
243
  <doc:example>
239
- <doc:source jsfiddle="false">
240
- <script>
241
- function BuzzController($resource) {
242
- this.userId = 'googlebuzz';
243
- this.Activity = $resource(
244
- 'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments',
245
- {alt:'json', callback:'JSON_CALLBACK'},
246
- {get:{method:'JSONP', params:{visibility:'@self'}}, replies: {method:'JSONP', params:{visibility:'@self', comments:'@comments'}}}
247
- );
244
+ <doc:source jsfiddle="false">
245
+ <script>
246
+ function BuzzController($resource) {
247
+ this.userId = 'googlebuzz';
248
+ this.Activity = $resource(
249
+ 'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments',
250
+ {alt:'json', callback:'JSON_CALLBACK'},
251
+ {
252
+ get:{method:'JSONP', params:{visibility:'@self'}},
253
+ replies: {method:'JSONP', params:{visibility:'@self', comments:'@comments'}}
248
254
  }
249
-
250
- BuzzController.prototype = {
251
- fetch: function() {
252
- this.activities = this.Activity.get({userId:this.userId});
253
- },
254
- expandReplies: function(activity) {
255
- activity.replies = this.Activity.replies({userId:this.userId, activityId:activity.id});
256
- }
257
- };
258
- BuzzController.$inject = ['$resource'];
259
- </script>
260
-
261
- <div ng-controller="BuzzController">
262
- <input ng-model="userId"/>
263
- <button ng-click="fetch()">fetch</button>
264
- <hr/>
265
- <div ng-repeat="item in activities.data.items">
266
- <h1 style="font-size: 15px;">
267
- <img src="{{item.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
268
- <a href="{{item.actor.profileUrl}}">{{item.actor.name}}</a>
269
- <a href ng-click="expandReplies(item)" style="float: right;">Expand replies: {{item.links.replies[0].count}}</a>
270
- </h1>
271
- {{item.object.content | html}}
272
- <div ng-repeat="reply in item.replies.data.items" style="margin-left: 20px;">
273
- <img src="{{reply.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
274
- <a href="{{reply.actor.profileUrl}}">{{reply.actor.name}}</a>: {{reply.content | html}}
275
- </div>
276
- </div>
255
+ );
256
+ }
257
+
258
+ BuzzController.prototype = {
259
+ fetch: function() {
260
+ this.activities = this.Activity.get({userId:this.userId});
261
+ },
262
+ expandReplies: function(activity) {
263
+ activity.replies = this.Activity.replies({userId:this.userId, activityId:activity.id});
264
+ }
265
+ };
266
+ BuzzController.$inject = ['$resource'];
267
+ </script>
268
+
269
+ <div ng-controller="BuzzController">
270
+ <input ng-model="userId"/>
271
+ <button ng-click="fetch()">fetch</button>
272
+ <hr/>
273
+ <div ng-repeat="item in activities.data.items">
274
+ <h1 style="font-size: 15px;">
275
+ <img src="{{item.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
276
+ <a href="{{item.actor.profileUrl}}">{{item.actor.name}}</a>
277
+ <a href ng-click="expandReplies(item)" style="float: right;">Expand replies:
278
+ {{item.links.replies[0].count}}</a>
279
+ </h1>
280
+ {{item.object.content | html}}
281
+ <div ng-repeat="reply in item.replies.data.items" style="margin-left: 20px;">
282
+ <img src="{{reply.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
283
+ <a href="{{reply.actor.profileUrl}}">{{reply.actor.name}}</a>: {{reply.content | html}}
277
284
  </div>
278
- </doc:source>
279
- <doc:scenario>
280
- </doc:scenario>
285
+ </div>
286
+ </div>
287
+ </doc:source>
288
+ <doc:scenario>
289
+ </doc:scenario>
281
290
  </doc:example>
282
291
  */
283
292
  angular.module('ngResource', ['ng']).
@@ -318,9 +327,9 @@ angular.module('ngResource', ['ng']).
318
327
 
319
328
 
320
329
  /**
321
- * This method is intended for encoding *key* or *value* parts of query component. We need a custom
322
- * method because encodeURIComponent is too aggressive and encodes stuff that doesn't have to be
323
- * encoded per http://tools.ietf.org/html/rfc3986:
330
+ * This method is intended for encoding *key* or *value* parts of query component. We need a
331
+ * custom method because encodeURIComponent is too aggressive and encodes stuff that doesn't
332
+ * have to be encoded per http://tools.ietf.org/html/rfc3986:
324
333
  * query = *( pchar / "/" / "?" )
325
334
  * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
326
335
  * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
@@ -355,8 +364,9 @@ angular.module('ngResource', ['ng']).
355
364
  if (param === 'hasOwnProperty') {
356
365
  throw $resourceMinErr('badname', "hasOwnProperty is not a valid parameter name.");
357
366
  }
358
- if (!(new RegExp("^\\d+$").test(param)) && param && (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
359
- urlParams[param] = true;
367
+ if (!(new RegExp("^\\d+$").test(param)) && param &&
368
+ (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
369
+ urlParams[param] = true;
360
370
  }
361
371
  });
362
372
  url = url.replace(/\\:/g, ':');
@@ -399,7 +409,7 @@ angular.module('ngResource', ['ng']).
399
409
  };
400
410
 
401
411
 
402
- function ResourceFactory(url, paramDefaults, actions) {
412
+ function resourceFactory(url, paramDefaults, actions) {
403
413
  var route = new Route(url);
404
414
 
405
415
  actions = extend({}, DEFAULT_ACTIONS, actions);
@@ -409,7 +419,8 @@ angular.module('ngResource', ['ng']).
409
419
  actionParams = extend({}, paramDefaults, actionParams);
410
420
  forEach(actionParams, function(value, key){
411
421
  if (isFunction(value)) { value = value(); }
412
- ids[key] = value && value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
422
+ ids[key] = value && value.charAt && value.charAt(0) == '@' ?
423
+ getter(data, value.substr(1)) : value;
413
424
  });
414
425
  return ids;
415
426
  }
@@ -428,6 +439,7 @@ angular.module('ngResource', ['ng']).
428
439
  Resource[name] = function(a1, a2, a3, a4) {
429
440
  var params = {}, data, success, error;
430
441
 
442
+ /* jshint -W086 */ /* (purposefully fall through case statements) */
431
443
  switch(arguments.length) {
432
444
  case 4:
433
445
  error = a4;
@@ -459,14 +471,18 @@ angular.module('ngResource', ['ng']).
459
471
  case 0: break;
460
472
  default:
461
473
  throw $resourceMinErr('badargs',
462
- "Expected up to 4 arguments [params, data, success, error], got {0} arguments", arguments.length);
474
+ "Expected up to 4 arguments [params, data, success, error], got {0} arguments",
475
+ arguments.length);
463
476
  }
477
+ /* jshint +W086 */ /* (purposefully fall through case statements) */
464
478
 
465
479
  var isInstanceCall = data instanceof Resource;
466
480
  var value = isInstanceCall ? data : (action.isArray ? [] : new Resource(data));
467
481
  var httpConfig = {};
468
- var responseInterceptor = action.interceptor && action.interceptor.response || defaultResponseInterceptor;
469
- var responseErrorInterceptor = action.interceptor && action.interceptor.responseError || undefined;
482
+ var responseInterceptor = action.interceptor && action.interceptor.response ||
483
+ defaultResponseInterceptor;
484
+ var responseErrorInterceptor = action.interceptor && action.interceptor.responseError ||
485
+ undefined;
470
486
 
471
487
  forEach(action, function(value, key) {
472
488
  if (key != 'params' && key != 'isArray' && key != 'interceptor') {
@@ -475,18 +491,23 @@ angular.module('ngResource', ['ng']).
475
491
  });
476
492
 
477
493
  if (hasBody) httpConfig.data = data;
478
- route.setUrlParams(httpConfig, extend({}, extractParams(data, action.params || {}), params), action.url);
494
+ route.setUrlParams(httpConfig,
495
+ extend({}, extractParams(data, action.params || {}), params),
496
+ action.url);
479
497
 
480
498
  var promise = $http(httpConfig).then(function(response) {
481
499
  var data = response.data,
482
500
  promise = value.$promise;
483
501
 
484
502
  if (data) {
485
- if ( angular.isArray(data) != !!action.isArray ) {
486
- throw $resourceMinErr('badcfg', 'Error in resource configuration. Expected response' +
487
- ' to contain an {0} but got an {1}',
503
+ // Need to convert action.isArray to boolean in case it is undefined
504
+ // jshint -W018
505
+ if ( angular.isArray(data) !== (!!action.isArray) ) {
506
+ throw $resourceMinErr('badcfg', 'Error in resource configuration. Expected ' +
507
+ 'response to contain an {0} but got an {1}',
488
508
  action.isArray?'array':'object', angular.isArray(data)?'array':'object');
489
509
  }
510
+ // jshint +W018
490
511
  if (action.isArray) {
491
512
  value.length = 0;
492
513
  forEach(data, function(item) {
@@ -544,13 +565,13 @@ angular.module('ngResource', ['ng']).
544
565
  });
545
566
 
546
567
  Resource.bind = function(additionalParamDefaults){
547
- return ResourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
568
+ return resourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
548
569
  };
549
570
 
550
571
  return Resource;
551
572
  }
552
573
 
553
- return ResourceFactory;
574
+ return resourceFactory;
554
575
  }]);
555
576
 
556
577
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license AngularJS v1.2.0-rc.3
2
+ * @license AngularJS v1.2.0
3
3
  * (c) 2010-2012 Google, Inc. http://angularjs.org
4
4
  * License: MIT
5
5
  */
@@ -16,8 +16,9 @@
16
16
  *
17
17
  * {@installModule route}
18
18
  *
19
+ * <div doc-module-components="ngRoute"></div>
19
20
  */
20
-
21
+ /* global -ngRouteModule */
21
22
  var ngRouteModule = angular.module('ngRoute', ['ng']).
22
23
  provider('$route', $RouteProvider);
23
24
 
@@ -69,9 +70,9 @@ function $RouteProvider(){
69
70
  *
70
71
  * Object properties:
71
72
  *
72
- * - `controller` – `{(string|function()=}` – Controller fn that should be associated with newly
73
- * created scope or the name of a {@link angular.Module#controller registered controller}
74
- * if passed as a string.
73
+ * - `controller` – `{(string|function()=}` – Controller fn that should be associated with
74
+ * newly created scope or the name of a {@link angular.Module#controller registered
75
+ * controller} if passed as a string.
75
76
  * - `controllerAs` – `{string=}` – A controller alias name. If present the controller will be
76
77
  * published to scope under the `controllerAs` name.
77
78
  * - `template` – `{string=|function()=}` – html template as a string or a function that
@@ -93,17 +94,22 @@ function $RouteProvider(){
93
94
  * `$location.path()` by applying the current route
94
95
  *
95
96
  * - `resolve` - `{Object.<string, function>=}` - An optional map of dependencies which should
96
- * be injected into the controller. If any of these dependencies are promises, they will be
97
- * resolved and converted to a value before the controller is instantiated and the
98
- * `$routeChangeSuccess` event is fired. The map object is:
97
+ * be injected into the controller. If any of these dependencies are promises, the router
98
+ * will wait for them all to be resolved or one to be rejected before the controller is
99
+ * instantiated.
100
+ * If all the promises are resolved successfully, the values of the resolved promises are
101
+ * injected and {@link ngRoute.$route#$routeChangeSuccess $routeChangeSuccess} event is
102
+ * fired. If any of the promises are rejected the
103
+ * {@link ngRoute.$route#$routeChangeError $routeChangeError} event is fired. The map object
104
+ * is:
99
105
  *
100
106
  * - `key` – `{string}`: a name of a dependency to be injected into the controller.
101
107
  * - `factory` - `{string|function}`: If `string` then it is an alias for a service.
102
108
  * Otherwise if function, then it is {@link api/AUTO.$injector#invoke injected}
103
- * and the return value is treated as the dependency. If the result is a promise, it is resolved
104
- * before its value is injected into the controller. Be aware that `ngRoute.$routeParams` will
105
- * still refer to the previous route within these resolve functions. Use `$route.current.params`
106
- * to access the new route parameters, instead.
109
+ * and the return value is treated as the dependency. If the result is a promise, it is
110
+ * resolved before its value is injected into the controller. Be aware that
111
+ * `ngRoute.$routeParams` will still refer to the previous route within these resolve
112
+ * functions. Use `$route.current.params` to access the new route parameters, instead.
107
113
  *
108
114
  * - `redirectTo` – {(string|function())=} – value to update
109
115
  * {@link ng.$location $location} path with and trigger route redirection.
@@ -215,8 +221,15 @@ function $RouteProvider(){
215
221
  };
216
222
 
217
223
 
218
- this.$get = ['$rootScope', '$location', '$routeParams', '$q', '$injector', '$http', '$templateCache', '$sce',
219
- function( $rootScope, $location, $routeParams, $q, $injector, $http, $templateCache, $sce) {
224
+ this.$get = ['$rootScope',
225
+ '$location',
226
+ '$routeParams',
227
+ '$q',
228
+ '$injector',
229
+ '$http',
230
+ '$templateCache',
231
+ '$sce',
232
+ function($rootScope, $location, $routeParams, $q, $injector, $http, $templateCache, $sce) {
220
233
 
221
234
  /**
222
235
  * @ngdoc object
@@ -245,8 +258,9 @@ function $RouteProvider(){
245
258
  *
246
259
  * You can define routes through {@link ngRoute.$routeProvider $routeProvider}'s API.
247
260
  *
248
- * The `$route` service is typically used in conjunction with the {@link ngRoute.directive:ngView `ngView`}
249
- * directive and the {@link ngRoute.$routeParams `$routeParams`} service.
261
+ * The `$route` service is typically used in conjunction with the
262
+ * {@link ngRoute.directive:ngView `ngView`} directive and the
263
+ * {@link ngRoute.$routeParams `$routeParams`} service.
250
264
  *
251
265
  * @example
252
266
  This example shows how changing the URL hash causes the `$route` to match a route against the
@@ -255,7 +269,7 @@ function $RouteProvider(){
255
269
  Note that this example is using {@link ng.directive:script inlined templates}
256
270
  to get it working on jsfiddle as well.
257
271
 
258
- <example module="ngView" deps="angular-route.js">
272
+ <example module="ngViewExample" deps="angular-route.js">
259
273
  <file name="index.html">
260
274
  <div ng-controller="MainCntl">
261
275
  Choose:
@@ -288,7 +302,9 @@ function $RouteProvider(){
288
302
  </file>
289
303
 
290
304
  <file name="script.js">
291
- angular.module('ngView', ['ngRoute']).config(function($routeProvider, $locationProvider) {
305
+ angular.module('ngViewExample', ['ngRoute'])
306
+
307
+ .config(function($routeProvider, $locationProvider) {
292
308
  $routeProvider.when('/Book/:bookId', {
293
309
  templateUrl: 'book.html',
294
310
  controller: BookCntl,
@@ -374,7 +390,8 @@ function $RouteProvider(){
374
390
  *
375
391
  * @param {Object} angularEvent Synthetic event object.
376
392
  * @param {Route} current Current route information.
377
- * @param {Route|Undefined} previous Previous route information, or undefined if current is first route entered.
393
+ * @param {Route|Undefined} previous Previous route information, or undefined if current is
394
+ * first route entered.
378
395
  */
379
396
 
380
397
  /**
@@ -469,7 +486,8 @@ function $RouteProvider(){
469
486
  last = $route.current;
470
487
 
471
488
  if (next && last && next.$$route === last.$$route
472
- && angular.equals(next.pathParams, last.pathParams) && !next.reloadOnSearch && !forceReload) {
489
+ && angular.equals(next.pathParams, last.pathParams)
490
+ && !next.reloadOnSearch && !forceReload) {
473
491
  last.params = next.params;
474
492
  angular.copy(last.params, $routeParams);
475
493
  $rootScope.$broadcast('$routeUpdate', last);
@@ -496,7 +514,8 @@ function $RouteProvider(){
496
514
  template, templateUrl;
497
515
 
498
516
  angular.forEach(locals, function(value, key) {
499
- locals[key] = angular.isString(value) ? $injector.get(value) : $injector.invoke(value);
517
+ locals[key] = angular.isString(value) ?
518
+ $injector.get(value) : $injector.invoke(value);
500
519
  });
501
520
 
502
521
  if (angular.isDefined(template = next.template)) {
@@ -591,7 +610,7 @@ ngRouteModule.provider('$routeParams', $RouteParamsProvider);
591
610
  * Requires the {@link ngRoute `ngRoute`} module to be installed.
592
611
  *
593
612
  * The route parameters are a combination of {@link ng.$location `$location`}'s
594
- * {@link ng.$location#search `search()`} and {@link ng.$location#path `path()`}.
613
+ * {@link ng.$location#methods_search `search()`} and {@link ng.$location#methods_path `path()`}.
595
614
  * The `path` parameters are extracted when the {@link ngRoute.$route `$route`} path is matched.
596
615
  *
597
616
  * In case of parameter name collision, `path` params take precedence over `search` params.
@@ -652,8 +671,8 @@ ngRouteModule.directive('ngView', ngViewFactory);
652
671
  <a href="Book/Gatsby/ch/4?key=value">Gatsby: Ch4</a> |
653
672
  <a href="Book/Scarlet">Scarlet Letter</a><br/>
654
673
 
655
- <div class="example-animate-container">
656
- <div ng-view class="view-example"></div>
674
+ <div class="view-animate-container">
675
+ <div ng-view class="view-animate"></div>
657
676
  </div>
658
677
  <hr />
659
678
 
@@ -681,7 +700,9 @@ ngRouteModule.directive('ngView', ngViewFactory);
681
700
  </file>
682
701
 
683
702
  <file name="animations.css">
684
- .example-animate-container {
703
+ .view-animate-container {
704
+ position:relative;
705
+ height:100px!important;
685
706
  position:relative;
686
707
  background:white;
687
708
  border:1px solid black;
@@ -689,14 +710,12 @@ ngRouteModule.directive('ngView', ngViewFactory);
689
710
  overflow:hidden;
690
711
  }
691
712
 
692
- .example-animate-container > div {
713
+ .view-animate {
693
714
  padding:10px;
694
715
  }
695
716
 
696
- .view-example.ng-enter, .view-example.ng-leave {
717
+ .view-animate.ng-enter, .view-animate.ng-leave {
697
718
  -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
698
- -moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
699
- -o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
700
719
  transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
701
720
 
702
721
  display:block;
@@ -711,39 +730,33 @@ ngRouteModule.directive('ngView', ngViewFactory);
711
730
  padding:10px;
712
731
  }
713
732
 
714
- .example-animate-container {
715
- position:relative;
716
- height:100px;
717
- }
718
-
719
- .view-example.ng-enter {
733
+ .view-animate.ng-enter {
720
734
  left:100%;
721
735
  }
722
- .view-example.ng-enter.ng-enter-active {
736
+ .view-animate.ng-enter.ng-enter-active {
723
737
  left:0;
724
738
  }
725
-
726
- .view-example.ng-leave { }
727
- .view-example.ng-leave.ng-leave-active {
739
+ .view-animate.ng-leave.ng-leave-active {
728
740
  left:-100%;
729
741
  }
730
742
  </file>
731
743
 
732
744
  <file name="script.js">
733
- angular.module('ngViewExample', ['ngRoute', 'ngAnimate'], function($routeProvider, $locationProvider) {
734
- $routeProvider.when('/Book/:bookId', {
735
- templateUrl: 'book.html',
736
- controller: BookCntl,
737
- controllerAs: 'book'
738
- });
739
- $routeProvider.when('/Book/:bookId/ch/:chapterId', {
740
- templateUrl: 'chapter.html',
741
- controller: ChapterCntl,
742
- controllerAs: 'chapter'
743
- });
745
+ angular.module('ngViewExample', ['ngRoute', 'ngAnimate'],
746
+ function($routeProvider, $locationProvider) {
747
+ $routeProvider.when('/Book/:bookId', {
748
+ templateUrl: 'book.html',
749
+ controller: BookCntl,
750
+ controllerAs: 'book'
751
+ });
752
+ $routeProvider.when('/Book/:bookId/ch/:chapterId', {
753
+ templateUrl: 'chapter.html',
754
+ controller: ChapterCntl,
755
+ controllerAs: 'chapter'
756
+ });
744
757
 
745
- // configure html5 to get links working on jsfiddle
746
- $locationProvider.html5Mode(true);
758
+ // configure html5 to get links working on jsfiddle
759
+ $locationProvider.html5Mode(true);
747
760
  });
748
761
 
749
762
  function MainCntl($route, $routeParams, $location) {
@@ -800,6 +813,7 @@ function ngViewFactory( $route, $anchorScroll, $compile, $controller,
800
813
  return function(scope, $element, attr) {
801
814
  var currentScope,
802
815
  currentElement,
816
+ autoScrollExp = attr.autoscroll,
803
817
  onloadExp = attr.onload || '';
804
818
 
805
819
  scope.$on('$routeChangeSuccess', update);
@@ -823,10 +837,15 @@ function ngViewFactory( $route, $anchorScroll, $compile, $controller,
823
837
  if (template) {
824
838
  var newScope = scope.$new();
825
839
  linker(newScope, function(clone) {
826
- cleanupLastView();
827
-
828
840
  clone.html(template);
829
- $animate.enter(clone, null, $element);
841
+ $animate.enter(clone, null, currentElement || $element, function onNgViewEnter () {
842
+ if (angular.isDefined(autoScrollExp)
843
+ && (!autoScrollExp || scope.$eval(autoScrollExp))) {
844
+ $anchorScroll();
845
+ }
846
+ });
847
+
848
+ cleanupLastView();
830
849
 
831
850
  var link = $compile(clone.contents()),
832
851
  current = $route.current;
@@ -847,15 +866,12 @@ function ngViewFactory( $route, $anchorScroll, $compile, $controller,
847
866
  link(currentScope);
848
867
  currentScope.$emit('$viewContentLoaded');
849
868
  currentScope.$eval(onloadExp);
850
-
851
- // $anchorScroll might listen on event...
852
- $anchorScroll();
853
869
  });
854
870
  } else {
855
871
  cleanupLastView();
856
872
  }
857
873
  }
858
- }
874
+ };
859
875
  }
860
876
  };
861
877
  }