Added Escape keydown gesture

This commit is contained in:
Damien Broqua 2024-02-04 15:37:42 +01:00
parent 061e72c459
commit d692090022
3 changed files with 48 additions and 4 deletions

View file

@ -78,6 +78,12 @@ Vue.createApp({
], ],
}; };
}, },
created() {
window.addEventListener("keydown", this.keyDown);
},
destroyed() {
window.removeEventListener("keydown", this.keyDown);
},
methods: { methods: {
search(event) { search(event) {
event.preventDefault(); event.preventDefault();
@ -189,5 +195,13 @@ Vue.createApp({
orderedItems(items) { orderedItems(items) {
return items.sort(); return items.sort();
}, },
keyDown(event) {
const keycode = event.code;
if (this.modalIsVisible && keycode === "Escape") {
event.preventDefault();
this.modalIsVisible = false;
}
},
}, },
}).mount("#ajouter-album"); }).mount("#ajouter-album");

View file

@ -34,6 +34,11 @@ Vue.createApp({
}, },
created() { created() {
this.fetch(); this.fetch();
window.addEventListener("keydown", this.keyDown);
},
destroyed() {
window.removeEventListener("keydown", this.keyDown);
}, },
methods: { methods: {
formatParams(param) { formatParams(param) {
@ -241,5 +246,16 @@ Vue.createApp({
return render; return render;
}, },
keyDown(event) {
const keycode = event.code;
if (this.showModalDelete && keycode === "Escape") {
event.preventDefault();
this.showModalDelete = false;
}
if (this.showModalShare && keycode === "Escape") {
event.preventDefault();
this.showModalShare = false;
}
},
}, },
}).mount("#collection"); }).mount("#collection");

View file

@ -25,10 +25,10 @@ if (typeof item !== "undefined") {
this.setTrackList(); this.setTrackList();
this.setIdentifiers(); this.setIdentifiers();
window.addEventListener("keydown", this.changeImage); window.addEventListener("keydown", this.keyDown);
}, },
destroyed() { destroyed() {
window.removeEventListener("keydown", this.changeImage); window.removeEventListener("keydown", this.keyDown);
}, },
watch: { watch: {
shareMessage(message) { shareMessage(message) {
@ -139,12 +139,12 @@ if (typeof item !== "undefined") {
this.setImage(); this.setImage();
}, },
changeImage(event) { changeImage(event) {
event.preventDefault();
const direction = event.code; const direction = event.code;
if ( if (
this.modalIsVisible &&
["ArrowRight", "ArrowLeft", "Escape"].indexOf(direction) !== ["ArrowRight", "ArrowLeft", "Escape"].indexOf(direction) !==
-1 -1
) { ) {
switch (direction) { switch (direction) {
case "ArrowRight": case "ArrowRight":
@ -159,6 +159,20 @@ if (typeof item !== "undefined") {
return true; return true;
}, },
keyDown(event) {
const keycode = event.code;
if (this.modalIsVisible) {
this.changeImage(event);
}
if (this.showModalDelete && keycode === "Escape") {
event.preventDefault();
this.showModalDelete = false;
}
if (this.showModalShare && keycode === "Escape") {
event.preventDefault();
this.showModalShare = false;
}
},
showAllIdentifiers() { showAllIdentifiers() {
this.identifiersMode = "all"; this.identifiersMode = "all";
this.setIdentifiers(); this.setIdentifiers();