Skip to content

Commit

Permalink
Make eventhub events specific to the field's unique id
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainjule committed Jan 23, 2019
1 parent 2307724 commit f62b775
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion index.js

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions src/components/input/MarkdownInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="k-markdown-input-wrapper" :data-size="size">
<k-markdown-toolbar v-if="buttons"
ref="toolbar"
:name="name"
:id="id"
:modals="modals"
:editor="editor"
:invisibles="invisibles"
Expand Down Expand Up @@ -46,10 +46,10 @@ export default {
skipNextChangeEvent: false,
currentDialog: null,
currentTokenType: null,
id: '',
}
},
props: {
name: String,
autofocus: Boolean,
modals: Boolean,
blank: Boolean,
Expand Down Expand Up @@ -82,6 +82,9 @@ export default {
},
},
},
created() {
this.id = this._uid
},
mounted() {
this.editor = CodeMirror.fromTextArea(this.$refs.input, this.options);
this.editor.setValue(this.value || '');
Expand All @@ -96,14 +99,14 @@ export default {
}
// Register shortcuts
this.$root.$on('md-registerShortcut' + this.name, (shortcut, fn) => {
this.$root.$on('md-registerShortcut' + this.id, (shortcut, fn) => {
let map = {}
map[shortcut] = fn
this.editor.addKeyMap(map)
})
// Open dialogs
this.$root.$on('md-openDialog' + this.name, dialog => {
this.$root.$on('md-openDialog' + this.id, dialog => {
let dialogName = dialog == 'images' ? 'files' : dialog
if(this.$refs[dialogName + "Dialog"]) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/toolbar/MarkdownToolbar.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<nav class="k-toolbar k-markdown-toolbar">
<div class="k-toolbar-buttons k-markdown-toolbar-buttons">
<component v-for="(button, index) in layout" :is="'k-markdown-button-' + buttonName(button)" :key="index" :button="button" :name="buttonName(button)" :currentTokenType="currentTokenType" :buttonIndex="index" :editor="editor" :modals="modals" :fieldname="name"/>
<component v-for="(button, index) in layout" :is="'k-markdown-button-' + buttonName(button)" :key="index" :button="button" :name="buttonName(button)" :currentTokenType="currentTokenType" :buttonIndex="index" :editor="editor" :modals="modals" :id="id"/>
<div v-if="invisibles" class="k-markdown-toolbar-buttons-right">
<component is="k-markdown-button-invisibles" button="invisibles" name="invisibles" buttonIndex="100" :editor="editor" :modals="modals"/>
</div>
Expand All @@ -12,7 +12,7 @@
<script>
export default {
props: {
name: String,
id: String,
buttons: Array,
editor: Object,
modals: Boolean,
Expand Down
4 changes: 2 additions & 2 deletions src/components/toolbar/buttons/button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
props: {
button: [String, Object],
buttonIndex: String,
fieldname: String,
id: String,
editor: Object,
modals: Boolean,
currentTokenType: String,
Expand Down Expand Up @@ -40,7 +40,7 @@ export default {
watch: {
editor(val) {
if(typeof val !== 'undefined' && this.shortcut) {
this.$root.$emit('md-registerShortcut' + this.fieldname, this.shortcut, this.action)
this.$root.$emit('md-registerShortcut' + this.id, this.shortcut, this.action)
}
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/toolbar/buttons/email.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default {
action() {
// open a modal if allowed
if(this.modals) {
this.$root.$emit('md-openDialog' + this.fieldname, 'email')
this.$root.$emit('md-openDialog' + this.id, 'email')
}
// else, insert an inline tag
else {
Expand Down
2 changes: 1 addition & 1 deletion src/components/toolbar/buttons/file.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
},
methods: {
action() {
this.$root.$emit('md-openDialog' + this.fieldname, 'files')
this.$root.$emit('md-openDialog' + this.id, 'files')
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/toolbar/buttons/image.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
},
methods: {
action() {
this.$root.$emit('md-openDialog' + this.fieldname, 'images')
this.$root.$emit('md-openDialog' + this.id, 'images')
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/toolbar/buttons/link.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default {
action() {
// open a modal if allowed
if(this.modals) {
this.$root.$emit('md-openDialog' + this.fieldname, 'link')
this.$root.$emit('md-openDialog' + this.id, 'link')
}
// else, insert an inline tag
else {
Expand Down
2 changes: 1 addition & 1 deletion src/components/toolbar/buttons/pagelink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
},
methods: {
action() {
this.$root.$emit('md-openDialog' + this.fieldname, 'pages')
this.$root.$emit('md-openDialog' + this.id, 'pages')
}
}
};
Expand Down

0 comments on commit f62b775

Please sign in to comment.