DEV: De-jQuerify `get-url` (#17314)

This commit is contained in:
Jarek Radosz 2022-07-04 02:25:15 +02:00 committed by GitHub
parent 9f83e8e33c
commit e1f16b4641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 3 deletions

View File

@ -5,7 +5,11 @@ let snapshot;
export default function getURL(url) { export default function getURL(url) {
if (baseUri === undefined) { if (baseUri === undefined) {
setPrefix($('meta[name="discourse-base-uri"]').attr("content") || ""); setPrefix(
document
.querySelector('meta[name="discourse-base-uri"]')
?.getAttribute("content") || ""
);
} }
if (!url) { if (!url) {
@ -104,9 +108,14 @@ export function setupS3CDN(configS3BaseUrl, configS3CDN, opts) {
// prefix directory. For example from `/forum` to `/about-us` which is not discourse // prefix directory. For example from `/forum` to `/about-us` which is not discourse
export function samePrefix(url) { export function samePrefix(url) {
if (baseUri === undefined) { if (baseUri === undefined) {
setPrefix($('meta[name="discourse-base-uri"]').attr("content") || ""); setPrefix(
document
.querySelector('meta[name="discourse-base-uri"]')
?.getAttribute("content") || ""
);
} }
let origin = window.location.origin; let origin = window.location.origin;
let cmp = url[0] === "/" ? baseUri || "/" : origin + baseUri || origin; let cmp = url[0] === "/" ? baseUri || "/" : origin + baseUri || origin;
return url.indexOf(cmp) === 0; return url.startsWith(cmp);
} }