2020-02-09 19:48:45 +01:00
|
|
|
<template>
|
2020-10-24 18:21:41 +02:00
|
|
|
<component :is="self ? 'MkA' : 'a'" class="xlcxczvw _link" :[attr]="self ? url.substr(local.length) : url" :rel="rel" :target="target"
|
2020-02-09 19:48:45 +01:00
|
|
|
@mouseover="onMouseover"
|
|
|
|
@mouseleave="onMouseleave"
|
|
|
|
:title="url"
|
|
|
|
>
|
|
|
|
<slot></slot>
|
2020-10-17 13:12:00 +02:00
|
|
|
<Fa :icon="faExternalLinkSquareAlt" v-if="target === '_blank'" class="icon"/>
|
2020-02-09 19:48:45 +01:00
|
|
|
</component>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 13:12:00 +02:00
|
|
|
import { defineComponent } from 'vue';
|
2020-02-09 19:48:45 +01:00
|
|
|
import { faExternalLinkSquareAlt } from '@fortawesome/free-solid-svg-icons';
|
2021-03-23 09:30:14 +01:00
|
|
|
import { url as local } from '@client/config';
|
|
|
|
import { isDeviceTouch } from '@client/scripts/is-device-touch';
|
|
|
|
import * as os from '@client/os';
|
2020-02-09 19:48:45 +01:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
export default defineComponent({
|
2020-02-09 19:48:45 +01:00
|
|
|
props: {
|
|
|
|
url: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
rel: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
2020-02-10 12:51:17 +01:00
|
|
|
const self = this.url.startsWith(local);
|
2020-02-09 19:48:45 +01:00
|
|
|
return {
|
|
|
|
local,
|
2020-02-10 12:51:17 +01:00
|
|
|
self: self,
|
|
|
|
attr: self ? 'to' : 'href',
|
|
|
|
target: self ? null : '_blank',
|
2020-02-09 19:48:45 +01:00
|
|
|
showTimer: null,
|
|
|
|
hideTimer: null,
|
2020-10-17 13:12:00 +02:00
|
|
|
checkTimer: null,
|
|
|
|
close: null,
|
2020-02-09 19:48:45 +01:00
|
|
|
faExternalLinkSquareAlt
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
2020-10-17 13:12:00 +02:00
|
|
|
async showPreview() {
|
2020-02-09 19:48:45 +01:00
|
|
|
if (!document.body.contains(this.$el)) return;
|
2020-10-17 13:12:00 +02:00
|
|
|
if (this.close) return;
|
2020-02-09 19:48:45 +01:00
|
|
|
|
2021-03-23 09:30:14 +01:00
|
|
|
const { dispose } = await os.popup(import('@client/components/url-preview-popup.vue'), {
|
2020-10-17 13:12:00 +02:00
|
|
|
url: this.url,
|
|
|
|
source: this.$el
|
|
|
|
});
|
2020-02-09 19:48:45 +01:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
this.close = () => {
|
|
|
|
dispose();
|
|
|
|
};
|
|
|
|
|
|
|
|
this.checkTimer = setInterval(() => {
|
|
|
|
if (!document.body.contains(this.$el)) this.closePreview();
|
|
|
|
}, 1000);
|
2020-02-09 19:48:45 +01:00
|
|
|
},
|
|
|
|
closePreview() {
|
2020-10-17 13:12:00 +02:00
|
|
|
if (this.close) {
|
|
|
|
clearInterval(this.checkTimer);
|
|
|
|
this.close();
|
|
|
|
this.close = null;
|
2020-02-09 19:48:45 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onMouseover() {
|
2020-06-03 06:30:17 +02:00
|
|
|
if (isDeviceTouch) return;
|
2020-02-09 19:48:45 +01:00
|
|
|
clearTimeout(this.showTimer);
|
|
|
|
clearTimeout(this.hideTimer);
|
|
|
|
this.showTimer = setTimeout(this.showPreview, 500);
|
|
|
|
},
|
|
|
|
onMouseleave() {
|
2020-06-03 06:30:17 +02:00
|
|
|
if (isDeviceTouch) return;
|
2020-02-09 19:48:45 +01:00
|
|
|
clearTimeout(this.showTimer);
|
|
|
|
clearTimeout(this.hideTimer);
|
|
|
|
this.hideTimer = setTimeout(this.closePreview, 500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.xlcxczvw {
|
|
|
|
word-break: break-all;
|
|
|
|
|
|
|
|
> .icon {
|
|
|
|
padding-left: 2px;
|
|
|
|
font-size: .9em;
|
|
|
|
font-weight: 400;
|
|
|
|
font-style: normal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|