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() {
// Event Name
var eventName = ('ontouchend' in document.documentElement) ? 'touchend' : 'click';
var eventName = lychee.getEventName();
/* Buttons */
header.dom('#title').on(eventName, function(e) {

View File

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

View File

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

View File

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

View File

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