RTE link
This commit is contained in:
@@ -944,6 +944,12 @@
|
||||
hideLinkPanel();
|
||||
return;
|
||||
}
|
||||
restoreSelection();
|
||||
const range = savedRange ? savedRange.cloneRange() : getSelectionRange();
|
||||
if (!range || range.collapsed) {
|
||||
hideLinkPanel();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const linkEl = findLinkAtSelection();
|
||||
if (linkEl && linkEl.setAttribute) {
|
||||
@@ -952,23 +958,19 @@
|
||||
return;
|
||||
}
|
||||
} catch {}
|
||||
const range = savedRange ? savedRange.cloneRange() : getSelectionRange();
|
||||
if (!range || range.collapsed) {
|
||||
hideLinkPanel();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const docRef = content.ownerDocument || document;
|
||||
const anchor = docRef.createElement('a');
|
||||
anchor.setAttribute('href', url);
|
||||
anchor.setAttribute('target', '_blank');
|
||||
anchor.setAttribute('rel', 'noopener');
|
||||
const fragment = range.extractContents();
|
||||
anchor.appendChild(fragment);
|
||||
range.insertNode(anchor);
|
||||
} catch {
|
||||
restoreSelection();
|
||||
exec('createLink', url);
|
||||
exec('createLink', url);
|
||||
const linkAfter = findLinkAtSelection();
|
||||
if (!linkAfter) {
|
||||
try {
|
||||
const docRef = content.ownerDocument || document;
|
||||
const anchor = docRef.createElement('a');
|
||||
anchor.setAttribute('href', url);
|
||||
anchor.setAttribute('target', '_blank');
|
||||
anchor.setAttribute('rel', 'noopener');
|
||||
const fragment = range.extractContents();
|
||||
anchor.appendChild(fragment);
|
||||
range.insertNode(anchor);
|
||||
} catch {}
|
||||
}
|
||||
hideLinkPanel();
|
||||
});
|
||||
@@ -986,6 +988,13 @@
|
||||
} catch {}
|
||||
restoreSelection();
|
||||
exec('unlink');
|
||||
const stillLinked = findLinkAtSelection();
|
||||
if (stillLinked && stillLinked.parentNode) {
|
||||
while (stillLinked.firstChild) {
|
||||
stillLinked.parentNode.insertBefore(stillLinked.firstChild, stillLinked);
|
||||
}
|
||||
stillLinked.parentNode.removeChild(stillLinked);
|
||||
}
|
||||
hideLinkPanel();
|
||||
});
|
||||
linkCancel.addEventListener('click', hideLinkPanel);
|
||||
|
||||
Reference in New Issue
Block a user