Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _getAnchorForClickOpenHyperlink(ev: React.MouseEvent, element: HTMLElement): HTMLAnchorElement {
const { clickOpenHyperlinkViewMode, readonly } = this.props;
const isPrimaryButton = ev.button === 0;
if (!isPrimaryButton || !clickOpenHyperlinkViewMode || readonly || this.mode !== LeanRoosterModes.View) {
return null;
}
// Hyperlink plugin will handle CTRL+Click when editor is created and FireFox will handle for contenteditable
const ctrlOpen = Browser.isMac ? ev.metaKey : ev.ctrlKey;
if ((this._editor && ctrlOpen) || (Browser.isFirefox && ctrlOpen)) {
return null;
}
const anchor = findClosestElementAncestor(element, this._contentDiv, "a[href]");
if (anchor) {
return anchor as HTMLAnchorElement;
}
return null;
}
Browser
{this.renderSpan(Browser.isChrome, 'Chrome')}
{this.renderSpan(Browser.isEdge, 'Edge')}
{this.renderSpan(Browser.isFirefox, 'Firefox')}
{this.renderSpan(Browser.isIE11OrGreater, 'IE10/11')}
{this.renderSpan(Browser.isIE, 'IE')}
{this.renderSpan(Browser.isIEOrEdge, 'IE/Edge')}
{this.renderSpan(Browser.isSafari, 'Safari')}
{this.renderSpan(Browser.isWebKit, 'Webkit')}
OS
{this.renderSpan(Browser.isMac, 'MacOS')}
{this.renderSpan(Browser.isWin, 'Windows')}
User Agent
{window.navigator.userAgent}
App Version
{window.navigator.appVersion}
) : (
<div>Please focus into editor</div>
);
const anchor = this.editor.getElementAtCursor(
'A',
event.rawEvent.srcElement
) as HTMLAnchorElement;
if (anchor) {
if (this.onLinkClick) {
this.onLinkClick(anchor, event.rawEvent);
return;
}
let href: string;
if (
!Browser.isFirefox &&
(href = this.tryGetHref(anchor)) &&
(Browser.isMac ? event.rawEvent.metaKey : event.rawEvent.ctrlKey)
) {
try {
const target = this.target || '_blank';
const window = this.editor.getDocument().defaultView;
window.open(href, target);
} catch {}
}
}
}
}
return key && commands.filter(cmd => (Browser.isMac ? cmd.macKey : cmd.winKey) == key)[0];
});
export function getCommandFromEvent(event: PluginEvent): RoosterShortcutCommands {
if (event.eventType !== PluginEventType.KeyDown) {
return RoosterShortcutCommands.None;
}
const commands = Browser.isMac ? macCommands : winCommands;
const keyboardEvent = (event as PluginDomEvent).rawEvent as KeyboardEvent;
for (const cmd of commands) {
if (
!keyboardEvent.altKey &&
cmd.ctrlKey === keyboardEvent.ctrlKey &&
cmd.metaKey === keyboardEvent.metaKey &&
cmd.shiftKey === keyboardEvent.shiftKey &&
cmd.which === keyboardEvent.which
) {
return cmd.command;
}
}
return RoosterShortcutCommands.None;
}