From 60e74d06c09785d47e5e96da50ae0f6bd528499b Mon Sep 17 00:00:00 2001 From: Fred Chasen Date: Tue, 25 Sep 2018 23:35:58 -0700 Subject: [PATCH] Get inline stylesheet for viewer.html --- examples/viewer.html | 7 ++----- package.json | 2 +- src/polyfill/previewer.js | 6 +++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/examples/viewer.html b/examples/viewer.html index f197528..e63b6d1 100644 --- a/examples/viewer.html +++ b/examples/viewer.html @@ -42,10 +42,7 @@ .then(str => (new DOMParser()).parseFromString(str, "text/html")) // Gather all stylesheets from html document - let stylesheets = Array.from(html.querySelectorAll("link[rel='stylesheet']")); - let hrefs = stylesheets.map((sheet) => { - return sheet.href; - }); + let hrefs = previewer.removeStyles(html); // Add a stylesheet url in params let stylesheet = params && params.get("stylesheet") && decodeURIComponent(params.get("stylesheet")); @@ -74,7 +71,7 @@ .pagedjs_page { background-color: #fdfdfd; - margin-bottom: 20px; + margin: 10px auto; flex: none; box-shadow: 0 0 0 1px rgba(0, 0,0,0.2); } diff --git a/package.json b/package.json index 397ba14..1e4a0c1 100755 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "author": "Fred Chasen", "license": "MIT", "homepage": "https://pagedmedia.org", - "main": "lib/paged.js", + "main": "lib/index.js", "module": "src/index.js", "browser": "dist/paged.js", "dependencies": { diff --git a/src/polyfill/previewer.js b/src/polyfill/previewer.js index 3151e29..2fa27e3 100644 --- a/src/polyfill/previewer.js +++ b/src/polyfill/previewer.js @@ -93,16 +93,16 @@ class Previewer { return template.content; } - removeStyles() { + removeStyles(doc=document) { // Get all stylesheets - let stylesheets = Array.from(document.querySelectorAll("link[rel='stylesheet']")); + let stylesheets = Array.from(doc.querySelectorAll("link[rel='stylesheet']")); let hrefs = stylesheets.map((sheet) => { sheet.remove(); return sheet.href; }); // Get inline styles - let inlineStyles = Array.from(document.querySelectorAll("style:not([data-pagedjs-inserted-styles])")); + let inlineStyles = Array.from(doc.querySelectorAll("style:not([data-pagedjs-inserted-styles])")); inlineStyles.forEach((inlineStyle) => { let obj = {}; obj[window.location.href] = inlineStyle.textContent; -- 2.22.0