diff options
-rw-r--r-- | dist/reader_iframe.min.js | 2 | ||||
-rw-r--r-- | js/reader_iframe.js | 29 |
2 files changed, 19 insertions, 12 deletions
diff --git a/dist/reader_iframe.min.js b/dist/reader_iframe.min.js index 4edac94..ed3107a 100644 --- a/dist/reader_iframe.min.js +++ b/dist/reader_iframe.min.js @@ -1 +1 @@ -"use strict";let Reader;function enable_swipes(){$(window).off("swipeleft swiperight"),$(window).on("swipeleft",(function(){Reader.Page.next()})),$(window).on("swiperight",(function(){Reader.Page.prev()}))}$(document).ready((function(){Reader=parent.__get_reader(),$(window).on("doubletap",(function(){getSelection().toString().trim().match(/^$/)&&Reader.toggleFullscreen()})),$(window).on("click tap",(function(e){if(0==e.button){if($(".modal").is(":visible"))return;"undefined"!=typeof EpubeApp?EpubeApp.toggleActionBar():Reader.showUI(!0)}})),$(window).on("touchstart",(function(){enable_swipes()})),$(window).on("mousedown",(function(){$(window).off("swipeleft swiperight")})),$(window).on("wheel",(function(e){e.originalEvent.deltaY>0?Reader.Page.next():e.originalEvent.deltaY<0&&Reader.Page.prev()})),$(window).on("mouseup touchend",(function(){if(!navigator.onLine)return;const e=getSelection().toString().trim();e.match(/^[\w]+$/)&&Reader.lookupWord(e,(function(){"undefined"!=typeof EpubeApp&&EpubeApp.showActionBar(!1),getSelection().removeAllRanges()}))})),enable_swipes()}));
\ No newline at end of file +"use strict";let Reader;function enable_swipes(){$(window).off("swipeleft swiperight"),$(window).on("swipeleft",(function(){Reader.Page.next()})),$(window).on("swiperight",(function(){Reader.Page.prev()}))}$(document).ready((function(){Reader=parent.__get_reader(),$(window).on("click tap",(function(e){if(0==e.button){if($(".modal").is(":visible"))return;"undefined"!=typeof EpubeApp?EpubeApp.toggleActionBar():Reader.showUI(!0)}})),$(window).on("touchstart",(function(){enable_swipes()})),$(window).on("mousedown",(function(){$(window).off("swipeleft swiperight")})),$(window).on("wheel",(function(e){e.originalEvent.deltaY>0?Reader.Page.next():e.originalEvent.deltaY<0&&Reader.Page.prev()}));let e=null;$(document).on("selectionchange",(function(){navigator.onLine&&(window.clearTimeout(e),e=window.setTimeout((function(){const e=getSelection().toString().trim();e.match(/^[\w]+$/)&&Reader.lookupWord(e,(function(){"undefined"!=typeof EpubeApp&&EpubeApp.showActionBar(!1),getSelection().removeAllRanges()}))}),250))})),enable_swipes()}));
\ No newline at end of file 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(); |