2015-03-13 12:39:28 +03:00
|
|
|
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';
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
const {TextArea, run} = Ember;
|
|
|
|
|
|
|
|
export default TextArea.extend(EditorAPI, EditorShortcuts, EditorScroll, {
|
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();
|
|
|
|
|
2015-03-13 12:39:28 +03:00
|
|
|
this.sendAction('setEditor', this);
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable editing in the textarea (used while an upload is in progress)
|
|
|
|
*/
|
2015-10-28 14:36:45 +03:00
|
|
|
disable() {
|
|
|
|
let textarea = this.get('element');
|
2015-03-13 12:39:28 +03:00
|
|
|
textarea.setAttribute('readonly', 'readonly');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reenable editing in the textarea
|
|
|
|
*/
|
2015-10-28 14:36:45 +03:00
|
|
|
enable() {
|
|
|
|
let textarea = this.get('element');
|
2015-03-13 12:39:28 +03:00
|
|
|
textarea.removeAttribute('readonly');
|
|
|
|
}
|
|
|
|
});
|