Added slide::stopTimer, fixed pageDown to next step of inner navigation

This commit is contained in:
miripiruni 2013-05-05 02:15:58 +04:00
parent b8fd510d46
commit 03d73e8d79
1 changed files with 31 additions and 30 deletions

View File

@ -80,18 +80,18 @@ window.shower = window.shower || (function(window, document, undefined) {
return false; return false;
} }
clearInterval(timer); slide.stopTimer();
if (slide.isFinished()) { if (slide.isFinished()) {
timer = setInterval(function() { timer = setInterval(function() {
clearInterval(timer); slide.stopTimer();
shower.next(); shower.next();
}, },
slide.timing * (slide.innerLength || 1)); slide.timing * (slide.innerLength || 1));
} else { } else {
timer = setInterval(function() { timer = setInterval(function() {
if (slide.isFinished()) { if (slide.isFinished()) {
clearInterval(timer); slide.stopTimer();
shower.next(); shower.next();
} else { } else {
slide.next(shower); slide.next(shower);
@ -103,6 +103,18 @@ window.shower = window.shower || (function(window, document, undefined) {
return this; return this;
}, },
/**
* Stop timer
*/
stopTimer : function() {
if (timer) {
clearInterval(timer);
timer = false;
}
return this;
},
/** /**
* Previous step of inner navigation or if current step is step 0 then go to previous slide. * Previous step of inner navigation or if current step is step 0 then go to previous slide.
* @returns {Object|Boolean} Current slide * @returns {Object|Boolean} Current slide
@ -399,32 +411,19 @@ window.shower = window.shower || (function(window, document, undefined) {
/** /**
* *
* @param {Function} [callback] * @param {Function} [callback]
* @returns {boolean}
*/ */
shower._turnNextSlide = function(callback) { shower._turnNextSlide = function(callback) {
var currentSlideNumber = shower.getCurrentSlideNumber(), var currentSlideNumber = shower.getCurrentSlideNumber(),
ret = false,
slide;
slide = shower.slideList[currentSlideNumber]; slide = shower.slideList[currentSlideNumber];
if (shower.isSlideMode()) { slide.stopTimer();
if (slide.hasInnerNavigation && ! slide.isFinished()) { slide.next(shower);
slide.process(shower);
} else {
shower.next();
}
} else { // listMode
shower.next();
// Slides starts from 0. So return next slide number.
ret = currentSlideNumber + 2;
}
if (typeof(callback) === 'function') { if (typeof(callback) === 'function') {
callback(); callback();
} }
return ret; return;
}; };
/** /**
@ -464,7 +463,7 @@ window.shower = window.shower || (function(window, document, undefined) {
} }
slide = shower.slideList[currentSlideNumber]; slide = shower.slideList[currentSlideNumber];
slide.timing && clearInterval(timer); slide.timing && slide.stopTimer();
if (shower.isSlideMode()) { if (shower.isSlideMode()) {
slide.prev(shower); slide.prev(shower);
@ -482,28 +481,31 @@ window.shower = window.shower || (function(window, document, undefined) {
/** /**
* Show first slide. * Show first slide.
* @param {Function} [callback] * @param {Function} [callback]
* @returns {Number}
*/ */
shower.first = function(callback) { shower.first = function(callback) {
var slide = shower.slideList[shower.getCurrentSlideNumber()];
slide.timing && slide.stopTimer();
shower.go(0);
if (typeof(callback) === 'function') { if (typeof(callback) === 'function') {
callback(); callback();
} }
return shower.go(0);
}; };
/** /**
* Show last slide. * Show last slide.
* @param {Function} [callback] * @param {Function} [callback]
* @returns {Boolean}
*/ */
shower.last = function(callback) { shower.last = function(callback) {
var slide = shower.slideList[shower.getCurrentSlideNumber()];
slide.timing && slide.stopTimer();
shower.go(shower.slideList.length - 1); shower.go(shower.slideList.length - 1);
if (typeof(callback) === 'function') { if (typeof(callback) === 'function') {
callback(); callback();
} }
return true;
}; };
/** /**
@ -552,7 +554,7 @@ window.shower = window.shower || (function(window, document, undefined) {
currentSlideNumber = shower.getCurrentSlideNumber(); currentSlideNumber = shower.getCurrentSlideNumber();
clearInterval(timer); shower.slideList[currentSlideNumber].stopTimer();
if (shower.isSlideMode() && isHistoryApiSupported) { if (shower.isSlideMode() && isHistoryApiSupported) {
history.pushState(null, null, url.pathname + shower.getSlideHash(currentSlideNumber)); history.pushState(null, null, url.pathname + shower.getSlideHash(currentSlideNumber));
@ -851,20 +853,19 @@ window.shower = window.shower || (function(window, document, undefined) {
case 36: // Home case 36: // Home
e.preventDefault(); e.preventDefault();
slide.timing && clearInterval(timer);
shower.first(); shower.first();
break; break;
case 35: // End case 35: // End
e.preventDefault(); e.preventDefault();
slide.timing && clearInterval(timer);
shower.last(); shower.last();
break; break;
case 9: // Tab = +1; Shift + Tab = -1 case 9: // Tab = +1; Shift + Tab = -1
case 32: // Space = +1; Shift + Space = -1 case 32: // Space = +1; Shift + Space = -1
e.preventDefault(); e.preventDefault();
shower[e.shiftKey ? 'previous' : 'next'](); shower[e.shiftKey ? '_turnPreviousSlide' : '_turnNextSlide']();
break; break;
default: default: