summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2020-09-14 14:08:20 +0300
committerAndrew Dolgov <[email protected]>2020-09-14 14:08:20 +0300
commit40d215d8bf746a02977ebbc4138138e2e1800ea9 (patch)
treec2230d941dfa8d133780d9a8ed66e38b60eeee13 /js
parent3dd691939c9c8755b47a4761ec36660b7ec2c140 (diff)
experimental: add optional soft hyphenation
Diffstat (limited to 'js')
-rw-r--r--js/reader.js36
1 files changed, 30 insertions, 6 deletions
diff --git a/js/reader.js b/js/reader.js
index e271762..08c5628 100644
--- a/js/reader.js
+++ b/js/reader.js
@@ -163,14 +163,22 @@ const Reader = {
minSpreadWidth: 961
});
- Reader.applyStyles(true);
+ localforage.getItem("epube.enable-hyphens").then(function(enable_hyphens) {
+ if (enable_hyphens) {
+ /* global hyphenationPatternsEnUs, createHyphenator */
+ Reader.hyphenateHTML = createHyphenator(hyphenationPatternsEnUs, { html: true });
+ }
+
+ Reader.applyStyles(true);
- /* rendition.hooks.content.register(function() {
- Reader.applyStyles();
- }); */
+ /* rendition.hooks.content.register(function() {
+ Reader.applyStyles();
+ }); */
+
+ rendition.display().then(function() {
+ console.log("book displayed");
+ });
- rendition.display().then(function() {
- console.log("book displayed");
});
rendition.hooks.content.register(function(contents) {
@@ -234,6 +242,15 @@ const Reader = {
});
+ localforage.getItem("epube.enable-hyphens").then(function(enable) {
+ $(".enable_hyphens_checkbox")
+ .attr("checked", enable)
+ .off("click")
+ .on("click", function(evt) {
+ localforage.setItem("epube.enable-hyphens", evt.target.checked);
+ });
+ });
+
localforage.getItem("epube.keep-ui-visible").then(function(keep) {
$(".keep_ui_checkbox")
.attr("checked", keep)
@@ -440,6 +457,13 @@ const Reader = {
.css("background", "")
.css("background-color", "");
+ if (typeof Reader.hyphenateHTML != "undefined") {
+ $(doc).find('p').each((i,p) => {
+ p = $(p);
+
+ p.html(Reader.hyphenateHTML(p.html()));
+ });
+ }
});
book.ready.then(function() {