Added keyboard control on slideshow
authorveltr
Fri, 28 Jun 2013 15:47:00 +0200
changeset 206 24607434c13b
parent 205 2b050be8ffd7
child 207 43f08ce0e5aa
Added keyboard control on slideshow
integration/v2/img/slideshow-controls.png
integration/v2/js/slideshow.js
Binary file integration/v2/img/slideshow-controls.png has changed
--- a/integration/v2/js/slideshow.js	Fri Jun 28 15:38:29 2013 +0200
+++ b/integration/v2/js/slideshow.js	Fri Jun 28 15:47:00 2013 +0200
@@ -71,13 +71,36 @@
         }
     }
     
-    function nextSlide() {
+    var playInterval, playing = false;
+    
+    function toggleSlideShow() {
+        clearInterval(playInterval);
+        playing = !playing;
+        var jqppbtn = $(".play-pause");
+        if (playing) {
+            jqppbtn.addClass("pause");
+            playInterval = setInterval(nextSlide,4000,false);
+        } else {
+            jqppbtn.removeClass("pause");
+        }
+        return false;
+    }
+    
+    function nextSlide(resetInterval) {
+        if (!!resetInterval && playing) {
+            playing = false;
+            toggleSlideShow();
+        }
         currentSlide = (currentSlide + 1) % slides.length;
         showSlide();
         return false;
     }
     
-    function prevSlide() {
+    function prevSlide(resetInterval) {
+        if (!!resetInterval && playing) {
+            playing = false;
+            toggleSlideShow();
+        }
         currentSlide = (currentSlide > 0 ? currentSlide - 1 : slides.length - 1);
         showSlide();
         return false;
@@ -126,20 +149,8 @@
         && typeof document.webkitIsFullScreen === "undefined") {
         $(".full-screen").remove();
     }
-    
-    var playInterval, playing = false;
-    
-    $(".play-pause").click(function() {
-        clearInterval(playInterval);
-        playing = !playing;
-        if (playing) {
-            $(this).addClass("pause");
-            playInterval = setInterval(nextSlide,4000);
-        } else {
-            $(this).removeClass("pause");
-        }
-        return false;
-    });
+        
+    $(".play-pause").click(toggleSlideShow);
     
     slides.forEach(function(slide, k) {
         if (!slide.path) {
@@ -158,4 +169,25 @@
     
     jqwin.resize(showSlide);
     
+    $(document).keydown(function(e) {
+        if (e.keyCode === 122) { // F11
+            fullScreen();
+            return false;
+        }
+        if (e.keyCode === 32) { // Space
+            jqControls.show();
+            resetTO();
+            toggleSlideShow();
+            return false;
+        }
+        if (e.keyCode === 37) { // Left-Arrow
+            prevSlide(true);
+            return false;
+        }
+        if (e.keyCode === 39) { // Right-Arrow
+            nextSlide(true);
+            return false;
+        }
+    });
+    
 });
\ No newline at end of file