From b89487b6c34ddebb62958cfa9f6d809eb2bcc2fe Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 20 Oct 2015 20:21:58 +0200 Subject: [PATCH] Dirty work-around to have Edge handled as IE --- .../3rdParty/redactor/plugins/wmonkeypatch.js | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index 870cfe9b67..72494756e4 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -925,6 +925,7 @@ RedactorPlugins.wmonkeypatch = function() { * Partially overwrites the 'link' module. * * - force consistent caret position upon link insert + * - inserting a link failed with Microsoft Edge, but forcing utils.browser('msie') to return true is potentially dangerous */ link: function() { // link.insert @@ -946,7 +947,39 @@ RedactorPlugins.wmonkeypatch = function() { // link.set var $mpSet = this.link.set; this.link.set = (function(text, link, target) { - $mpSet.call(this, text, link, target); + // work-around for Microsoft Edge + if (/\sEdge\//.test(window.navigator.userAgent)) { + text = $.trim(text.replace(/<|>/g, '')); + + this.selection.restore(); + var blocks = this.selection.getBlocks(); + + if (text === '' && link === '') return; + if (text === '' && link !== '') text = link; + + if (!this.link.$node) { + var $a = $('').text(text); + if (target !== '') $a.attr('target', target); + + $a = $(this.insert.node($a)); + + if (this.selection.getText().match(/\s$/)) + { + $a.after(" "); + } + + this.selection.selectElement($a); + + this.code.sync(); + this.core.setCallback('insertedLink', $a); + } + else { + $mpSet.call(this, text, link, target); + } + } + else { + $mpSet.call(this, text, link, target); + } var selection = window.getSelection(); if (selection.rangeCount) { -- 2.20.1