summaryrefslogtreecommitdiff
path: root/js/read.js
blob: 4fb74ceea590287bc3cac758c2f022fbe39838a2 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
var _store_position = 0;

function next_page() {
	_store_position = 1;

	window.book.nextPage();
}

function prev_page() {
	window.book.prevPage();
}

function hotkey_handler(e) {
	try {
		console.log('K:' + e.which);

		// right
		if (e.which == 39) {
			next_page();
		}

		// left
		if (e.which == 37) {
			prev_page();
		}

	} catch (e) {
		console.warn(e);
	}
}

function init_taps() {
	try {
		window.addEventListener("mouseup",
			function(event) {
				if (event.button == 0) {
					var doc = document.documentElement;
					var margin_x = 64;
					var margin_y_top = 48;
					var margin_y_bottom = 48;

					//console.log(event.clientY + " " + doc.clientHeight);

					if (event.clientY < margin_y_top || event.clientY >= doc.clientHeight - margin_y_bottom) {
						return;
					}

					if (event.clientX >= doc.clientWidth - margin_x) {
						console.log("RIGHT SIDE");
						next_page();
					}

					if (event.clientX <= margin_x) {
						console.log("LEFT SIDE");
						prev_page();
					}
				}
			}
		);
	} catch (e) {
		console.warn(e);
	}
}

function lmargin(incr) {
	var cur = parseInt(window.book.settings.styles.lineHeight.replace("%", ""));
	var size = cur + incr;

	localStorage["epube:lineHeight"] = size;

	window.book.setStyle("lineHeight", size + "%");

}

function apply_font(elem) {
	var font = elem[elem.selectedIndex].value;

	localStorage["epube:fontFamily"] = font;

	window.book.setStyle("fontFamily", font);

}
function zoom(incr) {
	var cur = parseInt(window.book.settings.styles.fontSize.replace("px", ""));
	var size = cur + incr;

	localStorage["epube:fontSize"] = size;

	window.book.setStyle("fontSize", size + "px");

}

function clear_lastread() {
	if (confirm("Clear stored last read location?")) {
		$.post("backend.php", { op: "storelastread", page: -1, cfi: "", id: $.urlParam("id") }, function(data) {
			$(".lastread_input").val(data.page);
		});
	}
}

function mark_as_read() {
	if (confirm("Mark book as read?")) {
		var total = window.book.pagination.totalPages;
		var lastCfi = book.pagination.cfiFromPage(total);

		$.post("backend.php", { op: "storelastread", page: total, cfi: lastCfi, id: $.urlParam("id") }, function(data) {
			$(".lastread_input").val(data.page);
		});
	}
}

function save_and_close() {
	if (navigator.onLine) {
		var currentPage = book.pagination.pageFromCfi(book.getCurrentLocationCfi());
		var currentCfi = book.getCurrentLocationCfi();
		var totalPages = book.pagination.totalPages;

		localforage.setItem("epube-book." + $.urlParam("b") + ".lastread",
			{cfi: currentCfi, page: currentPage, total: totalPages});

		$.post("backend.php", { op: "storelastread", id: $.urlParam("id"), page: currentPage,
			cfi: currentCfi }, function(data) {
				window.location = "index.php";
			});
	} else {
		window.location = "index.php";
	}
}

function invert() {
	localStorage["night_mode"] = localStorage["night_mode"] == "0" ? 1 : 0;

	apply_night_mode();
}

function apply_night_mode() {
	if (localStorage["night_mode"] == "1") {
		window.book.setStyle("background", "black");
		window.book.setStyle("color", "#ccc");

		$("body").css("background", "black");

	} else {
		window.book.setStyle("background", "white");
		window.book.setStyle("color", "black");

		$("body").css("background", "white");

	}
}