Commit ce373040 authored by miripiruni's avatar miripiruni

Fixed problems with touch devices; Small refactoring.

parent c4edbb3e
...@@ -104,12 +104,12 @@ window.shower = (function(window, document, undefined) { ...@@ -104,12 +104,12 @@ window.shower = (function(window, document, undefined) {
}; };
/** /**
* Get containing slide id. * Get slide id from HTML element.
* @private * @private
* @param {domElem} el * @param {domElem} el
* @returns {String} * @returns {String}
*/ */
shower._getContainingSlideId = function(el) { shower._getSlideIdByEl = function(el) {
while ('BODY' !== el.nodeName && 'HTML' !== el.nodeName) { while ('BODY' !== el.nodeName && 'HTML' !== el.nodeName) {
if (el.classList.contains('slide')) { if (el.classList.contains('slide')) {
return el.id; return el.id;
...@@ -122,28 +122,33 @@ window.shower = (function(window, document, undefined) { ...@@ -122,28 +122,33 @@ window.shower = (function(window, document, undefined) {
}; };
/** /**
* Dispatch single slide mode. * For touch devices: check if click on links...
* @TODO: Renaming needed? Or just some handlers rewriting? *
* @TODO: add support for textareas/inputs/...
*
* @private * @private
* @param {domElem} e * @param {domElem} e
* @returns {Undefined} * @returns {Boolean}
*/ */
shower._dispatchSingleSlideMode = function(e) { shower._checkInteractiveElement = function(e) {
// Process links
// @TODO: presentation links support
if ('A' === e.target.nodeName) { if ('A' === e.target.nodeName) {
e.preventDefault(); return true;
} else {
window.open(e.target.getAttribute('href'));
return false; return false;
} }
};
var slideId = shower._getContainingSlideId(e.target), /**
i = slideList.length - 1, * Get slide number by slideId
* @param {Number} slideId (HTML id or position in slideList)
* @returns {Number}
*/
shower.getSlideNumber = function(slideId) {
var i = slideList.length - 1,
slideNumber; slideNumber;
if (slideId === '') { if (slideId === '') {
return false; slideNumber = 0;
} }
for (; i >= 0; --i) { for (; i >= 0; --i) {
...@@ -153,16 +158,10 @@ window.shower = (function(window, document, undefined) { ...@@ -153,16 +158,10 @@ window.shower = (function(window, document, undefined) {
} }
} }
shower.go(slideNumber); return slideNumber;
if (shower.isListMode()) {
e.preventDefault();
shower.enterSlideMode();
}
return true;
}; };
/** /**
* Show next slide. If slide is last returns false, otherwise return slide * Show next slide. If slide is last returns false, otherwise return slide
* number which been shown. * number which been shown.
...@@ -690,25 +689,37 @@ window.shower = (function(window, document, undefined) { ...@@ -690,25 +689,37 @@ window.shower = (function(window, document, undefined) {
} }
}, false); }, false);
document.addEventListener('click', shower._dispatchSingleSlideMode, false); document.addEventListener('click', function(e) {
document.addEventListener('touchend', shower._dispatchSingleSlideMode, false); if (shower.isListMode() && shower._getSlideIdByEl(e.target)) {
e.preventDefault();
shower.go(shower.getSlideNumber(shower._getSlideIdByEl(e.target)));
shower.enterSlideMode();
}
}, false);
document.addEventListener('touchstart', function(e) { document.addEventListener('touchstart', function(e) {
if ( ! shower.isListMode()) { if (shower._getSlideIdByEl(e.target)) {
var currentSlideNumber = shower.getCurrentSlideNumber(), if (shower.isSlideMode() && ! shower._checkInteractiveElement(e)) {
x = e.touches[0].pageX; var x = e.touches[0].pageX;
if (x > window.innerWidth / 2) { if (x > window.innerWidth / 2) {
currentSlideNumber++; shower.next();
} else { } else {
currentSlideNumber--; shower.previous();
}
} }
shower.go(currentSlideNumber); if (shower.isListMode()) {
shower.go(shower.getSlideNumber(shower._getSlideIdByEl(e.target)));
shower.enterSlideMode();
} }
}
}, false); }, false);
document.addEventListener('touchmove', function(e) { document.addEventListener('touchmove', function(e) {
if ( ! shower.isListMode()) { if (shower.isSlideMode()) {
e.preventDefault(); e.preventDefault();
} }
}, false); }, false);
......
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