From 50972bb76ab49c730191193b2158b3d09296d9ca Mon Sep 17 00:00:00 2001 From: Oleg Roschupkin Date: Thu, 1 Mar 2012 17:41:23 +0900 Subject: [PATCH] Add slideshow (via data-timing). Closes issue #17. --- en.htm | 4 ++-- scripts/script.js | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/en.htm b/en.htm index cbff7e9..193fc03 100755 --- a/en.htm +++ b/en.htm @@ -27,7 +27,7 @@

Shower Presentation Template

Vadim Makeev, Opera Software

-
+

Shower Presentation Template

@@ -35,7 +35,7 @@
-
+

Header

diff --git a/scripts/script.js b/scripts/script.js index 1025c85..883b894 100755 --- a/scripts/script.js +++ b/scripts/script.js @@ -4,6 +4,7 @@ slides = document.querySelectorAll('div.slide'), progress = document.querySelector('div.progress div'), slideList = [], + timer, l = slides.length, i; for (i = 0; i < l; i++) { @@ -15,7 +16,8 @@ slideList.push({ id: slides[i].id, - hasInnerNavigation: null !== slides[i].querySelector('.next') + hasInnerNavigation: null !== slides[i].querySelector('.next'), + hasTiming: null != slides[i].dataset.timing }); } @@ -147,6 +149,25 @@ updateProgress(getCurrentSlideNumber()); updateCurrentAndPassedSlides(getCurrentSlideNumber()); + runSlideshowIfPresented(getCurrentSlideNumber()); + } + } + + function runSlideshowIfPresented(slideNumber) { + slideNumber = normalizeSlideNumber(slideNumber); + + clearTimeout(timer); + + if (slideList[slideNumber].hasTiming) { + // Compute number of milliseconds from format "X:Y", where X is + // number of minutes, and Y is number of seconds + var timing = document.getElementById(slideList[slideNumber].id).dataset.timing.split(':'); + timing = parseInt(timing[0]) * 60 * 1000 + parseInt(timing[1]) * 1000; + + timer = setTimeout( function () { + goToSlide(slideNumber + 1); + runSlideshowIfPresented(slideNumber + 1); + }, timing ); } } @@ -179,6 +200,7 @@ enterSlideMode(); updateProgress(getCurrentSlideNumber()); updateCurrentAndPassedSlides(getCurrentSlideNumber()); + runSlideshowIfPresented(getCurrentSlideNumber()) } }, false); @@ -214,6 +236,7 @@ updateProgress(currentSlideNumber); updateCurrentAndPassedSlides(currentSlideNumber); + runSlideshowIfPresented(currentSlideNumber); } break; @@ -255,6 +278,9 @@ ) { currentSlideNumber++; goToSlide(currentSlideNumber); + if (!isListMode()) { + runSlideshowIfPresented(currentSlideNumber); + } } break;