mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 10:53:34 +03:00
352c4af1d7
no issue - ran [es5-getter-ember-codemod](https://github.com/rondale-sc/es5-getter-ember-codemod) - [es5 getters RFC](https://github.com/emberjs/rfcs/blob/master/text/0281-es5-getters.md) - updates the majority of `object.get('property')` with `object.property` with exceptions: - `.get('nested.property')` - it's not possible to determine if this is relying on "safe" path chaining for when `nested` doesn't exist - `.get('config.x')` and `.get('settings.x')` - both our `config` and `settings` services are proxy objects which do not support es5 getters - this PR is not exhaustive, there are still a number of places where `.get('service.foo')` and similar could be replaced but it gets us a long way there in a quick and automated fashion
75 lines
2.0 KiB
JavaScript
75 lines
2.0 KiB
JavaScript
import TextArea from '@ember/component/text-area';
|
|
import TextInputMixin from 'ghost-admin/mixins/text-input';
|
|
import {run} from '@ember/runloop';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default TextArea.extend(TextInputMixin, {
|
|
resizeDetector: service(),
|
|
|
|
classNames: 'gh-input',
|
|
|
|
autoExpand: false,
|
|
|
|
didReceiveAttrs() {
|
|
this._super(...arguments);
|
|
|
|
// trigger auto-expand any time the value changes
|
|
if (this.autoExpand) {
|
|
run.scheduleOnce('afterRender', this, this._autoExpand);
|
|
}
|
|
},
|
|
|
|
willInsertElement() {
|
|
this._super(...arguments);
|
|
|
|
// disable the draggable resize element that browsers add to textareas
|
|
if (this.autoExpand) {
|
|
this.element.style.resize = 'none';
|
|
}
|
|
},
|
|
|
|
didInsertElement() {
|
|
this._super(...arguments);
|
|
|
|
// set up resize handler on element insert so that we can autoexpand
|
|
// when the element container changes size
|
|
if (this.autoExpand) {
|
|
run.scheduleOnce('afterRender', this, this._setupAutoExpand);
|
|
}
|
|
|
|
if (this.didCreateTextarea) {
|
|
this.didCreateTextarea(this.element);
|
|
}
|
|
},
|
|
|
|
willDestroyElement() {
|
|
this._teardownAutoExpand();
|
|
this._super(...arguments);
|
|
},
|
|
|
|
_autoExpand() {
|
|
let el = this.element;
|
|
|
|
// collapse the element first so that we can shrink as well as expand
|
|
// then set the height to match the text height
|
|
if (el) {
|
|
el.style.height = 0;
|
|
el.style.height = `${el.scrollHeight}px`;
|
|
}
|
|
},
|
|
|
|
_setupAutoExpand() {
|
|
this._resizeCallback = run.bind(this, this._onResize);
|
|
this.resizeDetector.setup(this.autoExpand, this._resizeCallback);
|
|
this._autoExpand();
|
|
},
|
|
|
|
_onResize() {
|
|
this._autoExpand();
|
|
},
|
|
|
|
_teardownAutoExpand() {
|
|
this.resizeDetector.teardown(this.autoExpand, this._resizeCallback);
|
|
}
|
|
});
|