From 3a4977524dde9c3670efa08dce79406e14e049f9 Mon Sep 17 00:00:00 2001 From: Jesse Glover Date: Sun, 18 Aug 2024 00:09:58 -0500 Subject: [PATCH] updates to zephr.js. Updated way that the base URL is handled. --- zephyrcore/zephyr.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/zephyrcore/zephyr.js b/zephyrcore/zephyr.js index 2301b81..31be201 100644 --- a/zephyrcore/zephyr.js +++ b/zephyrcore/zephyr.js @@ -5,8 +5,19 @@ export default class ZephyrJS extends HTMLElement { static baseUrl = ''; + /** + * Sets the base URL for loading templates. + * If a CDN link is provided, it is used as is. + * If a relative path is provided, it's treated as a local path. + */ static setBaseUrl(url) { - ZephyrJS.baseUrl = url.endsWith('/') ? url : url + '/'; + if (url.startsWith('http')) { + // CDN or full URL + ZephyrJS.baseUrl = url.endsWith('/') ? url : url + '/'; + } else { + // Local relative path + ZephyrJS.baseUrl = new URL(url, window.location.origin).href; + } } /**