summaryrefslogtreecommitdiff
path: root/js/reader_iframe.js
blob: 6baf788e55142df9eaab79f50b304778238f8adf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
'use strict';

/* global EpubeApp */

let Reader;
let App;

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();
	App = parent.__get_app();

	/*$(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) {

			if ($(".modal").is(":visible"))
					return;

			if (typeof EpubeApp != "undefined")
				EpubeApp.toggleActionBar();
			else
				Reader.showUI(true);
		}
	});

	$(window).on("touchstart", function() {
		enable_swipes();
	});

	$(window).on("mousedown", function() {
		$(window).off("swipeleft swiperight");
	});

	$(window).on("wheel", function(evt) {
		if (evt.originalEvent.deltaY > 0) {
			Reader.Page.next();
		} else if (evt.originalEvent.deltaY < 0) {
			Reader.Page.prev();
		}
	});

	let selectionChangeTimeout = null;

	$(document).on("selectionchange", function() {
		if (!App.isOnline()) return;

		window.clearTimeout(selectionChangeTimeout);

		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);

	});

	enable_swipes();
});