mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
feac9682d0
- Refactor to handle deprecations including removal of all Views, ArrayControllers, and ItemControllers.
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
import Ember from 'ember';
|
|
import EditorAPI from 'ghost/mixins/ed-editor-api';
|
|
import EditorShortcuts from 'ghost/mixins/ed-editor-shortcuts';
|
|
import EditorScroll from 'ghost/mixins/ed-editor-scroll';
|
|
|
|
export default Ember.TextArea.extend(EditorAPI, EditorShortcuts, EditorScroll, {
|
|
focus: false,
|
|
|
|
/**
|
|
* Tell the controller about focusIn events, will trigger an autosave on a new document
|
|
*/
|
|
focusIn: function () {
|
|
this.sendAction('onFocusIn');
|
|
},
|
|
|
|
/**
|
|
* Sets the focus of the textarea if needed
|
|
*/
|
|
setFocus: function () {
|
|
if (this.get('focus')) {
|
|
this.$().val(this.$().val()).focus();
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Sets up properties at render time
|
|
*/
|
|
didInsertElement: function () {
|
|
this._super();
|
|
|
|
this.setFocus();
|
|
|
|
this.sendAction('setEditor', this);
|
|
|
|
Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
|
|
},
|
|
|
|
afterRenderEvent: function () {
|
|
if (this.get('focus') && this.get('focusCursorAtEnd')) {
|
|
this.setSelection('end');
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Disable editing in the textarea (used while an upload is in progress)
|
|
*/
|
|
disable: function () {
|
|
var textarea = this.get('element');
|
|
textarea.setAttribute('readonly', 'readonly');
|
|
},
|
|
|
|
/**
|
|
* Reenable editing in the textarea
|
|
*/
|
|
enable: function () {
|
|
var textarea = this.get('element');
|
|
textarea.removeAttribute('readonly');
|
|
}
|
|
});
|