2014-11-30 11:27:09 -08:00
|
|
|
/*global device*/
|
2015-10-28 11:36:45 +00:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2015-12-15 11:09:34 +00:00
|
|
|
const {TextField, computed} = Ember;
|
2015-08-19 12:55:40 +01:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
export default TextField.extend({
|
2014-08-08 09:30:51 -04:00
|
|
|
focus: true,
|
2015-08-25 20:36:40 +01:00
|
|
|
classNames: 'gh-input',
|
2014-11-30 11:27:09 -08:00
|
|
|
attributeBindings: ['autofocus'],
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
autofocus: computed(function () {
|
2015-01-30 22:18:26 +00:00
|
|
|
if (this.get('focus')) {
|
|
|
|
return (device.ios()) ? false : 'autofocus';
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2014-11-30 11:27:09 -08:00
|
|
|
}),
|
|
|
|
|
2015-12-15 11:09:34 +00:00
|
|
|
_focusField() {
|
2014-11-30 11:27:09 -08:00
|
|
|
// This fix is required until Mobile Safari has reliable
|
|
|
|
// autofocus, select() or focus() support
|
2015-01-30 22:18:26 +00:00
|
|
|
if (this.get('focus') && !device.ios()) {
|
2014-08-08 09:30:51 -04:00
|
|
|
this.$().val(this.$().val()).focus();
|
|
|
|
}
|
2015-12-15 11:09:34 +00:00
|
|
|
},
|
2014-06-23 17:50:28 +00:00
|
|
|
|
2015-12-15 11:09:34 +00:00
|
|
|
_trimValue() {
|
2015-10-28 11:36:45 +00:00
|
|
|
let text = this.$().val();
|
2014-06-23 17:50:28 +00:00
|
|
|
this.$().val(text.trim());
|
2015-12-15 11:09:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this._focusField();
|
|
|
|
},
|
|
|
|
|
|
|
|
focusOut() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this._trimValue();
|
|
|
|
}
|
2014-06-23 17:50:28 +00:00
|
|
|
});
|