mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-07 18:58:30 +02:00
Archive snapshots of websites locally (#672)
* Add basic HTML snapshots * Implement asset list * Add snapshot creation tests * Add deletion tests * Show file size * Remove snapshots * Create new snapshots * Switch to single-file * CSS tweak * Remove auto refresh * Show delete link when there is no file yet * Add current date to display name * Add flag for snapshot support * Add option for disabling automatic snapshots * Make snapshots sharable * Document image variants * Update README.md * Add migrations * Fix tests
This commit is contained in:
54
bookmarks/frontend/behaviors/form.js
Normal file
54
bookmarks/frontend/behaviors/form.js
Normal file
@@ -0,0 +1,54 @@
|
||||
import { registerBehavior, swap } from "./index";
|
||||
|
||||
class FormBehavior {
|
||||
constructor(element) {
|
||||
this.element = element;
|
||||
element.addEventListener("submit", this.onFormSubmit.bind(this));
|
||||
}
|
||||
|
||||
async onFormSubmit(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const url = this.element.action;
|
||||
const formData = new FormData(this.element);
|
||||
if (event.submitter) {
|
||||
formData.append(event.submitter.name, event.submitter.value);
|
||||
}
|
||||
|
||||
await fetch(url, {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
redirect: "manual", // ignore redirect
|
||||
});
|
||||
|
||||
// Dispatch refresh events
|
||||
const refreshEvents = this.element.getAttribute("refresh-events");
|
||||
if (refreshEvents) {
|
||||
refreshEvents.split(",").forEach((eventName) => {
|
||||
document.dispatchEvent(new CustomEvent(eventName));
|
||||
});
|
||||
}
|
||||
|
||||
// Refresh form
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
async refresh() {
|
||||
const refreshUrl = this.element.getAttribute("refresh-url");
|
||||
const html = await fetch(refreshUrl).then((response) => response.text());
|
||||
swap(this.element, html);
|
||||
}
|
||||
}
|
||||
|
||||
class FormAutoSubmitBehavior {
|
||||
constructor(element) {
|
||||
this.element = element;
|
||||
this.element.addEventListener("change", () => {
|
||||
const form = this.element.closest("form");
|
||||
form.dispatchEvent(new Event("submit", { cancelable: true }));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
registerBehavior("ld-form", FormBehavior);
|
||||
registerBehavior("ld-form-auto-submit", FormAutoSubmitBehavior);
|
Reference in New Issue
Block a user