Skip to content

Add 'scrollStopped' event #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 63 additions & 8 deletions angular-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ angular.module('duScroll', [
'duScroll.smoothScroll',
'duScroll.scrollContainer',
'duScroll.spyContext',
'duScroll.scrollHelpers'
'duScroll.scrollHelpers',
'duScroll.scrollNotify'
])
//Default animation duration for smoothScroll directive
.value('duScrollDuration', 350)
//Scrollspy debounce interval, set to 0 to disable
.value('duScrollSpyWait', 100)
//Scrollspy debouce interval, set to 0 to disable
.value('duScrollDebouce', 300)
//Scrollspy throttle interval, set to 0 to disable
.value('duScrollThrottle', 100)
//Wether or not multiple scrollspies can be active at once
.value('duScrollGreedy', false)
//Default offset for smoothScroll directive
Expand Down Expand Up @@ -239,7 +242,7 @@ angular.module('duScroll.requestAnimation', ['duScroll.polyfill'])


angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
.factory('spyAPI', ["$rootScope", "$timeout", "$window", "$document", "scrollContainerAPI", "duScrollGreedy", "duScrollSpyWait", function($rootScope, $timeout, $window, $document, scrollContainerAPI, duScrollGreedy, duScrollSpyWait) {
.factory('spyAPI', ["$rootScope", "$timeout", "$window", "$document", "scrollContainerAPI", "duScrollGreedy", "duScrollThrottle", function($rootScope, $timeout, $window, $document, scrollContainerAPI, duScrollGreedy, duScrollThrottle) {
'use strict';

var createScrollHandler = function(context) {
Expand Down Expand Up @@ -295,7 +298,7 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
context.currentlyActive = toBeActive;
};

if(!duScrollSpyWait) {
if(!duScrollThrottle) {
return handler;
}

Expand All @@ -308,7 +311,7 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
if(queued) {
handler();
}
}, duScrollSpyWait, false);
}, duScrollThrottle, false);
} else {
queued = true;
}
Expand Down Expand Up @@ -336,9 +339,9 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
var destroyContext = function($scope) {
var id = $scope.$id;
var context = contexts[id], container = context.container;
if(container) {
if(container)
container.off('scroll', context.handler);
}

delete contexts[id];
};

Expand Down Expand Up @@ -456,6 +459,39 @@ angular.module('duScroll.scrollContainerAPI', [])
}]);


angular.module('duScroll.notifyAPI', [])
.factory('notifyAPI', ["$rootScope", "$timeout", "duScrollDebouce", function($rootScope, $timeout, duScrollDebouce) {
'use strict';

var stopedScrollTimer;

var createScrollDebouceHandler = function() {
return function() {
$timeout.cancel(stopedScrollTimer);
stopedScrollTimer = $timeout(function() {
$rootScope.$broadcast('duScrollspy:scrollStopped');
}, duScrollDebouce, false);
};
};

var context = {};

var addNotifier = function(container) {
context.debouceHandler = createScrollDebouceHandler();
container.on('scroll', context.debouceHandler);
};

var removeNotifier = function(container) {
container.off('scroll', context.debouceHandler);
};

return {
addNotifier: addNotifier,
removeNotifier: removeNotifier,
};
}]);


angular.module('duScroll.smoothScroll', ['duScroll.scrollHelpers', 'duScroll.scrollContainerAPI'])
.directive('duSmoothScroll', ["duScrollDuration", "duScrollOffset", "scrollContainerAPI", function(duScrollDuration, duScrollOffset, scrollContainerAPI) {
'use strict';
Expand Down Expand Up @@ -594,3 +630,22 @@ angular.module('duScroll.scrollspy', ['duScroll.spyAPI'])
}
};
}]);


angular.module('duScroll.scrollNotify', ['duScroll.notifyAPI'])
.directive('duScrollNotify', ["notifyAPI", function(notifyAPI){
'use strict';

return {
restrict: 'A',
link : function ($scope, $element, $attr){

notifyAPI.addNotifier($element);

$scope.$on('$destroy', function() {
notifyAPI.removeNotifier($element);
});

}
};
}]);
2 changes: 1 addition & 1 deletion angular-scroll.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion angular-scroll.min.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ var sources = [
'src/services/request-animation.js',
'src/services/spy-api.js',
'src/services/scroll-container-api.js',
'src/services/notify-api.js',
'src/directives/smooth-scroll.js',
'src/directives/spy-context.js',
'src/directives/scroll-container.js',
'src/directives/scrollspy.js'
'src/directives/scrollspy.js',
'src/directives/scroll-notify.js'
];

var targets = 'angular-scroll.{js,min.js,min.js.map}';
Expand Down
17 changes: 17 additions & 0 deletions src/directives/scroll-notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
angular.module('duScroll.scrollNotify', ['duScroll.notifyAPI'])
.directive('duScrollNotify', function(notifyAPI){
'use strict';

return {
restrict: 'A',
link : function ($scope, $element, $attr){

notifyAPI.addNotifier($element);

$scope.$on('$destroy', function() {
notifyAPI.removeNotifier($element);
});

}
};
});
9 changes: 6 additions & 3 deletions src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ angular.module('duScroll', [
'duScroll.smoothScroll',
'duScroll.scrollContainer',
'duScroll.spyContext',
'duScroll.scrollHelpers'
'duScroll.scrollHelpers',
'duScroll.scrollNotify'
])
//Default animation duration for smoothScroll directive
.value('duScrollDuration', 350)
//Scrollspy debounce interval, set to 0 to disable
.value('duScrollSpyWait', 100)
//Scrollspy debouce interval, set to 0 to disable
.value('duScrollDebouce', 300)
//Scrollspy throttle interval, set to 0 to disable
.value('duScrollThrottle', 100)
//Wether or not multiple scrollspies can be active at once
.value('duScrollGreedy', false)
//Default offset for smoothScroll directive
Expand Down
31 changes: 31 additions & 0 deletions src/services/notify-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
angular.module('duScroll.notifyAPI', [])
.factory('notifyAPI', function($rootScope, $timeout, duScrollDebouce) {
'use strict';

var stopedScrollTimer;

var createScrollDebouceHandler = function() {
return function() {
$timeout.cancel(stopedScrollTimer);
stopedScrollTimer = $timeout(function() {
$rootScope.$broadcast('duScrollspy:scrollStopped');
}, duScrollDebouce, false);
};
};

var context = {};

var addNotifier = function(container) {
context.debouceHandler = createScrollDebouceHandler();
container.on('scroll', context.debouceHandler);
};

var removeNotifier = function(container) {
container.off('scroll', context.debouceHandler);
};

return {
addNotifier: addNotifier,
removeNotifier: removeNotifier,
};
});
10 changes: 5 additions & 5 deletions src/services/spy-api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
.factory('spyAPI', function($rootScope, $timeout, $window, $document, scrollContainerAPI, duScrollGreedy, duScrollSpyWait) {
.factory('spyAPI', function($rootScope, $timeout, $window, $document, scrollContainerAPI, duScrollGreedy, duScrollThrottle) {
'use strict';

var createScrollHandler = function(context) {
Expand Down Expand Up @@ -55,7 +55,7 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
context.currentlyActive = toBeActive;
};

if(!duScrollSpyWait) {
if(!duScrollThrottle) {
return handler;
}

Expand All @@ -68,7 +68,7 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
if(queued) {
handler();
}
}, duScrollSpyWait, false);
}, duScrollThrottle, false);
} else {
queued = true;
}
Expand Down Expand Up @@ -96,9 +96,9 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI'])
var destroyContext = function($scope) {
var id = $scope.$id;
var context = contexts[id], container = context.container;
if(container) {
if(container)
container.off('scroll', context.handler);
}

delete contexts[id];
};

Expand Down