Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Simplify how the stylesheet is included in the selection iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
ianb committed Jan 5, 2017
1 parent 40a6657 commit 64ffddd
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions addon/data/selector-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ const ui = (function () { // eslint-disable-line no-unused-vars
}
exports.isHeader = isHeader;

function htmlQuote(s) {
s = s + "";
return s.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;');
}

function makeEl(tagName, className) {
let el = iframe.document.createElement(tagName);
if (className) {
Expand Down Expand Up @@ -73,24 +78,22 @@ const ui = (function () { // eslint-disable-line no-unused-vars
this.element.scrolling = "no";
this.updateElementSize();
this.element.onload = () => {
var parsedDom = (new DOMParser()).parseFromString(
"<html><head><title></title></head><body></body>",
let linkUrl = self.options["inline-selection.css"];
var parsedDom = (new DOMParser()).parseFromString(`
<html>
<head>
<link rel="stylesheet" id="pageshot-stylesheet" href="${htmlQuote(linkUrl)}">
<title></title>
</head>
<body></body>
</html>`,
"text/html"
);
this.document = this.element.contentDocument;
this.document.replaceChild(
this.document.adoptNode(parsedDom.documentElement),
this.document.documentElement
);
let linkUrl = self.options["inline-selection.css"];
var link = this.document.getElementById("pageshot-stylesheet");
if (! link) {
link = this.document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("id", "pageshot-stylesheet");
link.setAttribute("href", linkUrl);
this.document.head.appendChild(link);
}
installHandlerOnDocument(this.document);
resolve();
};
Expand Down

0 comments on commit 64ffddd

Please sign in to comment.