-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.js
103 lines (86 loc) · 3.54 KB
/
load.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// LOADING CONTENT
function loadHTML(url, elementId) {
fetch(url)
.then(response => response.text())
.then(html => {
// Parse the HTML string
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
// Get the content section element
const contentSection = document.getElementById(elementId);
// Insert the parsed HTML content
contentSection.innerHTML = doc.body.innerHTML;
// Execute scripts in the parsed HTML content
const scripts = doc.querySelectorAll('script');
scripts.forEach(script => {
// Create a new script element
const scriptElement = document.createElement('script');
// Set the src attribute if present
if (script.src) {
scriptElement.src = script.src;
}
// Set the type attribute based on whether it's a module or not
if (script.getAttribute('type') === 'module') {
scriptElement.type = 'module';
} else {
scriptElement.type = 'text/javascript';
}
// Set the inline script content if present
if (!script.src && script.textContent.trim()) {
scriptElement.textContent = script.textContent;
}
// Append the new script element to the document's head or body
if (script.src) {
document.head.appendChild(scriptElement);
} else {
document.body.appendChild(scriptElement);
}
});
})
.catch(error => console.error('Error loading HTML:', error));
}
// var buttons = document.querySelectorAll('[redir]');
// buttons.forEach(function(button) {
// button.addEventListener("click", function() {
// var page = this.getAttribute('redir');
// var loading = document.getElementById('loading');
// var content = document.getElementById('content-section');
// loading.style.display = 'block';
// content.innerHTML = '';
// setTimeout(function() {
// loadHTML(`subpages/${page}.html`, 'content-section');
// loading.style.display = 'none';
// content.style.display = 'block';
// }, 500);
// });
// });
// defaultLoad = 'login';
// setTimeout(function() {
// loadHTML(`subpages/${defaultLoad}.html`, 'content-section');
// var loading = document.getElementById('loading');
// var video = document.getElementById('video-container'); // Accessing the style tag by its ID
// video.style.display = 'block'; // or 'inline', 'inline-block', 'flex', etc.
// loading.style.display = 'none';
// }, 500);
function loadContent() {
const path = window.location.pathname;
let page = 'login'; // Default page
if (path === '/login') {
page = 'login';
} else if (path === '/signup') {
page = 'signup';
} else if (path === '/client') {
page = 'client';
}
// loadHTML(page);
// fetch(page)
// .then(response => response.text())
// .then(html => {
// document.getElementById('content').innerHTML = html;
// // Initialize scripts for the loaded page
// initializeScripts();
// })
// .catch(error => console.log('Error loading page:', error));
}
window.onload = loadContent;
window.onpopstate = loadContent;