cf36851265
replaces #41, #60 - update ember-suave and grunt-jscs to 3.0 - standardize Ember global de-structuring rules across app & tests
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
/* global CodeMirror */
|
|
import Ember from 'ember';
|
|
|
|
const {Component, run} = Ember;
|
|
|
|
export default Component.extend({
|
|
classNameBindings: ['isFocused:focused'],
|
|
|
|
value: '', // make sure a value exists
|
|
isFocused: false,
|
|
|
|
// options for the editor
|
|
lineNumbers: true,
|
|
indentUnit: 4,
|
|
mode: 'htmlmixed',
|
|
theme: 'xq-light',
|
|
|
|
_editor: null, // reference to CodeMirror editor
|
|
|
|
didInsertElement() {
|
|
this._super(...arguments);
|
|
|
|
let options = this.getProperties('lineNumbers', 'indentUnit', 'mode', 'theme');
|
|
let editor = new CodeMirror(this.get('element'), options);
|
|
|
|
editor.getDoc().setValue(this.get('value'));
|
|
|
|
// events
|
|
editor.on('focus', run.bind(this, 'set', 'isFocused', true));
|
|
editor.on('blur', run.bind(this, 'set', 'isFocused', false));
|
|
editor.on('change', () => {
|
|
run(this, function () {
|
|
this.set('value', editor.getDoc().getValue());
|
|
});
|
|
});
|
|
|
|
this._editor = editor;
|
|
},
|
|
|
|
willDestroyElement() {
|
|
this._super(...arguments);
|
|
|
|
let editor = this._editor.getWrapperElement();
|
|
editor.parentNode.removeChild(editor);
|
|
this._editor = null;
|
|
}
|
|
});
|