Fix for presenter notes, fix timing for inner nav; Refactoring.
This commit is contained in:
parent
496e00972d
commit
8cd2aa3544
101
shower.js
101
shower.js
|
@ -75,7 +75,7 @@ window.shower = (function(window, document, undefined) {
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
shower._isNumber = function(arg) {
|
shower._isNumber = function(arg) {
|
||||||
return ! isNaN(parseFloat(arg)) && isFinite(arg);
|
return ! isNaN(parseFloat(arg)) && isFinite(arg);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,7 +128,7 @@ window.shower = (function(window, document, undefined) {
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
shower._checkInteractiveElement = function(e) {
|
shower._checkInteractiveElement = function(e) {
|
||||||
return 'A' === e.target.nodeName;
|
return 'A' === e.target.nodeName;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -168,16 +168,19 @@ window.shower = (function(window, document, undefined) {
|
||||||
throw new Error('Gimme slide number as Number, baby!');
|
throw new Error('Gimme slide number as Number, baby!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Also triggers popstate and invoke shower.enter__Mode()
|
||||||
url.hash = shower.getSlideHash(slideNumber);
|
url.hash = shower.getSlideHash(slideNumber);
|
||||||
|
|
||||||
if (shower.isSlideMode()) {
|
if (shower.isSlideMode()) {
|
||||||
|
shower.showPresenterNotes(slideNumber);
|
||||||
shower.updateProgress(slideNumber);
|
shower.updateProgress(slideNumber);
|
||||||
shower.updateCurrentAndPassedSlides(slideNumber);
|
shower.updateCurrentAndPassedSlides(slideNumber);
|
||||||
shower.showPresenterNotes(slideNumber);
|
shower.runInnerNavigation(slideNumber);
|
||||||
|
|
||||||
if (typeof(callback) === 'function') {
|
}
|
||||||
callback();
|
|
||||||
}
|
if (typeof(callback) === 'function') {
|
||||||
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
return slideNumber;
|
return slideNumber;
|
||||||
|
@ -185,7 +188,7 @@ window.shower = (function(window, document, undefined) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show next slide or show next item of Inner navigation. If slide is last
|
* Show next slide or show next item of Inner navigation. If slide is last
|
||||||
* returns false, otherwise return slide number which been shown.
|
* 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}
|
||||||
*/
|
*/
|
||||||
|
@ -197,9 +200,13 @@ window.shower = (function(window, document, undefined) {
|
||||||
// navigation or inner navigation is fully shown
|
// navigation or inner navigation is fully shown
|
||||||
// NOTE: But first of all check if there is no current slide
|
// NOTE: But first of all check if there is no current slide
|
||||||
if (
|
if (
|
||||||
-1 === currentSlideNumber ||
|
(
|
||||||
! slideList[currentSlideNumber].hasInnerNavigation ||
|
-1 === currentSlideNumber ||
|
||||||
! shower.increaseInnerNavigation(currentSlideNumber)
|
! slideList[currentSlideNumber].hasInnerNavigation ||
|
||||||
|
! shower.increaseInnerNavigation(currentSlideNumber)
|
||||||
|
) &&
|
||||||
|
// If exist next slide
|
||||||
|
(currentSlideNumber + 2) <= slideList.length
|
||||||
) {
|
) {
|
||||||
shower.go(currentSlideNumber + 1);
|
shower.go(currentSlideNumber + 1);
|
||||||
// Slides starts from 0. So return next slide number.
|
// Slides starts from 0. So return next slide number.
|
||||||
|
@ -273,32 +280,22 @@ window.shower = (function(window, document, undefined) {
|
||||||
shower.enterSlideMode = function(callback) {
|
shower.enterSlideMode = function(callback) {
|
||||||
var currentSlideNumber = shower.getCurrentSlideNumber();
|
var currentSlideNumber = shower.getCurrentSlideNumber();
|
||||||
|
|
||||||
if (currentSlideNumber === -1) {
|
// Anyway: change body class (@TODO: refactoring)
|
||||||
currentSlideNumber = 0;
|
body.classList.remove('list');
|
||||||
}
|
body.classList.add('full');
|
||||||
|
|
||||||
shower.go(currentSlideNumber);
|
|
||||||
|
|
||||||
|
// Preparing URL for shower.go()
|
||||||
if (shower.isListMode() && isHistoryApiSupported) {
|
if (shower.isListMode() && isHistoryApiSupported) {
|
||||||
history.pushState(null, null, url.pathname + '?full' + shower.getSlideHash(currentSlideNumber));
|
history.pushState(null, null, url.pathname + '?full' + shower.getSlideHash(currentSlideNumber));
|
||||||
}
|
}
|
||||||
|
|
||||||
body.classList.remove('list');
|
shower._applyTransform(shower._getTransform());
|
||||||
body.classList.add('full');
|
|
||||||
|
|
||||||
if (window.console && window.console.clear) {
|
|
||||||
console.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
shower.updateProgress(currentSlideNumber);
|
|
||||||
shower.updateCurrentAndPassedSlides(currentSlideNumber);
|
|
||||||
shower.runInnerNavigation(currentSlideNumber);
|
|
||||||
|
|
||||||
if (typeof(callback) === 'function') {
|
if (typeof(callback) === 'function') {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
return shower._applyTransform(shower._getTransform());
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -307,24 +304,32 @@ window.shower = (function(window, document, undefined) {
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
shower.enterListMode = function(callback) {
|
shower.enterListMode = function(callback) {
|
||||||
|
// Anyway: change body class (@TODO: refactoring)
|
||||||
|
body.classList.remove('full');
|
||||||
|
body.classList.add('list');
|
||||||
|
|
||||||
|
shower.clearPresenterNotes();
|
||||||
|
|
||||||
|
if (shower.isListMode()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var currentSlideNumber = shower.getCurrentSlideNumber();
|
var currentSlideNumber = shower.getCurrentSlideNumber();
|
||||||
|
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
|
|
||||||
body.classList.remove('full');
|
|
||||||
body.classList.add('list');
|
|
||||||
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
shower.scrollToSlide(currentSlideNumber);
|
shower.scrollToSlide(currentSlideNumber);
|
||||||
|
shower._applyTransform('none');
|
||||||
|
|
||||||
if (typeof(callback) === 'function') {
|
if (typeof(callback) === 'function') {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
return shower._applyTransform('none');
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -469,11 +474,22 @@ window.shower = (function(window, document, undefined) {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear presenter notes in console.
|
||||||
|
*/
|
||||||
|
shower.clearPresenterNotes = function() {
|
||||||
|
if (window.console && window.console.clear) {
|
||||||
|
console.clear();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show presenter notes in console.
|
* Show presenter notes in console.
|
||||||
* @param {Number} slideNumber slide number (sic!). Attention: starts from zero.
|
* @param {Number} slideNumber slide number (sic!). Attention: starts from zero.
|
||||||
*/
|
*/
|
||||||
shower.showPresenterNotes = function(slideNumber) {
|
shower.showPresenterNotes = function(slideNumber) {
|
||||||
|
shower.clearPresenterNotes();
|
||||||
|
|
||||||
if (window.console) {
|
if (window.console) {
|
||||||
slideNumber = shower._normalizeSlideNumber(slideNumber);
|
slideNumber = shower._normalizeSlideNumber(slideNumber);
|
||||||
|
|
||||||
|
@ -481,11 +497,12 @@ window.shower = (function(window, document, undefined) {
|
||||||
nextSlideId = slideList[slideNumber + 1] ? slideList[slideNumber + 1].id : null,
|
nextSlideId = slideList[slideNumber + 1] ? slideList[slideNumber + 1].id : null,
|
||||||
notes = document.getElementById(slideId).querySelector('footer');
|
notes = document.getElementById(slideId).querySelector('footer');
|
||||||
|
|
||||||
if (notes) {
|
if (notes && notes.innerHTML) {
|
||||||
console.info(notes.innerHTML.replace(/\n\s+/g,'\n'));
|
console.info(notes.innerHTML.replace(/\n\s+/g,'\n'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextSlideId) {
|
if (nextSlideId) {
|
||||||
|
|
||||||
var next = document.getElementById(nextSlideId).querySelector('h2');
|
var next = document.getElementById(nextSlideId).querySelector('h2');
|
||||||
|
|
||||||
if (next) {
|
if (next) {
|
||||||
|
@ -537,7 +554,7 @@ window.shower = (function(window, document, undefined) {
|
||||||
timing);
|
timing);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -567,13 +584,11 @@ window.shower = (function(window, document, undefined) {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Event handlers
|
// Event handlers
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', function() {
|
window.addEventListener('DOMContentLoaded', function() {
|
||||||
if (body.classList.contains('full')) {
|
if (body.classList.contains('full') || shower.isSlideMode()) {
|
||||||
|
shower.go(shower.getCurrentSlideNumber());
|
||||||
shower.enterSlideMode();
|
shower.enterSlideMode();
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
@ -606,8 +621,11 @@ window.shower = (function(window, document, undefined) {
|
||||||
if (shower.isListMode()) {
|
if (shower.isListMode()) {
|
||||||
var slideNumber = e.shiftKey ? currentSlideNumber : 0;
|
var slideNumber = e.shiftKey ? currentSlideNumber : 0;
|
||||||
|
|
||||||
|
// Warning: go must be before enterSlideMode. Else there are
|
||||||
|
// bug in Chrome
|
||||||
shower.go(slideNumber);
|
shower.go(slideNumber);
|
||||||
shower.enterSlideMode();
|
shower.enterSlideMode();
|
||||||
|
shower.showPresenterNotes(slideNumber);
|
||||||
} else {
|
} else {
|
||||||
shower.enterListMode();
|
shower.enterListMode();
|
||||||
}
|
}
|
||||||
|
@ -667,10 +685,17 @@ window.shower = (function(window, document, undefined) {
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
document.addEventListener('click', function(e) {
|
document.addEventListener('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
var slideNumber = shower.getSlideNumber(shower._getSlideIdByEl(e.target));
|
||||||
|
|
||||||
|
// Click on slide in List mode
|
||||||
if (shower.isListMode() && shower._getSlideIdByEl(e.target)) {
|
if (shower.isListMode() && shower._getSlideIdByEl(e.target)) {
|
||||||
e.preventDefault();
|
// Warning: go must be before enterSlideMode. Else there are
|
||||||
shower.go(shower.getSlideNumber(shower._getSlideIdByEl(e.target)));
|
// bug in Chrome
|
||||||
|
shower.go(slideNumber);
|
||||||
shower.enterSlideMode();
|
shower.enterSlideMode();
|
||||||
|
shower.showPresenterNotes(slideNumber);
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue