Updated implementation, should now work without special hacks
authorAlexander Ebert <ebert@woltlab.com>
Thu, 2 Jul 2015 12:23:46 +0000 (14:23 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 2 Jul 2015 12:23:46 +0000 (14:23 +0200)
Some features are still missing and have not been implemented yet, this commit ensures that everyone is able to test the current implementation.

com.woltlab.wcf/templates/wysiwyg.tpl
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js
wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js
wcfsetup/install/files/js/WoltLab/WCF/BBCode/ToHtml.js
wcfsetup/install/files/js/WoltLab/WCF/UI/Confirmation.js

index 84aff377ef070621e1893920013352ee08ccbc57..c8f1477baee654eee70c815724b387d6ece0e0c5 100644 (file)
@@ -4,10 +4,15 @@ var __REDACTOR_BUTTONS = [ {implode from=$__wcf->getBBCodeHandler()->getButtonBB
 var __REDACTOR_SMILIES = { {implode from=$__wcf->getSmileyCache()->getCategorySmilies() item=smiley}'{@$smiley->smileyCode|encodeJS}': '{@$smiley->getURL()|encodeJS}'{/implode} };
 var __REDACTOR_SOURCE_BBCODES = [ {implode from=$__wcf->getBBCodeHandler()->getSourceBBCodes() item=__bbcode}'{@$__bbcode->bbcodeTag}'{/implode} ];
 var __REDACTOR_CODE_HIGHLIGHTERS = { {implode from=$__wcf->getBBCodeHandler()->getHighlighters() item=__highlighter}'{@$__highlighter}': '{lang}wcf.bbcode.code.{@$__highlighter}.title{/lang}'{/implode} };
-</script>
-<script data-relocate="true">
-$(function() {
-       WCF.Language.addObject({
+var __REDACTOR_AMD_DEPENDENCIES = { };
+
+require(['Language', 'WoltLab/WCF/BBCode/FromHtml', 'WoltLab/WCF/BBCode/ToHtml'], function(Language, BBCodeFromHTML, BBCodeToHTML) {
+       __REDACTOR_AMD_DEPENDENCIES = {
+               BBCodeFromHTML: BBCodeFromHTML,
+               BBCodeToHTML: BBCodeToHTML
+       };
+       
+       Language.addObject({
                'wcf.attachment.dragAndDrop.dropHere': '{lang}wcf.attachment.dragAndDrop.dropHere{/lang}',
                'wcf.attachment.dragAndDrop.dropNow': '{lang}wcf.attachment.dragAndDrop.dropNow{/lang}',
                'wcf.bbcode.button.fontColor': '{lang}wcf.bbcode.button.fontColor{/lang}',
@@ -70,6 +75,7 @@ $(function() {
                        convertVideoLinks: false,
                        direction: '{lang}wcf.global.pageDirection{/lang}',
                        lang: '{@$__wcf->getLanguage()->getFixedLanguageCode()}',
+                       linebreaks: true,
                        maxHeight: 500,
                        minHeight: 200,
                        plugins: [ 'wutil', 'wmonkeypatch', 'wbutton', 'wbbcode', 'wfontcolor', 'wfontfamily', 'wfontsize' ],
@@ -95,6 +101,7 @@ $(function() {
                        $config.plugins.splice(2, 0, 'table');
                {/if}
                
+               // TODO: is this still required?
                if ($.browser.iOS) {
                        // using a zero-width space breaks iOS' detection of the start of a sentence, causing the first word to be lowercased
                        $config.emptyHtml = '<p><br></p>';
index 129a4c38b769e731b901ba51f8c1795b9c315b48..ea74dff77298771a87717423ed4bccf90eaf2d2f 100644 (file)
@@ -292,11 +292,11 @@ RedactorPlugins.wbbcode = function() {
                /**
                 * Converts source contents from HTML into BBCode.
                 * 
-                * @param       string          html
+                * @param       string          message
                 */
-               convertFromHtml: function(html) {
+               convertFromHtml: function(message) {
                        // DEBUG ONLY
-                       return this.opts.woltlab.bbcode.fromHtml.convert(html);
+                       return __REDACTOR_AMD_DEPENDENCIES.BBCodeFromHTML.convert(message);
                        
                        var $searchFor = [ ];
                        
@@ -557,11 +557,11 @@ RedactorPlugins.wbbcode = function() {
                /**
                 * Converts source contents from BBCode to HTML.
                 * 
-                * @param       string          data
+                * @param       string          message
                 */
-               convertToHtml: function(data) {
+               convertToHtml: function(message) {
                        // DEBUG ONLY
-                       return this.opts.woltlab.bbcode.toHtml.convert(data);
+                       return __REDACTOR_AMD_DEPENDENCIES.BBCodeToHTML.convert(message);
                        
                        WCF.System.Event.fireEvent('com.woltlab.wcf.redactor', 'beforeConvertToHtml', { data: data });
                        
index ceb0244e44938d0e13662df0db44570bc504bfc2..cd35245c5ae8f3e0666c3f6adbd42a3839eecb88 100644 (file)
@@ -716,28 +716,17 @@ RedactorPlugins.wutil = function() {
                 * Sets the selection after the last direct children of the editor.
                 */
                selectionEndOfEditor: function() {
-                       this.focus.setEnd();
-                       
-                       var $lastChild = this.$editor.children(':last')[0];
-                       if ($lastChild.tagName === 'P') {
-                               // sometimes the last <p> is just empty, causing the method to fail
-                               if ($lastChild.innerHTML === '') {
-                                       $lastChild.remove();
-                                       $lastChild = $(this.opts.emptyHtml).appendTo(this.$editor)[0];
-                               }
+                       var lastChild = this.$editor[0].lastElementChild;
+                       if (lastChild === null || lastChild.nodeName === 'BLOCKQUOTE' || (lastChild.nodeName === 'DIV' && lastChild.classList.contains('codeBox'))) {
+                               var element = this.utils.createSpaceElement();
+                               this.$editor[0].appendChild(element);
                                
-                               if ($lastChild.lastChild.nodeType === Element.TEXT_NODE) {
-                                       this.caret.set($lastChild.lastChild, $lastChild.lastChild.length, $lastChild.lastChild, $lastChild.lastChild.length);
-                               }
-                               else {
-                                       this.caret.setEnd($lastChild);
-                               }
+                               this.caret.setEnd(element);
+                               this.wutil.saveSelection();
                        }
                        else {
-                               this.wutil.setCaretAfter($lastChild);
+                               this.focus.setEnd();
                        }
-                       
-                       this.wutil.saveSelection();
                },
                
                /**
index 25166aede1e1fe70331465c235f98eb0083f3ff0..9a40c18d1f2f76e1bc922433601d674d5ea0b69e 100644 (file)
@@ -29,8 +29,7 @@ define(['EventHandler', 'Language', 'StringUtil', 'WoltLab/WCF/BBCode/Parser'],
                        }
                        
                        message = stack.join('');
-                       var x = message;
-                       console.debug(x);
+                       
                        message = message.replace(/\n/g, '<br>');
                        
                        return message;
index 836411beb0feda30866599798e27ecc1832bc4e7..ec32bcdce84e37bb03e0ff0fb5b81828024ff9b1 100644 (file)
@@ -35,6 +35,8 @@ define(['Core', 'Language', 'UI/Dialog'], function(Core, Language, UIDialog) {
                 * @param       {object<string, *>}     options         confirmation options
                 */
                show: function(options) {
+                       if (UIDialog === undefined) UIDialog = require('UI/Dialog');
+                       
                        if (_active) {
                                return;
                        }