mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-09 10:22:51 +03:00
Finished off main functionality of custom tinymce code editor
This commit is contained in:
39
resources/assets/js/vues/code-editor.js
Normal file
39
resources/assets/js/vues/code-editor.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const codeLib = require('../code');
|
||||
|
||||
const methods = {
|
||||
show() {
|
||||
if (!this.editor) this.editor = codeLib.popupEditor(this.$refs.editor, this.language);
|
||||
this.$refs.overlay.style.display = 'flex';
|
||||
},
|
||||
hide() {
|
||||
this.$refs.overlay.style.display = 'none';
|
||||
},
|
||||
updateEditorMode(language) {
|
||||
codeLib.setMode(this.editor, language);
|
||||
},
|
||||
open(code, language, callback) {
|
||||
this.show();
|
||||
this.updateEditorMode(language);
|
||||
this.language = language;
|
||||
codeLib.setContent(this.editor, code);
|
||||
this.code = code;
|
||||
this.callback = callback;
|
||||
},
|
||||
save() {
|
||||
if (!this.callback) return;
|
||||
this.callback(this.editor.getValue(), this.language);
|
||||
this.hide();
|
||||
}
|
||||
};
|
||||
|
||||
const data = {
|
||||
editor: null,
|
||||
language: '',
|
||||
code: '',
|
||||
callback: null
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
methods,
|
||||
data
|
||||
};
|
@@ -7,12 +7,15 @@ function exists(id) {
|
||||
let vueMapping = {
|
||||
'search-system': require('./search'),
|
||||
'entity-dashboard': require('./entity-search'),
|
||||
'code-editor': require('./code-editor')
|
||||
};
|
||||
|
||||
window.vues = {};
|
||||
|
||||
Object.keys(vueMapping).forEach(id => {
|
||||
if (exists(id)) {
|
||||
let config = vueMapping[id];
|
||||
config.el = '#' + id;
|
||||
new Vue(config);
|
||||
window.vues[id] = new Vue(config);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user