diff --git a/app/assets/javascripts/discourse/app/components/cook-text.js b/app/assets/javascripts/discourse/app/components/cook-text.js index f3ad48f5492..234d0906d6b 100644 --- a/app/assets/javascripts/discourse/app/components/cook-text.js +++ b/app/assets/javascripts/discourse/app/components/cook-text.js @@ -16,7 +16,7 @@ const CookText = Component.extend({ next(() => window .requireModule("pretty-text/upload-short-url") - .resolveAllShortUrls(ajax, this.siteSettings) + .resolveAllShortUrls(ajax, this.siteSettings, this.element) ); }); } diff --git a/app/assets/javascripts/pretty-text/addon/upload-short-url.js b/app/assets/javascripts/pretty-text/addon/upload-short-url.js index f37a5d4d4cb..5ccdc41417a 100644 --- a/app/assets/javascripts/pretty-text/addon/upload-short-url.js +++ b/app/assets/javascripts/pretty-text/addon/upload-short-url.js @@ -43,12 +43,14 @@ export function resetCache() { _cache = {}; } -function retrieveCachedUrl($upload, siteSettings, dataAttribute, callback) { - const cachedUpload = lookupCachedUploadUrl($upload.data(dataAttribute)); +function retrieveCachedUrl(upload, siteSettings, dataAttribute, callback) { + const cachedUpload = lookupCachedUploadUrl( + upload.getAttribute(`data-${dataAttribute}`) + ); const url = getAttributeBasedUrl(dataAttribute, cachedUpload, siteSettings); if (url) { - $upload.removeAttr(`data-${dataAttribute}`); + upload.removeAttribute(`data-${dataAttribute}`); if (url !== MISSING) { callback(url); } @@ -77,43 +79,40 @@ function getAttributeBasedUrl(dataAttribute, cachedUpload, siteSettings) { return cachedUpload.short_path; } -function _loadCachedShortUrls($uploads, siteSettings) { - $uploads.each((_idx, upload) => { - const $upload = $(upload); +function _loadCachedShortUrls(uploadElements, siteSettings) { + uploadElements.forEach(upload => { switch (upload.tagName) { case "A": - retrieveCachedUrl($upload, siteSettings, "orig-href", url => { - $upload.attr("href", url); + retrieveCachedUrl(upload, siteSettings, "orig-href", url => { + upload.href = url; }); break; case "IMG": - retrieveCachedUrl($upload, siteSettings, "orig-src", url => { - $upload.attr("src", url); + retrieveCachedUrl(upload, siteSettings, "orig-src", url => { + upload.src = url; }); break; case "SOURCE": // video/audio tag > source tag - retrieveCachedUrl($upload, siteSettings, "orig-src", url => { - $upload.attr("src", url); - + retrieveCachedUrl(upload, siteSettings, "orig-src", url => { if (url.startsWith(`//${window.location.host}`)) { let hostRegex = new RegExp("//" + window.location.host, "g"); url = url.replace(hostRegex, ""); } let fullUrl = window.location.origin + url; - $upload.attr("src", fullUrl); + upload.src = fullUrl; // this is necessary, otherwise because of the src change the // video/audio just doesn't bother loading! - let $parent = $upload.parent(); - $parent[0].load(); + upload.parentElement.load(); // set the url and text for the tag within the