Only use touchend when really available and on mobile #345

This commit is contained in:
Tobias Reich 2015-07-09 17:30:31 +02:00
parent 68d9505015
commit aca4fcf400
6 changed files with 38 additions and 30 deletions

View File

@ -19,7 +19,7 @@ header.dom = function(selector) {
header.bind = function() { header.bind = function() {
// Event Name // Event Name
var eventName = ('ontouchend' in document.documentElement) ? 'touchend' : 'click'; var eventName = lychee.getEventName();
/* Buttons */ /* Buttons */
header.dom('#title').on(eventName, function(e) { header.dom('#title').on(eventName, function(e) {

View File

@ -6,8 +6,7 @@
$(document).ready(function() { $(document).ready(function() {
/* Event Name */ /* Event Name */
var touchendSupport = (/Android|iPhone|iPad|iPod/i).test(navigator.userAgent || navigator.vendor || window.opera) && ('ontouchend' in document.documentElement), var eventName = lychee.getEventName();
eventName = (touchendSupport===true ? 'touchend' : 'click');
/* Set API error handler */ /* Set API error handler */
api.onError = lychee.error; api.onError = lychee.error;

View File

@ -384,6 +384,15 @@ lychee.loadDropbox = function(callback) {
} }
lychee.getEventName = function() {
let touchendSupport = (/Android|iPhone|iPad|iPod/i).test(navigator.userAgent || navigator.vendor || window.opera) && ('ontouchend' in document.documentElement),
eventName = (touchendSupport===true ? 'touchend' : 'click');
return eventName;
}
lychee.removeHTML = function(html = '') { lychee.removeHTML = function(html = '') {
if (html==='') return html; if (html==='') return html;

View File

@ -30,7 +30,7 @@ sidebar.bind = function() {
// event handlers should be removed before binding a new one. // event handlers should be removed before binding a new one.
// Event Name // Event Name
let eventName = ('ontouchend' in document.documentElement) ? 'touchend' : 'click' let eventName = lychee.getEventName();
sidebar sidebar
.dom('#edit_title') .dom('#edit_title')

View File

@ -13,40 +13,40 @@ swipe = {
swipe.start = function(obj, tolerance) { swipe.start = function(obj, tolerance) {
if (obj) swipe.obj = obj; if (obj) swipe.obj = obj
if (tolerance) swipe.tolerance = tolerance; if (tolerance) swipe.tolerance = tolerance
return true; return true
} }
swipe.move = function(e) { swipe.move = function(e) {
if (swipe.obj===null) return false; if (swipe.obj===null) return false
swipe.offset = -1 * e.x; swipe.offset = -1 * e.x
swipe.obj.css({ swipe.obj.css({
WebkitTransform : 'translateX(' + swipe.offset + 'px)', WebkitTransform : 'translateX(' + swipe.offset + 'px)',
MozTransform : 'translateX(' + swipe.offset + 'px)', MozTransform : 'translateX(' + swipe.offset + 'px)',
transform : 'translateX(' + swipe.offset + 'px)' transform : 'translateX(' + swipe.offset + 'px)'
}); })
} }
swipe.stop = function(e, left, right) { swipe.stop = function(e, left, right) {
if (e.x<=-swipe.tolerance) left(true); if (e.x<=-swipe.tolerance) left(true)
else if (e.x>=swipe.tolerance) right(true); else if (e.x>=swipe.tolerance) right(true)
else if (swipe.obj!==null) { else if (swipe.obj!==null) {
swipe.obj.css({ swipe.obj.css({
WebkitTransform : 'translateX(0px)', WebkitTransform : 'translateX(0px)',
MozTransform : 'translateX(0px)', MozTransform : 'translateX(0px)',
transform : 'translateX(0px)' transform : 'translateX(0px)'
}); })
} }
swipe.obj = null; swipe.obj = null
swipe.offset = 0; swipe.offset = 0
} }

View File

@ -9,17 +9,17 @@ var lychee = { content: $('#content') },
$(document).ready(function() { $(document).ready(function() {
/* Event Name */ // Event Name
if ('ontouchend' in document.documentElement) eventName = 'touchend'; var touchendSupport = (/Android|iPhone|iPad|iPod/i).test(navigator.userAgent || navigator.vendor || window.opera) && ('ontouchend' in document.documentElement),
else eventName = 'click'; eventName = (touchendSupport===true ? 'touchend' : 'click');
/* Set API error handler */ // Set API error handler
api.onError = error; api.onError = error;
/* Infobox */ // Infobox
header.dom('#button_info').on(eventName, sidebar.toggle); header.dom('#button_info').on(eventName, sidebar.toggle);
/* Direct Link */ // Direct Link
header.dom('#button_direct').on(eventName, function() { header.dom('#button_direct').on(eventName, function() {
var link = $('#imageview #image').css('background-image').replace(/"/g,'').replace(/url\(|\)$/ig, ''); var link = $('#imageview #image').css('background-image').replace(/"/g,'').replace(/url\(|\)$/ig, '');