diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-03-10 18:00:15 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-03-10 18:00:15 +0300 |
| commit | 0b48a52fd74be11ed8a60faecbac2ac17e9985bb (patch) | |
| tree | 760cad7fceda5719e252df8de3fa72878f4b5ccd /js | |
| parent | 54563402754706950366e7afe6bf36a6f89152e9 (diff) | |
| download | the-epube-intity/epub-js.tar.gz the-epube-intity/epub-js.tar.xz | |
misc stuff intity/epub-js
Diffstat (limited to 'js')
| -rw-r--r-- | js/reader.js | 113 |
1 files changed, 59 insertions, 54 deletions
diff --git a/js/reader.js b/js/reader.js index 5b489e0..0d0b45a 100644 --- a/js/reader.js +++ b/js/reader.js @@ -102,7 +102,7 @@ const Reader = { }); } - Reader.applyTheme(); + //Reader.applyTheme(); const bookinfo = await localforage.getItem(Reader.cacheId()); @@ -222,14 +222,21 @@ const Reader = { Reader.hyphenate.ru = createHyphenator(hyphenationPatternsRu, { html: true }); } - Reader.applyTheme(); + //Reader.applyTheme(); console.log('book displayed'); Reader.initRenditionHooks(book, rendition); Reader.initModals(); Reader.initToc(book); - Reader.initStyleHooks(book); + + book.rendition.hooks.content.register((rendition) => { + console.log('rendition content hook', rendition); + + Reader.cleanupEmbeddedStyles(rendition); + //Reader.applyTheme(); + }); + await Reader.Page.openLastRead(); console.log('startup finished'); @@ -399,7 +406,7 @@ const Reader = { Reader.Page._moved_next = 0; }, 150); - Reader.applyTheme(); + //Reader.applyTheme(); Reader.resizeSideColumns(); try { @@ -650,53 +657,6 @@ const Reader = { }); }, - initStyleHooks: function(book) { - return; - - /* embedded styles may conflict with our font sizes, etc */ - book.packaging.spine.hooks.content.register(function(doc/*, section */) { - - $(doc).find("p") - .filter((i, e) => (($(e).text().length >= MIN_LENGTH_TO_JUSTIFY) ? e : null)) - .css("text-align", "justify"); - - $(doc).find("html") - .attr("class", ""); - - $(doc).find("pre") - .css("white-space", "pre-wrap"); - - $(doc).find("a, p, span, em, i, strong, b, body, header, section, div, big, small, table, tr, td, ul, ol, li") - .attr("class", "") - .css("font-family", "inherit") - .css("font-size", "inherit") - .css("line-height", "inherit") - .css("color", "") - .css("border", "none ! important") - .css("background", "") - .css("background-color", "") - .attr("width", "") - .attr("height", ""); - - // same as above except for allowed font-size - $(doc).find("h1, h2, h3, h4, h5") - .attr("class", "") - .css("font-family", "inherit") - .css("color", "") - .css("border", "none ! important") - .css("background", "") - .css("background-color", ""); - - if (typeof Reader.hyphenate.en != "undefined") { - $(doc).find('p, div').each((i,p) => { - p = $(p); - - p.html(Reader.hyphenate.en(p.html())); - p.html(Reader.hyphenate.ru(p.html())); - }); - } - }); - }, generateFontsCss: function(base_url) { return ` /** Calibri */ @@ -943,6 +903,51 @@ const Reader = { $(".toc-bar-entry.current-position") .css('left', cur_pct + '%'); }, + cleanupEmbeddedStyles: function(rendition) { + console.log('cleanup embedded styles', rendition, 'document', rendition.document); + + const doc = $(rendition.document); + + doc.find("p") + .filter((i, e) => (($(e).text().length >= MIN_LENGTH_TO_JUSTIFY) ? e : null)) + .css("text-align", "justify"); + + doc.find("html") + .attr("class", ""); + + doc.find("pre") + .css("white-space", "pre-wrap"); + + doc.find("a, p, span, em, i, strong, b, body, header, section, div, big, small, table, tr, td, ul, ol, li") + .attr("class", "") + .css("font-family", "inherit") + .css("font-size", "inherit") + .css("line-height", "inherit") + .css("color", "") + .css("border", "none ! important") + .css("background", "") + .css("background-color", "") + .attr("width", "") + .attr("height", ""); + + // same as above except for allowed font-size + doc.find("h1, h2, h3, h4, h5") + .attr("class", "") + .css("font-family", "inherit") + .css("color", "") + .css("border", "none ! important") + .css("background", "") + .css("background-color", ""); + + if (typeof Reader.hyphenate.en != "undefined") { + doc.find('p, div').each((i,p) => { + p = $(p); + + p.html(Reader.hyphenate.en(p.html())); + p.html(Reader.hyphenate.ru(p.html())); + }); + } + }, applyTheme: async function() { let fontSize = await localforage.getItem("epube.fontSize"); let fontFamily = await localforage.getItem("epube.fontFamily"); @@ -954,7 +959,7 @@ const Reader = { console.log('style', fontFamily, fontSize, lineHeight); - console.log('applying rendition styls...'); + console.log('applying rendition styles...'); $.each(window.book.rendition.getContents(), function(i, c) { console.log('rendition', i, '=', c); @@ -1234,8 +1239,8 @@ const Reader = { if (!load_failed) Reader.initSecondStage(); - else - Reader.applyTheme(); // fade in, etc + /* else + Reader.applyTheme(); // fade in, etc */ }, }, |
