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