Commit b8a1ccdf authored by miripiruni's avatar miripiruni

Code style: 4 spaces -> 1 tab. Hail Hitler!

parent dfaa6470
...@@ -12,149 +12,149 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -12,149 +12,149 @@ window.shower = window.shower || (function(window, document, undefined) {
timer, timer,
isHistoryApiSupported = !!(window.history && window.history.pushState); isHistoryApiSupported = !!(window.history && window.history.pushState);
/** /**
* Slide constructor * Slide constructor
* *
* @param {Object} opts * @param {Object} opts
* @param {String} opts.id html id attribute or automaticaly assigned order number * @param {String} opts.id html id attribute or automaticaly assigned order number
* @param {Number} opts.number slide number * @param {Number} opts.number slide number
* @param {Boolean} opts.hasInnerNavigation * @param {Boolean} opts.hasInnerNavigation
* @param {Number} [opts.timing] * @param {Number} [opts.timing]
* @param {Number} [opts.innerLength] * @param {Number} [opts.innerLength]
* @param {Number} [opts.innerComplete = 0] * @param {Number} [opts.innerComplete = 0]
* @constructor * @constructor
*/ */
function Slide(opts) { function Slide(opts) {
for (var prop in opts) { for (var prop in opts) {
if (opts.hasOwnProperty(prop)) { if (opts.hasOwnProperty(prop)) {
this[prop] = opts[prop]; this[prop] = opts[prop];
} }
} }
} }
Slide.prototype = { Slide.prototype = {
/** /**
* Get slide number. * Get slide number.
* @returns {Number} * @returns {Number}
*/ */
getSlideNumber : function() { getSlideNumber : function() {
return this.number; return this.number;
}, },
isLast : function() { isLast : function() {
return shower.slideList.length === this.number + 1 return shower.slideList.length === this.number + 1
}, },
/** /**
* Check if inner navigation is finished * Check if inner navigation is finished
* @returns {boolean} * @returns {boolean}
*/ */
isFinished : function() { isFinished : function() {
return this.innerComplete >= this.innerLength; return this.innerComplete >= this.innerLength;
}, },
/** /**
* Start inner navigation by timer or just switch slide after timer. * Start inner navigation by timer or just switch slide after timer.
* time sets in HTML: .slide[data-timing=MM:SS] * time sets in HTML: .slide[data-timing=MM:SS]
* @returns {Object} Current slide * @returns {Object} Current slide
*/ */
process : function(shower) { process : function(shower) {
if (this.timing) { if (this.timing) {
this.initTimer(shower); this.initTimer(shower);
return this; return this;
} }
this.next(shower); this.next(shower);
return this; return this;
}, },
/** /**
* Init timer for inner navigation or for just turn to next slide * Init timer for inner navigation or for just turn to next slide
* @param shower * @param shower
* @returns {Object|Boolean} Current slide * @returns {Object|Boolean} Current slide
*/ */
initTimer : function(shower) { initTimer : function(shower) {
var slide = this; var slide = this;
if ( ! slide.timing) { if ( ! slide.timing) {
return false; return false;
} }
clearInterval(timer); clearInterval(timer);
if (slide.isFinished()) { if (slide.isFinished()) {
timer = setInterval(function() { timer = setInterval(function() {
clearInterval(timer); clearInterval(timer);
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); clearInterval(timer);
shower.next(); shower.next();
} else { } else {
slide.next(shower); slide.next(shower);
} }
}, },
slide.timing); slide.timing);
} }
return this; 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
*/ */
prev : function(shower) { prev : function(shower) {
var prevSteps, var prevSteps,
slide = this; slide = this;
if ( ! slide.hasInnerNavigation || slide.isFinished() || slide.innerComplete === 0) { if ( ! slide.hasInnerNavigation || slide.isFinished() || slide.innerComplete === 0) {
shower.prev(); shower.prev();
return false; return false;
} }
prevSteps = document.getElementById(slide.id).querySelectorAll('.next.active'); prevSteps = document.getElementById(slide.id).querySelectorAll('.next.active');
if ( ! prevSteps || prevSteps.length < 1) { if ( ! prevSteps || prevSteps.length < 1) {
return false; return false;
} }
if (slide.innerComplete > 0) { if (slide.innerComplete > 0) {
slide.innerComplete--; slide.innerComplete--;
prevSteps[prevSteps.length - 1].classList.remove('active'); prevSteps[prevSteps.length - 1].classList.remove('active');
} else { } else {
shower.prev(); shower.prev();
} }
return this; return this;
}, },
/** /**
* Next step of inner navigation or if current step is last then go to next slide. * Next step of inner navigation or if current step is last then go to next slide.
* @returns {Object|Boolean} Current slide * @returns {Object|Boolean} Current slide
*/ */
next : function(shower) { next : function(shower) {
var nextSteps, var nextSteps,
slide = this; slide = this;
if ( ! slide.hasInnerNavigation || slide.isFinished()) { if ( ! slide.hasInnerNavigation || slide.isFinished()) {
shower.next(); shower.next();
return false; return false;
} }
if ( ! slide.isFinished()) { if ( ! slide.isFinished()) {
nextSteps = document.getElementById(slide.id).querySelectorAll('.next:not(.active)'); nextSteps = document.getElementById(slide.id).querySelectorAll('.next:not(.active)');
nextSteps[0].classList.add('active'); nextSteps[0].classList.add('active');
slide.innerComplete++; slide.innerComplete++;
} }
return this; return this;
} }
}; };
/** /**
* Get value at named data store for the DOM element. * Get value at named data store for the DOM element.
...@@ -168,7 +168,7 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -168,7 +168,7 @@ window.shower = window.shower || (function(window, document, undefined) {
}; };
shower.slideList = []; shower.slideList = [];
/** /**
* Shower initialization * Shower initialization
...@@ -177,7 +177,7 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -177,7 +177,7 @@ window.shower = window.shower || (function(window, document, undefined) {
* @returns {Object} shower * @returns {Object} shower
*/ */
shower.init = function(slideSelector, progressSelector) { shower.init = function(slideSelector, progressSelector) {
var timing; var timing;
slideSelector = slideSelector || '.slide'; slideSelector = slideSelector || '.slide';
progressSelector = progressSelector || 'div.progress div'; progressSelector = progressSelector || 'div.progress div';
...@@ -195,24 +195,24 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -195,24 +195,24 @@ window.shower = window.shower || (function(window, document, undefined) {
timing = shower._getData(slides[i], 'timing'); timing = shower._getData(slides[i], 'timing');
if (timing && timing.indexOf(':') !== -1) { if (timing && timing.indexOf(':') !== -1) {
timing = timing.split(':'); timing = timing.split(':');
// Compute number of milliseconds from format "mm:ss" // Compute number of milliseconds from format "mm:ss"
timing = (parseInt(timing[0], 10) * 60 + parseInt(timing[1], 10)) * 1000; timing = (parseInt(timing[0], 10) * 60 + parseInt(timing[1], 10)) * 1000;
if (slides[i].querySelector('.next')) { if (slides[i].querySelector('.next')) {
timing = timing / (slides[i].querySelectorAll('.next').length + 1); timing = timing / (slides[i].querySelectorAll('.next').length + 1);
} }
} }
shower.slideList.push(new Slide({ shower.slideList.push(new Slide({
id : slides[i].id, id : slides[i].id,
number : i, number : i,
hasInnerNavigation : null !== slides[i].querySelector('.next'), hasInnerNavigation : null !== slides[i].querySelector('.next'),
timing : parseInt(timing, 10) || undefined, timing : parseInt(timing, 10) || undefined,
innerLength : slides[i].querySelectorAll('.next').length, innerLength : slides[i].querySelectorAll('.next').length,
innerComplete : 0 innerComplete : 0
})); }));
} }
return shower; return shower;
}; };
...@@ -309,30 +309,30 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -309,30 +309,30 @@ window.shower = window.shower || (function(window, document, undefined) {
return 'A' === e.target.nodeName; return 'A' === e.target.nodeName;
}; };
/** /**
* Get slide number by slideId. * Get slide number by slideId.
* @param {String} slideId * @param {String} slideId
* @returns {Number} * @returns {Number}
*/ */
shower.getSlideNumber = function(slideId) { shower.getSlideNumber = function(slideId) {
var i = shower.slideList.length - 1, var i = shower.slideList.length - 1,
slideNumber; slideNumber;
if (slideId === '') { if (slideId === '') {
slideNumber = 0; slideNumber = 0;
} }
// As fast as you can ;-) // As fast as you can ;-)
// http://jsperf.com/for-vs-foreach/46 // http://jsperf.com/for-vs-foreach/46
for (; i >= 0; --i) { for (; i >= 0; --i) {
if (slideId === shower.slideList[i].id) { if (slideId === shower.slideList[i].id) {
slideNumber = i; slideNumber = i;
break; break;
} }
} }
return slideNumber; return slideNumber;
}; };
/** /**
* Go to slide number. * Go to slide number.
...@@ -341,7 +341,7 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -341,7 +341,7 @@ window.shower = window.shower || (function(window, document, undefined) {
* @returns {Number} * @returns {Number}
*/ */
shower.go = function(slideNumber, callback) { shower.go = function(slideNumber, callback) {
var slide; var slide;
if ( ! shower._isNumber(slideNumber)) { if ( ! shower._isNumber(slideNumber)) {
throw new Error('Gimme slide number as Number, baby!'); throw new Error('Gimme slide number as Number, baby!');
...@@ -355,10 +355,10 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -355,10 +355,10 @@ window.shower = window.shower || (function(window, document, undefined) {
if (shower.isSlideMode()) { if (shower.isSlideMode()) {
shower.showPresenterNotes(slideNumber); shower.showPresenterNotes(slideNumber);
slide = shower.slideList[slideNumber]; slide = shower.slideList[slideNumber];
if (slide.timing) { if (slide.timing) {
slide.initTimer(shower); slide.initTimer(shower);
} }
} }
if (typeof(callback) === 'function') { if (typeof(callback) === 'function') {
...@@ -376,14 +376,14 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -376,14 +376,14 @@ window.shower = window.shower || (function(window, document, undefined) {
*/ */
shower.next = function(callback) { shower.next = function(callback) {
var currentSlideNumber = shower.getCurrentSlideNumber(), var currentSlideNumber = shower.getCurrentSlideNumber(),
nextSlide = shower.slideList[currentSlideNumber + 1]; nextSlide = shower.slideList[currentSlideNumber + 1];
// If don't exist next slide // If don't exist next slide
if (! nextSlide) { if (! nextSlide) {
return false; return false;
} }
shower.go(currentSlideNumber + 1); shower.go(currentSlideNumber + 1);
if (typeof(callback) === 'function') { if (typeof(callback) === 'function') {
callback(); callback();
...@@ -392,89 +392,89 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -392,89 +392,89 @@ window.shower = window.shower || (function(window, document, undefined) {
return true; return true;
}; };
/** /**
* *
* @param {Function} [callback] * @param {Function} [callback]
* @returns {boolean} * @returns {boolean}
*/ */
shower._turnNextSlide = function(callback) { shower._turnNextSlide = function(callback) {
var currentSlideNumber = shower.getCurrentSlideNumber(), var currentSlideNumber = shower.getCurrentSlideNumber(),
nextSlide = shower.slideList[currentSlideNumber + 1], nextSlide = shower.slideList[currentSlideNumber + 1],
ret = false, ret = false,
slide; slide;
slide = shower.slideList[currentSlideNumber]; slide = shower.slideList[currentSlideNumber];
if (shower.isSlideMode()) { if (shower.isSlideMode()) {
if (slide.hasInnerNavigation && ! slide.isFinished()) { if (slide.hasInnerNavigation && ! slide.isFinished()) {
slide.process(shower); slide.process(shower);
} else { } else {
shower.next(); shower.next();
} }
} else { // listMode } else { // listMode
shower.next(); shower.next();
// Slides starts from 0. So return next slide number. // Slides starts from 0. So return next slide number.
ret = currentSlideNumber + 2; ret = currentSlideNumber + 2;
} }
if (typeof(callback) === 'function') { if (typeof(callback) === 'function') {
callback(); callback();
} }
return ret; return ret;
}; };
/** /**
* Show previous slide. Returns false on a first slide, otherwise returns shown slide number. * 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. * @param {Function} [callback] runs only if shower.previous() is successfully completed.
* @returns {Boolean} * @returns {Boolean}
*/ */
shower.prev = shower.previous = function(callback) { shower.prev = shower.previous = function(callback) {
var currentSlideNumber = shower.getCurrentSlideNumber(); var currentSlideNumber = shower.getCurrentSlideNumber();
// Slides starts from 0 // Slides starts from 0
if (currentSlideNumber < 1) { if (currentSlideNumber < 1) {
return false; return false;
} }
shower.go(currentSlideNumber - 1); shower.go(currentSlideNumber - 1);
if (typeof(callback) === 'function') { if (typeof(callback) === 'function') {
callback(); callback();
} }
return true; return true;
}; };
/** /**
* Show previous slide. Returns false on a first slide, otherwise returns shown slide number. * 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. * @param {Function} [callback] runs only if shower.previous() is successfully completed.
* @returns {Boolean} * @returns {Boolean}
*/ */
shower._turnPreviousSlide = function(callback) { shower._turnPreviousSlide = function(callback) {
var currentSlideNumber = shower.getCurrentSlideNumber(), var currentSlideNumber = shower.getCurrentSlideNumber(),
slide; slide;
// Slides starts from 0 // Slides starts from 0
if (currentSlideNumber < 1) { if (currentSlideNumber < 1) {
return false; return false;
} }
slide = shower.slideList[currentSlideNumber]; slide = shower.slideList[currentSlideNumber];
slide.timing && clearInterval(timer); slide.timing && clearInterval(timer);
if (shower.isSlideMode()) { if (shower.isSlideMode()) {
slide.prev(shower); slide.prev(shower);
} else { } else {
shower.go(currentSlideNumber - 1); shower.go(currentSlideNumber - 1);
} }
if (typeof(callback) === 'function') { if (typeof(callback) === 'function') {
callback(); callback();
} }
return true; return true;
}; };
/** /**
* Show first slide. * Show first slide.
...@@ -495,11 +495,11 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -495,11 +495,11 @@ window.shower = window.shower || (function(window, document, undefined) {
* @returns {Boolean} * @returns {Boolean}
*/ */
shower.last = function(callback) { shower.last = function(callback) {
shower.go(shower.slideList.length - 1) shower.go(shower.slideList.length - 1)
if (typeof(callback) === 'function') { if (typeof(callback) === 'function') {
callback(); callback();
} }
return true; return true;
}; };
...@@ -535,7 +535,7 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -535,7 +535,7 @@ window.shower = window.shower || (function(window, document, undefined) {
* @returns {Boolean} * @returns {Boolean}
*/ */
shower.enterListMode = function(callback) { shower.enterListMode = function(callback) {
var currentSlideNumber; var currentSlideNumber;
// Anyway: change body class (@TODO: refactoring) // Anyway: change body class (@TODO: refactoring)
body.classList.remove('full'); body.classList.remove('full');
...@@ -786,13 +786,13 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -786,13 +786,13 @@ window.shower = window.shower || (function(window, document, undefined) {
document.addEventListener('keydown', function(e) { document.addEventListener('keydown', function(e) {
var currentSlideNumber, var currentSlideNumber,
slide; slide;
// Shortcut for alt, ctrl and meta keys // Shortcut for alt, ctrl and meta keys
if (e.altKey || e.ctrlKey || e.metaKey) { return; } if (e.altKey || e.ctrlKey || e.metaKey) { return; }
currentSlideNumber = shower.getCurrentSlideNumber(); currentSlideNumber = shower.getCurrentSlideNumber();
slide = shower.slideList[currentSlideNumber]; slide = shower.slideList[currentSlideNumber];
switch (e.which) { switch (e.which) {
case 116: // F5 case 116: // F5
...@@ -848,13 +848,13 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -848,13 +848,13 @@ window.shower = window.shower || (function(window, document, undefined) {
case 36: // Home case 36: // Home
e.preventDefault(); e.preventDefault();
slide.timing && clearInterval(timer); slide.timing && clearInterval(timer);
shower.first(); shower.first();
break; break;
case 35: // End case 35: // End
e.preventDefault(); e.preventDefault();
slide.timing && clearInterval(timer); slide.timing && clearInterval(timer);
shower.last(); shower.last();
break; break;
...@@ -873,7 +873,7 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -873,7 +873,7 @@ window.shower = window.shower || (function(window, document, undefined) {
document.addEventListener('click', function(e) { document.addEventListener('click', function(e) {
var slideNumber = shower.getSlideNumber(shower._getSlideIdByEl(e.target)), var slideNumber = shower.getSlideNumber(shower._getSlideIdByEl(e.target)),
slide; slide;
// Click on slide in List mode // Click on slide in List mode
if (shower.isListMode() && shower._getSlideIdByEl(e.target)) { if (shower.isListMode() && shower._getSlideIdByEl(e.target)) {
...@@ -883,17 +883,17 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -883,17 +883,17 @@ window.shower = window.shower || (function(window, document, undefined) {
shower.enterSlideMode(); shower.enterSlideMode();
shower.showPresenterNotes(slideNumber); shower.showPresenterNotes(slideNumber);
slide = shower.slideList[slideNumber]; slide = shower.slideList[slideNumber];
if (slide.timing) { if (slide.timing) {
slide.initTimer(shower); slide.initTimer(shower);
} }
} }
}, false); }, false);
document.addEventListener('touchstart', function(e) { document.addEventListener('touchstart', function(e) {
var slideNumber = shower.getSlideNumber(shower._getSlideIdByEl(e.target)), var slideNumber = shower.getSlideNumber(shower._getSlideIdByEl(e.target)),
slide, slide,
x; x;
if (shower._getSlideIdByEl(e.target)) { if (shower._getSlideIdByEl(e.target)) {
if (shower.isSlideMode() && ! shower._checkInteractiveElement(e)) { if (shower.isSlideMode() && ! shower._checkInteractiveElement(e)) {
...@@ -913,10 +913,10 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -913,10 +913,10 @@ window.shower = window.shower || (function(window, document, undefined) {
shower.enterSlideMode(); shower.enterSlideMode();
shower.showPresenterNotes(slideNumber); shower.showPresenterNotes(slideNumber);
slide = shower.slideList[slideNumber]; slide = shower.slideList[slideNumber];
if (slide.timing) { if (slide.timing) {
slide.initTimer(shower); slide.initTimer(shower);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment