diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-12-23 17:05:26 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-12-23 17:05:26 +0900 |
| commit | 3a990dce7520eb1e4fabb2dbdf0860f2c60432e4 (patch) | |
| tree | 5a84dd1f42dc985f56b3223dafb8c55807e8ff44 | |
| parent | enhance(client): tweak channel pages (diff) | |
| download | sharkey-3a990dce7520eb1e4fabb2dbdf0860f2c60432e4.tar.gz sharkey-3a990dce7520eb1e4fabb2dbdf0860f2c60432e4.tar.bz2 sharkey-3a990dce7520eb1e4fabb2dbdf0860f2c60432e4.zip | |
refactor(client): refactor
| -rw-r--r-- | packages/client/src/components/global/url.vue | 88 | ||||
| -rw-r--r-- | packages/client/src/pages/channels.vue | 2 | ||||
| -rw-r--r-- | packages/client/src/scripts/use-tooltip.ts | 3 |
3 files changed, 28 insertions, 65 deletions
diff --git a/packages/client/src/components/global/url.vue b/packages/client/src/components/global/url.vue index 097fcddef6..56a8c3453a 100644 --- a/packages/client/src/components/global/url.vue +++ b/packages/client/src/components/global/url.vue @@ -1,7 +1,5 @@ <template> -<component :is="self ? 'MkA' : 'a'" class="ieqqeuvs _link" :[attr]="self ? url.substr(local.length) : url" :rel="rel" :target="target" - @mouseover="onMouseover" - @mouseleave="onMouseleave" +<component :is="self ? 'MkA' : 'a'" ref="el" class="ieqqeuvs _link" :[attr]="self ? url.substr(local.length) : url" :rel="rel" :target="target" @contextmenu.stop="() => {}" > <template v-if="!self"> @@ -20,11 +18,11 @@ </template> <script lang="ts"> -import { defineComponent } from 'vue'; +import { defineComponent, ref } from 'vue'; import { toUnicode as decodePunycode } from 'punycode/'; import { url as local } from '@/config'; -import { isTouchUsing } from '@/scripts/touch'; import * as os from '@/os'; +import { useTooltip } from '@/scripts/use-tooltip'; export default defineComponent({ props: { @@ -35,74 +33,36 @@ export default defineComponent({ rel: { type: String, required: false, + default: null, } }, - data() { - const self = this.url.startsWith(local); + setup(props) { + const self = props.url.startsWith(local); + const url = new URL(props.url); + const el = ref(); + + useTooltip(el, (showing) => { + os.popup(import('@/components/url-preview-popup.vue'), { + showing, + url: props.url, + source: el.value, + }, {}, 'closed'); + }); + return { local, - schema: null as string | null, - hostname: null as string | null, - port: null as string | null, - pathname: null as string | null, - query: null as string | null, - hash: null as string | null, + schema: url.protocol, + hostname: decodePunycode(url.hostname), + port: url.port, + pathname: decodeURIComponent(url.pathname), + query: decodeURIComponent(url.search), + hash: decodeURIComponent(url.hash), self: self, attr: self ? 'to' : 'href', target: self ? null : '_blank', - showTimer: null, - hideTimer: null, - checkTimer: null, - close: null, + el, }; }, - created() { - const url = new URL(this.url); - this.schema = url.protocol; - this.hostname = decodePunycode(url.hostname); - this.port = url.port; - this.pathname = decodeURIComponent(url.pathname); - this.query = decodeURIComponent(url.search); - this.hash = decodeURIComponent(url.hash); - }, - methods: { - async showPreview() { - if (!document.body.contains(this.$el)) return; - if (this.close) return; - - const { dispose } = await os.popup(import('@/components/url-preview-popup.vue'), { - url: this.url, - source: this.$el - }); - - this.close = () => { - dispose(); - }; - - this.checkTimer = setInterval(() => { - if (!document.body.contains(this.$el)) this.closePreview(); - }, 1000); - }, - closePreview() { - if (this.close) { - clearInterval(this.checkTimer); - this.close(); - this.close = null; - } - }, - onMouseover() { - if (isTouchUsing) return; - clearTimeout(this.showTimer); - clearTimeout(this.hideTimer); - this.showTimer = setTimeout(this.showPreview, 500); - }, - onMouseleave() { - if (isTouchUsing) return; - clearTimeout(this.showTimer); - clearTimeout(this.hideTimer); - this.hideTimer = setTimeout(this.closePreview, 500); - } - } }); </script> diff --git a/packages/client/src/pages/channels.vue b/packages/client/src/pages/channels.vue index 3bc62b5b56..48877ab3ec 100644 --- a/packages/client/src/pages/channels.vue +++ b/packages/client/src/pages/channels.vue @@ -39,7 +39,7 @@ export default defineComponent({ actions: [{ icon: 'fas fa-plus', text: this.$ts.create, - handler: this.create + handler: this.create, }], tabs: [{ active: this.tab === 'featured', diff --git a/packages/client/src/scripts/use-tooltip.ts b/packages/client/src/scripts/use-tooltip.ts index 0df4baca7b..d0c6756eb1 100644 --- a/packages/client/src/scripts/use-tooltip.ts +++ b/packages/client/src/scripts/use-tooltip.ts @@ -18,6 +18,9 @@ export function useTooltip( const open = () => { close(); if (!isHovering) return; + if (elRef.value == null) return; + const el = elRef.value instanceof Element ? elRef.value : elRef.value.$el; + if (!document.body.contains(el)) return; // openしようとしたときに既に元要素がDOMから消えている場合があるため const showing = ref(true); onShow(showing); |