From 5c197660638b8f4f603ed087bedf88cb1c980832 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Fri, 6 Jan 2012 19:19:31 -0800 Subject: feat(ng:include): enable/disable scrolling through autoscroll attribute --- src/widgets.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/widgets.js') diff --git a/src/widgets.js b/src/widgets.js index 155b8c08..63ddaf36 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -43,6 +43,13 @@ * instance of angular.module.ng.$rootScope.Scope to set the HTML fragment to. * @param {string=} onload Expression to evaluate when a new partial is loaded. * + * @param {string=} autoscroll Whether `ng:include` should call {@link angular.module.ng.$autoScroll + * $autoScroll} to scroll the viewport after the content is loaded. + * + * - If the attribute is not set, disable scrolling. + * - If the attribute is set without value, enable scrolling. + * - Otherwise enable scrolling only if the expression evaluates to truthy value. + * * @example @@ -84,7 +91,9 @@ angularWidget('ng:include', function(element){ var compiler = this, srcExp = element.attr("src"), scopeExp = element.attr("scope") || '', - onloadExp = element[0].getAttribute('onload') || ''; //workaround for jquery bug #7537 + onloadExp = element[0].getAttribute('onload') || '', //workaround for jquery bug #7537 + autoScrollExp = element.attr('autoscroll'); + if (element[0]['ng:compiled']) { this.descend(true); this.directives(true); @@ -123,7 +132,9 @@ angularWidget('ng:include', function(element){ if (childScope) childScope.$destroy(); childScope = useScope ? useScope : scope.$new(); compiler.compile(element)(childScope); - $autoScroll(); + if (isDefined(autoScrollExp) && (!autoScrollExp || scope.$eval(autoScrollExp))) { + $autoScroll(); + } scope.$eval(onloadExp); } }).error(clearContent); -- cgit v1.2.3