]> BookStack Code Mirror - bookstack/blob - resources/assets/js/vues/code-editor.js
Finished off main functionality of custom tinymce code editor
[bookstack] / resources / assets / js / vues / code-editor.js
1 const codeLib = require('../code');
2
3 const methods = {
4     show() {
5         if (!this.editor) this.editor = codeLib.popupEditor(this.$refs.editor, this.language);
6         this.$refs.overlay.style.display = 'flex';
7     },
8     hide() {
9         this.$refs.overlay.style.display = 'none';
10     },
11     updateEditorMode(language) {
12         codeLib.setMode(this.editor, language);
13     },
14     open(code, language, callback) {
15         this.show();
16         this.updateEditorMode(language);
17         this.language = language;
18         codeLib.setContent(this.editor, code);
19         this.code = code;
20         this.callback = callback;
21     },
22     save() {
23         if (!this.callback) return;
24         this.callback(this.editor.getValue(), this.language);
25         this.hide();
26     }
27 };
28
29 const data = {
30     editor: null,
31     language: '',
32     code: '',
33     callback: null
34 };
35
36 module.exports = {
37     methods,
38     data
39 };