Skip to content

Commit

Permalink
make sure init script is appended after the notes
Browse files Browse the repository at this point in the history
see #1057
  • Loading branch information
gildas-lormeau committed Nov 22, 2022
1 parent b684511 commit 912ce41
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
14 changes: 4 additions & 10 deletions lib/single-file-extension-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1893,17 +1893,13 @@ pre code {
element.style.removeProperty("-sf-" + pointerEvents);
});
doc.body.removeAttribute("contentEditable");
const scriptElement = doc.createElement("script");
scriptElement.setAttribute(SCRIPT_TEMPLATE_SHADOW_ROOT, "");
scriptElement.textContent = getEmbedScript();
doc.body.appendChild(scriptElement);
const newResources = Object.keys(updatedResources).filter(url => updatedResources[url].type == "stylesheet").map(url => updatedResources[url]);
newResources.forEach(resource => {
const element = doc.createElement("style");
doc.body.appendChild(element);
element.textContent = resource.content;
});
return singlefile.helper.serialize(doc, compressHTML);
return singlefile.helper.serialize(doc, compressHTML) + "<script " + SCRIPT_TEMPLATE_SHADOW_ROOT + ">" + getEmbedScript() + "</script>";
}

function onUpdate(saved) {
Expand Down Expand Up @@ -2060,11 +2056,9 @@ pre code {
window.onresize = reflowNotes;
window.onUpdate = () => {};
document.documentElement.onmouseup = document.documentElement.ontouchend = onMouseUp;
window.addEventListener("DOMContentLoaded", () => {
processNode(document);
reflowNotes();
document.querySelectorAll(${JSON.stringify(NOTE_TAGNAME)}).forEach(noteElement => attachNoteListeners(noteElement));
});
processNode(document);
reflowNotes();
document.querySelectorAll(${JSON.stringify(NOTE_TAGNAME)}).forEach(noteElement => attachNoteListeners(noteElement));
})()`);
}

Expand Down
14 changes: 4 additions & 10 deletions src/ui/content/content-ui-editor-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -1890,17 +1890,13 @@ pre code {
element.style.removeProperty("-sf-" + pointerEvents);
});
doc.body.removeAttribute("contentEditable");
const scriptElement = doc.createElement("script");
scriptElement.setAttribute(SCRIPT_TEMPLATE_SHADOW_ROOT, "");
scriptElement.textContent = getEmbedScript();
doc.body.appendChild(scriptElement);
const newResources = Object.keys(updatedResources).filter(url => updatedResources[url].type == "stylesheet").map(url => updatedResources[url]);
newResources.forEach(resource => {
const element = doc.createElement("style");
doc.body.appendChild(element);
element.textContent = resource.content;
});
return singlefile.helper.serialize(doc, compressHTML);
return singlefile.helper.serialize(doc, compressHTML) + "<script " + SCRIPT_TEMPLATE_SHADOW_ROOT + ">" + getEmbedScript() + "</script>";
}

function onUpdate(saved) {
Expand Down Expand Up @@ -2057,11 +2053,9 @@ pre code {
window.onresize = reflowNotes;
window.onUpdate = () => {};
document.documentElement.onmouseup = document.documentElement.ontouchend = onMouseUp;
window.addEventListener("DOMContentLoaded", () => {
processNode(document);
reflowNotes();
document.querySelectorAll(${JSON.stringify(NOTE_TAGNAME)}).forEach(noteElement => attachNoteListeners(noteElement));
});
processNode(document);
reflowNotes();
document.querySelectorAll(${JSON.stringify(NOTE_TAGNAME)}).forEach(noteElement => attachNoteListeners(noteElement));
})()`);
}

Expand Down

0 comments on commit 912ce41

Please sign in to comment.