Ghost/ghost/admin/app/components/gh-cm-editor.js
Austin Burdine cf36851265 deps: grunt-jscs,ember-suave@3.0.0
replaces #41, #60
- update ember-suave and grunt-jscs to 3.0
- standardize Ember global de-structuring rules across app & tests
2016-06-11 13:39:31 -06:00

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;
}
});