From 47568440c08487f804b6eee47e1a4023529dea9f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 1 Feb 2018 15:22:59 +0300 Subject: another take on overriding inline epub styles --- read.html | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'read.html') diff --git a/read.html b/read.html index c552960..873a81f 100644 --- a/read.html +++ b/read.html @@ -411,14 +411,18 @@ }); } + var fontSize; + var fontFamily; + var lineHeight; + Promise.all([ localforage.getItem("epube.fontSize"), localforage.getItem("epube.fontFamily"), localforage.getItem("epube.lineHeight") ]).then(function(res) { - var fontSize = res[0] ? res[0] + "px" : DEFAULT_FONT_SIZE + "px"; - var fontFamily = res[1] ? res[1] : DEFAULT_FONT_FAMILY; - var lineHeight = res[2] ? res[2] + "%" : DEFAULT_LINE_HEIGHT + "%"; + fontSize = res[0] ? res[0] + "px" : DEFAULT_FONT_SIZE + "px"; + fontFamily = res[1] ? res[1] : DEFAULT_FONT_FAMILY; + lineHeight = res[2] ? res[2] + "%" : DEFAULT_LINE_HEIGHT + "%"; book.setStyle("fontSize", fontSize); book.setStyle("fontFamily", fontFamily); @@ -428,9 +432,6 @@ }); - - //styles: { fontSize: '24px', lineHeight: '130%', fontFamily: 'Georgia' } - window.book = book; var rendered = book.renderTo("reader"); @@ -650,15 +651,12 @@ book.on("renderer:chapterDisplayed", function() { // cleanup possibly interfering styles - var c = $("#reader iframe").contents(); - - c.find("p") - .removeAttr("style") - .removeAttr("class") - .css("margin", "0px"); + // variables defined above after reading from localforage - c.find("*") - .removeAttr("class"); + $("#reader iframe").contents().find("*") + .css("font-family", fontFamily) + .css("font-size", fontSize) + .css("line-height", lineHeight); }); -- cgit v1.2.3