0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Unlink previously existing links when turning a selection into a link

This commit is contained in:
Matt Westcott 2016-09-29 17:15:57 +01:00
parent 09fccb2624
commit 2992782c99

View File

@ -77,9 +77,18 @@
linkHasExistingContent = true;
} else if (!lastSelection.collapsed) {
// Turning a selection into a link
a = document.createElement('a');
lastSelection.surroundContents(a);
// TODO: unlink all existing links in the selection
// unlink all previously existing links in the selection,
// now nested within 'a'
$('a[href]', a).each(function() {
var parent = this.parentNode;
while (this.firstChild) parent.insertBefore(this.firstChild, this);
parent.removeChild(this);
});
linkHasExistingContent = true;
} else {
// Inserting a new link at the cursor position