Merge pull request #1833 from Wevah/embedded-widget-fix

Embedded widget fix
This commit is contained in:
Maurice Parker 2020-03-01 14:25:23 -08:00 committed by GitHub
commit dc20aa0e22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -125,12 +125,17 @@ code, pre {
pre { pre {
white-space: pre-wrap; white-space: pre-wrap;
} }
img, figure, video, iframe, div { img, figure, video, div {
max-width: 100%; max-width: 100%;
height: auto !important; height: auto !important;
margin: 0 auto; margin: 0 auto;
} }
iframe {
max-width: 100%;
margin: 0 auto;
}
figcaption { figcaption {
font-size: 14px; font-size: 14px;
line-height: 1.3em; line-height: 1.3em;

View File

@ -324,9 +324,18 @@ private extension ArticleRenderer {
s += """ s += """
<script type="text/javascript"> <script type="text/javascript">
function stripStylesFromElement(element, propertiesToStrip) {
for (name of propertiesToStrip) {
element.style.removeProperty(name);
}
}
var init = { var init = {
wrapFrames: function () { wrapFrames: function () {
document.querySelectorAll("iframe").forEach(element => { document.querySelectorAll("iframe").forEach(element => {
if (element.height > 0 || parseInt(element.style.height) > 0)
return;
var wrapper = document.createElement("div"); var wrapper = document.createElement("div");
wrapper.classList.add("iframeWrap"); wrapper.classList.add("iframeWrap");
element.parentNode.insertBefore(wrapper, element); element.parentNode.insertBefore(wrapper, element);
@ -335,7 +344,7 @@ private extension ArticleRenderer {
}, },
stripStyles: function() { stripStyles: function() {
document.getElementsByTagName("body")[0].querySelectorAll("style, link[rel=stylesheet]").forEach(element => element.remove()); document.getElementsByTagName("body")[0].querySelectorAll("style, link[rel=stylesheet]").forEach(element => element.remove());
document.getElementsByTagName("body")[0].querySelectorAll("[style]").forEach(element => element.removeAttribute("style")); document.getElementsByTagName("body")[0].querySelectorAll("[style]").forEach(element => stripStylesFromElement(element, ["color", "background", "font"]));
}, },
linkHover: function() { linkHover: function() {
var anchors = document.getElementsByTagName("a"); var anchors = document.getElementsByTagName("a");