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
|
|
|
|
|
*/
|
2013-02-05 22:06:51 +04:00
|
|
|
|
window.shower = window.shower || (function(window, document, undefined) {
|
2012-12-01 13:47:28 +04:00
|
|
|
|
var shower = {},
|
2012-10-05 16:44:15 +04:00
|
|
|
|
url = window.location,
|
2011-07-16 04:52:21 +04:00
|
|
|
|
body = document.body,
|
2013-03-06 17:27:55 +04:00
|
|
|
|
slides = [],
|
|
|
|
|
progress = [],
|
2012-12-01 13:47:28 +04:00
|
|
|
|
timer,
|
2013-05-03 20:30:24 +04:00
|
|
|
|
isHistoryApiSupported = !!(window.history && window.history.pushState);
|
2010-10-30 04:16:19 +04:00
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
/**
|
|
|
|
|
* Slide constructor
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} opts
|
|
|
|
|
* @param {String} opts.id html id attribute or automaticaly assigned order number
|
|
|
|
|
* @param {Number} opts.number slide number
|
|
|
|
|
* @param {Boolean} opts.hasInnerNavigation
|
|
|
|
|
* @param {Number} [opts.timing]
|
|
|
|
|
* @param {Number} [opts.innerLength]
|
|
|
|
|
* @param {Number} [opts.innerComplete = 0]
|
|
|
|
|
* @constructor
|
|
|
|
|
*/
|
|
|
|
|
function Slide(opts) {
|
|
|
|
|
for (var prop in opts) {
|
|
|
|
|
if (opts.hasOwnProperty(prop)) {
|
|
|
|
|
this[prop] = opts[prop];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Slide.prototype = {
|
|
|
|
|
/**
|
|
|
|
|
* Get slide number.
|
|
|
|
|
* @returns {Number}
|
|
|
|
|
*/
|
|
|
|
|
getSlideNumber : function() {
|
|
|
|
|
return this.number;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
isLast : function() {
|
|
|
|
|
return shower.slideList.length === this.number + 1
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if inner navigation is finished
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
|
|
|
|
isFinished : function() {
|
|
|
|
|
return this.innerComplete >= this.innerLength;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Start inner navigation by timer or just switch slide after timer.
|
|
|
|
|
* time sets in HTML: .slide[data-timing=MM:SS]
|
|
|
|
|
* @returns {Object} Current slide
|
|
|
|
|
*/
|
|
|
|
|
process : function(shower) {
|
|
|
|
|
if (this.timing) {
|
|
|
|
|
this.initTimer(shower);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.next(shower);
|
|
|
|
|
return this;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Init timer for inner navigation or for just turn to next slide
|
|
|
|
|
* @param shower
|
|
|
|
|
* @returns {Object|Boolean} Current slide
|
|
|
|
|
*/
|
|
|
|
|
initTimer : function(shower) {
|
|
|
|
|
var slide = this;
|
|
|
|
|
|
|
|
|
|
if ( ! slide.timing) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-05 02:15:58 +04:00
|
|
|
|
slide.stopTimer();
|
2013-05-03 20:46:29 +04:00
|
|
|
|
|
|
|
|
|
if (slide.isFinished()) {
|
|
|
|
|
timer = setInterval(function() {
|
2013-05-05 02:15:58 +04:00
|
|
|
|
slide.stopTimer();
|
2013-05-03 20:46:29 +04:00
|
|
|
|
shower.next();
|
|
|
|
|
},
|
|
|
|
|
slide.timing * (slide.innerLength || 1));
|
|
|
|
|
} else {
|
|
|
|
|
timer = setInterval(function() {
|
|
|
|
|
if (slide.isFinished()) {
|
2013-05-05 02:15:58 +04:00
|
|
|
|
slide.stopTimer();
|
2013-05-03 20:46:29 +04:00
|
|
|
|
shower.next();
|
|
|
|
|
} else {
|
|
|
|
|
slide.next(shower);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
slide.timing);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
},
|
|
|
|
|
|
2013-05-05 02:15:58 +04:00
|
|
|
|
/**
|
|
|
|
|
* Stop timer
|
|
|
|
|
*/
|
|
|
|
|
stopTimer : function() {
|
|
|
|
|
if (timer) {
|
|
|
|
|
clearInterval(timer);
|
|
|
|
|
timer = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
},
|
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
/**
|
|
|
|
|
* Previous step of inner navigation or if current step is step 0 then go to previous slide.
|
|
|
|
|
* @returns {Object|Boolean} Current slide
|
|
|
|
|
*/
|
|
|
|
|
prev : function(shower) {
|
|
|
|
|
var prevSteps,
|
|
|
|
|
slide = this;
|
|
|
|
|
|
|
|
|
|
if ( ! slide.hasInnerNavigation || slide.isFinished() || slide.innerComplete === 0) {
|
|
|
|
|
shower.prev();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prevSteps = document.getElementById(slide.id).querySelectorAll('.next.active');
|
|
|
|
|
|
|
|
|
|
if ( ! prevSteps || prevSteps.length < 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (slide.innerComplete > 0) {
|
|
|
|
|
slide.innerComplete--;
|
|
|
|
|
prevSteps[prevSteps.length - 1].classList.remove('active');
|
|
|
|
|
} else {
|
|
|
|
|
shower.prev();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Next step of inner navigation or if current step is last then go to next slide.
|
|
|
|
|
* @returns {Object|Boolean} Current slide
|
|
|
|
|
*/
|
|
|
|
|
next : function(shower) {
|
|
|
|
|
var nextSteps,
|
|
|
|
|
slide = this;
|
|
|
|
|
|
|
|
|
|
if ( ! slide.hasInnerNavigation || slide.isFinished()) {
|
|
|
|
|
shower.next();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( ! slide.isFinished()) {
|
|
|
|
|
nextSteps = document.getElementById(slide.id).querySelectorAll('.next:not(.active)');
|
|
|
|
|
nextSteps[0].classList.add('active');
|
|
|
|
|
|
|
|
|
|
slide.innerComplete++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
};
|
2013-03-24 18:34:47 +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
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
shower.slideList = [];
|
2013-03-24 18:34:47 +04:00
|
|
|
|
|
2013-03-06 17:27:55 +04:00
|
|
|
|
/**
|
2013-03-24 18:59:46 +04:00
|
|
|
|
* Shower initialization
|
|
|
|
|
* @param {String} [slideSelector]
|
|
|
|
|
* @param {String} [progressSelector]
|
2013-03-06 17:27:55 +04:00
|
|
|
|
* @returns {Object} shower
|
|
|
|
|
*/
|
|
|
|
|
shower.init = function(slideSelector, progressSelector) {
|
2013-05-10 15:12:21 +04:00
|
|
|
|
var timing;
|
2013-03-24 18:59:46 +04:00
|
|
|
|
|
2013-03-06 17:27:55 +04:00
|
|
|
|
slideSelector = slideSelector || '.slide';
|
|
|
|
|
progressSelector = progressSelector || 'div.progress div';
|
|
|
|
|
|
|
|
|
|
slides = document.querySelectorAll(slideSelector);
|
|
|
|
|
progress = document.querySelector(progressSelector);
|
|
|
|
|
|
2013-03-06 17:46:41 +04:00
|
|
|
|
for (var i = 0; i < slides.length; i++) {
|
2013-05-10 12:29:05 +04:00
|
|
|
|
// Slide IDs are optional.
|
|
|
|
|
// In case of missing ID we set it to the slide number
|
2013-03-06 17:27:55 +04:00
|
|
|
|
if ( ! slides[i].id) {
|
|
|
|
|
slides[i].id = i + 1;
|
|
|
|
|
}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
|
2013-05-10 15:12:21 +04:00
|
|
|
|
timing = shower._getData(slides[i], 'timing');
|
2013-05-10 12:29:05 +04:00
|
|
|
|
|
|
|
|
|
// Parsing timing in [S] or [M:S] format
|
|
|
|
|
// and returning it in milliseconds
|
2013-05-10 15:12:21 +04:00
|
|
|
|
if (timing && /^(\d{1,2}:)?\d{1,3}$/.test(timing)) {
|
2013-05-10 12:29:05 +04:00
|
|
|
|
if (timing.indexOf(':') !== -1) {
|
|
|
|
|
timing = timing.split(':');
|
2013-05-10 15:12:21 +04:00
|
|
|
|
timing = (parseInt(timing[0], 10) * 60 + parseInt(timing[1], 10)) * 1000;
|
2013-05-10 12:29:05 +04:00
|
|
|
|
} else {
|
2013-05-10 15:12:21 +04:00
|
|
|
|
timing = parseInt(timing, 10) * 1000;
|
2013-05-10 12:29:05 +04:00
|
|
|
|
}
|
2013-05-10 15:12:21 +04:00
|
|
|
|
if (timing === 0) {
|
|
|
|
|
timing = false;
|
2013-05-03 20:46:29 +04:00
|
|
|
|
}
|
2013-05-10 12:29:05 +04:00
|
|
|
|
} else {
|
2013-05-10 15:12:21 +04:00
|
|
|
|
timing = false;
|
2013-05-03 20:46:29 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shower.slideList.push(new Slide({
|
|
|
|
|
id : slides[i].id,
|
|
|
|
|
number : i,
|
|
|
|
|
hasInnerNavigation : null !== slides[i].querySelector('.next'),
|
2013-05-10 12:29:05 +04:00
|
|
|
|
timing : timing,
|
2013-05-03 20:46:29 +04:00
|
|
|
|
innerLength : slides[i].querySelectorAll('.next').length,
|
|
|
|
|
innerComplete : 0
|
|
|
|
|
}));
|
|
|
|
|
}
|
2013-01-29 03:50:02 +04:00
|
|
|
|
|
2013-03-06 17:48:34 +04:00
|
|
|
|
return shower;
|
2013-03-06 17:27:55 +04:00
|
|
|
|
};
|
2011-07-16 05:13:35 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
/**
|
2013-01-22 01:25:08 +04:00
|
|
|
|
* Get slide scale value.
|
2012-12-01 13:47:28 +04:00
|
|
|
|
* @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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2013-01-22 01:25:08 +04:00
|
|
|
|
* Set CSS transform with prefixes to body.
|
2012-12-01 13:47:28 +04:00
|
|
|
|
* @private
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @returns {Boolean}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
|
|
|
|
shower._applyTransform = function(transform) {
|
2013-05-03 20:51:00 +04:00
|
|
|
|
[
|
|
|
|
|
'WebkitTransform',
|
|
|
|
|
'MozTransform',
|
|
|
|
|
'msTransform',
|
|
|
|
|
'OTransform',
|
2013-05-03 21:18:15 +04:00
|
|
|
|
'transform'
|
2013-05-03 20:51:00 +04:00
|
|
|
|
].forEach(function(prop) {
|
|
|
|
|
body.style[prop] = 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
|
2013-01-20 14:09:58 +04:00
|
|
|
|
* @param {String|Number} arg
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @returns {Boolean}
|
|
|
|
|
*/
|
|
|
|
|
shower._isNumber = function(arg) {
|
2013-01-20 21:59:45 +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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-24 18:34:47 +04:00
|
|
|
|
if (slideNumber >= shower.slideList.length) {
|
|
|
|
|
slideNumber = shower.slideList.length - 1;
|
2013-01-18 17:04:01 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-02-13 20:25:48 +04:00
|
|
|
|
* @param {Node} 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-22 01:25:08 +04:00
|
|
|
|
* For touch devices: check if link is clicked.
|
2013-01-20 00:47:54 +04:00
|
|
|
|
*
|
2013-02-13 20:25:48 +04:00
|
|
|
|
* @TODO: add support for textarea/input/etc.
|
2013-01-20 00:47:54 +04:00
|
|
|
|
*
|
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 21:59:45 +04:00
|
|
|
|
return 'A' === e.target.nodeName;
|
2013-01-20 00:47:54 +04:00
|
|
|
|
};
|
2013-01-18 17:04:01 +04:00
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
/**
|
|
|
|
|
* Get slide number by slideId.
|
|
|
|
|
* @param {String} slideId
|
|
|
|
|
* @returns {Number}
|
|
|
|
|
*/
|
|
|
|
|
shower.getSlideNumber = function(slideId) {
|
|
|
|
|
var i = shower.slideList.length - 1,
|
|
|
|
|
slideNumber;
|
|
|
|
|
|
|
|
|
|
if (slideId === '') {
|
|
|
|
|
slideNumber = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// As fast as you can ;-)
|
|
|
|
|
// http://jsperf.com/for-vs-foreach/46
|
|
|
|
|
for (; i >= 0; --i) {
|
|
|
|
|
if (slideId === shower.slideList[i].id) {
|
|
|
|
|
slideNumber = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return slideNumber;
|
|
|
|
|
};
|
2013-01-18 17:04:01 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
/**
|
2013-01-22 01:25:08 +04:00
|
|
|
|
* Go to slide number.
|
2013-01-20 16:51:33 +04:00
|
|
|
|
* @param {Number} slideNumber slide number (sic!). Attention: starts from zero.
|
2013-01-22 01:25:08 +04:00
|
|
|
|
* @param {Function} [callback] runs only if you not in List mode.
|
2013-05-05 02:36:12 +04:00
|
|
|
|
* @returns {Number|Boolean}
|
2013-01-20 16:51:33 +04:00
|
|
|
|
*/
|
|
|
|
|
shower.go = function(slideNumber, callback) {
|
2013-05-03 20:46:29 +04:00
|
|
|
|
var slide;
|
2013-03-24 18:34:47 +04:00
|
|
|
|
|
2013-01-20 16:51:33 +04:00
|
|
|
|
if ( ! shower._isNumber(slideNumber)) {
|
|
|
|
|
throw new Error('Gimme slide number as Number, baby!');
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-05 02:36:12 +04:00
|
|
|
|
if ( ! shower.slideList[slideNumber]) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-20 21:59:45 +04:00
|
|
|
|
// Also triggers popstate and invoke shower.enter__Mode()
|
2013-01-20 16:51:33 +04:00
|
|
|
|
url.hash = shower.getSlideHash(slideNumber);
|
|
|
|
|
|
2013-01-21 20:22:28 +04:00
|
|
|
|
shower.updateProgress(slideNumber);
|
2013-01-22 01:25:08 +04:00
|
|
|
|
shower.updateActiveAndVisitedSlides(slideNumber);
|
2013-01-21 20:22:28 +04:00
|
|
|
|
|
2013-01-20 16:51:33 +04:00
|
|
|
|
if (shower.isSlideMode()) {
|
2013-01-20 21:59:45 +04:00
|
|
|
|
shower.showPresenterNotes(slideNumber);
|
2013-05-03 20:46:29 +04:00
|
|
|
|
slide = shower.slideList[slideNumber];
|
|
|
|
|
if (slide.timing) {
|
|
|
|
|
slide.initTimer(shower);
|
|
|
|
|
}
|
2013-01-20 21:59:45 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof(callback) === 'function') {
|
|
|
|
|
callback();
|
2013-01-20 16:51:33 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return slideNumber;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2013-01-22 01:25:08 +04:00
|
|
|
|
* Show next slide or show next Inner navigation item.
|
2013-05-03 20:52:31 +04:00
|
|
|
|
* Returns false on a last slide, otherwise returns shower.
|
2013-01-22 01:25:08 +04:00
|
|
|
|
* @param {Function} [callback] runs only if shower.next() is successfully completed.
|
2013-03-24 18:34:47 +04:00
|
|
|
|
* @returns {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(),
|
2013-05-03 20:46:29 +04:00
|
|
|
|
nextSlide = shower.slideList[currentSlideNumber + 1];
|
2012-10-05 16:44:15 +04:00
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
// If don't exist next slide
|
|
|
|
|
if (! nextSlide) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-01-18 17:04:01 +04:00
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
shower.go(currentSlideNumber + 1);
|
2013-01-20 16:51:33 +04:00
|
|
|
|
|
|
|
|
|
if (typeof(callback) === 'function') {
|
|
|
|
|
callback();
|
2012-10-05 16:44:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-03 20:52:31 +04:00
|
|
|
|
return this;
|
2012-12-01 13:47:28 +04:00
|
|
|
|
};
|
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {Function} [callback]
|
|
|
|
|
*/
|
|
|
|
|
shower._turnNextSlide = function(callback) {
|
|
|
|
|
var currentSlideNumber = shower.getCurrentSlideNumber(),
|
2013-05-05 02:15:58 +04:00
|
|
|
|
slide = shower.slideList[currentSlideNumber];
|
2013-05-03 20:46:29 +04:00
|
|
|
|
|
2013-05-05 02:36:12 +04:00
|
|
|
|
|
|
|
|
|
if (shower.isSlideMode()) {
|
|
|
|
|
slide.stopTimer();
|
|
|
|
|
slide.next(shower);
|
|
|
|
|
} else {
|
|
|
|
|
shower.go(currentSlideNumber + 1);
|
|
|
|
|
}
|
2013-05-03 20:46:29 +04:00
|
|
|
|
|
|
|
|
|
if (typeof(callback) === 'function') {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-05 02:15:58 +04:00
|
|
|
|
return;
|
2013-05-03 20:46:29 +04:00
|
|
|
|
};
|
2013-03-24 18:34:47 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
/**
|
2013-01-22 01:25:08 +04:00
|
|
|
|
* Show previous slide. Returns false on a first slide, otherwise returns shown slide number.
|
|
|
|
|
* @param {Function} [callback] runs only if shower.previous() is successfully completed.
|
2013-03-24 18:34:47 +04:00
|
|
|
|
* @returns {Boolean}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
2013-05-03 20:46:29 +04:00
|
|
|
|
shower.prev = shower.previous = function(callback) {
|
2013-03-24 18:34:47 +04:00
|
|
|
|
var currentSlideNumber = shower.getCurrentSlideNumber();
|
2012-12-01 13:47:28 +04:00
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
// Slides starts from 0
|
|
|
|
|
if (currentSlideNumber < 1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-01-18 17:04:01 +04:00
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
shower.go(currentSlideNumber - 1);
|
2011-07-20 22:08:31 +04:00
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
if (typeof(callback) === 'function') {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
2013-03-24 18:34:47 +04:00
|
|
|
|
|
|
|
|
|
return true;
|
2012-12-01 13:47:28 +04:00
|
|
|
|
};
|
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
/**
|
|
|
|
|
* Show previous slide. Returns false on a first slide, otherwise returns shown slide number.
|
|
|
|
|
* @param {Function} [callback] runs only if shower.previous() is successfully completed.
|
|
|
|
|
* @returns {Boolean}
|
|
|
|
|
*/
|
|
|
|
|
shower._turnPreviousSlide = function(callback) {
|
|
|
|
|
var currentSlideNumber = shower.getCurrentSlideNumber(),
|
2013-05-05 02:36:12 +04:00
|
|
|
|
slide = shower.slideList[currentSlideNumber];
|
2013-03-24 18:34:47 +04:00
|
|
|
|
|
2013-05-05 02:36:12 +04:00
|
|
|
|
slide.stopTimer();
|
2013-03-24 18:34:47 +04:00
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
if (shower.isSlideMode()) {
|
|
|
|
|
slide.prev(shower);
|
|
|
|
|
} else {
|
|
|
|
|
shower.go(currentSlideNumber - 1);
|
|
|
|
|
}
|
2013-03-24 18:34:47 +04:00
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
if (typeof(callback) === 'function') {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
2013-03-24 18:34:47 +04:00
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
return true;
|
|
|
|
|
};
|
2013-03-24 18:34:47 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
/**
|
|
|
|
|
* Show first slide.
|
2013-01-20 03:24:58 +04:00
|
|
|
|
* @param {Function} [callback]
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
2013-01-18 17:04:01 +04:00
|
|
|
|
shower.first = function(callback) {
|
2013-05-05 02:15:58 +04:00
|
|
|
|
var slide = shower.slideList[shower.getCurrentSlideNumber()];
|
|
|
|
|
|
|
|
|
|
slide.timing && slide.stopTimer();
|
|
|
|
|
shower.go(0);
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show last slide.
|
2013-01-20 03:24:58 +04:00
|
|
|
|
* @param {Function} [callback]
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
2013-01-18 17:04:01 +04:00
|
|
|
|
shower.last = function(callback) {
|
2013-05-05 02:15:58 +04:00
|
|
|
|
var slide = shower.slideList[shower.getCurrentSlideNumber()];
|
|
|
|
|
|
|
|
|
|
slide.timing && slide.stopTimer();
|
2013-05-03 21:20:28 +04:00
|
|
|
|
shower.go(shower.slideList.length - 1);
|
2013-03-24 18:34:47 +04:00
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
if (typeof(callback) === 'function') {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Switch to slide view.
|
2013-01-22 01:25:08 +04:00
|
|
|
|
* @param {Function} [callback] runs only if shower.enterSlideMode() is successfully completed.
|
2013-01-20 14:09:58 +04:00
|
|
|
|
* @returns {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();
|
|
|
|
|
|
2013-01-20 21:59:45 +04:00
|
|
|
|
// Anyway: change body class (@TODO: refactoring)
|
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-20 21:59:45 +04:00
|
|
|
|
// Preparing URL for shower.go()
|
|
|
|
|
if (shower.isListMode() && isHistoryApiSupported) {
|
|
|
|
|
history.pushState(null, null, url.pathname + '?full' + shower.getSlideHash(currentSlideNumber));
|
2013-01-18 17:04:01 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-20 21:59:45 +04:00
|
|
|
|
shower._applyTransform(shower._getTransform());
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-20 21:59:45 +04:00
|
|
|
|
return true;
|
2012-12-01 13:47:28 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Switch to list view.
|
2013-01-22 01:25:08 +04:00
|
|
|
|
* @param {Function} [callback] runs only if shower.enterListMode() is successfully completed.
|
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-05-03 20:46:29 +04:00
|
|
|
|
var currentSlideNumber;
|
2013-03-24 18:34:47 +04:00
|
|
|
|
|
2013-01-20 21:59:45 +04:00
|
|
|
|
// Anyway: change body class (@TODO: refactoring)
|
|
|
|
|
body.classList.remove('full');
|
|
|
|
|
body.classList.add('list');
|
|
|
|
|
|
|
|
|
|
shower.clearPresenterNotes();
|
|
|
|
|
|
|
|
|
|
if (shower.isListMode()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-24 18:34:47 +04:00
|
|
|
|
currentSlideNumber = shower.getCurrentSlideNumber();
|
2012-12-30 15:54:16 +04:00
|
|
|
|
|
2013-05-05 02:15:58 +04:00
|
|
|
|
shower.slideList[currentSlideNumber].stopTimer();
|
2013-01-20 15:36:50 +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 21:59:45 +04:00
|
|
|
|
shower._applyTransform('none');
|
2013-01-18 21:01:10 +04:00
|
|
|
|
|
2013-01-20 01:13:21 +04:00
|
|
|
|
if (typeof(callback) === 'function') {
|
2013-01-18 17:04:01 +04:00
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-20 21:59:45 +04:00
|
|
|
|
return true;
|
2012-12-01 13:47:28 +04:00
|
|
|
|
};
|
|
|
|
|
|
2013-01-18 21:01:10 +04:00
|
|
|
|
/**
|
2013-01-22 01:25:08 +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
|
|
|
|
|
|
|
|
|
/**
|
2013-01-22 01:25:08 +04:00
|
|
|
|
* 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.
|
2013-01-18 17:04:01 +04:00
|
|
|
|
* @returns {Number}
|
2012-12-01 13:47:28 +04:00
|
|
|
|
*/
|
|
|
|
|
shower.getCurrentSlideNumber = function() {
|
2013-03-24 18:34:47 +04:00
|
|
|
|
var i = shower.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) {
|
2013-03-24 18:34:47 +04:00
|
|
|
|
if (currentSlideId === shower.slideList[i].id) {
|
2011-08-09 20:47:32 +04:00
|
|
|
|
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
|
|
|
|
|
2013-03-24 18:34:47 +04:00
|
|
|
|
if (shower.slideList[slideNumber]) {
|
|
|
|
|
currentSlide = document.getElementById(shower.slideList[slideNumber].id);
|
2012-12-01 13:47:28 +04:00
|
|
|
|
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
|
|
|
|
|
2013-03-24 18:34:47 +04:00
|
|
|
|
progress.style.width = (100 / (shower.slideList.length - 1) * shower._normalizeSlideNumber(slideNumber)).toFixed(2) + '%';
|
2012-12-01 13:47:28 +04:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2013-01-22 01:25:08 +04:00
|
|
|
|
* Update active and visited 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
|
|
|
|
*/
|
2013-01-22 01:25:08 +04:00
|
|
|
|
shower.updateActiveAndVisitedSlides = function(slideNumber) {
|
2012-12-01 13:47:28 +04:00
|
|
|
|
var i,
|
|
|
|
|
slide,
|
2013-03-24 18:34:47 +04:00
|
|
|
|
l = shower.slideList.length;
|
2012-12-01 13:47:28 +04:00
|
|
|
|
|
|
|
|
|
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) {
|
2013-03-24 18:34:47 +04:00
|
|
|
|
slide = document.getElementById(shower.slideList[i].id);
|
2012-12-01 13:47:28 +04:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-20 21:59:45 +04:00
|
|
|
|
/**
|
|
|
|
|
* Clear presenter notes in console.
|
|
|
|
|
*/
|
|
|
|
|
shower.clearPresenterNotes = function() {
|
|
|
|
|
if (window.console && window.console.clear) {
|
|
|
|
|
console.clear();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
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) {
|
2013-01-20 21:59:45 +04:00
|
|
|
|
shower.clearPresenterNotes();
|
|
|
|
|
|
2012-12-30 15:54:16 +04:00
|
|
|
|
if (window.console) {
|
2013-01-01 19:46:52 +04:00
|
|
|
|
slideNumber = shower._normalizeSlideNumber(slideNumber);
|
2012-12-30 15:54:16 +04:00
|
|
|
|
|
2013-03-24 18:34:47 +04:00
|
|
|
|
var slideId = shower.slideList[slideNumber].id,
|
|
|
|
|
nextSlideId = shower.slideList[slideNumber + 1] ? shower.slideList[slideNumber + 1].id : null,
|
2013-01-20 01:13:21 +04:00
|
|
|
|
notes = document.getElementById(slideId).querySelector('footer');
|
2013-01-01 19:46:52 +04:00
|
|
|
|
|
2013-01-20 21:59:45 +04:00
|
|
|
|
if (notes && notes.innerHTML) {
|
2012-12-30 15:54:16 +04:00
|
|
|
|
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) {
|
2013-01-20 21:59:45 +04:00
|
|
|
|
|
2013-01-01 19:46:52 +04:00
|
|
|
|
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);
|
|
|
|
|
|
2013-03-24 18:34:47 +04:00
|
|
|
|
return '#' + shower.slideList[slideNumber].id;
|
2012-12-01 13:47:28 +04:00
|
|
|
|
};
|
|
|
|
|
|
2011-08-09 20:47:32 +04:00
|
|
|
|
// Event handlers
|
|
|
|
|
|
2013-01-18 15:34:02 +04:00
|
|
|
|
window.addEventListener('DOMContentLoaded', function() {
|
2013-01-20 21:59:45 +04:00
|
|
|
|
if (body.classList.contains('full') || shower.isSlideMode()) {
|
|
|
|
|
shower.go(shower.getCurrentSlideNumber());
|
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) {
|
2013-07-11 23:08:59 +04:00
|
|
|
|
var currentSlideNumber = shower.getCurrentSlideNumber(),
|
|
|
|
|
slide = shower.slideList[ currentSlideNumber !== -1 ? currentSlideNumber : 0 ],
|
|
|
|
|
slideNumber;
|
2013-02-13 00:00:03 +04:00
|
|
|
|
|
2013-07-11 23:08:59 +04:00
|
|
|
|
switch (e.which) {
|
|
|
|
|
case 80: // P Alt Cmd
|
|
|
|
|
if (shower.isListMode() && e.altKey && e.metaKey) {
|
|
|
|
|
e.preventDefault();
|
2012-12-01 13:47:28 +04:00
|
|
|
|
|
2013-07-11 23:08:59 +04:00
|
|
|
|
slideNumber = slide.number;
|
2011-07-20 22:08:31 +04:00
|
|
|
|
|
2013-07-11 23:08:59 +04:00
|
|
|
|
shower.go(slideNumber);
|
|
|
|
|
shower.enterSlideMode();
|
|
|
|
|
shower.showPresenterNotes(slideNumber);
|
|
|
|
|
|
|
|
|
|
slide.timing && slide.initTimer(shower);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2012-12-08 16:45:00 +04:00
|
|
|
|
|
2013-07-11 23:08:59 +04:00
|
|
|
|
case 116: // F5 (Shift)
|
|
|
|
|
e.preventDefault();
|
2012-12-08 16:45:00 +04:00
|
|
|
|
if (shower.isListMode()) {
|
2013-07-11 23:08:59 +04:00
|
|
|
|
slideNumber = e.shiftKey ? slide.number : 0;
|
2012-12-08 16:45:00 +04:00
|
|
|
|
|
|
|
|
|
shower.go(slideNumber);
|
|
|
|
|
shower.enterSlideMode();
|
2013-01-20 21:59:45 +04:00
|
|
|
|
shower.showPresenterNotes(slideNumber);
|
2013-05-07 21:23:12 +04:00
|
|
|
|
|
2013-05-05 02:54:06 +04:00
|
|
|
|
slide.timing && slide.initTimer(shower);
|
2012-12-08 16:45:00 +04:00
|
|
|
|
} 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();
|
2013-07-11 23:08:59 +04:00
|
|
|
|
|
2012-12-01 13:47:28 +04:00
|
|
|
|
shower.enterSlideMode();
|
2013-01-28 23:32:23 +04:00
|
|
|
|
shower.showPresenterNotes(currentSlideNumber);
|
2013-05-05 02:40:27 +04:00
|
|
|
|
|
2013-07-11 23:08:59 +04:00
|
|
|
|
slide.timing && slide.initTimer(shower);
|
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
|
2013-01-22 01:25:08 +04:00
|
|
|
|
case 72: // H
|
|
|
|
|
case 75: // K
|
2013-07-11 23:08:59 +04:00
|
|
|
|
if (e.altKey || e.ctrlKey || e.metaKey) { return; }
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
shower._turnPreviousSlide();
|
2011-07-20 22:08:31 +04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 34: // PgDown
|
|
|
|
|
case 40: // Down
|
|
|
|
|
case 39: // Right
|
2013-01-22 01:25:08 +04:00
|
|
|
|
case 76: // L
|
|
|
|
|
case 74: // J
|
2013-07-11 23:08:59 +04:00
|
|
|
|
if (e.altKey || e.ctrlKey || e.metaKey) { return; }
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
shower._turnNextSlide();
|
2011-07-20 22:08:31 +04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 36: // Home
|
2013-07-11 23:08:59 +04:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
shower.first();
|
2011-07-20 22:08:31 +04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 35: // End
|
2013-07-11 23:08:59 +04:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
shower.last();
|
2011-07-20 22:08:31 +04:00
|
|
|
|
break;
|
|
|
|
|
|
2013-07-11 23:08:59 +04:00
|
|
|
|
case 9: // Tab (Shift)
|
|
|
|
|
case 32: // Space (Shift)
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
shower[e.shiftKey ? '_turnPreviousSlide' : '_turnNextSlide']();
|
2011-07-20 22:08:31 +04:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
// Behave as usual
|
|
|
|
|
}
|
2011-07-18 13:39:47 +04:00
|
|
|
|
}, false);
|
|
|
|
|
|
2013-03-06 17:46:41 +04:00
|
|
|
|
shower.init();
|
|
|
|
|
|
2013-01-20 00:47:54 +04:00
|
|
|
|
document.addEventListener('click', function(e) {
|
2013-03-24 18:34:47 +04:00
|
|
|
|
var slideNumber = shower.getSlideNumber(shower._getSlideIdByEl(e.target)),
|
2013-05-03 20:46:29 +04:00
|
|
|
|
slide;
|
2013-01-20 21:59:45 +04:00
|
|
|
|
|
|
|
|
|
// Click on slide in List mode
|
2013-01-20 00:47:54 +04:00
|
|
|
|
if (shower.isListMode() && shower._getSlideIdByEl(e.target)) {
|
2013-01-22 01:25:08 +04:00
|
|
|
|
// Warning: go must be before enterSlideMode.
|
|
|
|
|
// Otherwise there is a bug in Chrome
|
2013-01-20 21:59:45 +04:00
|
|
|
|
shower.go(slideNumber);
|
2013-01-20 00:47:54 +04:00
|
|
|
|
shower.enterSlideMode();
|
2013-01-20 21:59:45 +04:00
|
|
|
|
shower.showPresenterNotes(slideNumber);
|
2013-03-24 18:34:47 +04:00
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
slide = shower.slideList[slideNumber];
|
|
|
|
|
if (slide.timing) {
|
|
|
|
|
slide.initTimer(shower);
|
|
|
|
|
}
|
2013-01-20 00:47:54 +04:00
|
|
|
|
}
|
|
|
|
|
}, false);
|
2011-07-20 22:08:31 +04:00
|
|
|
|
|
2013-01-18 15:34:02 +04:00
|
|
|
|
document.addEventListener('touchstart', function(e) {
|
2013-01-29 03:50:02 +04:00
|
|
|
|
var slideNumber = shower.getSlideNumber(shower._getSlideIdByEl(e.target)),
|
2013-05-03 20:46:29 +04:00
|
|
|
|
slide,
|
|
|
|
|
x;
|
2013-01-29 03:50:02 +04:00
|
|
|
|
|
2013-01-20 00:47:54 +04:00
|
|
|
|
if (shower._getSlideIdByEl(e.target)) {
|
|
|
|
|
if (shower.isSlideMode() && ! shower._checkInteractiveElement(e)) {
|
2013-01-29 03:50:02 +04:00
|
|
|
|
x = e.touches[0].pageX;
|
2013-01-20 00:47:54 +04:00
|
|
|
|
|
|
|
|
|
if (x > window.innerWidth / 2) {
|
2013-05-07 21:23:12 +04:00
|
|
|
|
shower._turnNextSlide();
|
2013-01-20 00:47:54 +04:00
|
|
|
|
} else {
|
2013-05-07 21:23:12 +04:00
|
|
|
|
shower._turnPreviousSlide();
|
2013-01-20 00:47:54 +04:00
|
|
|
|
}
|
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()) {
|
2013-01-29 03:50:02 +04:00
|
|
|
|
// Warning: go must be before enterSlideMode.
|
|
|
|
|
// Otherwise there is a bug in Chrome
|
2013-01-20 00:47:54 +04:00
|
|
|
|
shower.go(shower.getSlideNumber(shower._getSlideIdByEl(e.target)));
|
|
|
|
|
shower.enterSlideMode();
|
2013-01-29 03:50:02 +04:00
|
|
|
|
shower.showPresenterNotes(slideNumber);
|
2013-03-24 18:34:47 +04:00
|
|
|
|
|
2013-05-03 20:46:29 +04:00
|
|
|
|
slide = shower.slideList[slideNumber];
|
|
|
|
|
if (slide.timing) {
|
|
|
|
|
slide.initTimer(shower);
|
|
|
|
|
}
|
2013-01-20 00:47:54 +04:00
|
|
|
|
}
|
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;
|
|
|
|
|
|
2013-01-29 03:50:02 +04:00
|
|
|
|
})(this, this.document);
|