Skip to content

Commit

Permalink
Merge pull request AsgardCms#652 from mikemand/feature/allow-custom-c…
Browse files Browse the repository at this point in the history
…onfig

Allow CKEditor custom config to work in Vue component
  • Loading branch information
nWidart authored Nov 21, 2018
2 parents 928a4aa + 366b4a2 commit 9c5b5d7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 43 deletions.
94 changes: 51 additions & 43 deletions Modules/Core/Assets/js/components/CkEditor.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<template>
<div class="ckeditor">
<textarea
:name="name"
:id="id"
:value="value"
:types="types"
:config="config">
</textarea>
</div>
<textarea
:name="name"
:id="id"
:value="value"
:types="types"
:config="config"
></textarea>
</template>

<script>
Expand All @@ -18,77 +16,87 @@
props: {
name: {
type: String,
default: () => `editor-${++inc}`
default: () => `editor-${++inc}`,
},
value: {
type: String
type: String,
default: () => '',
},
id: {
type: String,
default: () => `editor-${inc}`
default: () => `editor-${inc}`,
},
types: {
type: String,
default: () => `classic`
default: () => 'classic',
},
config: {
type: Object,
default: () => {}
}
default: () => {
if (window.AsgardCMS.ckeditorCustomConfig !== '') {
return {
customConfig: window.AsgardCMS.ckeditorCustomConfig,
};
}
return undefined;
},
},
},
data () {
return { destroyed: false }
data() {
return { destroyed: false };
},
computed: {
instance () {
return CKEDITOR.instances[this.id]
}
instance() {
return CKEDITOR.instances[this.id];
},
},
watch: {
value (val) {
value(val) {
if (this.instance) {
let html = this.instance.getData();
const html = this.instance.getData();
if (val !== html) {
this.instance.setData(val);
}
}
}
},
},
mounted () {
mounted() {
if (typeof CKEDITOR === 'undefined') {
console.log('CKEDITOR is missing (http://ckeditor.com/)')
console.log('CKEDITOR is missing (http://ckeditor.com/)');
} else {
if (this.types === 'inline') {
CKEDITOR.inline(this.id, this.config)
CKEDITOR.inline(this.id, this.config);
} else {
CKEDITOR.replace(this.id, this.config)
CKEDITOR.replace(this.id, this.config);
}
this.instance.on('change', () => {
let html = this.instance.getData()
const html = this.instance.getData();
if (html !== this.value) {
this.$emit('input', html)
this.$emit('update:value', html)
this.$emit('input', html);
this.$emit('update:value', html);
}
})
});
this.instance.on('blur', () => {
this.$emit('blur', this.instance)
})
this.$emit('blur', this.instance);
});
this.instance.on('focus', () => {
this.$emit('focus', this.instance)
})
this.$emit('focus', this.instance);
});
}
},
beforeDestroy () {
beforeDestroy() {
if (!this.destroyed) {
this.instance.focusManager.blur(true)
this.instance.removeAllListeners()
this.instance.focusManager.blur(true);
this.instance.removeAllListeners();
try {
this.instance.destroy()
} catch (e) { }
this.destroyed = true
this.instance.destroy();
} catch (e) {
}
this.destroyed = true;
}
}
}
},
};
</script>
<style>
.ckeditor::after {
Expand Down
1 change: 1 addition & 0 deletions Themes/Adminlte/views/layouts/master.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
locales: {!! json_encode(LaravelLocalization::getSupportedLocales()) !!},
currentLocale: '{{ locale() }}',
editor: '{{ $activeEditor }}',
ckeditorCustomConfig: '{{ config('asgard.core.core.ckeditor-config-file-path', '') }}',
adminPrefix: '{{ config('asgard.core.core.admin-prefix') }}',
hideDefaultLocaleInURL: '{{ config('laravellocalization.hideDefaultLocaleInURL') }}',
filesystem: '{{ config('asgard.media.config.filesystem') }}'
Expand Down

0 comments on commit 9c5b5d7

Please sign in to comment.