mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 11:34:24 +03:00
69662bd5d2
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
27 lines
645 B
JavaScript
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;
|