1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/components/gh-ed-editor.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

import TextArea from 'ember-components/text-area';
import run from 'ember-runloop';
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';
import {InvokeActionMixin} from 'ember-invoke-action';
export default TextArea.extend(EditorAPI, EditorShortcuts, EditorScroll, InvokeActionMixin, {
focus: false,
/**
* Tell the controller about focusIn events, will trigger an autosave on a new document
*/
focusIn() {
this.sendAction('onFocusIn');
},
/**
* Sets the focus of the textarea if needed
*/
setFocus() {
if (this.get('focus')) {
this.$().val(this.$().val()).focus();
}
},
/**
* Sets up properties at render time
*/
didInsertElement() {
this._super(...arguments);
this.setFocus();
this.invokeAction('setEditor', this);
run.scheduleOnce('afterRender', this, this.afterRenderEvent);
},
afterRenderEvent() {
if (this.get('focus') && this.get('focusCursorAtEnd')) {
this.setSelection('end');
}
},
actions: {
toggleCopyHTMLModal(generatedHTML) {
this.invokeAction('toggleCopyHTMLModal', generatedHTML);
}
}
});