mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 11:22:19 +03:00
ff09a20ac8
refs https://github.com/TryGhost/Team/issues/482 - replace titles and descriptions with text fields when clicked - save on blur - blur+save on <kbd>Enter</kbd> - blur+restore on <kbd>Escape</kbd> - create newline with <kbd>Shift+Enter</kbd> in description fields - if there's no available image or fallback show a "+ Add image" header in the previews when hovering - if there is an image show an upload/change image button when hovering - show a delete image button when hovering once a custom image has been uploaded Co-authored-by: Sanne de Vries <sannedv@protonmail.com>
60 lines
1.3 KiB
JavaScript
60 lines
1.3 KiB
JavaScript
/* global key */
|
|
import Component from '@ember/component';
|
|
import {run} from '@ember/runloop';
|
|
|
|
export default Component.extend({
|
|
tagName: 'section',
|
|
classNames: 'modal-content',
|
|
|
|
_previousKeymasterScope: null,
|
|
|
|
// Allowed Actions
|
|
closeModal: () => {},
|
|
|
|
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() {
|
|
this.closeModal();
|
|
}
|
|
},
|
|
|
|
_setupShortcuts() {
|
|
run(function () {
|
|
document.activeElement.blur();
|
|
});
|
|
|
|
this._previousKeymasterScope = key.getScope();
|
|
|
|
key('enter', 'modal', () => {
|
|
this.send('confirm');
|
|
});
|
|
|
|
key('escape', 'modal', (event) => {
|
|
if (!event.target.dataset.preventEscapeCloseModal) {
|
|
this.send('closeModal');
|
|
}
|
|
});
|
|
|
|
key.setScope('modal');
|
|
},
|
|
|
|
_removeShortcuts() {
|
|
key.unbind('enter', 'modal');
|
|
key.unbind('escape', 'modal');
|
|
key.setScope(this._previousKeymasterScope);
|
|
}
|
|
});
|