Skip to content

Commit

Permalink
Released 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
oblador committed May 4, 2017
1 parent 54ed345 commit 740d17e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
19 changes: 14 additions & 5 deletions angular-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ var duScroll = angular.module('duScroll', [
.value('duScrollDuration', 350)
//Scrollspy debounce interval, set to 0 to disable
.value('duScrollSpyWait', 100)
//Scrollspy forced refresh interval, use if your content changes or reflows without scrolling.
//0 to disable
.value('duScrollSpyRefreshInterval', 0)
//Wether or not multiple scrollspies can be active at once
.value('duScrollGreedy', false)
//Default offset for smoothScroll directive
Expand Down Expand Up @@ -69,7 +72,7 @@ angular.module('duScroll.scrollHelpers', ['duScroll.requestAnimation'])
}
var el = unwrap(this);
if(isDocument(el)) {
return $window.scrollTo(left, top);
return angular.element($window).duScrollTo(left, top);
}
el.scrollLeft = left;
el.scrollTop = top;
Expand Down Expand Up @@ -120,7 +123,7 @@ angular.module('duScroll.scrollHelpers', ['duScroll.requestAnimation'])
progress = timestamp - startTime;
var percent = (progress >= duration ? 1 : easing(progress/duration));

el.scrollTo(
el.duScrollTo(
startLeft + Math.ceil(deltaLeft * percent),
startTop + Math.ceil(deltaTop * percent)
);
Expand Down Expand Up @@ -254,7 +257,7 @@ angular.module('duScroll.requestAnimation', ['duScroll.polyfill'])


angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
.factory('spyAPI', ["$rootScope", "$timeout", "$window", "$document", "scrollContainerAPI", "duScrollGreedy", "duScrollSpyWait", "duScrollBottomSpy", "duScrollActiveClass", function($rootScope, $timeout, $window, $document, scrollContainerAPI, duScrollGreedy, duScrollSpyWait, duScrollBottomSpy, duScrollActiveClass) {
.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) {
'use strict';

var createScrollHandler = function(context) {
Expand Down Expand Up @@ -283,7 +286,7 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
for(i = 0; i < spies.length; i++) {
spy = spies[i];
pos = spy.getTargetPosition();
if (!pos) continue;
if (!pos || !spy.$element) continue;

if((duScrollBottomSpy && bottomReached) || (pos.top + spy.offset - containerOffset < 20 && (duScrollGreedy || pos.top*-1 + containerOffset) < pos.height)) {
//Find the one closest the viewport top or the page bottom if it's reached
Expand All @@ -300,7 +303,7 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
toBeActive = toBeActive.spy;
}
if(currentlyActive === toBeActive || (duScrollGreedy && !toBeActive)) return;
if(currentlyActive) {
if(currentlyActive && currentlyActive.$element) {
currentlyActive.$element.removeClass(duScrollActiveClass);
$rootScope.$broadcast(
'duScrollspy:becameInactive',
Expand Down Expand Up @@ -360,6 +363,9 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
var destroyContext = function($scope) {
var id = $scope.$id;
var context = contexts[id], container = context.container;
if(context.intervalPromise) {
$interval.cancel(context.intervalPromise);
}
if(container) {
container.off('scroll', context.handler);
}
Expand Down Expand Up @@ -411,6 +417,9 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
context.container.off('scroll', context.handler);
}
context.container = scrollContainerAPI.getContainer(spy.$scope);
if (duScrollSpyRefreshInterval && !context.intervalPromise) {
context.intervalPromise = $interval(context.handler, duScrollSpyRefreshInterval, 0, false);
}
context.container.on('scroll', context.handler).triggerHandler('scroll');
}
};
Expand Down
Loading

0 comments on commit 740d17e

Please sign in to comment.