pack/templates/js/contentFolder.js

43 lines
1.3 KiB
JavaScript

{% include "js/mod/base.js" %}
{% include "js/mod/token.js" %}
{% include "js/mod/middleware.js" %}
{% include "js/mod/confirm.js" %}
get("#confirmButtonNo").on("click", (e) => G_CONFIRM = false );
get("#confirmButtonYes").on("click", (e) => G_CONFIRM = true );
get(".delete").forEach((el) => el.on("click", tryAuth(deleteEntry)));
async function deleteEntry(e) {
let target = e.target.parentElement.parentElement.children[0].children[1];
target = target.href.replace("/r", "/api/files");
if (!(await getConfirm())) return;
await jfetch(target, "DELETE")
.then((json) => {
e.target.parentElement.parentElement.remove();
})
.catch(getErr((err) => {
console.log(err);
alert("An unexpected error occurred! Check console for more details.");
}));
}
get("#back").on("click", tryAuth(goBack));
async function goBack(e) {
let path = window.location.pathname.split("/");
if (path.length === 5) { // Looking at repo features, so back goes to home.
window.location = "/";
} else {
window.location = path.slice(0, -2).join("/");
}
}
function init() {
let url = window.location.toString();
if (url[url.length-1] !== "/") {
window.history.pushState({}, "", url + "/");
}
}
init();