about summary refs log tree commit diff stats
path: root/js/reader.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/reader.js')
-rw-r--r--js/reader.js113
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 */
 
 		},
 	},