File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed
Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 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'
96106import CloseIcon from ' vue-material-design-icons/Close.vue'
97107import ContentCopyIcon from ' vue-material-design-icons/ContentCopy.vue'
98108import LinkOffIcon from ' vue-material-design-icons/LinkOff.vue'
109+ import OpenInNewIcon from ' vue-material-design-icons/OpenInNew.vue'
99110import PencilIcon from ' vue-material-design-icons/Pencil.vue'
100111
101112import CopyToClipboardMixin from ' ../../mixins/CopyToClipboardMixin.js'
113+ import { openLink } from ' ../../helpers/links.js'
102114
103115const 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 () {
Original file line number Diff line number Diff 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+
5977export {
6078 domHref ,
6179 parseHref ,
6280 isLinkToSelfWithHash ,
81+ openLink ,
6382}
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments