UNPKG

jodit

Version:

Jodit is an awesome and useful wysiwyg editor with filebrowser

31 lines (30 loc) 1.11 kB
/*! * Jodit Editor (https://xdsoft.net/jodit/) * Released under MIT see LICENSE.txt in the project root for license information. * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net */ import { Dom } from "../../../core/dom/dom.js"; import { attr } from "../../../core/helpers/utils/attr.js"; /** @private */ export function applyLink(j, image, imageLink, imageLinkOpenInNewTab) { // Link let link = Dom.closest(image, 'a', j.editor); if (imageLink) { if (!link) { link = Dom.wrap(image, 'a', j.createInside); } attr(link, 'href', imageLink); attr(link, 'target', imageLinkOpenInNewTab ? '_blank' : null); if (!imageLinkOpenInNewTab) { const relParts = (attr(link, 'rel') || '') .split(/\s+/) .filter(p => p && p !== 'noopener' && p !== 'noreferrer'); attr(link, 'rel', relParts.length ? relParts.join(' ') : null); } } else { if (link && link.parentNode) { link.parentNode.replaceChild(image, link); } } }