Skip to content

Commit

Permalink
Merge pull request #5 from ericjjj/develop
Browse files Browse the repository at this point in the history
Fix insertLink bug
  • Loading branch information
playmyswift authored Mar 12, 2018
2 parents 509cf1e + 34c1b1d commit 88713fb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smeditor",
"version": "0.1.9",
"version": "0.1.10",
"description": "smeditor",
"author": "eric <[email protected]>",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion release/smeditor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion release/smeditor.js.map

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/components/InsertLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<div class="insert-link-box">
<span class="cancel" @click='cancelClick'>X</span>
<p>插入链接</p>
<input type="text" name="link" placeholder="链接地址" v-model='link'>
<input type="text" name="text" placeholder="链接文本" v-model='text' v-on:keyup.enter='conformClick'>
<input type="text" name="link" placeholder="链接地址" v-model='link'>
<button @click='conformClick'> 确认</button>
</div>
</div>
Expand All @@ -18,14 +18,20 @@ export default {
text: ''
}
},
props: ['insertLink', 'cancel'],
props: ['insertLink', 'cancel', 'propText'],
methods: {
conformClick () {
this.insertLink(this.link, this.text)
},
cancelClick () {
this.cancel()
}
},
watch: {
'propText': function () {
this.text = this.propText
this.link = this.propLink
}
}
}
</script>
Expand Down
31 changes: 26 additions & 5 deletions src/components/SMEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@
<insert-options
v-show="isInsertShow"
:insertImage="insertImageClick"
:insertLink="insertLink"
:insertLine="insertLine"
:insertVideo="insertVideoClick"
:insertQuote="insertQuote"
:insertBlock="insertBlock"
:uploadImages='uploadImages'
></insert-options>
Expand All @@ -93,8 +91,14 @@
>
</div>
<p class="select-words" v-show="selectWords">{{selectWords.length}}个字</p>
<insert-link :insertLink='insertLink' v-if='isInsertLinkShow' :cancel='insertLinkCancel'></insert-link>
<insert-video :insertVideo='insertVideo' v-if='isInsertVideoShow' :cancel='insertVideoCancel'></insert-video>
<insert-link
:insertLink='insertLink'
:propText='insertLinkSection.text'
:propLink='insertLinkSection.link'
v-show='isInsertLinkShow'
:cancel='insertLinkCancel'
></insert-link>
<insert-video :insertVideo='insertVideo' v-show='isInsertVideoShow' :cancel='insertVideoCancel'></insert-video>
</div>
</template>

Expand Down Expand Up @@ -156,7 +160,14 @@ export default {
cursor: {},
// 鼠标选中节点
selectNode: {},
buttonsBarFixed: false
buttonsBarFixed: false,
insertLinkSection: {
node: '',
start: 0,
end: 0,
text: '',
link: ''
}
}
},
methods: {
Expand Down Expand Up @@ -319,12 +330,18 @@ export default {
// 点击插入链接
insertLinkClick () {
this.closeAlert()
this.insertLinkSection.text = window.getSelection().toString()
getCursor(this)
this.isInsertLinkShow = true
},
// 插入链接
insertLink (url, title) {
restoreCursor(this)
const node = getSelectedNode()
if (node.localName === 'a') {
node.outerHTML = `<a href=${url} target="_blank">${title}</>`
return false
}
document.execCommand('insertHTML', false, `<a href=${url} target="_blank">${title}</>`)
},
// 取消插入链接
Expand Down Expand Up @@ -526,6 +543,10 @@ function getCursor (self) {
self.cursor = window.getSelection().getRangeAt(0)
}
// function delHtmlTag (str) {
// return str.replace(/<[^>]+>/g, '')
// }
function isImageCaption (el) {
return el.className === 'image-caption'
}
Expand Down

0 comments on commit 88713fb

Please sign in to comment.