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-06-13 17:34:09 +03:00
|
|
|
export default Ember.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
|
|
|
|
*/
|
|
|
|
focusIn: function () {
|
|
|
|
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
|
|
|
*/
|
|
|
|
setFocus: function () {
|
|
|
|
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
|
|
|
*/
|
|
|
|
didInsertElement: function () {
|
2015-06-22 19:35:17 +03:00
|
|
|
this._super();
|
|
|
|
|
2015-06-03 05:56:42 +03:00
|
|
|
this.setFocus();
|
|
|
|
|
2015-03-13 12:39:28 +03:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
});
|