2015-02-12 21:22:32 -07:00
|
|
|
import Ember from 'ember';
|
2014-11-30 11:27:09 -08:00
|
|
|
/*global device*/
|
2014-06-23 17:50:28 +00:00
|
|
|
var TrimFocusInput = Ember.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'],
|
|
|
|
|
|
|
|
autofocus: Ember.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-07-07 18:14:23 +01:00
|
|
|
focusField: Ember.on('didInsertElement', function () {
|
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-07-07 18:14:23 +01:00
|
|
|
}),
|
2014-06-23 17:50:28 +00:00
|
|
|
|
2015-07-07 18:14:23 +01:00
|
|
|
trimValue: Ember.on('focusOut', function () {
|
2014-06-23 17:50:28 +00:00
|
|
|
var text = this.$().val();
|
|
|
|
this.$().val(text.trim());
|
2015-07-07 18:14:23 +01:00
|
|
|
})
|
2014-06-23 17:50:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default TrimFocusInput;
|