Skip to content

Commit d63741e

Browse files
committed
fix(links): Add open button to link bubble
Fixes: #1226 Signed-off-by: Jonas <[email protected]>
1 parent 3237f62 commit d63741e

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/components/Link/LinkBubbleView.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
<div class="link-view-bubble__title">
1111
{{ title }}
1212
</div>
13+
<!-- open link -->
14+
<NcButton
15+
:title="t('text', 'Open link')"
16+
:aria-label="t('text', 'Open link')"
17+
type="tertiary"
18+
@click="openLink(href)">
19+
<template #icon>
20+
<OpenInNewIcon :size="20" />
21+
</template>
22+
</NcButton>
1323
<!-- copy link -->
1424
<NcButton :title="copyLinkTooltip"
1525
:aria-label="copyLinkTooltip"
@@ -96,9 +106,11 @@ import CheckIcon from 'vue-material-design-icons/Check.vue'
96106
import CloseIcon from 'vue-material-design-icons/Close.vue'
97107
import ContentCopyIcon from 'vue-material-design-icons/ContentCopy.vue'
98108
import LinkOffIcon from 'vue-material-design-icons/LinkOff.vue'
109+
import OpenInNewIcon from 'vue-material-design-icons/OpenInNew.vue'
99110
import PencilIcon from 'vue-material-design-icons/Pencil.vue'
100111
101112
import CopyToClipboardMixin from '../../mixins/CopyToClipboardMixin.js'
113+
import { openLink } from '../../helpers/links.js'
102114
103115
const PROTOCOLS_WITH_PREVIEW = ['http:', 'https:']
104116
@@ -114,6 +126,7 @@ export default {
114126
NcReferenceList,
115127
NcTextField,
116128
LinkOffIcon,
129+
OpenInNewIcon,
117130
PencilIcon,
118131
},
119132
@@ -193,6 +206,7 @@ export default {
193206
},
194207
195208
methods: {
209+
openLink,
196210
t,
197211
198212
resetBubble() {

src/helpers/links.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,27 @@ const isLinkToSelfWithHash = function(href) {
5656
return href?.startsWith('#') || href?.startsWith(locationNoHash + '#')
5757
}
5858

59+
/**
60+
* Open links, to be used as custom click handler
61+
*
62+
* @param {string} href the link href
63+
*/
64+
const openLink = function (href) {
65+
const linkUrl = new URL(href, window.location.href)
66+
// Consider rerouting links to Collectives if already inside Collectives app
67+
const collectivesUrlBase = '/apps/collectives'
68+
if (window.OCA.Collectives?.vueRouter
69+
&& linkUrl.pathname.toString().startsWith(generateUrl(collectivesUrlBase))) {
70+
const collectivesUrl = linkUrl.href.substring(linkUrl.href.indexOf(collectivesUrlBase) + collectivesUrlBase.length)
71+
window.OCA.Collectives.vueRouter.push(collectivesUrl)
72+
return
73+
}
74+
window.open(linkUrl, '_blank')
75+
}
76+
5977
export {
6078
domHref,
6179
parseHref,
6280
isLinkToSelfWithHash,
81+
openLink,
6382
}

src/plugins/LinkBubblePluginView.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ class LinkBubblePluginView {
109109
}
110110

111111
updateTooltip(view, { mark, nodeStart }) {
112-
let referenceEl = view.nodeDOM(nodeStart)
112+
let referenceEl
113+
try {
114+
referenceEl = view.nodeDOM(nodeStart)
115+
} catch (e) {
116+
// Prevent throwing error at rerouting in `openLink()`
117+
return
118+
}
113119
if (Object.prototype.toString.call(referenceEl) === '[object Text]') {
114120
referenceEl = referenceEl.parentElement
115121
}

0 commit comments

Comments
 (0)