0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/core/client/app/components/gh-trim-focus-input.js

42 lines
907 B
JavaScript
Raw Normal View History

/*global device*/
import Ember from 'ember';
const {TextField, computed} = Ember;
export default TextField.extend({
2014-08-08 09:30:51 -04:00
focus: true,
classNames: 'gh-input',
attributeBindings: ['autofocus'],
autofocus: computed(function () {
if (this.get('focus')) {
return (device.ios()) ? false : 'autofocus';
}
return false;
}),
_focusField() {
// This fix is required until Mobile Safari has reliable
// autofocus, select() or focus() support
if (this.get('focus') && !device.ios()) {
2014-08-08 09:30:51 -04:00
this.$().val(this.$().val()).focus();
}
},
_trimValue() {
let text = this.$().val();
this.$().val(text.trim());
},
didInsertElement() {
this._super(...arguments);
this._focusField();
},
focusOut() {
this._super(...arguments);
this._trimValue();
}
});