1
1
/*!
2
2
* angular-ui-scroll
3
3
* https://github.com/angular-ui/ui-scroll.git
4
- * Version: 1.5.1 -- 2016-08-10T12:02:43.502Z
4
+ * Version: 1.5.1 -- 2016-10-30T12:41:33.695Z
5
5
* License: MIT
6
6
*/
7
7
@@ -414,7 +414,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
414
414
return viewport ;
415
415
}
416
416
417
- function Adapter ( $attr , viewport , buffer , adjustBuffer ) {
417
+ function Adapter ( $attr , viewport , buffer , adjustBuffer , element ) {
418
418
var viewportScope = viewport . scope ( ) || $rootScope ;
419
419
var disabled = false ;
420
420
var self = this ;
@@ -517,23 +517,44 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
517
517
var scope = viewportScope ;
518
518
var assign = undefined ;
519
519
if ( expression ) {
520
- var match = expression . match ( / ^ ( \S + ) (?: \s + o n \s + ( \w (?: \w | \d ) * ) ) ? $ / ) ;
520
+ // it is ok to have relaxed validation for the first part of the 'on' expression.
521
+ // additional validation will be done by the $parse service below
522
+ var match = expression . match ( / ^ ( \S + ) (?: \s + o n \s + ( \w (?: \w | \d ) * ) ) ? / ) ;
521
523
if ( ! match ) throw new Error ( 'Expected injection expression in form of \'target\' or \'target on controller\' but got \'' + expression + '\'' ) ;
522
524
var target = match [ 1 ] ;
523
- var controllerName = match [ 2 ] ;
524
- if ( controllerName ) {
525
- var candidate = viewport ;
526
- scope = undefined ;
525
+ var onControllerName = match [ 2 ] ;
526
+
527
+ var parseControllers = function parseControllers ( controllerName ) {
528
+ var as = arguments . length <= 1 || arguments [ 1 ] === undefined ? false : arguments [ 1 ] ;
529
+
530
+ var candidate = element ;
527
531
while ( candidate . length ) {
528
- var controller = candidate . attr ( 'ng-controller' ) ;
529
- if ( controller === controllerName ) {
532
+ var candidateName = ( candidate . attr ( 'ng-controller' ) || '' ) . match ( / ( \w (?: \w | \d ) * ) (?: \s + a s \s + ( \w (?: \w | \d ) * ) ) ? / ) ;
533
+ if ( candidateName && candidateName [ as ? 2 : 1 ] === controllerName ) {
530
534
scope = candidate . scope ( ) ;
531
535
break ;
532
536
}
533
537
candidate = candidate . parent ( ) ;
534
538
}
535
- if ( ! scope ) throw new Error ( 'Failed to locate target controller \'' + controllerName + '\' to inject \'' + target + '\'' ) ;
539
+ } ;
540
+
541
+ if ( onControllerName ) {
542
+ // 'on' syntax parsing
543
+ scope = null ;
544
+ parseControllers ( onControllerName ) ;
545
+ if ( ! scope ) {
546
+ throw new Error ( 'Failed to locate target controller \'' + onControllerName + '\' to inject \'' + target + '\'' ) ;
547
+ }
548
+ } else {
549
+ // try to parse with 'Controller As' syntax
550
+ var controllerAsName = undefined ;
551
+ var dotIndex = target . indexOf ( '.' ) ;
552
+ if ( dotIndex > 0 ) {
553
+ controllerAsName = target . substr ( 0 , dotIndex ) ;
554
+ parseControllers ( controllerAsName , true ) ;
555
+ }
536
556
}
557
+
537
558
assign = $parse ( target ) . assign ;
538
559
}
539
560
return function ( value ) {
@@ -569,8 +590,9 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
569
590
function link ( $scope , element , $attr , controllers , linker ) {
570
591
571
592
var match = $attr . uiScroll . match ( / ^ \s * ( \w + ) \s + i n \s + ( [ ( \w | \$ ) \. ] + ) \s * $ / ) ;
572
-
573
- if ( ! match ) throw new Error ( 'Expected uiScroll in form of \'_item_ in _datasource_\' but got \'' + $attr . uiScroll + '\'' ) ;
593
+ if ( ! match ) {
594
+ throw new Error ( 'Expected uiScroll in form of \'_item_ in _datasource_\' but got \'' + $attr . uiScroll + '\'' ) ;
595
+ }
574
596
575
597
function parseNumericAttr ( value , defaultValue ) {
576
598
var result = $parse ( value ) ( $scope ) ;
@@ -594,7 +616,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
594
616
595
617
var buffer = new Buffer ( bufferSize ) ;
596
618
var viewport = new Viewport ( buffer , element , viewportController , padding ) ;
597
- var adapter = new Adapter ( $attr , viewport , buffer , adjustBuffer ) ;
619
+ var adapter = new Adapter ( $attr , viewport , buffer , adjustBuffer , element ) ;
598
620
if ( viewportController ) viewportController . adapter = adapter ;
599
621
600
622
var isDatasourceValid = function isDatasourceValid ( ) {
0 commit comments