new logic for inner navigation; minor cleanup

This commit is contained in:
Vadim Makeev 2011-08-10 13:06:49 +04:00
parent 766cd63ecf
commit f43c65f394
1 changed files with 3 additions and 31 deletions

View File

@ -122,8 +122,7 @@
} }
} }
// Increases inner navigation by adding 'active' class to next inactive // Increases inner navigation by adding 'active' class to next inactive inner navigation item
// inner navigation item.
function increaseInnerNavigation(slideNumber) { function increaseInnerNavigation(slideNumber) {
// Shortcut for slides without inner navigation // Shortcut for slides without inner navigation
if (true !== slideList[slideNumber].hasInnerNavigation) { return -1; } if (true !== slideList[slideNumber].hasInnerNavigation) { return -1; }
@ -134,39 +133,17 @@
if (null !== node) { if (null !== node) {
node.classList.add('active'); node.classList.add('active');
// NOTE: 'auto-added' class is used in resetInnerNavigation - to
// overcome problems with manually added 'active' class.
node.classList.add('auto-added');
return activeNodes.length + 1; return activeNodes.length + 1;
} else { } else {
return -1; return -1;
} }
} }
// Resets inner navigation by removing 'active' class from all previously
// activated elements.
function resetInnerNavigation(slideNumber) {
// Shortcut for slides without inner navigation
if (true !== slideList[slideNumber].hasInnerNavigation) { return; }
var activeNodes = document.querySelectorAll(
getSlideHash(slideNumber) + ' .active.auto-added'
),
i = 0, l;
for (l = activeNodes.length; i < l; i++) {
activeNodes[i].classList.remove('active');
activeNodes[i].classList.remove('auto-added');
}
}
// Event handlers // Event handlers
window.addEventListener('DOMContentLoaded', function () { window.addEventListener('DOMContentLoaded', function () {
if (!isListMode()) { if (!isListMode()) {
// "?full" is present without slide hash, so we should display first // "?full" is present without slide hash, so we should display first slide
// slide
if (-1 === getCurrentSlideNumber()) { if (-1 === getCurrentSlideNumber()) {
history.replaceState(null, null, url.pathname + '?full' + getSlideHash(0)); history.replaceState(null, null, url.pathname + '?full' + getSlideHash(0));
} }
@ -226,7 +203,6 @@
case 75: // k case 75: // k
e.preventDefault(); e.preventDefault();
resetInnerNavigation(currentSlideNumber);
currentSlideNumber--; currentSlideNumber--;
goToSlide(currentSlideNumber); goToSlide(currentSlideNumber);
break; break;
@ -244,7 +220,6 @@
!slideList[currentSlideNumber].hasInnerNavigation || !slideList[currentSlideNumber].hasInnerNavigation ||
-1 === increaseInnerNavigation(currentSlideNumber) -1 === increaseInnerNavigation(currentSlideNumber)
) { ) {
resetInnerNavigation(currentSlideNumber);
currentSlideNumber++; currentSlideNumber++;
goToSlide(currentSlideNumber); goToSlide(currentSlideNumber);
} }
@ -253,7 +228,6 @@
case 36: // Home case 36: // Home
e.preventDefault(); e.preventDefault();
resetInnerNavigation(currentSlideNumber);
currentSlideNumber = 0; currentSlideNumber = 0;
goToSlide(currentSlideNumber); goToSlide(currentSlideNumber);
break; break;
@ -261,7 +235,6 @@
case 35: // End case 35: // End
e.preventDefault(); e.preventDefault();
resetInnerNavigation(currentSlideNumber);
currentSlideNumber = slideList.length - 1; currentSlideNumber = slideList.length - 1;
goToSlide(currentSlideNumber); goToSlide(currentSlideNumber);
break; break;
@ -270,7 +243,6 @@
case 32: // Space = +1; Shift + Space = -1 case 32: // Space = +1; Shift + Space = -1
e.preventDefault(); e.preventDefault();
resetInnerNavigation(currentSlideNumber);
currentSlideNumber += e.shiftKey ? -1 : 1; currentSlideNumber += e.shiftKey ? -1 : 1;
goToSlide(currentSlideNumber); goToSlide(currentSlideNumber);
break; break;
@ -303,4 +275,4 @@
} }
}, false); }, false);
}()); }());