Skip to content

Commit

Permalink
fix: handle anchor only links correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
gearsdigital committed Aug 14, 2022
1 parent 16e26e3 commit 70da1c9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ and it works with default textareas as well.</p>
<p>Yes, absolutely. Just write (or paste) the URL into the Link field.</p>
</details>

<details>
<summary><b>Can I create anchor only links?</b></summary>
<p>It is possible to have anchor only links if you want to jump to a specific part of the same page you're currently editing - just leave the Link-Field empty and fill the Anchor-Field.</p>
</details>

<details>
<summary><b>Can I customize the result list page title?</b></summary>
<p>Yes, you can use the option <code>title</code> to build a title that fit your needs by using <a href="https://getkirby.com/docs/guide/blueprints/query-language">Kirby Query Language</a>.</p>
Expand Down
2 changes: 1 addition & 1 deletion index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions src/components/dialogs/EnhancedToolbarLinkDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,21 @@ export default {
appendAnchor(href) {
let anchor = this.$refs.dialog.model.anchor;
if (!anchor) {
return href;
}
// ensure href to be defined, otherwise it would get concatenated
// to "undefined + #anchor" below
if (!href) {
href = "";
}
if (anchor.startsWith("#")) {
return href + anchor;
}
if (anchor) {
return href + "#" + anchor;
}
return href;
return href + "#" + anchor;
},
listener(evt) {
if (evt.detail.page !== null) {
Expand Down
17 changes: 12 additions & 5 deletions src/components/dialogs/EnhancedToolbarWriterLinkDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,21 @@ export default {
appendAnchor(href) {
let anchor = this.$refs.dialog.model.anchor;
if (anchor && anchor.startsWith("#")) {
return href + anchor;
if (!anchor) {
return href;
}
if (anchor && anchor) {
return href + "#" + anchor;
// ensure href to be defined, otherwise it would get concatenated
// to "undefined + #anchor" below
if (!href) {
href = "";
}
return href;
if (anchor.startsWith("#")) {
return href + anchor;
}
return href + "#" + anchor;
},
listener(evt) {
if (evt.detail.page === null) {
Expand Down

0 comments on commit 70da1c9

Please sign in to comment.