From b5b8279bcb876b6c3602b0ef7ae425d81a815e6e Mon Sep 17 00:00:00 2001 From: Oleg Roschupkin Date: Thu, 1 Mar 2012 13:54:31 +0900 Subject: [PATCH] Fix bug with Enter when no slide is active. Closes issue #56. --- scripts/script.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/script.js b/scripts/script.js index 1c9121c..159ebca 100755 --- a/scripts/script.js +++ b/scripts/script.js @@ -53,10 +53,10 @@ return -1; } - function scrollToCurrentSlide() { - var currentSlide = document.getElementById( - slideList[getCurrentSlideNumber()].id - ); + function scrollToSlide(slideNumber) { + if (-1 === slideNumber ) { return; } + + var currentSlide = document.getElementById(slideList[slideNumber].id); if (null != currentSlide) { window.scrollTo(0, currentSlide.offsetTop); @@ -156,7 +156,7 @@ window.addEventListener('popstate', function (e) { if (isListMode()) { enterListMode(); - scrollToCurrentSlide(); + scrollToSlide(getCurrentSlideNumber()); } else { enterSlideMode(); } @@ -177,7 +177,7 @@ switch (e.which) { case 116: // F5 case 13: // Enter - if (isListMode()) { + if (isListMode() && -1 !== currentSlideNumber) { e.preventDefault(); history.pushState(null, null, url.pathname + '?full' + getSlideHash(currentSlideNumber)); @@ -193,7 +193,7 @@ history.pushState(null, null, url.pathname + getSlideHash(currentSlideNumber)); enterListMode(); - scrollToCurrentSlide(); + scrollToSlide(currentSlideNumber); } break; @@ -217,7 +217,9 @@ // Only go to next slide if current slide have no inner // navigation or inner navigation is fully shown + // NOTE: But first of all check if there is no current slide if ( + -1 === currentSlideNumber || !slideList[currentSlideNumber].hasInnerNavigation || -1 === increaseInnerNavigation(currentSlideNumber) ) { @@ -276,4 +278,4 @@ } }, false); -}()); \ No newline at end of file +}());