2018-01-21 00:32:13 +08:00
|
|
|
const codeLib = require('../libs/code');
|
2017-07-01 20:23:46 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
},
|
2017-07-01 22:50:28 +08:00
|
|
|
updateLanguage(lang) {
|
|
|
|
this.language = lang;
|
|
|
|
this.updateEditorMode(lang);
|
|
|
|
},
|
2017-07-01 20:23:46 +08:00
|
|
|
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
|
|
|
|
};
|