mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-07 10:58:25 +02:00

* return updated HTML from bookmark actions * open details through URL * fix details update * improve modal behavior * use a frame * make behaviors properly destroy themselves * remove page and details params from tag urls * use separate behavior for details and tags * remove separate details view * make it work with other views * add asset actions * remove asset refresh for now * remove details partial * fix tests * remove old partials * update tests * cache and reuse tags * extract search autocomplete behavior * remove details param from pagination * fix tests * only return details modal when navigating in frame * fix link target * remove unused behaviors * use auto submit behavior for user select * fix import
56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
import { Behavior, registerBehavior } from "./index";
|
|
|
|
class AutoSubmitBehavior extends Behavior {
|
|
constructor(element) {
|
|
super(element);
|
|
|
|
this.submit = this.submit.bind(this);
|
|
element.addEventListener("change", this.submit);
|
|
}
|
|
|
|
destroy() {
|
|
this.element.removeEventListener("change", this.submit);
|
|
}
|
|
|
|
submit() {
|
|
this.element.closest("form").requestSubmit();
|
|
}
|
|
}
|
|
|
|
class UploadButton extends Behavior {
|
|
constructor(element) {
|
|
super(element);
|
|
this.fileInput = element.nextElementSibling;
|
|
|
|
this.onClick = this.onClick.bind(this);
|
|
this.onChange = this.onChange.bind(this);
|
|
|
|
element.addEventListener("click", this.onClick);
|
|
this.fileInput.addEventListener("change", this.onChange);
|
|
}
|
|
|
|
destroy() {
|
|
this.element.removeEventListener("click", this.onClick);
|
|
this.fileInput.removeEventListener("change", this.onChange);
|
|
}
|
|
|
|
onClick(event) {
|
|
event.preventDefault();
|
|
this.fileInput.click();
|
|
}
|
|
|
|
onChange() {
|
|
// Check if the file input has a file selected
|
|
if (!this.fileInput.files.length) {
|
|
return;
|
|
}
|
|
const form = this.fileInput.closest("form");
|
|
form.requestSubmit(this.element);
|
|
// remove selected file so it doesn't get submitted again
|
|
this.fileInput.value = "";
|
|
}
|
|
}
|
|
|
|
registerBehavior("ld-auto-submit", AutoSubmitBehavior);
|
|
registerBehavior("ld-upload-button", UploadButton);
|