mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 22:02:11 +03:00
9ed5aad186
no issue - the upcoming Module Unification re-organisation in Ember will no longer support nested components - this PR pre-emptively moves our usage of nested components into a flat file structure
56 lines
1.2 KiB
JavaScript
56 lines
1.2 KiB
JavaScript
/* global key */
|
|
import Component from '@ember/component';
|
|
import {invokeAction} from 'ember-invoke-action';
|
|
import {run} from '@ember/runloop';
|
|
|
|
export default Component.extend({
|
|
tagName: 'section',
|
|
classNames: 'modal-content',
|
|
|
|
_previousKeymasterScope: null,
|
|
|
|
_setupShortcuts() {
|
|
run(function () {
|
|
document.activeElement.blur();
|
|
});
|
|
this._previousKeymasterScope = key.getScope();
|
|
|
|
key('enter', 'modal', () => {
|
|
this.send('confirm');
|
|
});
|
|
|
|
key('escape', 'modal', () => {
|
|
this.send('closeModal');
|
|
});
|
|
|
|
key.setScope('modal');
|
|
},
|
|
|
|
_removeShortcuts() {
|
|
key.unbind('enter', 'modal');
|
|
key.unbind('escape', 'modal');
|
|
|
|
key.setScope(this._previousKeymasterScope);
|
|
},
|
|
|
|
didInsertElement() {
|
|
this._super(...arguments);
|
|
this._setupShortcuts();
|
|
},
|
|
|
|
willDestroyElement() {
|
|
this._super(...arguments);
|
|
this._removeShortcuts();
|
|
},
|
|
|
|
actions: {
|
|
confirm() {
|
|
throw new Error('You must override the "confirm" action in your modal component');
|
|
},
|
|
|
|
closeModal() {
|
|
invokeAction(this, 'closeModal');
|
|
}
|
|
}
|
|
});
|