2018-11-09 16:17:35 -05:00
|
|
|
import codeLib from "../services/code";
|
2017-07-01 08:23:46 -04:00
|
|
|
|
|
|
|
const methods = {
|
|
|
|
show() {
|
|
|
|
if (!this.editor) this.editor = codeLib.popupEditor(this.$refs.editor, this.language);
|
2019-12-07 11:54:34 -05:00
|
|
|
this.$refs.overlay.components.overlay.show(() => {
|
|
|
|
codeLib.updateLayout(this.editor);
|
2020-04-05 16:55:31 -04:00
|
|
|
this.editor.focus();
|
2019-12-07 11:54:34 -05:00
|
|
|
});
|
2017-07-01 08:23:46 -04:00
|
|
|
},
|
|
|
|
hide() {
|
2019-08-24 13:26:28 -04:00
|
|
|
this.$refs.overlay.components.overlay.hide();
|
2017-07-01 08:23:46 -04:00
|
|
|
},
|
|
|
|
updateEditorMode(language) {
|
2019-12-07 11:23:44 -05:00
|
|
|
codeLib.setMode(this.editor, language, this.editor.getValue());
|
2017-07-01 08:23:46 -04:00
|
|
|
},
|
2017-07-01 10:50:28 -04:00
|
|
|
updateLanguage(lang) {
|
|
|
|
this.language = lang;
|
|
|
|
this.updateEditorMode(lang);
|
|
|
|
},
|
2017-07-01 08:23:46 -04: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
|
|
|
|
};
|
|
|
|
|
2018-11-09 16:17:35 -05:00
|
|
|
export default {
|
2017-07-01 08:23:46 -04:00
|
|
|
methods,
|
|
|
|
data
|
|
|
|
};
|