Fixed handling of floating attachments
authorAlexander Ebert <ebert@woltlab.com>
Fri, 19 Sep 2014 14:26:05 +0000 (16:26 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 19 Sep 2014 14:26:05 +0000 (16:26 +0200)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js

index 086e1d6f1467c8415ecaeca199f434cd549521ea..96a9a142e73572deb8e04f27bfdc9ca9e90a64bb 100644 (file)
@@ -287,7 +287,13 @@ RedactorPlugins.wbbcode = {
                html = html.replace(/<img [^>]*?class="smiley" alt="([^"]+?)".*?> ?/gi, '$1 '); // chrome, ie
                
                // attachments
-               html = html.replace(/<img [^>]*?class="redactorEmbeddedAttachment" data-attachment-id="(\d+)".*?>/gi, '[attach=$1][/attach]');
+               html = html.replace(/<img [^>]*?class="redactorEmbeddedAttachment" data-attachment-id="(\d+)"( style="float: (left|right)")?>/gi, function(match, attachmentID, styleTag, alignment) {
+                       if (alignment) {
+                               return '[attach=' + attachmentID + ',' + alignment + '][/attach]';
+                       }
+                       
+                       return '[attach=' + attachmentID + '][/attach]';
+               });
                
                // [img]
                html = html.replace(/<img [^>]*?src=(["'])([^"']+?)\1 style="float: (left|right)[^"]*".*?>/gi, "[img='$2',$3][/img]");
@@ -588,11 +594,18 @@ RedactorPlugins.wbbcode = {
                if ($attachmentUrl) {
                        var $imageAttachmentIDs = this._getImageAttachmentIDs();
                        
-                       data = data.replace(/\[attach=(\d+)\]\[\/attach\]/g, function(match, attachmentID) {
+                       data = data.replace(/\[attach=(\d+)(,[^\]]*)?\]\[\/attach\]/g, function(match, attachmentID, alignment) {
                                attachmentID = parseInt(attachmentID);
                                
                                if (WCF.inArray(attachmentID, $imageAttachmentIDs)) {
-                                       return '<img src="' + $attachmentUrl.replace(/987654321/, attachmentID) + '" class="redactorEmbeddedAttachment" data-attachment-id="' + attachmentID + '" />';
+                                       var $style = '';
+                                       if (alignment) {
+                                               if (alignment.match(/^,'?(left|right)'?/)) {
+                                                       $style = ' style="float: ' + RegExp.$1 + '"';
+                                               }
+                                       }
+                                       
+                                       return '<img src="' + $attachmentUrl.replace(/987654321/, attachmentID) + '" class="redactorEmbeddedAttachment" data-attachment-id="' + attachmentID + '"' + $style + ' />';
                                }
                                
                                return match;