Skip to content

Commit

Permalink
Added latest build.
Browse files Browse the repository at this point in the history
  • Loading branch information
reimund committed Feb 1, 2016
1 parent ab0cae4 commit bcb6fe4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
19 changes: 15 additions & 4 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 @@ -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 Expand Up @@ -595,12 +604,14 @@ angular.module('duScroll.scrollspy', ['duScroll.spyAPI'])
};

return {
scope: { duScrollspy: '=' },
link: function ($scope, $element, $attr) {
var href = $attr.ngHref || $attr.href;
var targetId;

if (href && href.indexOf('#') !== -1) {
targetId = href.replace(/.*(?=#[^\s]+$)/, '').substring(1);
} else if($scope.duScrollspy) {
targetId = $scope.duScrollspy;
} else if($attr.duScrollspy) {
targetId = $attr.duScrollspy;
} else if($attr.duSmoothScroll) {
Expand Down
Loading

0 comments on commit bcb6fe4

Please sign in to comment.