Excluded smilies from editing/attachments with fixed source
authorAlexander Ebert <ebert@woltlab.com>
Tue, 7 Jun 2016 16:23:50 +0000 (18:23 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 7 Jun 2016 16:23:57 +0000 (18:23 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabImage.js
wcfsetup/install/files/style/ui/redactor.scss

index 2f45234abe7bcb041b105e1d0cfaa54015958bc8..c9001d31bb96c5090f407a3c7bf42fdcb89d0865 100644 (file)
@@ -10,35 +10,48 @@ $.Redactor.prototype.WoltLabImage = function() {
                        // TODO: float
                        var mpShowEdit = this.image.showEdit;
                        this.image.showEdit = function($image) {
+                               var image = $image[0];
+                               if (image.classList.contains('smiley')) {
+                                       // smilies cannot be edited
+                                       return;
+                               }
+                               
                                mpShowEdit($image);
                                
-                               elById('redactor-image-source').value = $image[0].src;
+                               elById('redactor-image-source').value = image.src;
                                
                                var float = elById('redactor-image-float');
-                               if ($image[0].classList.contains('messageFloatObjectLeft')) float.value = 'left';
-                               else if ($image[0].classList.contains('messageFloatObjectRight')) float.value = 'right';
+                               if (image.classList.contains('messageFloatObjectLeft')) float.value = 'left';
+                               else if (image.classList.contains('messageFloatObjectRight')) float.value = 'right';
+                               
+                               // hide source if image is an attachment
+                               if (image.classList.contains('woltlabAttachment')) {
+                                       elRemove(elById('redactor-image-source-container'));
+                               }
                        };
                        
                        var mpUpdate = this.image.update;
                        this.image.update = (function() {
+                               var image = this.observe.image[0];
+                               
                                var sourceInput = elById('redactor-image-source');
                                var showError = function(inputElement, message) {
                                        $('<small class="innerError" />').text(message).insertAfter(inputElement);
                                };
                                
-                               // check if source is valid
-                               var source = sourceInput.value.trim();
-                               if (source === '') {
-                                       return showError(sourceInput, WCF.Language.get('wcf.global.form.error.empty'));
+                               if (!image.classList.contains('woltlabAttachment')) {
+                                       // check if source is valid
+                                       var source = sourceInput.value.trim();
+                                       if (source === '') {
+                                               return showError(sourceInput, WCF.Language.get('wcf.global.form.error.empty'));
+                                       }
+                                       else if (!source.match(this.opts.regexps.url)) {
+                                               return showError(sourceInput, WCF.Language.get('wcf.editor.image.source.error.invalid'));
+                                       }
+                                       
+                                       // update image source
+                                       image.src = source;
                                }
-                               else if (!source.match(this.opts.regexps.url)) {
-                                       return showError(sourceInput, WCF.Language.get('wcf.editor.image.source.error.invalid'));
-                               }
-                               
-                               var image = this.observe.image[0];
-                               
-                               // update image source
-                               image.src = source;
                                
                                // remove old float classes
                                image.classList.remove('messageFloatObjectLeft');
@@ -59,7 +72,7 @@ $.Redactor.prototype.WoltLabImage = function() {
                        
                        // overwrite modal template
                        this.opts.modal['image-edit'] = '<div class="section">'
-                                       + '<dl>'
+                                       + '<dl id="redactor-image-source-container">'
                                                + '<dt><label for="redactor-image-source">' + WCF.Language.get('wcf.editor.image.source') + '</label></dt>'
                                                + '<dd>'
                                                        + '<input type="text" id="redactor-image-source" class="long">'
index 741b8990a2930a9c72e0e856601b323918375555..b17a341735f55052e9ad23852bfd301e5fdc3316 100644 (file)
        }
        
        img {
-               // TODO: the border was required for 'Old Redactor', check if it is still a thing
-               border: 1px solid transparent;
                max-width: 100%;
+               
+               &:not(.smiley) {
+                       // show cursor to indicate editing capability excluding smilies
+                       cursor: pointer;
+               }
        }
        
        // TODO: this is somewhat out of sync