summaryrefslogtreecommitdiff
path: root/www/lib/angular-carousel/src/directives/rn-carousel-auto-slide.js
diff options
context:
space:
mode:
Diffstat (limited to 'www/lib/angular-carousel/src/directives/rn-carousel-auto-slide.js')
-rw-r--r--www/lib/angular-carousel/src/directives/rn-carousel-auto-slide.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/www/lib/angular-carousel/src/directives/rn-carousel-auto-slide.js b/www/lib/angular-carousel/src/directives/rn-carousel-auto-slide.js
new file mode 100644
index 00000000..a2e1a5fd
--- /dev/null
+++ b/www/lib/angular-carousel/src/directives/rn-carousel-auto-slide.js
@@ -0,0 +1,31 @@
+angular.module('angular-carousel')
+
+.directive('rnCarouselAutoSlide', ['$interval', function($interval) {
+ return {
+ restrict: 'A',
+ link: function (scope, element, attrs) {
+ var stopAutoPlay = function() {
+ if (scope.autoSlider) {
+ $interval.cancel(scope.autoSlider);
+ scope.autoSlider = null;
+ }
+ };
+ var restartTimer = function() {
+ scope.autoSlide();
+ };
+
+ scope.$watch('carouselIndex', restartTimer);
+
+ if (attrs.hasOwnProperty('rnCarouselPauseOnHover') && attrs.rnCarouselPauseOnHover !== 'false'){
+ element.on('mouseenter', stopAutoPlay);
+ element.on('mouseleave', restartTimer);
+ }
+
+ scope.$on('$destroy', function(){
+ stopAutoPlay();
+ element.off('mouseenter', stopAutoPlay);
+ element.off('mouseleave', restartTimer);
+ });
+ }
+ };
+}]);