Merge pull request #173 from shower/tg/152-non-existent-id
Non-existent slide id leads to the first slide (#152)
This commit is contained in:
commit
5a4437cb32
27
shower.js
27
shower.js
|
@ -599,13 +599,18 @@ window.shower = window.shower || (function(window, document, undefined) {
|
|||
/**
|
||||
* Get current slide number. Starts from zero. Warning: when you have
|
||||
* slide number 1 in URL this method will return 0.
|
||||
* If something is wrong return -1.
|
||||
* If there is no slide number in url, return -1.
|
||||
* If there is a slide number in url, but the slide does not exist, return 0.
|
||||
* @returns {Number}
|
||||
*/
|
||||
shower.getCurrentSlideNumber = function() {
|
||||
var i = shower.slideList.length - 1,
|
||||
currentSlideId = url.hash.substr(1);
|
||||
|
||||
if (currentSlideId === '') {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// As fast as you can ;-)
|
||||
// http://jsperf.com/for-vs-foreach/46
|
||||
for (; i >= 0; --i) {
|
||||
|
@ -614,7 +619,7 @@ window.shower = window.shower || (function(window, document, undefined) {
|
|||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -809,13 +814,27 @@ window.shower = window.shower || (function(window, document, undefined) {
|
|||
// Event handlers
|
||||
|
||||
window.addEventListener('DOMContentLoaded', function() {
|
||||
if (body.classList.contains('full') || shower.isSlideMode()) {
|
||||
shower.go(shower.getCurrentSlideNumber());
|
||||
var currentSlideNumber = shower.getCurrentSlideNumber(),
|
||||
isSlideMode = body.classList.contains('full') || shower.isSlideMode();
|
||||
|
||||
if (currentSlideNumber === -1 && isSlideMode) {
|
||||
shower.go(0);
|
||||
} else if (currentSlideNumber === 0 || isSlideMode) {
|
||||
shower.go(currentSlideNumber);
|
||||
}
|
||||
|
||||
if (isSlideMode) {
|
||||
shower.enterSlideMode();
|
||||
}
|
||||
}, false);
|
||||
|
||||
window.addEventListener('popstate', function() {
|
||||
var currentSlideNumber = shower.getCurrentSlideNumber();
|
||||
|
||||
if (currentSlideNumber !== -1) {
|
||||
shower.go(currentSlideNumber);
|
||||
}
|
||||
|
||||
if (shower.isListMode()) {
|
||||
shower.enterListMode();
|
||||
} else {
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue