assets/js/xletter-home.js in word-games-theme-2.5.5 vs assets/js/xletter-home.js in word-games-theme-2.5.6
- old
+ new
@@ -71,24 +71,26 @@
return new Promise((resolve, reject) => {
let resourceEle;
if (type === "text/javascript") {
resourceEle = document.createElement("script");
+ resourceEle.src = FILE_URL;
} else if (type === "text/css") {
resourceEle = document.createElement("link");
resourceEle.rel = "stylesheet";
+ resourceEle.href = FILE_URL;
} else {
reject({
status: false,
message: `Unsupported resource type: ${type}`,
});
return;
}
resourceEle.type = type;
resourceEle.async = async;
- resourceEle.href = FILE_URL;
+
resourceEle.addEventListener("load", () => {
resolve({ status: true });
});
@@ -169,45 +171,52 @@
}
const paramName = 'search';
if (new URLSearchParams(window.location.search).has(paramName)) {
loadResource("/assets/css/wordfinder-result.css", true, "text/css")
- .then((data) => {
- console.log("CSS loaded:", data);
- // Once the CSS is loaded, create the script element for JavaScript
- const jsScript = document.createElement("script");
- jsScript.src = "/assets/js/xletter-result.js";
- jsScript.onload = () => {
+ .then((data) => {
+ console.log("CSS loaded:", data);
+ })
+ .then(() => {
+ // Load the JavaScript file after the CSS file has loaded
+ loadResource("/assets/js/xletter-result.js", true, "text/javascript")
+ .then((data) => {
+ console.log("JavaScript loaded:", data);
getData(txtBox.value.toLowerCase());
- };
- document.body.appendChild(jsScript);
- })
- .catch((error) => {
- console.error("Error loading resource:", error);
- });
+ })
+ .catch((error) => {
+ console.error("Error loading JavaScript:", error);
+ });
+ })
+ .catch((error) => {
+ console.error("Error loading CSS:", error);
+ });
}
});
// Now you can use the loadScript function with additional data
function checkQueryParam() {
const urlParams = new URLSearchParams(window.location.search);
const paramName = 'search';
if (urlParams.has(paramName)) {
- loadResource("/assets/css/wordfinder-result.css", true, "text/css")
- .then((data) => {
- console.log("CSS loaded:", data);
- // Once the CSS is loaded, create the script element for JavaScript
- const jsScript = document.createElement("script");
- jsScript.src = "/assets/js/xletter-result.js";
- jsScript.onload = () => {
- console.log("JS loaded");
+ loadResource("/assets/css/wordfinder-result.css", true, "text/css")
+ .then((data) => {
+ console.log("CSS loaded:", data);
+ })
+ .then(() => {
+ // Load the JavaScript file after the CSS file has loaded
+ loadResource("/assets/js/xletter-result.js", true, "text/javascript")
+ .then((data) => {
+ console.log("JavaScript loaded:", data);
getData(txtBox.value.toLowerCase());
- };
- document.body.appendChild(jsScript);
- })
- .catch((error) => {
- console.error("Error loading resource:", error);
- });
+ })
+ .catch((error) => {
+ console.error("Error loading JavaScript:", error);
+ });
+ })
+ .catch((error) => {
+ console.error("Error loading CSS:", error);
+ });
}
}
checkQueryParam();