From: Alexander Ebert Date: Sun, 16 Nov 2014 11:57:44 +0000 (+0100) Subject: Attempt to fix WebKit's span madness X-Git-Tag: 2.1.0_Beta_1~246 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a6f248cd9f873893948b4ad4f56dd6e53bb1cd31;p=GitHub%2FWoltLab%2FWCF.git Attempt to fix WebKit's span madness --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index 17bce39edf..9067fe5de1 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -337,6 +337,8 @@ RedactorPlugins.wmonkeypatch = function() { * - fixes insertion in an empty editor w/o prior focus until the issue has been resolved by Imperavi */ insert: function() { + var $isWebKit = ($.browser.webkit || document.documentElement.style.hasOwnProperty('WebkitAppearance') || window.hasOwnProperty('chrome')); + var $focusEditor = (function() { var $html = this.$editor.html(); if (this.utils.isEmpty($html)) { @@ -359,12 +361,35 @@ RedactorPlugins.wmonkeypatch = function() { } }).bind(this); + // work-around for WebKit inserting lame spans + // bug report: https://code.google.com/p/chromium/issues/detail?id=335955 + // based upon the idea: http://www.neotericdesign.com/blog/2013/3/working-around-chrome-s-contenteditable-span-bug + var $fixWebKit = (function() { + this.$editor.find('span').each(function() { + var $span = $(this); + if ($span.data('verified') !== 'redactor') { + var $helper = $('helper').insertBefore($span); + + $helper.after($span.contents()); + + $helper.remove(); + $span.remove(); + } + }); + }).bind(this); + // insert.html var $mpHtml = this.insert.html; this.insert.html = (function(html, clean) { $focusEditor(); $mpHtml.call(this, html, clean); + + if ($isWebKit) { + setTimeout(function() { + $fixWebKit(); + }, 10); + } }).bind(this); // pasting in Safari is broken, try to avoid breaking everything and wait for Imperavi to address this bug @@ -673,6 +698,7 @@ RedactorPlugins.wmonkeypatch = function() { * - Explicitly set CSS values for within the editor, prevents Chrome from inserting random tags */ fixWebKit: function() { + return; if (!$.browser.webkit && !document.documentElement.style.hasOwnProperty('WebkitAppearance') && !window.hasOwnProperty('chrome')) { return; } @@ -686,7 +712,7 @@ RedactorPlugins.wmonkeypatch = function() { var $editorID = this.$editor.wcfIdentify(); var $style = document.createElement('style'); $style.type = 'text/css'; - $style.innerHTML = '#' + $editorID + ' span { font-size: ' + $default.fontSize + ', line-height: ' + $default.lineHeight + ' }'; + $style.innerHTML = '#' + $editorID + ' span { font-size: ' + $default.fontSize + '; line-height: ' + $default.lineHeight + ' }'; document.head.appendChild($style); } };