From 36075d3f6a1c5785f8ffe959b2a86421f3673d24 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 6 Jun 2017 13:36:17 +0300 Subject: popup dictionary window on touch events --- js/dict.js | 12 ++++++++++++ js/read.js | 14 ++++++++++++++ js/swipes.js | 1 + 3 files changed, 27 insertions(+) create mode 100644 js/dict.js (limited to 'js') diff --git a/js/dict.js b/js/dict.js new file mode 100644 index 0000000..7b36d78 --- /dev/null +++ b/js/dict.js @@ -0,0 +1,12 @@ +$(window).on("mouseup touchend", function() { + if (!navigator.onLine) return; + + var sel = getSelection().toString().trim(); + + if (sel.match(/^\w+$/)) { + parent.dict_lookup(sel, function() { + getSelection().removeAllRanges(); + }); + } +}); + diff --git a/js/read.js b/js/read.js index 0f83583..9ca4515 100644 --- a/js/read.js +++ b/js/read.js @@ -205,3 +205,17 @@ function search() { function toggle_transitions(elem) { localforage.setItem("epube.disable-transitions", elem.checked); } + +function dict_lookup(word, callback) { + $.post("backend.php", {op: 'define', word: word}, function(data) { + if (data) { + + $(".dict_result").html(data.result.join("
")); + $("#dict-modal").modal('show'); + + if (callback) callback(); + } + }); +} + + diff --git a/js/swipes.js b/js/swipes.js index 9844c06..5826648 100644 --- a/js/swipes.js +++ b/js/swipes.js @@ -6,3 +6,4 @@ $(window).on("swiperight", function() { parent.prev_page(); }); + -- cgit v1.2.3