chore: fixes
This commit is contained in:
parent
7bbb7041a9
commit
ac9fb1467d
1 changed files with 22 additions and 17 deletions
|
|
@ -32,21 +32,20 @@
|
|||
|
||||
<!-- JS LOADER -->
|
||||
<script>
|
||||
(function () {
|
||||
(function () {
|
||||
|
||||
function extractAboutHTML(responseText) {
|
||||
function extractSection(html, id) {
|
||||
|
||||
var temp = document.createElement("div");
|
||||
temp.innerHTML = responseText;
|
||||
var startTag = '<section id="' + id + '">';
|
||||
var endTag = '</section>';
|
||||
|
||||
var section = temp.getElementById("aboutSection");
|
||||
var start = html.indexOf(startTag);
|
||||
if (start === -1) return null;
|
||||
|
||||
if (section) {
|
||||
return section.innerHTML;
|
||||
}
|
||||
var end = html.indexOf(endTag, start);
|
||||
if (end === -1) return null;
|
||||
|
||||
return '<center><h2>About</h2></center>' +
|
||||
'<center><p>Failed to load About content.</p></center>';
|
||||
return html.substring(start, end + endTag.length);
|
||||
}
|
||||
|
||||
function loadAbout() {
|
||||
|
|
@ -55,22 +54,30 @@
|
|||
if (!target) return;
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open("GET", "about.html", true);
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
|
||||
if (xhr.readyState === 4) {
|
||||
|
||||
var html = xhr.responseText || "";
|
||||
|
||||
if (xhr.status === 200 || xhr.status === 0) {
|
||||
|
||||
target.innerHTML = extractAboutHTML(xhr.responseText);
|
||||
var section = extractSection(html, "aboutSection");
|
||||
|
||||
if (section) {
|
||||
target.innerHTML = section;
|
||||
} else {
|
||||
target.innerHTML =
|
||||
'<center><h2>About</h2></center>' +
|
||||
'<center><p>Could not find aboutSection in file.</p></center>';
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
target.innerHTML =
|
||||
'<center><h2>About</h2></center>' +
|
||||
'<center><p>Could not load about.html</p></center>';
|
||||
'<center><p>Failed to load about.html</p></center>';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -80,14 +87,12 @@
|
|||
} catch (e) {
|
||||
target.innerHTML =
|
||||
'<center><h2>About</h2></center>' +
|
||||
'<center><p>Error loading page</p></center>';
|
||||
'<center><p>Request error</p></center>';
|
||||
}
|
||||
}
|
||||
|
||||
if (window.addEventListener) {
|
||||
window.addEventListener("load", loadAbout, false);
|
||||
} else if (window.attachEvent) {
|
||||
window.attachEvent("onload", loadAbout);
|
||||
} else {
|
||||
window.onload = loadAbout;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue