Ghost/core/client/components/gh-trim-focus-input.js
Felix Rieseberg 69662bd5d2 gh-trim-focus-input autofocus fix for iOS Safari
Closes #4446
- Mobile Safari doesn’t support the HTML5 `autofocus` attribute, but
also doesn’t play nice with jQuery’s `focus()` and `select()` methods.
- Mobile Safari wouldn’t automatically select the input field anyway,
so this PR simply removes the “jumping input fields” error without
changing any actual behaviour.
- Disallowing the programmatic selection of input fields (with select,
focus or similar methods) is apparently considered a feature rather
than a bug (ref http://bugs.jquery.com/ticket/12789)
- `autofocus` attribute is now only set on non-iOS devices
2014-12-02 09:14:32 -08:00

27 lines
645 B
JavaScript

/*global device*/
var TrimFocusInput = Ember.TextField.extend({
focus: true,
attributeBindings: ['autofocus'],
autofocus: Ember.computed(function () {
return (device.ios()) ? false : 'autofocus';
}),
setFocus: function () {
// This fix is required until Mobile Safari has reliable
// autofocus, select() or focus() support
if (this.focus && !device.ios()) {
this.$().val(this.$().val()).focus();
}
}.on('didInsertElement'),
focusOut: function () {
var text = this.$().val();
this.$().val(text.trim());
}
});
export default TrimFocusInput;