Setup keyboard shortcuts for Lightbox, add option to disable animations

This commit is contained in:
simon987 2022-02-28 18:43:48 -05:00
parent ea7dfe7c84
commit d034851ecb
7 changed files with 115 additions and 8 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,7 @@
<template>
<div>
<div :class="{'disable-animations': $store.state.optSimpleLightbox}">
<FsLightbox
ref="lightbox"
:key="lightboxKey"
:toggler="showLightbox"
:sources="lightboxSources"
@ -10,7 +11,7 @@
:source-index="lightboxSlide"
:custom-toolbar-buttons="customButtons"
:slideshow-time="$store.getters.optLightboxSlideDuration * 1000"
:zoom-increment="0.5"
:zoom-increment="0.25"
:load-only-current-source="$store.getters.optLightboxLoadOnlyCurrent"
:on-close="onClose"
:on-open="onShow"
@ -29,6 +30,7 @@ export default {
components: {FsLightbox},
data() {
return {
disableAnimations: true,
customButtons: [
{
viewBox: "0 0 384.928 384.928",
@ -64,7 +66,83 @@ export default {
return this.$store.getters["uiLightboxTypes"];
}
},
mounted() {
const listener = document.onkeydown;
document.onkeydown = (e) => {
const ret = this.keyDownListener(e)
if (listener && ret) {
return listener(e);
}
};
},
methods: {
keyDownListener(e) {
if (this.$refs.lightbox === undefined) {
return true;
}
const lightboxStore = this.$refs.lightbox.fsLightboxStore.slice(-1)[0];
switch (e.key) {
case " ": {
console.log("SPACE")
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
// Find video at current slide, toggle play/pause
[...document.getElementsByClassName("fslightbox-absoluted")].forEach(elem => {
if (elem.style.transform === "translate(0px)" || elem.style.transform === "translate(0px, 0px)") {
const vid = elem.getElementsByTagName("video")[0];
console.log(elem)
console.log(vid)
if (vid) {
if (vid.paused) {
vid.play();
console.log("PLAY")
} else {
vid.pause()
console.log("PAUSE")
}
}
}
return false;
});
return false;
}
case "ArrowUp":
case "k": {
if (!lightboxStore.data.isThumbing) {
lightboxStore.core.thumbsToggler.toggleThumbs();
}
return false;
}
case "ArrowDown":
case "j": {
if (lightboxStore.data.isThumbing) {
lightboxStore.core.thumbsToggler.toggleThumbs();
}
return false;
}
case "h": {
lightboxStore.core.slideIndexChanger.jumpTo(lightboxStore.core.stageManager.getPreviousSlideIndex());
break;
}
case "l": {
lightboxStore.core.slideIndexChanger.jumpTo(lightboxStore.core.stageManager.getNextSlideIndex());
return false;
}
}
return true;
},
onDownloadClick() {
const url = this.lightboxSources[this.lightboxSlide];
@ -125,4 +203,20 @@ export default {
.fslightbox-toolbar-button:nth-child(7) {
order: 7;
}
.disable-animations .fslightbox-container {
background: rgba(30,30,30,.9);
}
.disable-animations .fslightbox-transform-transition {
transition: none;
}
.disable-animations .fslightbox-fade-in-strong {
animation: none;
}
.fslightbox-container video, .fslightbox-container img {
cursor: unset !important;
}
</style>

View File

@ -72,7 +72,8 @@ export default {
hideLegacy: "Hide the 'legacyES' Elasticsearch notice",
updateMimeMap: "Update the Media Types tree in real time",
useDatePicker: "Use a Date Picker component rather than a slider",
vidPreviewInterval: "Video preview frame duration in ms"
vidPreviewInterval: "Video preview frame duration in ms",
simpleLightbox: "Disable animations in image viewer",
},
queryMode: {
simple: "Simple",
@ -239,7 +240,8 @@ export default {
hideLegacy: "Masquer la notice 'legacyES' Elasticsearch",
updateMimeMap: "Mettre à jour l'arbre de Types de médias en temps réel",
useDatePicker: "Afficher un composant « Date Picker » plutôt qu'un slider",
vidPreviewInterval: "Durée des images d'aperçu video en millisecondes"
vidPreviewInterval: "Durée des images d'aperçu video en millisecondes",
simpleLightbox: "Désactiver les animations du visualiseur d'images",
},
queryMode: {
simple: "Simple",
@ -406,7 +408,8 @@ export default {
hideLegacy: "隐藏'legacyES' Elasticsearch 通知",
updateMimeMap: "媒体类型树的实时更新",
useDatePicker: "使用日期选择器组件而不是滑块",
vidPreviewInterval: "视频预览帧的持续时间,以毫秒为单位"
vidPreviewInterval: "视频预览帧的持续时间,以毫秒为单位",
simpleLightbox: "在图片查看器中,禁用动画",
},
queryMode: {
simple: "简单",

View File

@ -51,6 +51,7 @@ export default new Vuex.Store({
optUpdateMimeMap: false,
optUseDatePicker: false,
optVidPreviewInterval: 700,
optSimpleLightbox: true,
_onLoadSelectedIndices: [] as string[],
_onLoadSelectedMimeTypes: [] as string[],
@ -161,6 +162,7 @@ export default new Vuex.Store({
setOptUpdateMimeMap: (state, val) => state.optUpdateMimeMap = val,
setOptUseDatePicker: (state, val) => state.optUseDatePicker = val,
setOptVidPreviewInterval: (state, val) => state.optVidPreviewInterval = val,
setOptSimpleLightbox: (state, val) => state.optSimpleLightbox = val,
setOptLightboxLoadOnlyCurrent: (state, val) => state.optLightboxLoadOnlyCurrent = val,
setOptLightboxSlideDuration: (state, val) => state.optLightboxSlideDuration = val,
@ -378,5 +380,6 @@ export default new Vuex.Store({
optUpdateMimeMap: state => state.optUpdateMimeMap,
optUseDatePicker: state => state.optUseDatePicker,
optVidPreviewInterval: state => state.optVidPreviewInterval,
optSimpleLightbox: state => state.optSimpleLightbox,
}
})

View File

@ -45,6 +45,11 @@
<b-form-checkbox :checked="optUseDatePicker" @input="setOptUseDatePicker">
{{ $t("opt.useDatePicker") }}
</b-form-checkbox>
<b-form-checkbox :checked="optSimpleLightbox" @input="setOptSimpleLightbox">{{
$t("opt.simpleLightbox")
}}
</b-form-checkbox>
</b-card>
<br/>
@ -239,6 +244,7 @@ export default {
"optUpdateMimeMap",
"optUseDatePicker",
"optVidPreviewInterval",
"optSimpleLightbox",
]),
clientWidth() {
return window.innerWidth;
@ -285,6 +291,7 @@ export default {
"setOptUpdateMimeMap",
"setOptUseDatePicker",
"setOptVidPreviewInterval",
"setOptSimpleLightbox",
]),
onResetClick() {
localStorage.removeItem("sist2_configuration");

File diff suppressed because one or more lines are too long