2018-02-28 14:44:03 +03:00
|
|
|
import GhostTextInput from 'ghost-admin/components/gh-text-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
|
|
|
|
*/
|
2018-02-28 14:44:03 +03:00
|
|
|
const TrimFocusInputComponent = GhostTextInput.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
|
|
|
|
2017-01-23 15:03:05 +03:00
|
|
|
focusOut(event) {
|
2018-02-28 14:44:03 +03:00
|
|
|
this._trimInput(event.target.value, event);
|
|
|
|
this._super(...arguments);
|
2017-01-23 15:03:05 +03:00
|
|
|
},
|
|
|
|
|
2018-02-28 14:44:03 +03:00
|
|
|
_trimInput(value, event) {
|
2017-01-23 15:03:05 +03:00
|
|
|
if (value && typeof value.trim === 'function') {
|
|
|
|
value = value.trim();
|
2016-07-22 16:36:50 +03:00
|
|
|
}
|
2017-01-23 15:03:05 +03:00
|
|
|
|
2018-02-28 14:44:03 +03:00
|
|
|
this.element.value = value;
|
|
|
|
this._elementValueDidChange(event);
|
|
|
|
|
2019-03-06 16:53:54 +03:00
|
|
|
let inputMethod = this.input;
|
2018-02-28 14:44:03 +03:00
|
|
|
if (inputMethod) {
|
|
|
|
inputMethod(event);
|
|
|
|
}
|
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;
|