Skip to content

Commit d9b3f9c

Browse files
committed
distributives + demo updates
1 parent a6a32e9 commit d9b3f9c

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

demo/insideDirective/insideDirective.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ <h1 class="page-header page-header-exapmle">Scroller inside the directive</h1>
2121
This sample demonstrates encapsulation of the ui-scroll directive inside another custom directive wich has it's own controller and wich uses "Controller As" syntax in it's template.
2222
</div>
2323

24-
<my-dir></my-dir>
24+
<div ng-controller="mainController">
25+
<div ng-if="true">
26+
<my-dir></my-dir>
27+
</div>
28+
</div>
2529

2630
</div>
2731

demo/insideDirective/insideDirective.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
angular.module('application', ['ui.scroll', 'ui.scroll.jqlite'])
2+
.controller('mainController', ['$scope', function($scope) {
3+
$scope.show = true;
4+
}])
25
.directive('myDir', function() {
36
return {
47
restrict: 'E',

dist/ui-scroll.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-ui-scroll
33
* 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
55
* License: MIT
66
*/
77

@@ -415,6 +415,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
415415
}
416416

417417
function Adapter($attr, viewport, buffer, adjustBuffer, element) {
418+
var hasViewport = !!viewport.scope();
418419
var viewportScope = viewport.scope() || $rootScope;
419420
var disabled = false;
420421
var self = this;
@@ -524,34 +525,51 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
524525
var target = match[1];
525526
var onControllerName = match[2];
526527

527-
var parseControllers = function parseControllers(controllerName) {
528+
// ng-controller attr based DOM parsing
529+
var parseNgCtrlAttrs = function parseNgCtrlAttrs(controllerName) {
528530
var as = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
529531

530532
var candidate = element;
531533
while (candidate.length) {
534+
var candidateScope = candidate.scope();
532535
var candidateName = (candidate.attr('ng-controller') || '').match(/(\w(?:\w|\d)*)(?:\s+as\s+(\w(?:\w|\d)*))?/);
533536
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;
536552
}
537553
candidate = candidate.parent();
538554
}
539555
};
540556

541557
if (onControllerName) {
542-
// 'on' syntax parsing
558+
// 'on' syntax DOM parsing (adapter='adapter on ctrl')
543559
scope = null;
544-
parseControllers(onControllerName);
560+
parseNgCtrlAttrs(onControllerName);
545561
if (!scope) {
546562
throw new Error('Failed to locate target controller \'' + onControllerName + '\' to inject \'' + target + '\'');
547563
}
548564
} else {
549-
// try to parse with 'Controller As' syntax
565+
// try to parse DOM with 'Controller As' syntax (adapter='ctrl.adapter')
550566
var controllerAsName = undefined;
551567
var dotIndex = target.indexOf('.');
552568
if (dotIndex > 0) {
553569
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+
}
555573
}
556574
}
557575

0 commit comments

Comments
 (0)