This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/public/content/scripts/dynload.js

44 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-01-17 01:58:31 +00:00
/*
* Dynamic load project
*/
var DynLoad = (function () {
function DynLoad() {
}
// Add the hooks
DynLoad.init = function () {
2016-01-30 00:18:23 +00:00
if (this.active) {
return;
}
else {
this.active = true;
}
2016-01-17 01:58:31 +00:00
// Add an event listener to the document
document.addEventListener("click", function (e) {
// Check if a href attribute is set
if (e.target['href']) {
// Prevent the default action
e.preventDefault();
// Create a new ajax object
var loader = new AJAX();
// Set the url
loader.setUrl(e.target['href']);
// Add callbacks
loader.addCallback(200, function () {
var doc = (new DOMParser()).parseFromString(loader.response(), "text/html");
history.pushState(null, null, e.target['href']);
document.head.innerHTML = doc.head.innerHTML;
2016-01-30 00:18:23 +00:00
document.getElementById("contentwrapper").innerHTML = doc.getElementById("contentwrapper").innerHTML;
2016-01-17 01:58:31 +00:00
var evt = document.createEvent('Event');
evt.initEvent('load', false, false);
window.dispatchEvent(evt);
});
// Send request
loader.start(HTTPMethods.GET);
}
});
};
2016-01-30 00:18:23 +00:00
// Is active
DynLoad.active = false;
2016-01-17 01:58:31 +00:00
return DynLoad;
})();