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