summaryrefslogtreecommitdiff
path: root/packages/client/src/components/MkUrlPreviewPopup.vue
blob: 2f0ffaa3881b6d3cd05f668fdd84aa5de48a7ef2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<template>
<div class="fgmtyycl" :style="{ zIndex, top: top + 'px', left: left + 'px' }">
	<transition :name="$store.state.animation ? 'zoom' : ''" @after-leave="$emit('closed')">
		<MkUrlPreview v-if="showing" class="_popup _shadow" :url="url"/>
	</transition>
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import MkUrlPreview from '@/components/MkUrlPreview.vue';
import * as os from '@/os';

export default defineComponent({
	components: {
		MkUrlPreview,
	},

	props: {
		url: {
			type: String,
			required: true,
		},
		source: {
			required: true,
		},
		showing: {
			type: Boolean,
			required: true,
		},
	},

	data() {
		return {
			u: null,
			top: 0,
			left: 0,
			zIndex: os.claimZIndex('middle'),
		};
	},

	mounted() {
		const rect = this.source.getBoundingClientRect();
		const x = Math.max((rect.left + (this.source.offsetWidth / 2)) - (300 / 2), 6) + window.pageXOffset;
		const y = rect.top + this.source.offsetHeight + window.pageYOffset;

		this.top = y;
		this.left = x;
	},
});
</script>

<style lang="scss" scoped>
.fgmtyycl {
	position: absolute;
	width: 500px;
	max-width: calc(90vw - 12px);
	pointer-events: none;
}
</style>