commit f2f46bff3eae5aad7cbed7d5a18068b00aac1211
parent 0c259765806f057201948afa4d1fb2ac49641811
Author: unitehenry <unitehenry@gmail.com>
Date: Wed, 20 Nov 2019 10:56:22 -0500
setLinks
Diffstat:
3 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/demo/src/App.vue b/demo/src/App.vue
@@ -5,6 +5,7 @@
>
<striven-editor
ref="editor"
+ v-model="content"
:toolbar-hide="toolbarHide"
:minimal="minimal"
:toolbar-bottom="toolbarBottom"
@@ -14,9 +15,10 @@
:meta-url="metaUrl"
:on-enter="submitOnEnter"
></striven-editor>
- <div ref="customButton" style="display: flex; align-items: flex-end;">
- <div class="custom-button" @click="sendContent">Send</div>
- </div>
+ <div v-html="content"></div>
+ <!-- <div ref="customButton" style="display: flex; align-items: flex-end;"> -->
+ <!-- <div class="custom-button" @click="sendContent">Send</div> -->
+ <!-- </div> -->
</div>
</template>
@@ -64,7 +66,8 @@ export default {
}
},
customButton: () => this.$refs.customButton,
- editor: null
+ editor: null,
+ content: ""
};
},
mounted() {
diff --git a/src/striveneditor.js b/src/striveneditor.js
@@ -453,7 +453,6 @@ export default class StrivenEditor {
e.preventDefault();
if (this.browser.isEdge() || this.browser.isFirefox()) {
- console.log(string)
document.execCommand('insertHTML', false, `<a href="${string}">${string}</a>`);
} else {
document.execCommand('insertHTML', true, `<a href="${string}">${string}</a>`);
@@ -472,6 +471,7 @@ export default class StrivenEditor {
}
}
+ this.setLinks();
this.overflow();
};
@@ -525,6 +525,7 @@ export default class StrivenEditor {
const bodyBlur =body.onblur;
body.onblur =(e) =>{
this.editor.classList.remove("se-focus");
+ this.setLinks();
bodyBlur && bodyBlur();
}
@@ -534,6 +535,13 @@ export default class StrivenEditor {
body.textContent && this.toolbarState();
bodyClick && bodyClick;
}
+
+ const bodyKeyPress = body.onkeypress;
+ body.onkeypress = () => {
+ bodyKeyPress && bodyKeyPress();
+ this.setLinks();
+ }
+
return body;
}
@@ -1371,6 +1379,11 @@ export default class StrivenEditor {
return isEditor(activeEl);
}
+ setLinks() {
+ const links = [...this.body.querySelectorAll('a')];
+ links.length && links.forEach(link => link.setAttribute('target', 'blank'))
+ }
+
executeCommand(command) {
switch (command) {
case "insertOrderedList":
diff --git a/src/vue-striveneditor.vue b/src/vue-striveneditor.vue
@@ -35,6 +35,7 @@ export default {
// Listen to input event for v-model support
vm.editor.body.oninput = e => {
vm.pauseUpdate = true;
+ vm.editor.setLinks();
vm.$emit("input", vm.editor.getContent());
};
},