2016-06-30 20:14:25 +02:00
|
|
|
import TextArea from 'ember-components/text-area';
|
|
|
|
import run from 'ember-runloop';
|
2016-05-24 14:06:59 +02:00
|
|
|
import EditorAPI from 'ghost-admin/mixins/ed-editor-api';
|
|
|
|
import EditorShortcuts from 'ghost-admin/mixins/ed-editor-shortcuts';
|
|
|
|
import EditorScroll from 'ghost-admin/mixins/ed-editor-scroll';
|
2016-06-18 13:44:23 +02:00
|
|
|
import {InvokeActionMixin} from 'ember-invoke-action';
|
2015-03-13 10:39:28 +01:00
|
|
|
|
2016-06-18 13:44:23 +02:00
|
|
|
export default TextArea.extend(EditorAPI, EditorShortcuts, EditorScroll, InvokeActionMixin, {
|
2015-06-03 20:01:32 +02:00
|
|
|
focus: false,
|
2015-03-13 10:39:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tell the controller about focusIn events, will trigger an autosave on a new document
|
|
|
|
*/
|
2015-10-28 12:36:45 +01:00
|
|
|
focusIn() {
|
2015-03-13 10:39:28 +01:00
|
|
|
this.sendAction('onFocusIn');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-06-03 04:56:42 +02:00
|
|
|
* Sets the focus of the textarea if needed
|
2015-03-13 10:39:28 +01:00
|
|
|
*/
|
2015-10-28 12:36:45 +01:00
|
|
|
setFocus() {
|
2015-03-13 10:39:28 +01:00
|
|
|
if (this.get('focus')) {
|
|
|
|
this.$().val(this.$().val()).focus();
|
|
|
|
}
|
2015-06-03 04:56:42 +02:00
|
|
|
},
|
2015-03-13 10:39:28 +01:00
|
|
|
|
|
|
|
/**
|
2015-06-03 04:56:42 +02:00
|
|
|
* Sets up properties at render time
|
2015-03-13 10:39:28 +01:00
|
|
|
*/
|
2015-10-28 12:36:45 +01:00
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
2015-06-22 18:35:17 +02:00
|
|
|
|
2015-06-03 04:56:42 +02:00
|
|
|
this.setFocus();
|
|
|
|
|
2016-06-18 13:44:23 +02:00
|
|
|
this.invokeAction('setEditor', this);
|
2015-03-13 10:39:28 +01:00
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
run.scheduleOnce('afterRender', this, this.afterRenderEvent);
|
2015-03-13 10:39:28 +01:00
|
|
|
},
|
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
afterRenderEvent() {
|
2015-03-13 10:39:28 +01:00
|
|
|
if (this.get('focus') && this.get('focusCursorAtEnd')) {
|
|
|
|
this.setSelection('end');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-18 11:50:48 +01:00
|
|
|
actions: {
|
|
|
|
toggleCopyHTMLModal(generatedHTML) {
|
2016-06-18 13:44:23 +02:00
|
|
|
this.invokeAction('toggleCopyHTMLModal', generatedHTML);
|
2015-11-18 11:50:48 +01:00
|
|
|
}
|
2015-03-13 10:39:28 +01:00
|
|
|
}
|
|
|
|
});
|