2016-11-02 16:02:38 +01:00
|
|
|
function main(page) {
|
|
|
|
window.currPage = page;
|
|
|
|
window.currOpacity = 1;
|
|
|
|
document.getElementById("about-link").attributes.removeNamedItem("href");
|
|
|
|
document.getElementById("games-link").attributes.removeNamedItem("href");
|
|
|
|
document.getElementById("blog-link").attributes.removeNamedItem("href");
|
|
|
|
document.getElementById("about-link").onclick = function () { return openPage("about"); };
|
|
|
|
document.getElementById("games-link").onclick = function () { return openPage("games"); };
|
|
|
|
document.getElementById("blog-link").onclick = function () { return openPage("blog"); };
|
2016-11-03 00:24:27 +01:00
|
|
|
addBlogposts();
|
|
|
|
var search = window.location.search;
|
|
|
|
if (search != "") {
|
|
|
|
search = search.slice(1, -1);
|
|
|
|
var parts = search.split("=");
|
|
|
|
if (parts[0] == "id") {
|
2016-11-03 01:37:01 +01:00
|
|
|
var timestamp = void 0;
|
|
|
|
for (var i in window.blogpostData) {
|
|
|
|
console.log(window.blogpostData[i].source);
|
|
|
|
console.log(search + ".html");
|
|
|
|
if (window.blogpostData[i].source == parts[1] + ".html") {
|
|
|
|
timestamp = new Date(window.blogpostData[i].time).toUTCString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setBlogText(parts[1] + ".html", timestamp);
|
2016-11-03 00:24:27 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-02 16:02:38 +01:00
|
|
|
}
|
2016-11-03 00:24:27 +01:00
|
|
|
function openPage(page, new_url) {
|
|
|
|
if (new_url === void 0) { new_url = null; }
|
2016-11-02 16:02:38 +01:00
|
|
|
if (page == window.currPage) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
slideOpacity(function () {
|
|
|
|
document.getElementById(window.currPage).className = "hiddenarea";
|
|
|
|
window.currPage = page;
|
|
|
|
document.getElementById(page).style.opacity = "0";
|
|
|
|
document.getElementById(page).className = "";
|
2016-11-03 00:24:27 +01:00
|
|
|
var target = new_url || page;
|
2016-11-02 16:25:57 +01:00
|
|
|
var targetPg = "/" + target;
|
2016-11-02 16:05:56 +01:00
|
|
|
if (target == "about") {
|
|
|
|
target = "";
|
2016-11-02 16:25:57 +01:00
|
|
|
targetPg = "";
|
2016-11-02 16:05:56 +01:00
|
|
|
}
|
|
|
|
;
|
2016-11-02 16:25:57 +01:00
|
|
|
window.history.pushState(target, target, targetPg + "/");
|
2016-11-03 01:37:01 +01:00
|
|
|
document.getElementsByClassName("stuffarea")[0].scrollTop = 0;
|
2016-11-02 16:02:38 +01:00
|
|
|
slideOpacity(function () {
|
|
|
|
}, 1.5);
|
|
|
|
}, -1.5);
|
|
|
|
}
|
|
|
|
function slideOpacity(callback, step) {
|
|
|
|
var currElem = document.getElementById(window.currPage);
|
|
|
|
var id = setInterval(function () {
|
|
|
|
window.currOpacity += 0.02 * step;
|
|
|
|
currElem.style.opacity = "" + window.currOpacity;
|
|
|
|
if ((window.currOpacity <= 0 && step < 0) || (window.currOpacity >= 1 && step > 0)) {
|
|
|
|
clearInterval(id);
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}, 2);
|
|
|
|
}
|
2016-11-03 00:24:27 +01:00
|
|
|
function addBlogposts() {
|
|
|
|
window.blogpostData = JSON.parse(window.blogpostDataStr);
|
|
|
|
var div = document.getElementById("blog");
|
|
|
|
var blogpostData = window.blogpostData.sort(function (a, b) { return b.time - a.time; });
|
|
|
|
blogpostData.forEach(function (val) {
|
|
|
|
var title = document.createElement("h2");
|
|
|
|
title.innerHTML = val.title;
|
|
|
|
var timestamp = document.createElement("p");
|
|
|
|
timestamp.className += "timestamp";
|
|
|
|
timestamp.innerHTML = new Date(val.time).toUTCString();
|
|
|
|
title.appendChild(timestamp);
|
|
|
|
div.appendChild(title);
|
2016-11-03 01:37:01 +01:00
|
|
|
title.onclick = function () {
|
|
|
|
openPage("blogtext", "blogtext?id=" + val.source.slice(0, -5));
|
|
|
|
setBlogText(val.source, new Date(val.time).toUTCString());
|
|
|
|
};
|
2016-11-03 00:24:27 +01:00
|
|
|
});
|
|
|
|
}
|
2016-11-03 01:37:01 +01:00
|
|
|
function setBlogText(source, time) {
|
2016-11-03 00:24:27 +01:00
|
|
|
var xmlhttp = new XMLHttpRequest();
|
|
|
|
xmlhttp.onreadystatechange = function () {
|
|
|
|
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
|
|
|
|
if (xmlhttp.status == 200) {
|
|
|
|
document.getElementById("blogtext").innerHTML = xmlhttp.responseText;
|
2016-11-03 01:37:01 +01:00
|
|
|
var timestamp = document.createElement("p");
|
|
|
|
timestamp.className += "timestamp";
|
|
|
|
timestamp.innerHTML = time;
|
|
|
|
document.getElementById("blogtext").appendChild(timestamp);
|
2016-11-03 00:24:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
xmlhttp.open("GET", "/blogposts/" + source, true);
|
|
|
|
xmlhttp.send();
|
|
|
|
}
|