Skip to content

Commit 1988e44

Browse files
committed
distributives
1 parent b5ca4c2 commit 1988e44

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

dist/ui-scroll.js

Lines changed: 35 additions & 13 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-08-10T12:02:43.502Z
4+
* Version: 1.5.1 -- 2016-10-30T12:41:33.695Z
55
* License: MIT
66
*/
77

@@ -414,7 +414,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
414414
return viewport;
415415
}
416416

417-
function Adapter($attr, viewport, buffer, adjustBuffer) {
417+
function Adapter($attr, viewport, buffer, adjustBuffer, element) {
418418
var viewportScope = viewport.scope() || $rootScope;
419419
var disabled = false;
420420
var self = this;
@@ -517,23 +517,44 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
517517
var scope = viewportScope;
518518
var assign = undefined;
519519
if (expression) {
520-
var match = expression.match(/^(\S+)(?:\s+on\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+on\s+(\w(?:\w|\d)*))?/);
521523
if (!match) throw new Error('Expected injection expression in form of \'target\' or \'target on controller\' but got \'' + expression + '\'');
522524
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;
527531
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+as\s+(\w(?:\w|\d)*))?/);
533+
if (candidateName && candidateName[as ? 2 : 1] === controllerName) {
530534
scope = candidate.scope();
531535
break;
532536
}
533537
candidate = candidate.parent();
534538
}
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+
}
536556
}
557+
537558
assign = $parse(target).assign;
538559
}
539560
return function (value) {
@@ -569,8 +590,9 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
569590
function link($scope, element, $attr, controllers, linker) {
570591

571592
var match = $attr.uiScroll.match(/^\s*(\w+)\s+in\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+
}
574596

575597
function parseNumericAttr(value, defaultValue) {
576598
var result = $parse(value)($scope);
@@ -594,7 +616,7 @@ angular.module('ui.scroll', []).directive('uiScrollViewport', function () {
594616

595617
var buffer = new Buffer(bufferSize);
596618
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);
598620
if (viewportController) viewportController.adapter = adapter;
599621

600622
var isDatasourceValid = function isDatasourceValid() {

0 commit comments

Comments
 (0)