feat: open in new page when ctrl pressed

This commit is contained in:
三咲智子 2022-11-28 19:03:56 +08:00
parent 9fca8eee30
commit 2ff4041489
No known key found for this signature in database
GPG key ID: 69992F2250DFD93E

View file

@ -21,16 +21,22 @@ const rebloggedBy = $computed(() => props.status.reblog ? props.status.account :
const el = ref<HTMLElement>() const el = ref<HTMLElement>()
const router = useRouter() const router = useRouter()
function onclick(e: MouseEvent | KeyboardEvent) { function onclick(evt: MouseEvent | KeyboardEvent) {
const path = e.composedPath() as HTMLElement[] const path = evt.composedPath() as HTMLElement[]
const el = path.find(el => ['A', 'BUTTON', 'IMG', 'VIDEO'].includes(el.tagName?.toUpperCase())) const el = path.find(el => ['A', 'BUTTON', 'IMG', 'VIDEO'].includes(el.tagName?.toUpperCase()))
if (!el) if (!el)
go() go(evt)
} }
function go() { function go(evt: MouseEvent | KeyboardEvent) {
cacheStatus(status) const path = getStatusPath(status)
router.push(getStatusPath(status)) if (evt.metaKey || evt.ctrlKey) {
window.open(path)
}
else {
cacheStatus(status)
router.push(path)
}
} }
const createdAt = useFormattedDateTime(status.createdAt) const createdAt = useFormattedDateTime(status.createdAt)
@ -62,7 +68,7 @@ const timeago = useTimeAgo(() => status.createdAt, timeAgoOptions)
<div flex-auto /> <div flex-auto />
<div text-sm text-secondary flex="~ row nowrap" hover:underline> <div text-sm text-secondary flex="~ row nowrap" hover:underline>
<CommonTooltip :content="createdAt"> <CommonTooltip :content="createdAt">
<a :title="status.createdAt" :href="getStatusPath(status)" @click.prevent="go"> <a :title="status.createdAt" :href="getStatusPath(status)" @click.prevent="go($event)">
<time text-sm hover:underline :datetime="status.createdAt"> <time text-sm hover:underline :datetime="status.createdAt">
{{ timeago }} {{ timeago }}
</time> </time>