Skip to content

Commit d0c3ebe

Browse files
committed
Firefox createLink bug workaround
This fix workarounds FireFox createLink bug. Ref: https://bugzilla.mozilla.org/show_bug.cgi?id=451142
1 parent 462fff0 commit d0c3ebe

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/js/core.js

+1
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,7 @@
11491149
this.importSelection(exportedSelection);
11501150
} else {
11511151
this.options.ownerDocument.execCommand('createLink', false, targetUrl);
1152+
MediumEditor.util.ensureHref(MediumEditor.selection.getSelectionStart(this.options.ownerDocument), targetUrl);
11521153
}
11531154

11541155
if (this.options.targetBlank || opts.target === '_blank') {

src/js/util.js

+19
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,25 @@
572572
return doc.execCommand('formatBlock', false, tagName);
573573
},
574574

575+
/*
576+
* this function is called to ensure href is set correctly as FF does "encodeURI" on href value when execCommand createLink.
577+
* see also https://bugzilla.mozilla.org/show_bug.cgi?id=451142
578+
*/
579+
ensureHref: function (el, anchorUrl) {
580+
var i, url = anchorUrl;
581+
if (el.nodeName.toLowerCase() === 'a') {
582+
el.attributes.href.value = url;
583+
} else {
584+
el = el.getElementsByTagName('a');
585+
586+
for (i = 0; i < el.length; i += 1) {
587+
if (encodeURI(url) === el[i].attributes.href.value) {
588+
el[i].attributes.href.value = url;
589+
}
590+
}
591+
}
592+
},
593+
575594
/**
576595
* Set target to blank on the given el element
577596
*

0 commit comments

Comments
 (0)