Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to toggle linkification by prop #1337

Merged
merged 1 commit into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/components/AppSidebar/AppSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@
<!-- main title -->
<div class="app-sidebar-header__title">
<h2 v-show="!titleEditable"
v-linkify="title"
v-linkify="{text: title, linkify: linkifyTitle}"
class="app-sidebar-header__maintitle"
@click.self="editTitle($event)" />
@click.self="editTitle">
{{ title }}
</h2>
<template v-if="titleEditable">
<form
v-click-outside="() => onSubmitTitle()"
Expand Down Expand Up @@ -320,6 +322,14 @@ export default {
type: Boolean,
default: false,
},

/**
* Linkify the title
*/
linkifyTitle: {
type: Boolean,
default: false,
},
},

data() {
Expand Down Expand Up @@ -372,7 +382,7 @@ export default {
this.$emit('update:starred', this.isStarred)
},

editTitle(event) {
editTitle() {
this.$emit('update:titleEditable', true)
// Focus the title input
if (this.titleEditable) {
Expand Down
8 changes: 5 additions & 3 deletions src/directives/Linkify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import linkifyStr from 'linkifyjs/string'
// Use function shorthand for same behavior on bind and update
// https://vuejs.org/v2/guide/custom-directive.html#Function-Shorthand
export const directive = function(el, binding) {
el.innerHTML = linkifyStr(binding.value, {
defaultProtocol: 'https',
})
if (binding.value?.linkify === true) {
el.innerHTML = linkifyStr(binding.value.text, {
defaultProtocol: 'https',
})
}
}

export default directive