2019-09-20 18:10:48 +00:00
|
|
|
<template>
|
2019-10-03 13:12:49 +00:00
|
|
|
<div
|
|
|
|
id="image-viewer"
|
|
|
|
ref="viewer"
|
|
|
|
:class="{opened: link !== null}"
|
|
|
|
@wheel="onMouseWheel"
|
|
|
|
@touchstart.passive="onTouchStart"
|
|
|
|
@click="onClick"
|
|
|
|
>
|
2019-09-20 18:10:48 +00:00
|
|
|
<template v-if="link !== null">
|
|
|
|
<button class="close-btn" aria-label="Close"></button>
|
2020-03-09 16:39:05 +00:00
|
|
|
|
|
|
|
<button
|
|
|
|
v-if="previousImage"
|
|
|
|
class="previous-image-btn"
|
|
|
|
aria-label="Previous image"
|
|
|
|
@click.stop="previous"
|
|
|
|
></button>
|
|
|
|
<button
|
|
|
|
v-if="nextImage"
|
|
|
|
class="next-image-btn"
|
|
|
|
aria-label="Next image"
|
|
|
|
@click.stop="next"
|
|
|
|
></button>
|
|
|
|
|
2019-10-03 13:12:49 +00:00
|
|
|
<a class="open-btn" :href="link.link" target="_blank" rel="noopener"></a>
|
2019-09-20 18:10:48 +00:00
|
|
|
|
2019-10-03 13:12:49 +00:00
|
|
|
<img
|
|
|
|
ref="image"
|
|
|
|
:src="link.thumb"
|
|
|
|
alt=""
|
|
|
|
:style="computeImageStyles"
|
|
|
|
@load="onImageLoad"
|
|
|
|
@mousedown="onImageMouseDown"
|
|
|
|
@touchstart.passive="onImageTouchStart"
|
|
|
|
/>
|
2019-09-20 18:10:48 +00:00
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
<script lang="ts">
|
2020-03-09 16:39:05 +00:00
|
|
|
import Mousetrap from "mousetrap";
|
2022-06-19 00:25:21 +00:00
|
|
|
import {computed, defineComponent, ref, watch} from "vue";
|
2020-03-16 17:58:40 +00:00
|
|
|
import eventbus from "../js/eventbus";
|
2024-04-21 12:15:22 +00:00
|
|
|
import {ClientChan, ClientLinkPreview} from "../js/types";
|
|
|
|
import {SharedMsg} from "../../shared/types/msg";
|
2020-03-09 16:39:05 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
export default defineComponent({
|
2019-09-20 18:10:48 +00:00
|
|
|
name: "ImageViewer",
|
2022-06-19 00:25:21 +00:00
|
|
|
setup() {
|
|
|
|
const viewer = ref<HTMLDivElement>();
|
|
|
|
const image = ref<HTMLImageElement>();
|
|
|
|
|
|
|
|
const link = ref<ClientLinkPreview | null>(null);
|
|
|
|
const previousImage = ref<ClientLinkPreview | null>();
|
|
|
|
const nextImage = ref<ClientLinkPreview | null>();
|
|
|
|
const channel = ref<ClientChan | null>();
|
|
|
|
|
|
|
|
const position = ref<{
|
|
|
|
x: number;
|
|
|
|
y: number;
|
|
|
|
}>({
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
const transform = ref<{
|
|
|
|
scale: number;
|
|
|
|
x: number;
|
|
|
|
y: number;
|
|
|
|
}>({
|
|
|
|
scale: 1,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
const computeImageStyles = computed(() => {
|
2019-12-15 16:13:52 +00:00
|
|
|
// Sub pixels may cause the image to blur in certain browsers
|
|
|
|
// round it down to prevent that
|
2022-06-19 00:25:21 +00:00
|
|
|
const transformX = Math.floor(transform.value.x);
|
|
|
|
const transformY = Math.floor(transform.value.y);
|
2019-12-15 16:13:52 +00:00
|
|
|
|
2019-09-20 18:10:48 +00:00
|
|
|
return {
|
2022-06-19 00:25:21 +00:00
|
|
|
left: `${position.value.x}px`,
|
|
|
|
top: `${position.value.y}px`,
|
|
|
|
transform: `translate3d(${transformX}px, ${transformY}px, 0) scale3d(${transform.value.scale}, ${transform.value.scale}, 1)`,
|
2019-09-20 18:10:48 +00:00
|
|
|
};
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2019-10-03 13:12:49 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const closeViewer = () => {
|
|
|
|
if (link.value === null) {
|
2019-11-18 19:18:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
channel.value = null;
|
|
|
|
previousImage.value = null;
|
|
|
|
nextImage.value = null;
|
|
|
|
link.value = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
const setPrevNextImages = () => {
|
|
|
|
if (!channel.value || !link.value) {
|
2020-03-09 16:39:05 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const links = channel.value.messages
|
2024-04-21 12:15:22 +00:00
|
|
|
.map((msg: SharedMsg) => msg.previews)
|
2020-03-09 16:39:05 +00:00
|
|
|
.flat()
|
2024-04-21 12:15:22 +00:00
|
|
|
.filter((preview) => preview && preview.thumb);
|
2020-03-09 16:39:05 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const currentIndex = links.indexOf(link.value);
|
|
|
|
|
|
|
|
previousImage.value = links[currentIndex - 1] || null;
|
|
|
|
nextImage.value = links[currentIndex + 1] || null;
|
|
|
|
};
|
|
|
|
|
|
|
|
const previous = () => {
|
|
|
|
if (previousImage.value) {
|
|
|
|
link.value = previousImage.value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const next = () => {
|
|
|
|
if (nextImage.value) {
|
|
|
|
link.value = nextImage.value;
|
|
|
|
}
|
|
|
|
};
|
2020-03-09 16:39:05 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const prepareImage = () => {
|
|
|
|
const viewerEl = viewer.value;
|
|
|
|
const imageEl = image.value;
|
|
|
|
|
|
|
|
if (!viewerEl || !imageEl) {
|
|
|
|
return;
|
2020-03-09 16:39:05 +00:00
|
|
|
}
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
const width = viewerEl.offsetWidth;
|
|
|
|
const height = viewerEl.offsetHeight;
|
|
|
|
const scale = Math.min(1, width / imageEl.width, height / imageEl.height);
|
|
|
|
|
|
|
|
position.value.x = Math.floor(-image.value!.naturalWidth / 2);
|
|
|
|
position.value.y = Math.floor(-image.value!.naturalHeight / 2);
|
|
|
|
transform.value.scale = Math.max(scale, 0.1);
|
|
|
|
transform.value.x = width / 2;
|
|
|
|
transform.value.y = height / 2;
|
|
|
|
};
|
|
|
|
|
|
|
|
const onImageLoad = () => {
|
|
|
|
prepareImage();
|
|
|
|
};
|
|
|
|
|
|
|
|
const calculateZoomShift = (newScale: number, x: number, y: number, oldScale: number) => {
|
|
|
|
if (!image.value || !viewer.value) {
|
|
|
|
return;
|
2020-03-09 16:39:05 +00:00
|
|
|
}
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
const imageWidth = image.value.width;
|
|
|
|
const centerX = viewer.value.offsetWidth / 2;
|
|
|
|
const centerY = viewer.value.offsetHeight / 2;
|
2019-10-03 13:12:49 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
x:
|
|
|
|
centerX -
|
|
|
|
((centerX - (y - (imageWidth * x) / 2)) / x) * newScale +
|
|
|
|
(imageWidth * newScale) / 2,
|
|
|
|
y:
|
|
|
|
centerY -
|
|
|
|
((centerY - (oldScale - (imageWidth * x) / 2)) / x) * newScale +
|
|
|
|
(imageWidth * newScale) / 2,
|
|
|
|
};
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const correctPosition = () => {
|
|
|
|
const imageEl = image.value;
|
|
|
|
const viewerEl = viewer.value;
|
|
|
|
|
|
|
|
if (!imageEl || !viewerEl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const widthScaled = imageEl.width * transform.value.scale;
|
|
|
|
const heightScaled = imageEl.height * transform.value.scale;
|
|
|
|
const containerWidth = viewerEl.offsetWidth;
|
|
|
|
const containerHeight = viewerEl.offsetHeight;
|
2019-10-03 13:12:49 +00:00
|
|
|
|
|
|
|
if (widthScaled < containerWidth) {
|
2022-06-19 00:25:21 +00:00
|
|
|
transform.value.x = containerWidth / 2;
|
|
|
|
} else if (transform.value.x - widthScaled / 2 > 0) {
|
|
|
|
transform.value.x = widthScaled / 2;
|
|
|
|
} else if (transform.value.x + widthScaled / 2 < containerWidth) {
|
|
|
|
transform.value.x = containerWidth - widthScaled / 2;
|
2019-10-03 13:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (heightScaled < containerHeight) {
|
2022-06-19 00:25:21 +00:00
|
|
|
transform.value.y = containerHeight / 2;
|
|
|
|
} else if (transform.value.y - heightScaled / 2 > 0) {
|
|
|
|
transform.value.y = heightScaled / 2;
|
|
|
|
} else if (transform.value.y + heightScaled / 2 < containerHeight) {
|
|
|
|
transform.value.y = containerHeight - heightScaled / 2;
|
2019-10-03 13:12:49 +00:00
|
|
|
}
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
2019-10-03 13:12:49 +00:00
|
|
|
// Reduce multiple touch points into a single x/y/scale
|
2022-06-19 00:25:21 +00:00
|
|
|
const reduceTouches = (touches: TouchList) => {
|
2019-10-03 13:12:49 +00:00
|
|
|
let totalX = 0;
|
|
|
|
let totalY = 0;
|
|
|
|
let totalScale = 0;
|
|
|
|
|
|
|
|
for (let i = 0; i < touches.length; i++) {
|
|
|
|
const x = touches[i].clientX;
|
|
|
|
const y = touches[i].clientY;
|
|
|
|
|
|
|
|
totalX += x;
|
|
|
|
totalY += y;
|
|
|
|
|
|
|
|
for (let i2 = 0; i2 < touches.length; i2++) {
|
|
|
|
if (i !== i2) {
|
|
|
|
const x2 = touches[i2].clientX;
|
|
|
|
const y2 = touches[i2].clientY;
|
|
|
|
totalScale += Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (totalScale === 0) {
|
|
|
|
totalScale = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
x: totalX / touches.length,
|
|
|
|
y: totalY / touches.length,
|
|
|
|
scale: totalScale / touches.length,
|
|
|
|
};
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const onTouchStart = (e: TouchEvent) => {
|
2019-10-03 13:12:49 +00:00
|
|
|
// prevent sidebar touchstart event, we don't want to interact with sidebar while in image viewer
|
|
|
|
e.stopImmediatePropagation();
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
2019-10-03 13:12:49 +00:00
|
|
|
// Touch image manipulation:
|
|
|
|
// 1. Move around by dragging it with one finger
|
|
|
|
// 2. Change image scale by using two fingers
|
2022-06-19 00:25:21 +00:00
|
|
|
const onImageTouchStart = (e: TouchEvent) => {
|
|
|
|
const img = image.value;
|
|
|
|
let touch = reduceTouches(e.touches);
|
2019-10-03 13:12:49 +00:00
|
|
|
let currentTouches = e.touches;
|
|
|
|
let touchEndFingers = 0;
|
|
|
|
|
|
|
|
const currentTransform = {
|
|
|
|
x: touch.x,
|
|
|
|
y: touch.y,
|
|
|
|
scale: touch.scale,
|
|
|
|
};
|
|
|
|
|
|
|
|
const startTransform = {
|
2022-06-19 00:25:21 +00:00
|
|
|
x: transform.value.x,
|
|
|
|
y: transform.value.y,
|
|
|
|
scale: transform.value.scale,
|
2019-10-03 13:12:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const touchMove = (moveEvent) => {
|
2022-06-19 00:25:21 +00:00
|
|
|
touch = reduceTouches(moveEvent.touches);
|
2019-10-03 13:12:49 +00:00
|
|
|
|
|
|
|
if (currentTouches.length !== moveEvent.touches.length) {
|
|
|
|
currentTransform.x = touch.x;
|
|
|
|
currentTransform.y = touch.y;
|
|
|
|
currentTransform.scale = touch.scale;
|
2022-06-19 00:25:21 +00:00
|
|
|
startTransform.x = transform.value.x;
|
|
|
|
startTransform.y = transform.value.y;
|
|
|
|
startTransform.scale = transform.value.scale;
|
2019-10-03 13:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const deltaX = touch.x - currentTransform.x;
|
|
|
|
const deltaY = touch.y - currentTransform.y;
|
|
|
|
const deltaScale = touch.scale / currentTransform.scale;
|
|
|
|
currentTouches = moveEvent.touches;
|
|
|
|
touchEndFingers = 0;
|
|
|
|
|
|
|
|
const newScale = Math.min(3, Math.max(0.1, startTransform.scale * deltaScale));
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
const fixedPosition = calculateZoomShift(
|
2019-10-03 13:12:49 +00:00
|
|
|
newScale,
|
|
|
|
startTransform.scale,
|
|
|
|
startTransform.x,
|
|
|
|
startTransform.y
|
|
|
|
);
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
if (!fixedPosition) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
transform.value.x = fixedPosition.x + deltaX;
|
|
|
|
transform.value.y = fixedPosition.y + deltaY;
|
|
|
|
transform.value.scale = newScale;
|
|
|
|
correctPosition();
|
2019-10-03 13:12:49 +00:00
|
|
|
};
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const touchEnd = (endEvent: TouchEvent) => {
|
2019-10-03 13:12:49 +00:00
|
|
|
const changedTouches = endEvent.changedTouches.length;
|
|
|
|
|
|
|
|
if (currentTouches.length > changedTouches + touchEndFingers) {
|
|
|
|
touchEndFingers += changedTouches;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo: this is swipe to close, but it's not working very well due to unfinished delta calculation
|
|
|
|
/* if (
|
2022-06-19 00:25:21 +00:00
|
|
|
transform.value.scale <= 1 &&
|
2019-10-03 13:12:49 +00:00
|
|
|
endEvent.changedTouches[0].clientY - startTransform.y <= -70
|
|
|
|
) {
|
|
|
|
return this.closeViewer();
|
|
|
|
}*/
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
correctPosition();
|
2019-10-03 13:12:49 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
img?.removeEventListener("touchmove", touchMove);
|
|
|
|
img?.removeEventListener("touchend", touchEnd);
|
2019-10-03 13:12:49 +00:00
|
|
|
};
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
img?.addEventListener("touchmove", touchMove, {passive: true});
|
|
|
|
img?.addEventListener("touchend", touchEnd, {passive: true});
|
|
|
|
};
|
|
|
|
|
2019-10-03 13:12:49 +00:00
|
|
|
// Image mouse manipulation:
|
|
|
|
// 1. Mouse wheel scrolling will zoom in and out
|
|
|
|
// 2. If image is zoomed in, simply dragging it will move it around
|
2022-06-19 00:25:21 +00:00
|
|
|
const onImageMouseDown = (e: MouseEvent) => {
|
2019-10-03 13:12:49 +00:00
|
|
|
// todo: ignore if in touch event currently?
|
2022-06-19 00:25:21 +00:00
|
|
|
|
2019-10-03 13:12:49 +00:00
|
|
|
// only left mouse
|
2022-06-19 00:25:21 +00:00
|
|
|
// TODO: e.buttons?
|
2019-10-03 13:12:49 +00:00
|
|
|
if (e.which !== 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const viewerEl = viewer.value;
|
|
|
|
const imageEl = image.value;
|
|
|
|
|
|
|
|
if (!viewerEl || !imageEl) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-03 13:12:49 +00:00
|
|
|
|
|
|
|
const startX = e.clientX;
|
|
|
|
const startY = e.clientY;
|
2022-06-19 00:25:21 +00:00
|
|
|
const startTransformX = transform.value.x;
|
|
|
|
const startTransformY = transform.value.y;
|
|
|
|
const widthScaled = imageEl.width * transform.value.scale;
|
|
|
|
const heightScaled = imageEl.height * transform.value.scale;
|
|
|
|
const containerWidth = viewerEl.offsetWidth;
|
|
|
|
const containerHeight = viewerEl.offsetHeight;
|
|
|
|
const centerX = transform.value.x - widthScaled / 2;
|
|
|
|
const centerY = transform.value.y - heightScaled / 2;
|
2019-10-03 13:12:49 +00:00
|
|
|
let movedDistance = 0;
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const mouseMove = (moveEvent: MouseEvent) => {
|
2019-10-03 13:12:49 +00:00
|
|
|
moveEvent.stopPropagation();
|
|
|
|
moveEvent.preventDefault();
|
|
|
|
|
|
|
|
const newX = moveEvent.clientX - startX;
|
|
|
|
const newY = moveEvent.clientY - startY;
|
|
|
|
|
|
|
|
movedDistance = Math.max(movedDistance, Math.abs(newX), Math.abs(newY));
|
|
|
|
|
|
|
|
if (centerX < 0 || widthScaled + centerX > containerWidth) {
|
2022-06-19 00:25:21 +00:00
|
|
|
transform.value.x = startTransformX + newX;
|
2019-10-03 13:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (centerY < 0 || heightScaled + centerY > containerHeight) {
|
2022-06-19 00:25:21 +00:00
|
|
|
transform.value.y = startTransformY + newY;
|
2019-10-03 13:12:49 +00:00
|
|
|
}
|
2019-12-24 16:36:12 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
correctPosition();
|
2019-10-03 13:12:49 +00:00
|
|
|
};
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const mouseUp = (upEvent: MouseEvent) => {
|
|
|
|
correctPosition();
|
2019-10-03 13:12:49 +00:00
|
|
|
|
|
|
|
if (movedDistance < 2 && upEvent.button === 0) {
|
2022-06-19 00:25:21 +00:00
|
|
|
closeViewer();
|
2019-10-03 13:12:49 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
image.value?.removeEventListener("mousemove", mouseMove);
|
|
|
|
image.value?.removeEventListener("mouseup", mouseUp);
|
2019-10-03 13:12:49 +00:00
|
|
|
};
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
image.value?.addEventListener("mousemove", mouseMove);
|
|
|
|
image.value?.addEventListener("mouseup", mouseUp);
|
|
|
|
};
|
|
|
|
|
2019-10-03 13:12:49 +00:00
|
|
|
// If image is zoomed in, holding ctrl while scrolling will move the image up and down
|
2022-06-19 00:25:21 +00:00
|
|
|
const onMouseWheel = (e: WheelEvent) => {
|
2019-10-03 13:12:49 +00:00
|
|
|
// if image viewer is closing (css animation), you can still trigger mousewheel
|
|
|
|
// TODO: Figure out a better fix for this
|
2022-06-19 00:25:21 +00:00
|
|
|
if (link.value === null) {
|
2019-10-03 13:12:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
e.preventDefault(); // TODO: Can this be passive?
|
|
|
|
|
|
|
|
if (e.ctrlKey) {
|
2022-06-19 00:25:21 +00:00
|
|
|
transform.value.y += e.deltaY;
|
2019-10-03 13:12:49 +00:00
|
|
|
} else {
|
|
|
|
const delta = e.deltaY > 0 ? 0.1 : -0.1;
|
2022-06-19 00:25:21 +00:00
|
|
|
const newScale = Math.min(3, Math.max(0.1, transform.value.scale + delta));
|
|
|
|
const fixedPosition = calculateZoomShift(
|
2019-10-03 13:12:49 +00:00
|
|
|
newScale,
|
2022-06-19 00:25:21 +00:00
|
|
|
transform.value.scale,
|
|
|
|
transform.value.x,
|
|
|
|
transform.value.y
|
2019-10-03 13:12:49 +00:00
|
|
|
);
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
if (!fixedPosition) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
transform.value.scale = newScale;
|
|
|
|
transform.value.x = fixedPosition.x;
|
|
|
|
transform.value.y = fixedPosition.y;
|
2019-10-03 13:12:49 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
correctPosition();
|
|
|
|
};
|
|
|
|
|
|
|
|
const onClick = (e: Event) => {
|
2019-10-03 13:12:49 +00:00
|
|
|
// If click triggers on the image, ignore it
|
2022-06-19 00:25:21 +00:00
|
|
|
if (e.target === image.value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
closeViewer();
|
|
|
|
};
|
|
|
|
|
|
|
|
watch(link, (newLink, oldLink) => {
|
|
|
|
// TODO: history.pushState
|
|
|
|
if (newLink === null) {
|
|
|
|
eventbus.off("escapekey", closeViewer);
|
|
|
|
eventbus.off("resize", correctPosition);
|
|
|
|
Mousetrap.unbind("left");
|
|
|
|
Mousetrap.unbind("right");
|
2019-10-03 13:12:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
setPrevNextImages();
|
|
|
|
|
|
|
|
if (!oldLink) {
|
|
|
|
eventbus.on("escapekey", closeViewer);
|
|
|
|
eventbus.on("resize", correctPosition);
|
|
|
|
Mousetrap.bind("left", previous);
|
|
|
|
Mousetrap.bind("right", next);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
link,
|
2023-05-15 07:38:09 +00:00
|
|
|
channel,
|
2022-06-19 00:25:21 +00:00
|
|
|
image,
|
|
|
|
transform,
|
|
|
|
closeViewer,
|
|
|
|
next,
|
|
|
|
previous,
|
|
|
|
onImageLoad,
|
|
|
|
onImageMouseDown,
|
|
|
|
onMouseWheel,
|
|
|
|
onClick,
|
|
|
|
onTouchStart,
|
|
|
|
previousImage,
|
|
|
|
nextImage,
|
|
|
|
onImageTouchStart,
|
|
|
|
computeImageStyles,
|
|
|
|
viewer,
|
|
|
|
};
|
2019-09-20 18:10:48 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2019-09-20 18:10:48 +00:00
|
|
|
</script>
|