2013-01-20 01:13:21 +04:00
|
|
|
|
/**
|
|
|
|
|
* Shower HTML presentation engine: github.com/shower/shower
|
|
|
|
|
* @copyright 2010–2013 Vadim Makeev, pepelsbey.net
|
|
|
|
|
* @license MIT license: github.com/shower/shower/wiki/MIT-License
|
|
|
|
|
*/
|
2012-12-01 13:47:28 +04:00
|
|
|
|
window.shower = (function(window, document, undefined) {
|
|
|
|
|
var shower = {},
|
2012-10-05 16:44:15 +04:00
|
|
|
|
url = window.location,
|
2011-07-16 04:52:21 +04:00
|
|
|
|
body = document.body,
|
2012-12-01 13:47:28 +04:00
|
|
|
|
slides = document.querySelectorAll('.slide'),
|
2010-11-15 16:45:40 +03:00
|
|
|
|
progress = document.querySelector('div.progress div'),
|
2011-07-20 22:08:31 +04:00
|
|
|
|
slideList = [],
|
2012-12-01 13:47:28 +04:00
|
|
|
|
timer,
|
|
|
|
|
isHistoryApiSupported = !!(window.history && history.pushState),
|
2011-08-09 20:47:32 +04:00
|
|
|
|
l = slides.length, i;
|
2010-10-30 04:16:19 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
/**
|
|
|
|
|
* Get value at named data store for the DOM element.
|
|
|
|
|
* @private
|
2013-01-20 03:40:59 +04:00
|
|
|
|
* @param {HTMLElement} element
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @param {String} name
|
|
|
|
|
* @returns {String}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
|
|
|
|
shower._getData = function(element, name) {
|
|
|
|
|
return element.dataset ? element.dataset[name] : element.getAttribute('data-' + name);
|
2012-12-30 15:54:16 +04:00
|
|
|
|
};
|
2012-12-01 13:47:28 +04:00
|
|
|
|
|
2011-07-20 22:08:31 +04:00
|
|
|
|
for (i = 0; i < l; i++) {
|
2013-01-20 01:13:21 +04:00
|
|
|
|
// Slide IDs are optional. In case of missing ID we set it to the
|
2012-12-01 13:47:28 +04:00
|
|
|
|
// slide number
|
|
|
|
|
if ( ! slides[i].id) {
|
|
|
|
|
slides[i].id = i + 1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-09 20:47:32 +04:00
|
|
|
|
slideList.push({
|
|
|
|
|
id: slides[i].id,
|
2012-12-01 13:47:28 +04:00
|
|
|
|
hasInnerNavigation: null !== slides[i].querySelector('.next'),
|
|
|
|
|
hasTiming: (shower._getData(slides[i], 'timing') && shower._getData(slides[i], 'timing').indexOf(':') !== -1)
|
2011-08-09 20:47:32 +04:00
|
|
|
|
});
|
2010-11-08 04:34:56 +03:00
|
|
|
|
}
|
2011-07-16 05:13:35 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
/**
|
|
|
|
|
* Get slide scale value
|
|
|
|
|
* @private
|
|
|
|
|
* @returns {String}
|
|
|
|
|
*/
|
|
|
|
|
shower._getTransform = function() {
|
2011-07-20 22:08:31 +04:00
|
|
|
|
var denominator = Math.max(
|
|
|
|
|
body.clientWidth / window.innerWidth,
|
|
|
|
|
body.clientHeight / window.innerHeight
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return 'scale(' + (1 / denominator) + ')';
|
2012-12-01 13:47:28 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set CSS transform with prefixes to body
|
|
|
|
|
* @private
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @returns {Boolean}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
|
|
|
|
shower._applyTransform = function(transform) {
|
2011-07-12 15:08:29 +04:00
|
|
|
|
body.style.WebkitTransform = transform;
|
2011-12-12 21:13:08 +04:00
|
|
|
|
body.style.MozTransform = transform;
|
2011-07-12 15:08:29 +04:00
|
|
|
|
body.style.msTransform = transform;
|
2011-12-12 21:13:08 +04:00
|
|
|
|
body.style.OTransform = transform;
|
2011-07-12 15:08:29 +04:00
|
|
|
|
body.style.transform = transform;
|
2011-07-12 15:18:02 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-18 17:04:01 +04:00
|
|
|
|
/**
|
|
|
|
|
* Check if arg is number.
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Number|whatelse} arg Any type
|
|
|
|
|
* @returns {Boolean}
|
|
|
|
|
*/
|
|
|
|
|
shower._isNumber = function(arg) {
|
2013-01-20 03:15:29 +04:00
|
|
|
|
return ! isNaN(parseFloat(arg)) && isFinite(arg);
|
2013-01-18 17:04:01 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Normalize slide number.
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Number} slideNumber slide number (sic!)
|
|
|
|
|
* @returns {Number}
|
|
|
|
|
*/
|
|
|
|
|
shower._normalizeSlideNumber = function(slideNumber) {
|
|
|
|
|
if ( ! shower._isNumber(slideNumber)) {
|
|
|
|
|
throw new Error('Gimme slide number as Number, baby!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (slideNumber < 0) {
|
|
|
|
|
slideNumber = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (slideNumber >= slideList.length) {
|
|
|
|
|
slideNumber = slideList.length - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return slideNumber;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2013-01-20 00:47:54 +04:00
|
|
|
|
* Get slide id from HTML element.
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @private
|
2013-01-20 03:40:59 +04:00
|
|
|
|
* @param {HTMLElement} el
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @returns {String}
|
|
|
|
|
*/
|
2013-01-20 00:47:54 +04:00
|
|
|
|
shower._getSlideIdByEl = function(el) {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
while ('BODY' !== el.nodeName && 'HTML' !== el.nodeName) {
|
|
|
|
|
if (el.classList.contains('slide')) {
|
|
|
|
|
return el.id;
|
|
|
|
|
} else {
|
|
|
|
|
el = el.parentNode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return '';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2013-01-20 00:47:54 +04:00
|
|
|
|
* For touch devices: check if click on links...
|
|
|
|
|
*
|
|
|
|
|
* @TODO: add support for textareas/inputs/...
|
|
|
|
|
*
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @private
|
2013-01-20 03:40:59 +04:00
|
|
|
|
* @param {HTMLElement} e
|
2013-01-20 00:47:54 +04:00
|
|
|
|
* @returns {Boolean}
|
2013-01-18 17:04:01 +04:00
|
|
|
|
*/
|
2013-01-20 00:47:54 +04:00
|
|
|
|
shower._checkInteractiveElement = function(e) {
|
2013-01-20 03:15:53 +04:00
|
|
|
|
return 'A' === e.target.nodeName;
|
2013-01-20 00:47:54 +04:00
|
|
|
|
};
|
2013-01-18 17:04:01 +04:00
|
|
|
|
|
2013-01-20 00:47:54 +04:00
|
|
|
|
/**
|
|
|
|
|
* Get slide number by slideId
|
2013-01-20 03:20:58 +04:00
|
|
|
|
* @param {String} slideId (HTML id or position in slideList)
|
2013-01-20 00:47:54 +04:00
|
|
|
|
* @returns {Number}
|
|
|
|
|
*/
|
|
|
|
|
shower.getSlideNumber = function(slideId) {
|
|
|
|
|
var i = slideList.length - 1,
|
2013-01-18 21:01:10 +04:00
|
|
|
|
slideNumber;
|
2013-01-18 17:04:01 +04:00
|
|
|
|
|
2013-01-18 21:01:10 +04:00
|
|
|
|
if (slideId === '') {
|
2013-01-20 01:13:21 +04:00
|
|
|
|
slideNumber = 0;
|
2013-01-18 21:01:10 +04:00
|
|
|
|
}
|
2013-01-18 17:04:01 +04:00
|
|
|
|
|
2013-01-20 01:13:21 +04:00
|
|
|
|
// As fast as you can ;-)
|
|
|
|
|
// http://jsperf.com/for-vs-foreach/46
|
2013-01-18 21:01:10 +04:00
|
|
|
|
for (; i >= 0; --i) {
|
|
|
|
|
if (slideId === slideList[i].id) {
|
|
|
|
|
slideNumber = i;
|
|
|
|
|
break;
|
2013-01-18 17:04:01 +04:00
|
|
|
|
}
|
2013-01-18 21:01:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-20 00:47:54 +04:00
|
|
|
|
return slideNumber;
|
2013-01-18 17:04:01 +04:00
|
|
|
|
};
|
|
|
|
|
|
2013-01-20 00:47:54 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
/**
|
|
|
|
|
* Show next slide. If slide is last returns false, otherwise return slide
|
|
|
|
|
* number which been shown.
|
2013-01-20 03:24:58 +04:00
|
|
|
|
* @param {Function} [callback] runs only if shower.next() complete successfully
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @returns {Number|Boolean}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
2013-01-18 17:04:01 +04:00
|
|
|
|
shower.next = function(callback) {
|
2012-12-01 13:47:28 +04:00
|
|
|
|
var currentSlideNumber = shower.getCurrentSlideNumber(),
|
|
|
|
|
ret;
|
2012-10-05 16:44:15 +04:00
|
|
|
|
|
|
|
|
|
// Only go to next slide if current slide have no inner
|
|
|
|
|
// navigation or inner navigation is fully shown
|
|
|
|
|
// NOTE: But first of all check if there is no current slide
|
|
|
|
|
if (
|
|
|
|
|
-1 === currentSlideNumber ||
|
|
|
|
|
!slideList[currentSlideNumber].hasInnerNavigation ||
|
2012-12-01 13:47:28 +04:00
|
|
|
|
-1 === shower.increaseInnerNavigation(currentSlideNumber)
|
2012-10-05 16:44:15 +04:00
|
|
|
|
) {
|
2012-12-01 13:47:28 +04:00
|
|
|
|
shower.go(currentSlideNumber + 1);
|
|
|
|
|
// slides starts from 0
|
|
|
|
|
ret = currentSlideNumber + 2;
|
2013-01-18 17:04:01 +04:00
|
|
|
|
|
2013-01-20 01:13:21 +04:00
|
|
|
|
if (typeof(callback) === 'function') {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
callback();
|
|
|
|
|
}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
} else {
|
|
|
|
|
ret = false;
|
2012-10-05 16:44:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
return ret;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show previous slide. If slide is first returns false, otherwise return slide
|
|
|
|
|
* number which been shown.
|
2013-01-20 03:24:58 +04:00
|
|
|
|
* @param {Function} [callback] runs only if shower.previous() complete successfully
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @returns {Number|Boolean}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
2013-01-18 17:04:01 +04:00
|
|
|
|
shower.previous = function(callback) {
|
2012-12-01 13:47:28 +04:00
|
|
|
|
var currentSlideNumber = shower.getCurrentSlideNumber(),
|
|
|
|
|
ret;
|
|
|
|
|
|
|
|
|
|
// slides starts from 0
|
|
|
|
|
if (currentSlideNumber > 0) {
|
|
|
|
|
ret = currentSlideNumber;
|
|
|
|
|
shower.go(currentSlideNumber - 1);
|
2013-01-18 17:04:01 +04:00
|
|
|
|
|
2013-01-20 01:13:21 +04:00
|
|
|
|
if (typeof(callback) === 'function') {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
callback();
|
|
|
|
|
}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
} else {
|
|
|
|
|
ret = false;
|
|
|
|
|
}
|
2011-07-20 22:08:31 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
return ret;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show first slide.
|
2013-01-20 03:24:58 +04:00
|
|
|
|
* @param {Function} [callback]
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @returns {Number}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
2013-01-18 17:04:01 +04:00
|
|
|
|
shower.first = function(callback) {
|
2013-01-20 01:13:21 +04:00
|
|
|
|
if (typeof(callback) === 'function') {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
return shower.go(0);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show last slide.
|
2013-01-20 03:24:58 +04:00
|
|
|
|
* @param {Function} [callback]
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @returns {Number}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
2013-01-18 17:04:01 +04:00
|
|
|
|
shower.last = function(callback) {
|
2013-01-20 01:13:21 +04:00
|
|
|
|
if (typeof(callback) === 'function') {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
callback();
|
|
|
|
|
}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
return shower.go(slideList.length - 1);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Switch to slide view.
|
2013-01-20 03:24:58 +04:00
|
|
|
|
* @param {Function} [callback] runs only if shower.enterSlideMode() complete successfully
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @returns {Number|Boolean}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
2013-01-18 17:04:01 +04:00
|
|
|
|
shower.enterSlideMode = function(callback) {
|
2013-01-18 21:01:10 +04:00
|
|
|
|
var currentSlideNumber = shower.getCurrentSlideNumber();
|
|
|
|
|
|
|
|
|
|
if (currentSlideNumber === -1) {
|
|
|
|
|
currentSlideNumber = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shower.go(currentSlideNumber);
|
|
|
|
|
shower.showPresenterNotes(currentSlideNumber);
|
|
|
|
|
|
|
|
|
|
if (shower.isListMode() && isHistoryApiSupported) {
|
|
|
|
|
history.pushState(null, null, url.pathname + '?full' + shower.getSlideHash(currentSlideNumber));
|
2013-01-18 17:04:01 +04:00
|
|
|
|
}
|
2012-12-30 15:54:16 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
body.classList.remove('list');
|
|
|
|
|
body.classList.add('full');
|
2012-12-30 15:54:16 +04:00
|
|
|
|
|
2013-01-18 17:04:01 +04:00
|
|
|
|
if (window.console && window.console.clear) {
|
|
|
|
|
console.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-18 21:01:10 +04:00
|
|
|
|
shower.updateProgress(currentSlideNumber);
|
|
|
|
|
shower.updateCurrentAndPassedSlides(currentSlideNumber);
|
|
|
|
|
shower.runSlideshowIfPresented(currentSlideNumber);
|
2012-12-30 15:54:16 +04:00
|
|
|
|
|
2013-01-20 01:13:21 +04:00
|
|
|
|
if (typeof(callback) === 'function') {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
return shower._applyTransform(shower._getTransform());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Switch to list view.
|
2013-01-20 03:24:58 +04:00
|
|
|
|
* @param {Function} [callback] runs only if shower.enterListMode() complete successfully
|
2013-01-20 03:30:11 +04:00
|
|
|
|
* @returns {Boolean}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
2013-01-18 17:04:01 +04:00
|
|
|
|
shower.enterListMode = function(callback) {
|
2013-01-18 21:01:10 +04:00
|
|
|
|
var currentSlideNumber = shower.getCurrentSlideNumber();
|
2012-12-30 15:54:16 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
body.classList.remove('full');
|
|
|
|
|
body.classList.add('list');
|
2013-01-18 17:04:01 +04:00
|
|
|
|
|
2013-01-18 21:01:10 +04:00
|
|
|
|
if (shower.isSlideMode() && isHistoryApiSupported) {
|
|
|
|
|
history.pushState(null, null, url.pathname + shower.getSlideHash(currentSlideNumber));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shower.scrollToSlide(currentSlideNumber);
|
|
|
|
|
|
2013-01-20 01:13:21 +04:00
|
|
|
|
if (typeof(callback) === 'function') {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
return shower._applyTransform('none');
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-18 21:01:10 +04:00
|
|
|
|
/**
|
|
|
|
|
* Toggle Mode: Slide and List
|
2013-01-20 03:24:58 +04:00
|
|
|
|
* @param {Function} [callback]
|
2013-01-18 21:01:10 +04:00
|
|
|
|
*/
|
|
|
|
|
shower.toggleMode = function(callback) {
|
|
|
|
|
if (shower.isListMode()) {
|
|
|
|
|
shower.enterSlideMode();
|
|
|
|
|
} else {
|
|
|
|
|
shower.enterListMode();
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-20 01:13:21 +04:00
|
|
|
|
if (typeof(callback) === 'function') {
|
2013-01-18 21:01:10 +04:00
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
2012-12-01 13:47:28 +04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get current slide number. Starts from zero. Warning: when in url you have
|
|
|
|
|
* slide number 1 this method will return 0.
|
|
|
|
|
* If something wrong return -1.
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @returns {Number}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
|
|
|
|
shower.getCurrentSlideNumber = function() {
|
|
|
|
|
var i = slideList.length - 1,
|
2011-08-09 20:47:32 +04:00
|
|
|
|
currentSlideId = url.hash.substr(1);
|
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
// As fast as you can ;-)
|
|
|
|
|
// http://jsperf.com/for-vs-foreach/46
|
|
|
|
|
for (; i >= 0; --i) {
|
2011-08-09 20:47:32 +04:00
|
|
|
|
if (currentSlideId === slideList[i].id) {
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
2012-12-01 13:47:28 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Scroll to slide.
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @param {Number} slideNumber slide number (sic!)
|
2013-01-20 03:31:34 +04:00
|
|
|
|
* @returns {Boolean}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
|
|
|
|
shower.scrollToSlide = function(slideNumber) {
|
|
|
|
|
var currentSlide,
|
2013-01-20 03:31:34 +04:00
|
|
|
|
ret = false;
|
2011-07-20 22:08:31 +04:00
|
|
|
|
|
2013-01-18 15:34:02 +04:00
|
|
|
|
if ( ! shower._isNumber(slideNumber)) {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
throw new Error('Gimme slide number as Number, baby!');
|
2011-07-20 22:08:31 +04:00
|
|
|
|
}
|
2011-07-16 05:13:35 +04:00
|
|
|
|
|
2013-01-18 21:01:10 +04:00
|
|
|
|
if (shower.isSlideMode()) {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
throw new Error('You can\'t scroll to because you in slide mode. Please, switch to list mode.');
|
2012-12-01 13:47:28 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @TODO: WTF?
|
|
|
|
|
if (-1 === slideNumber) {
|
2013-01-20 03:31:34 +04:00
|
|
|
|
return ret;
|
2012-12-01 13:47:28 +04:00
|
|
|
|
}
|
2011-07-12 15:08:29 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
if (slideList[slideNumber]) {
|
|
|
|
|
currentSlide = document.getElementById(slideList[slideNumber].id);
|
|
|
|
|
window.scrollTo(0, currentSlide.offsetTop);
|
|
|
|
|
ret = true;
|
2011-07-20 22:08:31 +04:00
|
|
|
|
} else {
|
2012-12-01 13:47:28 +04:00
|
|
|
|
throw new Error('There is no slide with number ' + slideNumber);
|
2011-07-20 22:08:31 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
return ret;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2013-01-18 21:01:10 +04:00
|
|
|
|
* Check if it's List mode.
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @returns {Boolean}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
|
|
|
|
shower.isListMode = function() {
|
2012-12-10 05:20:47 +04:00
|
|
|
|
return isHistoryApiSupported ? ! /^full.*/.test(url.search.substr(1)) : body.classList.contains('list');
|
2012-12-01 13:47:28 +04:00
|
|
|
|
};
|
|
|
|
|
|
2013-01-18 21:01:10 +04:00
|
|
|
|
/**
|
|
|
|
|
* Check if it's Slide mode.
|
|
|
|
|
* @returns {Boolean}
|
|
|
|
|
*/
|
|
|
|
|
shower.isSlideMode = function() {
|
|
|
|
|
return isHistoryApiSupported ? /^full.*/.test(url.search.substr(1)) : body.classList.contains('full');
|
|
|
|
|
};
|
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
/**
|
|
|
|
|
* Update progress bar.
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @param {Number} slideNumber slide number (sic!)
|
|
|
|
|
* @returns {Boolean}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
|
|
|
|
shower.updateProgress = function(slideNumber) {
|
|
|
|
|
// if progress bar doesn't exist
|
|
|
|
|
if (null === progress) {
|
|
|
|
|
return false;
|
2011-07-20 22:08:31 +04:00
|
|
|
|
}
|
2012-10-05 16:45:47 +04:00
|
|
|
|
|
2013-01-18 15:34:02 +04:00
|
|
|
|
if ( ! shower._isNumber(slideNumber)) {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
throw new Error('Gimme slide number as Number, baby!');
|
2012-12-01 13:47:28 +04:00
|
|
|
|
}
|
2011-08-01 16:06:35 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
progress.style.width = (100 / (slideList.length - 1) * shower._normalizeSlideNumber(slideNumber)).toFixed(2) + '%';
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update current and passed slides.
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @param {Number} slideNumber slide number (sic!)
|
|
|
|
|
* @returns {Boolean}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
|
|
|
|
shower.updateCurrentAndPassedSlides = function(slideNumber) {
|
|
|
|
|
var i,
|
|
|
|
|
slide,
|
|
|
|
|
l = slideList.length;
|
|
|
|
|
|
|
|
|
|
slideNumber = shower._normalizeSlideNumber(slideNumber);
|
|
|
|
|
|
2013-01-18 15:34:02 +04:00
|
|
|
|
if ( ! shower._isNumber(slideNumber)) {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
throw new Error('Gimme slide number as Number, baby!');
|
2012-12-01 13:47:28 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < l; ++i) {
|
|
|
|
|
slide = document.getElementById(slideList[i].id);
|
|
|
|
|
|
|
|
|
|
if (i < slideNumber) {
|
2013-01-20 03:23:33 +04:00
|
|
|
|
slide.classList.remove('active');
|
|
|
|
|
slide.classList.add('visited');
|
2012-12-01 13:47:28 +04:00
|
|
|
|
} else if (i > slideNumber) {
|
2013-01-20 03:23:33 +04:00
|
|
|
|
slide.classList.remove('visited');
|
|
|
|
|
slide.classList.remove('active');
|
2012-12-01 13:47:28 +04:00
|
|
|
|
} else {
|
2013-01-20 03:23:33 +04:00
|
|
|
|
slide.classList.remove('visited');
|
|
|
|
|
slide.classList.add('active');
|
2012-12-01 13:47:28 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
2012-12-30 15:54:16 +04:00
|
|
|
|
/**
|
|
|
|
|
* Show presenter notes in console.
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @param {Number} slideNumber slide number (sic!). Attention: starts from zero.
|
2012-12-30 15:54:16 +04:00
|
|
|
|
*/
|
|
|
|
|
shower.showPresenterNotes = function(slideNumber) {
|
|
|
|
|
if (window.console) {
|
2013-01-01 19:46:52 +04:00
|
|
|
|
slideNumber = shower._normalizeSlideNumber(slideNumber);
|
2012-12-30 15:54:16 +04:00
|
|
|
|
|
2013-01-20 01:13:21 +04:00
|
|
|
|
var slideId = slideList[slideNumber].id,
|
|
|
|
|
nextSlideId = slideList[slideNumber + 1] ? slideList[slideNumber + 1].id : null,
|
|
|
|
|
notes = document.getElementById(slideId).querySelector('footer');
|
2013-01-01 19:46:52 +04:00
|
|
|
|
|
2012-12-30 15:54:16 +04:00
|
|
|
|
if (notes) {
|
|
|
|
|
console.info(notes.innerHTML.replace(/\n\s+/g,'\n'));
|
|
|
|
|
}
|
2013-01-20 01:13:21 +04:00
|
|
|
|
|
2013-01-01 19:46:52 +04:00
|
|
|
|
if (nextSlideId) {
|
|
|
|
|
var next = document.getElementById(nextSlideId).querySelector('h2');
|
2013-01-20 01:13:21 +04:00
|
|
|
|
|
2012-12-30 15:54:16 +04:00
|
|
|
|
if (next) {
|
|
|
|
|
next = next.innerHTML.replace(/^\s+|<[^>]+>/g,'');
|
|
|
|
|
console.info('NEXT: ' + next);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
/**
|
|
|
|
|
* Get slide hash.
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @param {Number} slideNumber slide number (sic!). Attention: starts from zero.
|
2013-01-20 03:32:53 +04:00
|
|
|
|
* @returns {String}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
|
|
|
|
shower.getSlideHash = function(slideNumber) {
|
2013-01-18 15:34:02 +04:00
|
|
|
|
if ( ! shower._isNumber(slideNumber)) {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
throw new Error('Gimme slide number as Number, baby!');
|
2012-12-01 13:47:28 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
slideNumber = shower._normalizeSlideNumber(slideNumber);
|
|
|
|
|
|
|
|
|
|
return '#' + slideList[slideNumber].id;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Go to slide number...
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @param {Number} slideNumber slide number (sic!). Attention: starts from zero.
|
2013-01-20 03:24:58 +04:00
|
|
|
|
* @param {Function} [callback] runs only if you not in List mode
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @returns {Number}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
2013-01-18 17:04:01 +04:00
|
|
|
|
shower.go = function(slideNumber, callback) {
|
2013-01-18 15:34:02 +04:00
|
|
|
|
if ( ! shower._isNumber(slideNumber)) {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
throw new Error('Gimme slide number as Number, baby!');
|
2012-12-01 13:47:28 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
url.hash = shower.getSlideHash(slideNumber);
|
|
|
|
|
|
2013-01-18 21:01:10 +04:00
|
|
|
|
if (shower.isSlideMode()) {
|
2012-12-01 13:47:28 +04:00
|
|
|
|
shower.updateProgress(slideNumber);
|
|
|
|
|
shower.updateCurrentAndPassedSlides(slideNumber);
|
2012-12-30 15:54:16 +04:00
|
|
|
|
shower.showPresenterNotes(slideNumber);
|
2011-08-01 16:06:35 +04:00
|
|
|
|
|
2013-01-20 01:13:21 +04:00
|
|
|
|
if (typeof(callback) === 'function') {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
callback();
|
2012-12-09 16:23:47 +04:00
|
|
|
|
}
|
2011-08-01 03:39:03 +04:00
|
|
|
|
}
|
2011-07-20 22:08:31 +04:00
|
|
|
|
|
2013-01-18 17:04:01 +04:00
|
|
|
|
return slideNumber;
|
2012-12-01 13:47:28 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* Run slide show if presented.
|
|
|
|
|
* @param {Number} slideNumber
|
2013-01-20 03:45:04 +04:00
|
|
|
|
* @returns {Boolean}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
|
|
|
|
shower.runSlideshowIfPresented = function(slideNumber) {
|
2013-01-18 15:34:02 +04:00
|
|
|
|
if ( ! shower._isNumber(slideNumber)) {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
throw new Error('Gimme slide number as Number, baby!');
|
2012-12-01 13:47:28 +04:00
|
|
|
|
}
|
2011-08-09 20:47:32 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
slideNumber = shower._normalizeSlideNumber(slideNumber);
|
2011-08-09 20:47:32 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
clearTimeout(timer);
|
|
|
|
|
|
|
|
|
|
if (slideList[slideNumber].hasTiming) {
|
|
|
|
|
// Compute number of milliseconds from format "X:Y", where X is
|
|
|
|
|
// number of minutes, and Y is number of seconds
|
|
|
|
|
var timing = shower._getData(document.getElementById(slideList[slideNumber].id), 'timing').split(':');
|
|
|
|
|
timing = parseInt(timing[0], 10) * 60 * 1000 + parseInt(timing[1], 10) * 1000;
|
|
|
|
|
|
|
|
|
|
timer = setTimeout(function() {
|
|
|
|
|
shower.go(slideNumber + 1);
|
|
|
|
|
shower.runSlideshowIfPresented(slideNumber + 1);
|
|
|
|
|
},
|
|
|
|
|
timing);
|
|
|
|
|
}
|
2013-01-20 03:45:04 +04:00
|
|
|
|
|
|
|
|
|
return true;
|
2012-12-01 13:47:28 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Increases inner navigation by adding 'active' class to next inactive inner navigation item
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @param {Number} slideNumber
|
|
|
|
|
* @returns {Number}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
|
|
|
|
shower.increaseInnerNavigation = function(slideNumber) {
|
|
|
|
|
var nextNodes,
|
|
|
|
|
node,
|
|
|
|
|
ret = -1;
|
|
|
|
|
|
2013-01-18 15:34:02 +04:00
|
|
|
|
if ( ! shower._isNumber(slideNumber)) {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
throw new Error('Gimme slide number as Number, baby!');
|
2012-12-01 13:47:28 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If inner navigation in this slide...
|
|
|
|
|
if (slideList[slideNumber].hasInnerNavigation) {
|
|
|
|
|
nextNodes = document.getElementById(slideList[slideNumber].id).querySelectorAll('.next:not(.active)');
|
|
|
|
|
|
|
|
|
|
if (0 !== nextNodes.length) {
|
|
|
|
|
node = nextNodes[0];
|
|
|
|
|
node.classList.add('active');
|
|
|
|
|
ret = nextNodes.length - 1;
|
|
|
|
|
}
|
2011-08-09 20:47:32 +04:00
|
|
|
|
}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-09 20:47:32 +04:00
|
|
|
|
|
|
|
|
|
// Event handlers
|
|
|
|
|
|
2013-01-18 15:34:02 +04:00
|
|
|
|
window.addEventListener('DOMContentLoaded', function() {
|
2013-01-18 21:01:10 +04:00
|
|
|
|
if (shower.isSlideMode()) {
|
2012-12-01 13:47:28 +04:00
|
|
|
|
shower.enterSlideMode();
|
2011-07-20 22:08:31 +04:00
|
|
|
|
}
|
|
|
|
|
}, false);
|
|
|
|
|
|
2013-01-20 03:45:45 +04:00
|
|
|
|
window.addEventListener('popstate', function() {
|
2012-12-01 13:47:28 +04:00
|
|
|
|
if (shower.isListMode()) {
|
|
|
|
|
shower.enterListMode();
|
2011-07-20 22:08:31 +04:00
|
|
|
|
} else {
|
2012-12-01 13:47:28 +04:00
|
|
|
|
shower.enterSlideMode();
|
2011-07-20 22:08:31 +04:00
|
|
|
|
}
|
|
|
|
|
}, false);
|
|
|
|
|
|
2013-01-20 03:45:45 +04:00
|
|
|
|
window.addEventListener('resize', function() {
|
2013-01-18 21:01:10 +04:00
|
|
|
|
if (shower.isSlideMode()) {
|
2012-12-01 13:47:28 +04:00
|
|
|
|
shower._applyTransform(shower._getTransform());
|
2011-07-20 22:08:31 +04:00
|
|
|
|
}
|
2011-07-16 04:52:21 +04:00
|
|
|
|
}, false);
|
2011-07-20 22:08:31 +04:00
|
|
|
|
|
2013-01-18 15:34:02 +04:00
|
|
|
|
document.addEventListener('keydown', function(e) {
|
2012-12-08 16:45:00 +04:00
|
|
|
|
// Shortcut for alt, ctrl and meta keys
|
2011-08-09 20:47:32 +04:00
|
|
|
|
if (e.altKey || e.ctrlKey || e.metaKey) { return; }
|
2012-12-01 13:47:28 +04:00
|
|
|
|
|
|
|
|
|
var currentSlideNumber = shower.getCurrentSlideNumber(),
|
|
|
|
|
innerNavigationCompleted = true;
|
2011-07-20 22:08:31 +04:00
|
|
|
|
|
2011-08-09 20:47:32 +04:00
|
|
|
|
switch (e.which) {
|
2012-02-15 16:46:51 +04:00
|
|
|
|
case 116: // F5
|
2012-12-08 16:45:00 +04:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
if (shower.isListMode()) {
|
|
|
|
|
var slideNumber = e.shiftKey ? currentSlideNumber : 0;
|
|
|
|
|
|
|
|
|
|
shower.go(slideNumber);
|
|
|
|
|
shower.enterSlideMode();
|
|
|
|
|
} else {
|
|
|
|
|
shower.enterListMode();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2011-07-20 22:08:31 +04:00
|
|
|
|
case 13: // Enter
|
2012-12-01 13:47:28 +04:00
|
|
|
|
if (shower.isListMode() && -1 !== currentSlideNumber) {
|
2011-07-20 22:08:31 +04:00
|
|
|
|
e.preventDefault();
|
2012-12-01 13:47:28 +04:00
|
|
|
|
shower.enterSlideMode();
|
2011-07-20 22:08:31 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 27: // Esc
|
2013-01-18 21:01:10 +04:00
|
|
|
|
if (shower.isSlideMode()) {
|
2011-07-20 22:08:31 +04:00
|
|
|
|
e.preventDefault();
|
2012-12-01 13:47:28 +04:00
|
|
|
|
shower.enterListMode();
|
2011-07-20 22:08:31 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 33: // PgUp
|
|
|
|
|
case 38: // Up
|
|
|
|
|
case 37: // Left
|
2011-07-25 13:13:11 +04:00
|
|
|
|
case 72: // h
|
2011-07-20 22:08:31 +04:00
|
|
|
|
case 75: // k
|
|
|
|
|
e.preventDefault();
|
2012-12-01 13:47:28 +04:00
|
|
|
|
shower.previous();
|
2011-07-20 22:08:31 +04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 34: // PgDown
|
|
|
|
|
case 40: // Down
|
|
|
|
|
case 39: // Right
|
2011-07-25 13:13:11 +04:00
|
|
|
|
case 76: // l
|
2011-07-20 22:08:31 +04:00
|
|
|
|
case 74: // j
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
2013-01-18 21:01:10 +04:00
|
|
|
|
if (shower.isSlideMode()) {
|
2012-12-01 13:47:28 +04:00
|
|
|
|
// Inner navigation is "completed" if current slide have
|
|
|
|
|
// no inner navigation or inner navigation is fully shown
|
|
|
|
|
innerNavigationCompleted = !slideList[currentSlideNumber].hasInnerNavigation ||
|
|
|
|
|
-1 === shower.increaseInnerNavigation(currentSlideNumber);
|
|
|
|
|
} else {
|
|
|
|
|
// Also inner navigation is always "completed" if we are in
|
|
|
|
|
// list mode
|
|
|
|
|
innerNavigationCompleted = true;
|
|
|
|
|
}
|
|
|
|
|
// NOTE: First of all check if there is no current slide
|
|
|
|
|
if (
|
|
|
|
|
-1 === currentSlideNumber || innerNavigationCompleted
|
|
|
|
|
) {
|
|
|
|
|
currentSlideNumber++;
|
|
|
|
|
shower.go(currentSlideNumber);
|
|
|
|
|
// We must run slideshow only in full mode
|
2013-01-18 21:01:10 +04:00
|
|
|
|
if (shower.isSlideMode()) {
|
2012-12-01 13:47:28 +04:00
|
|
|
|
shower.runSlideshowIfPresented(currentSlideNumber);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-07-20 22:08:31 +04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 36: // Home
|
|
|
|
|
e.preventDefault();
|
2012-12-01 13:47:28 +04:00
|
|
|
|
shower.first();
|
2011-07-20 22:08:31 +04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 35: // End
|
|
|
|
|
e.preventDefault();
|
2012-12-01 13:47:28 +04:00
|
|
|
|
shower.last();
|
2011-07-20 22:08:31 +04:00
|
|
|
|
break;
|
|
|
|
|
|
2011-08-09 20:47:32 +04:00
|
|
|
|
case 9: // Tab = +1; Shift + Tab = -1
|
2011-07-20 22:08:31 +04:00
|
|
|
|
case 32: // Space = +1; Shift + Space = -1
|
|
|
|
|
e.preventDefault();
|
2012-12-01 13:47:28 +04:00
|
|
|
|
shower[e.shiftKey ? 'previous' : 'next']();
|
2011-07-20 22:08:31 +04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
// Behave as usual
|
|
|
|
|
}
|
2011-07-18 13:39:47 +04:00
|
|
|
|
}, false);
|
|
|
|
|
|
2013-01-20 00:47:54 +04:00
|
|
|
|
document.addEventListener('click', function(e) {
|
|
|
|
|
if (shower.isListMode() && shower._getSlideIdByEl(e.target)) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
shower.go(shower.getSlideNumber(shower._getSlideIdByEl(e.target)));
|
|
|
|
|
shower.enterSlideMode();
|
|
|
|
|
}
|
|
|
|
|
}, false);
|
2011-07-20 22:08:31 +04:00
|
|
|
|
|
2013-01-18 15:34:02 +04:00
|
|
|
|
document.addEventListener('touchstart', function(e) {
|
2013-01-20 00:47:54 +04:00
|
|
|
|
if (shower._getSlideIdByEl(e.target)) {
|
|
|
|
|
if (shower.isSlideMode() && ! shower._checkInteractiveElement(e)) {
|
|
|
|
|
var x = e.touches[0].pageX;
|
|
|
|
|
|
|
|
|
|
if (x > window.innerWidth / 2) {
|
|
|
|
|
shower.next();
|
|
|
|
|
} else {
|
|
|
|
|
shower.previous();
|
|
|
|
|
}
|
2011-08-01 03:39:03 +04:00
|
|
|
|
}
|
2011-08-09 20:47:32 +04:00
|
|
|
|
|
2013-01-20 00:47:54 +04:00
|
|
|
|
if (shower.isListMode()) {
|
|
|
|
|
shower.go(shower.getSlideNumber(shower._getSlideIdByEl(e.target)));
|
|
|
|
|
shower.enterSlideMode();
|
|
|
|
|
}
|
2011-08-01 03:39:03 +04:00
|
|
|
|
}
|
2013-01-20 00:47:54 +04:00
|
|
|
|
|
|
|
|
|
|
2011-08-01 03:39:03 +04:00
|
|
|
|
}, false);
|
2011-07-20 22:08:31 +04:00
|
|
|
|
|
2013-01-18 15:34:02 +04:00
|
|
|
|
document.addEventListener('touchmove', function(e) {
|
2013-01-20 00:47:54 +04:00
|
|
|
|
if (shower.isSlideMode()) {
|
2011-08-01 03:39:03 +04:00
|
|
|
|
e.preventDefault();
|
2011-07-20 22:08:31 +04:00
|
|
|
|
}
|
|
|
|
|
}, false);
|
2010-11-08 02:26:01 +03:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
return shower;
|
|
|
|
|
|
|
|
|
|
})(this, this.document);
|