2014-11-30 22:27:09 +03:00
|
|
|
/*global device*/
|
2016-06-30 21:14:25 +03:00
|
|
|
import computed from 'ember-computed';
|
2016-06-20 17:20:25 +03:00
|
|
|
import GhostInput from 'ghost-admin/components/gh-input';
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2016-06-18 14:44:23 +03:00
|
|
|
/**
|
|
|
|
* This doesn't override the OneWayInput component because
|
|
|
|
* we need finer control. It borrows
|
|
|
|
* parts from both the OneWayInput component and Ember's default
|
|
|
|
* input component
|
|
|
|
*/
|
2016-06-20 17:20:25 +03:00
|
|
|
const TrimFocusInputComponent = GhostInput.extend({
|
2016-06-18 14:44:23 +03:00
|
|
|
|
2016-06-20 17:20:25 +03:00
|
|
|
shouldFocus: true,
|
2016-06-18 14:44:23 +03:00
|
|
|
|
2016-06-20 17:20:25 +03:00
|
|
|
attributeBindings: ['autofocus'],
|
2014-11-30 22:27:09 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
autofocus: computed(function () {
|
2016-06-20 17:20:25 +03:00
|
|
|
if (this.get('shouldFocus')) {
|
2015-01-31 01:18:26 +03:00
|
|
|
return (device.ios()) ? false : 'autofocus';
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2014-11-30 22:27:09 +03:00
|
|
|
}),
|
|
|
|
|
2016-06-20 17:20:25 +03:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
2015-12-15 14:09:34 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
2016-06-20 17:20:25 +03:00
|
|
|
this._focus();
|
|
|
|
},
|
|
|
|
|
|
|
|
sanitizeInput(input) {
|
2016-07-22 16:36:50 +03:00
|
|
|
if (input && typeof input.trim === 'function') {
|
|
|
|
return input.trim();
|
|
|
|
} else {
|
|
|
|
return input;
|
|
|
|
}
|
2016-06-18 14:44:23 +03:00
|
|
|
},
|
|
|
|
|
2016-06-20 17:20:25 +03:00
|
|
|
_focus() {
|
2016-06-18 14:44:23 +03:00
|
|
|
// Until mobile safari has better support
|
|
|
|
// for focusing, we just ignore it
|
2016-06-20 17:20:25 +03:00
|
|
|
if (this.get('shouldFocus') && !device.ios()) {
|
|
|
|
this.element.focus();
|
2016-06-18 14:44:23 +03:00
|
|
|
}
|
2015-12-15 14:09:34 +03:00
|
|
|
}
|
2014-06-23 21:50:28 +04:00
|
|
|
});
|
2016-06-18 14:44:23 +03:00
|
|
|
|
|
|
|
export default TrimFocusInputComponent;
|