From: Alexander Ebert Date: Mon, 5 Jan 2015 12:17:11 +0000 (+0100) Subject: Some improvements to code listing handling X-Git-Tag: 2.1.0_Beta_3~33 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3e9815e71886d3dacbc6dde3f49c74c6b9c424e0;p=GitHub%2FWoltLab%2FWCF.git Some improvements to code listing handling --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index dba47d0c1b..228522a13c 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -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) { + $('' + WCF.Language.get('wcf.global.form.error.empty') + '').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) { + $('' + WCF.Language.get('wcf.global.form.error.empty') + '').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 += '
  • ' + WCF.String.escapeHTML($code[$i]) + '
  • '; + for (var $i = 0; $i < $codeBoxContent.length; $i++) { + $codeContent += '
  • ' + WCF.String.escapeHTML($codeBoxContent[$i]) + '
  • '; } $list.append($($codeContent)); diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index 379b987ee3..bd3f27ffa5 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -918,7 +918,7 @@ RedactorPlugins.wmonkeypatch = function() { + '
    ' + '
    ' + '
    ' - + '' + + '' + '' + WCF.Language.get('wcf.bbcode.code.filename.description') + '' + '
    ' + '
    '