From 40d215d8bf746a02977ebbc4138138e2e1800ea9 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 14 Sep 2020 14:08:20 +0300 Subject: experimental: add optional soft hyphenation --- js/reader.js | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'js/reader.js') 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() { -- cgit v1.2.3