From 48d990cdbf05e0e463e08ef69319bebcfdbbf4d8 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 20 Nov 2020 12:00:12 +0300 Subject: better handling for selection dialog popup; disable double tap to fullscreen --- js/reader_iframe.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'js/reader_iframe.js') diff --git a/js/reader_iframe.js b/js/reader_iframe.js index 897be44..bcc5b44 100644 --- a/js/reader_iframe.js +++ b/js/reader_iframe.js @@ -19,13 +19,13 @@ function enable_swipes() { $(document).ready(function() { Reader = parent.__get_reader(); - $(window).on("doubletap", function(/* evt */) { + /*$(window).on("doubletap", function(evt) { const sel = getSelection().toString().trim(); if (sel.match(/^$/)) { Reader.toggleFullscreen(); } - }); + }); */ $(window).on("click tap", function(evt) { if (evt.button == 0) { @@ -56,19 +56,26 @@ $(document).ready(function() { } }); - $(window).on("mouseup touchend", function() { + let selectionChangeTimeout = null; + + $(document).on("selectionchange", function() { if (!navigator.onLine) return; - const sel = getSelection().toString().trim(); + window.clearTimeout(selectionChangeTimeout); - if (sel.match(/^[\w­]+$/)) { - Reader.lookupWord(sel, function() { - if (typeof EpubeApp != "undefined") - EpubeApp.showActionBar(false); + selectionChangeTimeout = window.setTimeout(function() { + const sel = getSelection().toString().trim(); + + if (sel.match(/^[\w­]+$/)) { + Reader.lookupWord(sel, function() { + if (typeof EpubeApp != "undefined") + EpubeApp.showActionBar(false); + + getSelection().removeAllRanges(); + }); + } + }, 250); - getSelection().removeAllRanges(); - }); - } }); enable_swipes(); -- cgit v1.2.3