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