@@ -21,6 +21,9 @@ var duScroll = angular.module('duScroll', [
2121 . value ( 'duScrollDuration' , 350 )
2222 //Scrollspy debounce interval, set to 0 to disable
2323 . value ( 'duScrollSpyWait' , 100 )
24+ //Scrollspy forced refresh interval, use if your content changes or reflows without scrolling.
25+ //0 to disable
26+ . value ( 'duScrollSpyRefreshInterval' , 0 )
2427 //Wether or not multiple scrollspies can be active at once
2528 . value ( 'duScrollGreedy' , false )
2629 //Default offset for smoothScroll directive
@@ -254,7 +257,7 @@ angular.module('duScroll.requestAnimation', ['duScroll.polyfill'])
254257
255258
256259angular . module ( 'duScroll.spyAPI' , [ 'duScroll.scrollContainerAPI' ] )
257- . factory ( 'spyAPI' , [ "$rootScope" , "$timeout" , "$window" , "$document" , "scrollContainerAPI" , "duScrollGreedy" , "duScrollSpyWait" , "duScrollBottomSpy" , "duScrollActiveClass" , function ( $rootScope , $timeout , $window , $document , scrollContainerAPI , duScrollGreedy , duScrollSpyWait , duScrollBottomSpy , duScrollActiveClass ) {
260+ . factory ( 'spyAPI' , [ "$rootScope" , "$timeout" , "$interval" , "$ window", "$document" , "scrollContainerAPI" , "duScrollGreedy" , "duScrollSpyWait" , "duScrollSpyRefreshInterval" , " duScrollBottomSpy", "duScrollActiveClass" , function ( $rootScope , $timeout , $interval , $ window, $document , scrollContainerAPI , duScrollGreedy , duScrollSpyWait , duScrollSpyRefreshInterval , duScrollBottomSpy , duScrollActiveClass ) {
258261 'use strict' ;
259262
260263 var createScrollHandler = function ( context ) {
@@ -283,7 +286,7 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
283286 for ( i = 0 ; i < spies . length ; i ++ ) {
284287 spy = spies [ i ] ;
285288 pos = spy . getTargetPosition ( ) ;
286- if ( ! pos ) continue ;
289+ if ( ! pos || ! spy . $element ) continue ;
287290
288291 if ( ( duScrollBottomSpy && bottomReached ) || ( pos . top + spy . offset - containerOffset < 20 && ( duScrollGreedy || pos . top * - 1 + containerOffset ) < pos . height ) ) {
289292 //Find the one closest the viewport top or the page bottom if it's reached
@@ -300,7 +303,7 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
300303 toBeActive = toBeActive . spy ;
301304 }
302305 if ( currentlyActive === toBeActive || ( duScrollGreedy && ! toBeActive ) ) return ;
303- if ( currentlyActive ) {
306+ if ( currentlyActive && currentlyActive . $element ) {
304307 currentlyActive . $element . removeClass ( duScrollActiveClass ) ;
305308 $rootScope . $broadcast (
306309 'duScrollspy:becameInactive' ,
@@ -360,6 +363,9 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
360363 var destroyContext = function ( $scope ) {
361364 var id = $scope . $id ;
362365 var context = contexts [ id ] , container = context . container ;
366+ if ( context . intervalPromise ) {
367+ $interval . cancel ( context . intervalPromise ) ;
368+ }
363369 if ( container ) {
364370 container . off ( 'scroll' , context . handler ) ;
365371 }
@@ -411,6 +417,9 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
411417 context . container . off ( 'scroll' , context . handler ) ;
412418 }
413419 context . container = scrollContainerAPI . getContainer ( spy . $scope ) ;
420+ if ( duScrollSpyRefreshInterval && ! context . intervalPromise ) {
421+ context . intervalPromise = $interval ( context . handler , duScrollSpyRefreshInterval , 0 , false ) ;
422+ }
414423 context . container . on ( 'scroll' , context . handler ) . triggerHandler ( 'scroll' ) ;
415424 }
416425 } ;
@@ -595,12 +604,14 @@ angular.module('duScroll.scrollspy', ['duScroll.spyAPI'])
595604 } ;
596605
597606 return {
607+ scope : { duScrollspy : '=' } ,
598608 link : function ( $scope , $element , $attr ) {
599609 var href = $attr . ngHref || $attr . href ;
600610 var targetId ;
601-
602611 if ( href && href . indexOf ( '#' ) !== - 1 ) {
603612 targetId = href . replace ( / .* (? = # [ ^ \s ] + $ ) / , '' ) . substring ( 1 ) ;
613+ } else if ( $scope . duScrollspy ) {
614+ targetId = $scope . duScrollspy ;
604615 } else if ( $attr . duScrollspy ) {
605616 targetId = $attr . duScrollspy ;
606617 } else if ( $attr . duSmoothScroll ) {
0 commit comments