This makes sure that we don't have to serve the open animation when the bar is actually closed.
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
import "./style.scss";
|
|
|
|
window.addEventListener('load', function () {
|
|
if (document.body.classList.contains('open')) {
|
|
import("./open").then(function (module) {
|
|
module.startOpenAnimation();
|
|
});
|
|
} else {
|
|
import("./closed").then(function (module) {
|
|
module.startClosedAnimation();
|
|
});
|
|
}
|
|
|
|
doIfAuthorized(showToggleButton);
|
|
});
|
|
|
|
function showToggleButton() {
|
|
const template = `
|
|
<div id="toggle-button">
|
|
<form method="post">
|
|
<button name="toggle">Verander dit</button>
|
|
</form>
|
|
</div>`;
|
|
|
|
const div = document.createElement('div');
|
|
div.innerHTML = template.trim();
|
|
const content = div.firstChild;
|
|
div.removeChild(content);
|
|
document.body.appendChild(content);
|
|
}
|
|
|
|
/**
|
|
* Run the specified callback if the user is authorized
|
|
*
|
|
* @param callback
|
|
*/
|
|
function doIfAuthorized(callback) {
|
|
const request = new XMLHttpRequest();
|
|
request.open('POST', window.location); // Post to self should work
|
|
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
|
request.onreadystatechange = function () {
|
|
switch (request.readyState) {
|
|
case XMLHttpRequest.DONE:
|
|
if (request.status === 200) {
|
|
callback();
|
|
}
|
|
break;
|
|
default:
|
|
// Wait for completion.
|
|
break;
|
|
}
|
|
};
|
|
request.send('auth_check=1');
|
|
}
|