ed1ae60bec
refs https://github.com/TryGhost/Team/issues/2680 When selecting a portion of text in KoenigBasicHtmlInput (caption input for images, newsletter footer text input, new signup notice), and then pasting a link, some funky things happen: - Part of the text disappears - The wrong part of the text is linked The cause of this is that `KoenigBasicHtmlInput` deletes the selected text range when pasting, even when pasting a link. so moving that part below the code that detected a valid link, fixes the issue. This also adds an option to not close an old style modal when pressing the enter key (e.g. pressing enter when entering a link causes the modal to close).
63 lines
1.4 KiB
JavaScript
63 lines
1.4 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,
|
|
closeOnEnter: true,
|
|
|
|
// 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();
|
|
|
|
if (this.closeOnEnter) {
|
|
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);
|
|
}
|
|
});
|