11/*!
22 * angular-ui-scroll
33 * https://github.com/angular-ui/ui-scroll.git
4- * Version: 1.4.1 -- 2016-06-02T19:39:46.238Z
4+ * Version: 1.5.0 -- 2016-06-09T21:24:24.010Z
55 * License: MIT
66 */
77
@@ -420,12 +420,15 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
420420 }
421421
422422 function Adapter ( $attr , viewport , buffer , adjustBuffer ) {
423- var _this = this ;
424-
425423 var viewportScope = viewport . scope ( ) || $rootScope ;
426424 var disabled = false ;
425+ var self = this ;
427426
428- injectValue ( $attr . adapter , this ) ;
427+ createValueInjector ( 'adapter' ) ( self ) ;
428+ var topVisibleInjector = createValueInjector ( 'topVisible' ) ;
429+ var topVisibleElementInjector = createValueInjector ( 'topVisibleElement' ) ;
430+ var topVisibleScopeInjector = createValueInjector ( 'topVisibleScope' ) ;
431+ var isLoadingInjector = createValueInjector ( 'isLoading' ) ;
429432
430433 // Adapter API definition
431434
@@ -475,8 +478,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
475478 } ;
476479
477480 this . loading = function ( value ) {
478- _this . isLoading = value ;
479- injectValue ( $attr . isLoading , value ) ;
481+ isLoadingInjector ( value ) ;
480482 } ;
481483
482484 this . calculateProperties = function ( ) {
@@ -498,12 +500,9 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
498500 topHeight += itemHeight ;
499501 } else {
500502 if ( isNewRow ) {
501- _this . topVisible = item . item ;
502- _this . topVisibleElement = item . element ;
503- _this . topVisibleScope = item . scope ;
504- injectValue ( $attr . topVisible , item . item ) ;
505- injectValue ( $attr . topVisibleElement , item . element ) ;
506- injectValue ( $attr . topVisibleScope , item . scope ) ;
503+ topVisibleInjector ( item . item ) ;
504+ topVisibleElementInjector ( item . element ) ;
505+ topVisibleScopeInjector ( item . scope ) ;
507506 }
508507 break ;
509508 }
@@ -512,13 +511,15 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
512511
513512 // private function definitions
514513
515- function injectValue ( expression , value ) {
514+ function createValueInjector ( attribute ) {
515+ var expression = $attr [ attribute ] ;
516+ var scope = viewportScope ;
517+ var assign = undefined ;
516518 if ( expression ) {
517519 var match = expression . match ( / ^ ( \S + ) (?: \s + o n \s + ( \w (?: \w | \d ) * ) ) ? $ / ) ;
518520 if ( ! match ) throw new Error ( 'Expected injection expression in form of \'target\' or \'target on controller\' but got \'' + expression + '\'' ) ;
519521 var target = match [ 1 ] ;
520522 var controllerName = match [ 2 ] ;
521- var scope = viewportScope ;
522523 if ( controllerName ) {
523524 var candidate = viewport ;
524525 scope = undefined ;
@@ -532,25 +533,13 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
532533 }
533534 if ( ! scope ) throw new Error ( 'Failed to locate target controller \'' + controllerName + '\' to inject \'' + target + '\'' ) ;
534535 }
535- $parse ( target ) . assign ( scope , value ) ;
536- /*
537- let scope = viewportScope;
538- let s = viewportScope;
539- let i = expression.indexOf('.');
540- if (i>0) {
541- let ctrlName = expression.slice(0, i);
542- while (s !== $rootScope) {
543- if (s.hasOwnProperty(ctrlName) && angular.isFunction(s[ctrlName])) {
544- scope = s;
545- expression = expression.slice(i+1);
546- break;
547- }
548- s = s.$parent;
549- }
550- }
551- $parse(expression).assign(scope, value);
552- */
536+ assign = $parse ( target ) . assign ;
553537 }
538+ return function ( value ) {
539+ if ( self !== value ) // just to avoid injecting adapter reference in the adapter itself. Kludgy, I know.
540+ self [ attribute ] = value ;
541+ if ( assign ) assign ( scope , value ) ;
542+ } ;
554543 }
555544
556545 function applyUpdate ( wrapper , newItems ) {
0 commit comments