Refactoring keydown listener PgDown/Down/Right/l/j

This commit is contained in:
miripiruni 2013-01-20 16:51:33 +04:00
parent 09750b072c
commit 496e00972d
1 changed files with 38 additions and 55 deletions

View File

@ -158,8 +158,34 @@ window.shower = (function(window, document, undefined) {
/** /**
* Show next slide. If slide is last returns false, otherwise return slide * Go to slide number...
* number which been shown. * @param {Number} slideNumber slide number (sic!). Attention: starts from zero.
* @param {Function} [callback] runs only if you not in List mode
* @returns {Number}
*/
shower.go = function(slideNumber, callback) {
if ( ! shower._isNumber(slideNumber)) {
throw new Error('Gimme slide number as Number, baby!');
}
url.hash = shower.getSlideHash(slideNumber);
if (shower.isSlideMode()) {
shower.updateProgress(slideNumber);
shower.updateCurrentAndPassedSlides(slideNumber);
shower.showPresenterNotes(slideNumber);
if (typeof(callback) === 'function') {
callback();
}
}
return slideNumber;
};
/**
* Show next slide or show next item of Inner navigation. If slide is last
* returns false, otherwise return slide number which been shown.
* @param {Function} [callback] runs only if shower.next() complete successfully * @param {Function} [callback] runs only if shower.next() complete successfully
* @returns {Number|Boolean} * @returns {Number|Boolean}
*/ */
@ -176,12 +202,16 @@ window.shower = (function(window, document, undefined) {
! shower.increaseInnerNavigation(currentSlideNumber) ! shower.increaseInnerNavigation(currentSlideNumber)
) { ) {
shower.go(currentSlideNumber + 1); shower.go(currentSlideNumber + 1);
// slides starts from 0 // Slides starts from 0. So return next slide number.
ret = currentSlideNumber + 2; ret = currentSlideNumber + 2;
}
if (typeof(callback) === 'function') { if (shower.isSlideMode()) {
callback(); shower.runInnerNavigation(currentSlideNumber + 1);
} }
if (typeof(callback) === 'function') {
callback();
} }
return ret; return ret;
@ -481,32 +511,6 @@ window.shower = (function(window, document, undefined) {
return '#' + slideList[slideNumber].id; return '#' + slideList[slideNumber].id;
}; };
/**
* Go to slide number...
* @param {Number} slideNumber slide number (sic!). Attention: starts from zero.
* @param {Function} [callback] runs only if you not in List mode
* @returns {Number}
*/
shower.go = function(slideNumber, callback) {
if ( ! shower._isNumber(slideNumber)) {
throw new Error('Gimme slide number as Number, baby!');
}
url.hash = shower.getSlideHash(slideNumber);
if (shower.isSlideMode()) {
shower.updateProgress(slideNumber);
shower.updateCurrentAndPassedSlides(slideNumber);
shower.showPresenterNotes(slideNumber);
if (typeof(callback) === 'function') {
callback();
}
}
return slideNumber;
};
/** /**
* Run slide show if presented. * Run slide show if presented.
* @param {Number} slideNumber * @param {Number} slideNumber
@ -528,8 +532,7 @@ window.shower = (function(window, document, undefined) {
timing = parseInt(timing[0], 10) * 60 * 1000 + parseInt(timing[1], 10) * 1000; timing = parseInt(timing[0], 10) * 60 * 1000 + parseInt(timing[1], 10) * 1000;
timer = setTimeout(function() { timer = setTimeout(function() {
shower.go(slideNumber + 1); shower.next();
shower.runInnerNavigation(slideNumber + 1);
}, },
timing); timing);
} }
@ -639,27 +642,7 @@ window.shower = (function(window, document, undefined) {
case 76: // l case 76: // l
case 74: // j case 74: // j
e.preventDefault(); e.preventDefault();
shower.next();
if (shower.isSlideMode()) {
// Inner navigation is "completed" if current slide have
// no inner navigation or inner navigation is fully shown
isInnerNavCompleted = ! slideList[currentSlideNumber].hasInnerNavigation ||
! shower.increaseInnerNavigation(currentSlideNumber);
} else {
// Also inner navigation is always "completed" if we are in
// list mode
isInnerNavCompleted = true;
}
if (
-1 === currentSlideNumber || isInnerNavCompleted
) {
currentSlideNumber++;
shower.go(currentSlideNumber);
if (shower.isSlideMode()) {
shower.runInnerNavigation(currentSlideNumber);
}
}
break; break;
case 36: // Home case 36: // Home