mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 19:48:50 +03:00
c4d16d5d67
Bumped all non-ember-core dependencies that do not require significant work or that contain unresolvable inter-dependencies. Skipped: - `ember-drag-drop` - our usage needs re-working for closure actions - `ember-infinity`, `ember-in-viewport` - one depends on the other and `ember-light-table` depends on a particular version of `ember-in-viewport` in a way that breaks if they are upgraded Removed/bumped: - removed ember-cli-es6-transform - removed ember-cli-cjs-transform - removed current-device - removed ember-responsive - bumped yarn.lock sub-dependencies - bumped @ember/jquery - bumped @tryghost/mobiledoc-kit - bumped autoprefixer - bumped broccoli-funnel - bumped coveralls - bumped ember-auto-import - bumped ember-moment - bumped ember-power-select - bumped ember-simple-auth - bumped broccoli-uglify-sourcemap - bumped ember-cli-eslint and eslint-plugin-ghost with fixes for new rules - bumped ember-cli-mirage - bumped ember-cli-pretender - bumped ember-power-calendar-moment - bumped ember-power-datepicker - bumped ember-composable-helpers - bumped ember-concurrency - bumped ember-load - bumped eslint - bumped walk-sync - bumped ember-useragent - bumped fs-extra - bumped ember-resolver - bumped @html-next/vertical-collection - bumped ember-cli-babel
88 lines
2.3 KiB
JavaScript
88 lines
2.3 KiB
JavaScript
import Mixin from '@ember/object/mixin';
|
|
import {computed} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
const keyCodes = {
|
|
13: 'Enter',
|
|
9: 'Tab'
|
|
};
|
|
|
|
export default Mixin.create({
|
|
userAgent: service(),
|
|
|
|
attributeBindings: ['autofocus'],
|
|
|
|
selectOnClick: false,
|
|
shouldFocus: false,
|
|
stopEnterKeyDownPropagation: false,
|
|
|
|
autofocus: computed(function () {
|
|
if (this.get('shouldFocus')) {
|
|
return (this.userAgent.os.isIOS) ? false : 'autofocus';
|
|
}
|
|
|
|
return false;
|
|
}),
|
|
|
|
didInsertElement() {
|
|
this._super(...arguments);
|
|
this._focus();
|
|
},
|
|
|
|
click(event) {
|
|
if (this.get('selectOnClick')) {
|
|
event.currentTarget.select();
|
|
}
|
|
},
|
|
|
|
keyDown(event) {
|
|
// stop event propagation when pressing "enter"
|
|
// most useful in the case when undesired (global) keyboard shortcuts
|
|
// are getting triggered while interacting with this particular input element.
|
|
if (event.keyCode === 13 && this.get('stopEnterKeyDownPropagation')) {
|
|
event.stopPropagation();
|
|
|
|
return true;
|
|
}
|
|
|
|
// prevent default TAB behaviour if we have a keyEvent for it
|
|
if (event.keyCode === 9 && typeof this.get('keyEvents.Tab') === 'function') {
|
|
event.preventDefault();
|
|
}
|
|
|
|
this._super(...arguments);
|
|
},
|
|
|
|
keyPress(event) {
|
|
// prevent default ENTER behaviour if we have a keyEvent for it
|
|
if (event.keyCode === 13 && typeof this.get('keyEvents.Enter') === 'function') {
|
|
event.preventDefault();
|
|
}
|
|
|
|
this._super(...arguments);
|
|
},
|
|
|
|
keyUp(event) {
|
|
if (event.keyCode) {
|
|
let methodName = this._getMethodFromKeyCode(event.keyCode);
|
|
let method = this.get(`keyEvents.${methodName}`);
|
|
if (method) {
|
|
method(event.target.value);
|
|
}
|
|
}
|
|
},
|
|
|
|
_focus() {
|
|
// Until mobile safari has better support
|
|
// for focusing, we just ignore it
|
|
if (this.get('shouldFocus') && !this.userAgent.os.isIOS) {
|
|
this.element.focus();
|
|
}
|
|
},
|
|
|
|
_getMethodFromKeyCode(keyCode) {
|
|
let methodName = keyCodes[keyCode.toString()];
|
|
return methodName;
|
|
}
|
|
});
|