Moved image handling further down to avoid required whitespaces chopped of
authorAlexander Ebert <ebert@woltlab.com>
Thu, 18 Dec 2014 12:57:12 +0000 (13:57 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 18 Dec 2014 12:57:12 +0000 (13:57 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js

index e5e4ddc9e2df0876b8366e744dea261d544b877b..c2e85cb90aa843a5424b99db42fd9a6c024fb7a3 100644 (file)
@@ -355,66 +355,6 @@ RedactorPlugins.wbbcode = function() {
                        html = html.replace(/<(?:s(trike)?|del)>/gi, '[s]');
                        html = html.replace(/<\/(?:s(trike)?|del)>/gi, '[/s]');
                        
-                       // smileys
-                       html = html.replace(/<img [^>]*?alt="([^"]+?)" class="smiley".*?> ?/gi, '$1 '); // firefox
-                       html = html.replace(/<img [^>]*?class="smiley" alt="([^"]+?)".*?> ?/gi, '$1 '); // chrome, ie
-                       
-                       // attachments
-                       html = html.replace(/<img [^>]*?class="redactorEmbeddedAttachment[^"]*" data-attachment-id="(\d+)"( style="([^"]+)")?>/gi, function(match, attachmentID, styleTag, style) {
-                               var $float = 'none';
-                               var $width = null;
-                               
-                               if (style) {
-                                       style = style.split(';');
-                                       
-                                       for (var $i = 0; $i < style.length; $i++) {
-                                               var $style = $.trim(style[$i]);
-                                               if ($style.match(/^float: (left|right)$/)) {
-                                                       $float = RegExp.$1;
-                                               }
-                                               else if ($style.match(/^width: (\d+)px$/)) {
-                                                       $width = RegExp.$1;
-                                               }
-                                       }
-                                       
-                                       if ($width !== null) {
-                                               return '[attach=' + attachmentID + ',' + $float + ',' + $width + '][/attach]';
-                                       }
-                                       else if ($float !== 'none') {
-                                               return '[attach=' + attachmentID + ',' + $float + '][/attach]';
-                                       }
-                               }
-                               
-                               return '[attach=' + attachmentID + '][/attach]';
-                       });
-                       
-                       // [img]
-                       html = html.replace(/<img [^>]*?src=(["'])([^"']+?)\1 style="([^"]+)".*?>/gi, function(match, quotationMarks, source, style) {
-                               var $float = 'none';
-                               var $width = 0;
-                               
-                               var $styles = style.split(';');
-                               for (var $i = 0; $i < $styles.length; $i++) {
-                                       var $style = $styles[$i];
-                                       if ($style.match(/float: (left|right|none)/)) {
-                                               $float = RegExp.$1;
-                                       }
-                                       else if ($style.match(/width: (\d+)px/)) {
-                                               $width = parseInt(RegExp.$1);
-                                       }
-                               }
-                               
-                               if ($width) {
-                                       return "[img='" + source + "'," + $float + "," + $width + "][/img]";
-                               }
-                               else if ($float !== 'none') {
-                                       return "[img='" + source + "'," + $float + "][/img]";
-                               }
-                               
-                               return "[img]" + source + "[/img]";
-                       });
-                       html = html.replace(/<img [^>]*?src=(["'])([^"']+?)\1.*?>/gi, '[img]$2[/img]');
-                       
                        // handle [color], [size], [font] and [tt]
                        var $components = html.split(/(<\/?span[^>]*>)/);
                        
@@ -532,6 +472,66 @@ RedactorPlugins.wbbcode = function() {
                                return '[align=' + alignment + ']' + $.trim(content) + '[/align]';
                        });
                        
+                       // smileys
+                       html = html.replace(/<img [^>]*?alt="([^"]+?)" class="smiley".*?> ?/gi, '$1 '); // firefox
+                       html = html.replace(/<img [^>]*?class="smiley" alt="([^"]+?)".*?> ?/gi, '$1 '); // chrome, ie
+                       
+                       // attachments
+                       html = html.replace(/<img [^>]*?class="redactorEmbeddedAttachment[^"]*" data-attachment-id="(\d+)"( style="([^"]+)")?>/gi, function(match, attachmentID, styleTag, style) {
+                               var $float = 'none';
+                               var $width = null;
+                               
+                               if (style) {
+                                       style = style.split(';');
+                                       
+                                       for (var $i = 0; $i < style.length; $i++) {
+                                               var $style = $.trim(style[$i]);
+                                               if ($style.match(/^float: (left|right)$/)) {
+                                                       $float = RegExp.$1;
+                                               }
+                                               else if ($style.match(/^width: (\d+)px$/)) {
+                                                       $width = RegExp.$1;
+                                               }
+                                       }
+                                       
+                                       if ($width !== null) {
+                                               return '[attach=' + attachmentID + ',' + $float + ',' + $width + '][/attach]';
+                                       }
+                                       else if ($float !== 'none') {
+                                               return '[attach=' + attachmentID + ',' + $float + '][/attach]';
+                                       }
+                               }
+                               
+                               return '[attach=' + attachmentID + '][/attach]';
+                       });
+                       
+                       // [img]
+                       html = html.replace(/<img [^>]*?src=(["'])([^"']+?)\1 style="([^"]+)".*?>/gi, function(match, quotationMarks, source, style) {
+                               var $float = 'none';
+                               var $width = 0;
+                               
+                               var $styles = style.split(';');
+                               for (var $i = 0; $i < $styles.length; $i++) {
+                                       var $style = $styles[$i];
+                                       if ($style.match(/float: (left|right|none)/)) {
+                                               $float = RegExp.$1;
+                                       }
+                                       else if ($style.match(/width: (\d+)px/)) {
+                                               $width = parseInt(RegExp.$1);
+                                       }
+                               }
+                               
+                               if ($width) {
+                                       return "[img='" + source + "'," + $float + "," + $width + "][/img]";
+                               }
+                               else if ($float !== 'none') {
+                                       return "[img='" + source + "'," + $float + "][/img]";
+                               }
+                               
+                               return "[img]" + source + "[/img]";
+                       });
+                       html = html.replace(/<img [^>]*?src=(["'])([^"']+?)\1.*?>/gi, '[img]$2[/img]');
+                       
                        // [*]
                        html = html.replace(/<li>/gi, '[*]');
                        html = html.replace(/<\/li>/gi, '');