Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private insertLink = (): void => {
const { editor, selectionRange } = this.props;
if (!this.linkField || !editor || editor.isDisposed()) {
return;
}
editor && !editor.isDisposed() && editor.select(selectionRange);
this.linkInserted = true; // don't need to restore the selection after dismiss if we're changing selection into a link
createLink(editor, this.linkField.value);
this.dismissDialog();
};
private onOk = () => {
this.props.onDismiss();
createLink(this.props.editor, this.txtUrl.value, null, this.txtDisplayText.value);
};
}
document.getElementById('insertLink').addEventListener('click', function() {
let editor = getCurrentEditor();
let range = editor.getSelectionRange();
let existingLink = queryNodesWithSelection(editor, 'a[href]')[0] as HTMLAnchorElement;
let url = window.prompt('Url', existingLink ? existingLink.href : 'http://');
let text = range.collapsed && !existingLink ? window.prompt('Text of link', url) : null;
createLink(editor, url, url, text);
});
export default function createLinkWithPrompt(editor: Editor, strings: Strings): void {
if (!editor || editor.isDisposed()) {
return;
}
let message = "Enter address";
if (strings) {
message = strings[CreateLinkWithPromptStringKey] || message;
}
const link = prompt(message);
if (link) {
createLink(editor, link);
}
}
).then(link => {
if (link) {
editor.focus();
createLink(editor, link, link);
}
});
},