From cf25ee8242754f1e1536da9b691ab60aa83126ef Mon Sep 17 00:00:00 2001 From: Antonin Caudron Date: Fri, 22 Nov 2019 10:21:16 +0100 Subject: [PATCH] Update anchor behavior --- frontend/js/components/Wysiwyg.vue | 10 +++++++--- frontend/js/libs/Quill/QuillConfiguration.js | 11 ++--------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/frontend/js/components/Wysiwyg.vue b/frontend/js/components/Wysiwyg.vue index 9090d41e1..91ff1c6e7 100755 --- a/frontend/js/components/Wysiwyg.vue +++ b/frontend/js/components/Wysiwyg.vue @@ -208,7 +208,11 @@ }, anchorHandler (value) { if (value === true) { - value = prompt('Enter Id:') + value = prompt('Enter anchor:') + } else { + let range = this.quill.getSelection() + const id = this.quill.getFormat(range).anchor || '' + value = prompt('Edit anchor:', id) } this.quill.format('anchor', value) }, @@ -438,8 +442,8 @@ color: $color__link; } - .ql-anchor { - text-underline: $color__link; + .ql-editor .ql-anchor { + text-decoration: underline $color__link; } .ql-snow.ql-toolbar { diff --git a/frontend/js/libs/Quill/QuillConfiguration.js b/frontend/js/libs/Quill/QuillConfiguration.js index 90f794cbc..d722a3e0e 100644 --- a/frontend/js/libs/Quill/QuillConfiguration.js +++ b/frontend/js/libs/Quill/QuillConfiguration.js @@ -73,13 +73,13 @@ class Anchor extends Inline { static create (value) { let node = super.create(value) value = this.sanitize(value) - console.log(value) node.setAttribute('id', value) + node.className = 'ql-anchor' return node } static sanitize (id) { - return sanitizeAnchor(id) ? id : '' + return id.replace(/\s+/g, '-').toLowerCase() } static formats (domNode) { @@ -93,13 +93,6 @@ class Anchor extends Inline { } } -function sanitizeAnchor (id) { - let anchor = document.createElement('span') - anchor.className = 'ql-anchor' - anchor.id = id.replace(/\s+/g, '-').toLowerCase() - return true -} - Anchor.blotName = anchor.blotName Anchor.tagName = anchor.tagName