FIX: Resolve short URLs after diffHTML was loaded (#14296)

Short URLs were resolved before diffHTML was loaded and content was
swapped by it, which meant that no URLs were found and the URLs remained
unsolved. This caused image elements to be blank.

* DEV: Updated diffHTML to 1.0.0-beta.20
This commit is contained in:
Bianca Nenciu
2021-09-09 16:25:58 +03:00
committed by GitHub
parent 02a6b991fe
commit 76f0cf10e6
7 changed files with 31 additions and 176 deletions

View File

@@ -390,6 +390,8 @@ export default Component.extend(TextareaTextManipulation, {
this.set("preview", cooked);
let previewPromise = Promise.resolve();
if (this.siteSettings.enable_diffhtml_preview) {
const cookedElement = document.createElement("div");
cookedElement.innerHTML = cooked;
@@ -407,40 +409,34 @@ export default Component.extend(TextareaTextManipulation, {
true
);
loadScript("/javascripts/diffhtml.min.js").then(() => {
// changing the contents of the preview element between two uses of
// diff.innerHTML did not apply the diff correctly
window.diff.release(this.element.querySelector(".d-editor-preview"));
previewPromise = loadScript("/javascripts/diffhtml.min.js").then(() => {
window.diff.innerHTML(
this.element.querySelector(".d-editor-preview"),
cookedElement.innerHTML,
{
parser: {
rawElements: ["script", "noscript", "style", "template"],
},
}
cookedElement.innerHTML
);
});
}
schedule("afterRender", () => {
if (this._state !== "inDOM" || !this.element) {
return;
}
previewPromise.then(() => {
schedule("afterRender", () => {
if (this._state !== "inDOM" || !this.element) {
return;
}
const preview = this.element.querySelector(".d-editor-preview");
if (!preview) {
return;
}
const preview = this.element.querySelector(".d-editor-preview");
if (!preview) {
return;
}
// prevents any tab focus in preview
preview.querySelectorAll("a").forEach((anchor) => {
anchor.setAttribute("tabindex", "-1");
// prevents any tab focus in preview
preview.querySelectorAll("a").forEach((anchor) => {
anchor.setAttribute("tabindex", "-1");
});
if (this.previewUpdated) {
this.previewUpdated($(preview));
}
});
if (this.previewUpdated) {
this.previewUpdated($(preview));
}
});
});
},

View File

@@ -7,7 +7,7 @@ export const PUBLIC_JS_VERSIONS = {
"Chart.min.js": "chart.js/3.5.1/Chart.min.js",
"chartjs-plugin-datalabels.min.js":
"chartjs-plugin-datalabels/2.0.0/chartjs-plugin-datalabels.min.js",
"diffhtml.min.js": "diffhtml/1.0.0-beta.18/diffhtml.min.js",
"diffhtml.min.js": "diffhtml/1.0.0-beta.20/diffhtml.min.js",
"jquery.magnific-popup.min.js":
"magnific-popup/1.1.0/jquery.magnific-popup.min.js",
"pikaday.js": "pikaday/1.8.0/pikaday.js",