62 lines
2.0 KiB
JavaScript
62 lines
2.0 KiB
JavaScript
var URLGenerator = function (page) {
|
|
this._page = page;
|
|
this._articles = {};
|
|
};
|
|
|
|
URLGenerator.prototype = {
|
|
registerSection: function (article, section) {
|
|
this._articles[article] = section;
|
|
},
|
|
getCurrentUrl: function () {
|
|
var ret = this.getPageUrl();
|
|
for (var i in this._articles) {
|
|
if (typeof this._articles[i] === "object" && this._articles[i] !== null) {
|
|
for (var j in this._articles[i]) {
|
|
ret+= "&a[" + i + "][" + j + "]=" + this._articles[i][j];
|
|
}
|
|
} else /*if (this._articles[i] != "")*/ {
|
|
ret+= "&a[" + i + "]=" + this._articles[i];
|
|
}
|
|
}
|
|
return ret;
|
|
},
|
|
getPageUrl: function () {
|
|
return "index.php?p="+this._page;
|
|
}
|
|
};
|
|
|
|
function loadArticle(src, article, section, initialrun = false) {
|
|
var sectionparam = "";
|
|
if (typeof section === "object" && section !== null) {
|
|
for (var i in section) {
|
|
sectionparam+= "§ion[" + i + "]=" + section[i];
|
|
}
|
|
} else if (""!=section) {
|
|
sectionparam = "§ion="+section;
|
|
}
|
|
|
|
var r = new XMLHttpRequest();
|
|
r.open("POST", "ajax/"+src, true);
|
|
r.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
r.onreadystatechange = function () {
|
|
if (r.readyState != 4 || r.status != 200) return;
|
|
document.getElementById(article).innerHTML = r.responseText;
|
|
urlgen.registerSection(article, section);
|
|
if (!initialrun) {
|
|
history.pushState({"main": document.getElementById("main").innerHTML, "html":r.responseText,"pageTitle":article}, "article="+article+sectionparam, urlgen.getCurrentUrl());
|
|
}
|
|
var galid = "gallery_"+article.replace(/\s+/, "");
|
|
if (r.responseText.includes("id='"+galid+"'")) {
|
|
baguetteBox.run("#"+galid, {animation: false});
|
|
}
|
|
};
|
|
r.send("article="+article+sectionparam);
|
|
}
|
|
window.onpopstate = function(e) {
|
|
if (e.state) {
|
|
document.getElementById("main").innerHTML = e.state.main;
|
|
//document.getElementById(e.state.pageTitle).innerHTML = e.state.html;
|
|
} else {
|
|
window.location.href = urlgen.getPageUrl();
|
|
}
|
|
}; |