summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2017-06-06 13:36:17 +0300
committerAndrew Dolgov <[email protected]>2017-06-06 13:36:17 +0300
commit36075d3f6a1c5785f8ffe959b2a86421f3673d24 (patch)
treec434522941ac208d686bb09549a66b270d76ab13
parent7e4ee45037eb013be2311cecc0af4dd8f3a2258b (diff)
popup dictionary window on touch events
-rw-r--r--js/dict.js12
-rw-r--r--js/read.js14
-rw-r--r--js/swipes.js1
-rw-r--r--read.html11
-rw-r--r--worker.js1
5 files changed, 37 insertions, 2 deletions
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("<br/>"));
+ $("#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();
});
+
diff --git a/read.html b/read.html
index 087834c..10850fe 100644
--- a/read.html
+++ b/read.html
@@ -339,6 +339,7 @@
EPUBJS.core.addScripts([baseUrl + "lib/bootstrap/v3/js/jquery.js",
baseUrl + "lib/jquery.mobile.custom.js",
+ baseUrl + "js/dict.js",
baseUrl + "js/swipes.js" ], null, renderer.doc.head);
EPUBJS.core.addCss(baseUrl + "lib/bootstrap/v3/css/bootstrap.css", null, renderer.doc.head);
@@ -509,7 +510,13 @@
};
- $("#reader iframe")[0].contentWindow.onmouseup = function(event) {
+ $("#reader iframe")[0].contentWindow.ontouchend = function(event) {
+ console.log('ontouchend');
+
+
+ };
+
+ /*$("#reader iframe")[0].contentWindow.onmouseup = function(event) {
if (!navigator.onLine) return;
@@ -530,7 +537,7 @@
}
});
}
- };
+ };*/
});
diff --git a/worker.js b/worker.js
index a6b2950..d2ed2f7 100644
--- a/worker.js
+++ b/worker.js
@@ -11,6 +11,7 @@ self.addEventListener('install', function(event) {
'js/read.js',
'js/offline.js',
'js/swipes.js',
+ 'js/dict.js',
'css/read.css',
'css/index.css',
'css/transitions.css',