|
1 | 1 | /*! |
2 | 2 | * angular-ui-scroll |
3 | 3 | * https://github.com/angular-ui/ui-scroll.git |
4 | | - * Version: 1.5.1 -- 2016-10-30T12:41:33.695Z |
| 4 | + * Version: 1.5.1 -- 2016-11-04T01:55:55.663Z |
5 | 5 | * License: MIT |
6 | 6 | */ |
7 | 7 |
|
@@ -415,6 +415,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () { |
415 | 415 | } |
416 | 416 |
|
417 | 417 | function Adapter($attr, viewport, buffer, adjustBuffer, element) { |
| 418 | + var hasViewport = !!viewport.scope(); |
418 | 419 | var viewportScope = viewport.scope() || $rootScope; |
419 | 420 | var disabled = false; |
420 | 421 | var self = this; |
@@ -524,34 +525,51 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () { |
524 | 525 | var target = match[1]; |
525 | 526 | var onControllerName = match[2]; |
526 | 527 |
|
527 | | - var parseControllers = function parseControllers(controllerName) { |
| 528 | + // ng-controller attr based DOM parsing |
| 529 | + var parseNgCtrlAttrs = function parseNgCtrlAttrs(controllerName) { |
528 | 530 | var as = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; |
529 | 531 |
|
530 | 532 | var candidate = element; |
531 | 533 | while (candidate.length) { |
| 534 | + var candidateScope = candidate.scope(); |
532 | 535 | var candidateName = (candidate.attr('ng-controller') || '').match(/(\w(?:\w|\d)*)(?:\s+as\s+(\w(?:\w|\d)*))?/); |
533 | 536 | if (candidateName && candidateName[as ? 2 : 1] === controllerName) { |
534 | | - scope = candidate.scope(); |
535 | | - break; |
| 537 | + scope = candidateScope; |
| 538 | + return true; |
| 539 | + } |
| 540 | + candidate = candidate.parent(); |
| 541 | + } |
| 542 | + }; |
| 543 | + |
| 544 | + // scope based DOM pasrsing |
| 545 | + var parseScopes = function parseScopes(controllerName) { |
| 546 | + var candidate = element; |
| 547 | + while (candidate.length) { |
| 548 | + var candidateScope = candidate.scope(); |
| 549 | + if (candidateScope && candidateScope.hasOwnProperty(controllerName) && candidateScope[controllerName].constructor.name === 'controller') { |
| 550 | + scope = candidateScope; |
| 551 | + return true; |
536 | 552 | } |
537 | 553 | candidate = candidate.parent(); |
538 | 554 | } |
539 | 555 | }; |
540 | 556 |
|
541 | 557 | if (onControllerName) { |
542 | | - // 'on' syntax parsing |
| 558 | + // 'on' syntax DOM parsing (adapter='adapter on ctrl') |
543 | 559 | scope = null; |
544 | | - parseControllers(onControllerName); |
| 560 | + parseNgCtrlAttrs(onControllerName); |
545 | 561 | if (!scope) { |
546 | 562 | throw new Error('Failed to locate target controller \'' + onControllerName + '\' to inject \'' + target + '\''); |
547 | 563 | } |
548 | 564 | } else { |
549 | | - // try to parse with 'Controller As' syntax |
| 565 | + // try to parse DOM with 'Controller As' syntax (adapter='ctrl.adapter') |
550 | 566 | var controllerAsName = undefined; |
551 | 567 | var dotIndex = target.indexOf('.'); |
552 | 568 | if (dotIndex > 0) { |
553 | 569 | controllerAsName = target.substr(0, dotIndex); |
554 | | - parseControllers(controllerAsName, true); |
| 570 | + if (!parseNgCtrlAttrs(controllerAsName, true) && !hasViewport) { |
| 571 | + parseScopes(controllerAsName); // the case of custom Directive/Component |
| 572 | + } |
555 | 573 | } |
556 | 574 | } |
557 | 575 |
|
|
0 commit comments