From: Alexander Ebert Date: Sat, 10 Jan 2015 12:56:40 +0000 (+0100) Subject: Try to guess the actual size when encountering a element X-Git-Tag: 2.1.0_Beta_4~108^2~3 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4f1c577ac747663e863d787612adae32e184575f;p=GitHub%2FWoltLab%2FWCF.git Try to guess the actual size when encountering a element --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index b08d6af705..70bfbcd472 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -1232,9 +1232,42 @@ RedactorPlugins.wbbcode = function() { 5: 12, 6: 10 }; - console.debug(html); + // replace

...

tags - html = html.replace(/]+>/g, function(match, level) { + html = html.replace(/]*)>/g, function(match, level, elementAttributes) { + if (elementAttributes && elementAttributes.match(/style="([^"]+?)"/)) { + if (/font-size: ?(\d+|\d+\.\d+)(px|pt|em|rem|%)/.test(RegExp.$1)) { + var $div = $('
').appendTo(document.body); + var $width = parseInt($div[0].clientWidth); + $div.remove(); + + // look for the closest matching size + var $bestMatch = -1; + var $isExactMatch = false; + $.each($levels, function(k, v) { + if ($bestMatch === -1) { + $bestMatch = k; + } + else { + if (Math.abs($width - v) < Math.abs($width - $levels[$bestMatch])) { + $bestMatch = k; + } + } + + if ($width == v) { + $isExactMatch = true; + } + }); + + if (!$isExactMatch) { + // if dealing with non-exact matches, lower size by one level + $bestMatch = ($bestMatch < 6) ? parseInt($bestMatch) + 1 : $bestMatch; + } + + level = $bestMatch; + } + } + return '[size=' + $levels[level] + ']'; }); html = html.replace(/<\/h[1-6]>/g, '[/size]');