Some improvements to code listing handling
authorAlexander Ebert <ebert@woltlab.com>
Mon, 5 Jan 2015 12:17:11 +0000 (13:17 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 5 Jan 2015 12:17:11 +0000 (13:17 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index dba47d0c1b9a3bc5923bac93d7d930c2fd7fa007..228522a13cc9fa0c04c2ba69ed93c482d48efd6e 100644 (file)
@@ -1808,9 +1808,18 @@ RedactorPlugins.wbbcode = function() {
                                        var $highlighter = $('#redactorCodeHighlighter');
                                        var $lineNumber = $('#redactorCodeLineNumber');
                                        
+                                       var $codeBoxContent = $codeBox.val().replace(/^\n+/, '').replace(/\n+$/, '');
+                                       if ($.trim($codeBoxContent).length === 0) {
+                                               if (!$codeBox.next('small.innerError').length) {
+                                                       $('<small class="innerError">' + WCF.Language.get('wcf.global.form.error.empty') + '</small>').insertAfter($codeBox);
+                                               }
+                                               
+                                               return;
+                                       }
+                                       
                                        var $codeFilename = $.trim($filename.val().replace(/['"]/g, ''));
                                        var $bbcode = '[code=' + $highlighter.val() + ',' + $lineNumber.val() + ($codeFilename.length ? ",'" + $codeFilename + "'" : '') + ']';
-                                       $bbcode += $codeBox.val().replace(/^\n+/, '').replace(/\n+$/, '').replace(/^$/, '\n');
+                                       $bbcode += $codeBoxContent;
                                        $bbcode += '[/code]';
                                        
                                        this.wutil.adjustSelectionForBlockElement();
@@ -1853,6 +1862,15 @@ RedactorPlugins.wbbcode = function() {
                                $codeBox.val($code.replace(/^\n+/, '').replace(/\n+$/, ''));
                                
                                $button.click($.proxy(function() {
+                                       var $codeBoxContent = $codeBox.val().replace(/^\n+/, '').replace(/\n+$/, '');
+                                       if ($.trim($codeBoxContent).length === 0) {
+                                               if (!$codeBox.next('small.innerError').length) {
+                                                       $('<small class="innerError">' + WCF.Language.get('wcf.global.form.error.empty') + '</small>').insertAfter($codeBox);
+                                               }
+                                               
+                                               return;
+                                       }
+                                       
                                        var $selectedHighlighter = $highlighter.val();
                                        codeBox.data('highlighter', $selectedHighlighter);
                                        codeBox.attr('data-highlighter', $selectedHighlighter);
@@ -1876,12 +1894,10 @@ RedactorPlugins.wbbcode = function() {
                                        var $start = parseInt($lineNumber.val());
                                        $list.prop('start', ($start > 1 ? $start : 1));
                                        
-                                       var $code = $codeBox.val().replace(/^\n+/, '').replace(/\n+$/, '').replace(/^$/, '\n');
-                                       $code = $code.split('\n');
-                                       console.debug($code);
+                                       $codeBoxContent = $codeBoxContent.split('\n');
                                        var $codeContent = '';
-                                       for (var $i = 0; $i < $code.length; $i++) {
-                                               $codeContent += '<li>' + WCF.String.escapeHTML($code[$i]) + '</li>';
+                                       for (var $i = 0; $i < $codeBoxContent.length; $i++) {
+                                               $codeContent += '<li>' + WCF.String.escapeHTML($codeBoxContent[$i]) + '</li>';
                                        }
                                        $list.append($($codeContent));
                                        
index 379b987ee33bdaa2b121bc9223227614b3290515..bd3f27ffa5b70bda42f6d69fa715dfad188f281b 100644 (file)
@@ -918,7 +918,7 @@ RedactorPlugins.wmonkeypatch = function() {
                                        + '<dl>'
                                                + '<dt><label for="redactorCodeFilename">' + WCF.Language.get('wcf.bbcode.code.filename') + '</label></dt>'
                                                + '<dd>'
-                                                       + '<input type="text" id="redactorCodeFilename" value="" />'
+                                                       + '<input type="text" id="redactorCodeFilename" value="" class="long" />'
                                                        + '<small>' + WCF.Language.get('wcf.bbcode.code.filename.description') + '</small>'
                                                + '</dd>'
                                        + '</dl>'