From ade92000ea4c7b05503211623b1672dc0c4b2ff1 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 26 Feb 2018 13:16:24 +0300 Subject: use jquery event handler for side taps --- js/read.js | 62 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 29 insertions(+), 33 deletions(-) (limited to 'js') diff --git a/js/read.js b/js/read.js index 82a3541..295a530 100644 --- a/js/read.js +++ b/js/read.js @@ -71,40 +71,36 @@ function hotkey_handler(e) { } } -function init_taps() { - try { - window.addEventListener("mouseup", - function(event) { - if (event.button == 0) { - - if ($(".modal").is(":visible")) - return; - - var doc = document.documentElement; - var margin_x = 64; - var margin_y_top = 48; - var margin_y_bottom = 48; - - //console.log(event.clientY + " " + doc.clientHeight); - - if (event.clientY < margin_y_top || event.clientY >= doc.clientHeight - margin_y_bottom) { - return; - } - - if (event.clientX >= doc.clientWidth - margin_x) { - console.log("RIGHT SIDE"); - next_page(); - } else if (event.clientX <= margin_x) { - console.log("LEFT SIDE"); - prev_page(); - } - } +$(document).ready(function() { + document.onkeydown = hotkey_handler; + + $(window).on("mouseup", function(evt) { + if (evt.button == 0) { + + if ($(".modal").is(":visible")) + return; + + var doc = document.documentElement; + var margin_x = 64; + var margin_y_top = 48; + var margin_y_bottom = 48; + + //console.log(event.clientY + " " + doc.clientHeight); + + if (evt.clientY < margin_y_top || evt.clientY >= doc.clientHeight - margin_y_bottom) { + return; } - ); - } catch (e) { - console.warn(e); - } -} + + if (evt.clientX >= doc.clientWidth - margin_x) { + console.log("RIGHT SIDE"); + next_page(); + } else if (evt.clientX <= margin_x) { + console.log("LEFT SIDE"); + prev_page(); + } + } + }); +}); function apply_line_height(elem) { var height = elem[elem.selectedIndex].value; -- cgit v1.2.3