Fixed a few issues related to editor API access
authorAlexander Ebert <ebert@woltlab.com>
Sun, 5 Oct 2014 14:23:11 +0000 (16:23 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 5 Oct 2014 14:23:11 +0000 (16:23 +0200)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js
wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js
wcfsetup/install/files/js/WCF.Message.js
wcfsetup/install/files/style/message.less
wcfsetup/install/files/style/redactor.less

index cb1322e93d5b9b33a01f4c8306a3aeeac017f67f..60cf3cb55b46f58e794a265a8d31154f12701a4e 100644 (file)
@@ -21,12 +21,12 @@ RedactorPlugins.wbbcode = function() {
                                // use stored editor contents
                                var $content = $.trim(this.wutil.getOption('wOriginalValue'));
                                if ($content.length) {
-                                       this.toggle();
-                                       this.$textarea.val($content);
-                                       this.toggle();
+                                       this.wutil.replaceText($content);
                                }
                                
                                delete this.opts.wOriginalValue;
+                               
+                               $(document).trigger('resize');
                        }, this);
                        
                        this.opts.pasteBeforeCallback = $.proxy(this.wbbcode._pasteBeforeCallback, this);
index 3e04b682339b4635414c1672c758fa96b28ea0b8..eb1f198168e125b8a1e2e3f4b21248e4972b4109 100644 (file)
@@ -39,7 +39,6 @@ RedactorPlugins.wmonkeypatch = function() {
                        
                        // events and callbacks
                        this.wmonkeypatch.bindEvents();
-                       
                },
                
                /**
@@ -75,7 +74,9 @@ RedactorPlugins.wmonkeypatch = function() {
                        // buttons response
                        if (this.opts.activeButtons) {
                                this.$editor.off('mouseup.redactor keyup.redactor focus.redactor');
+                               
                                this.$editor.on('mouseup.redactor keyup.redactor focus.redactor', $.proxy(this.observe.buttons, this));
+                               this.$editor.on('keyup.redactor', $.proxy(this.keyup.init, this));
                        }
                },
                
@@ -154,10 +155,6 @@ RedactorPlugins.wmonkeypatch = function() {
                                                $listItem.appendTo($dropdown);
                                        }
                                }).bind(this));
-                               
-                               /*$dropdown.children('a').each(function() {
-                                       $(this).wrap('li');
-                               });*/
                        }).bind(this);
                        
                        // dropdown.show
index 5a61101238baddd4a055be9b7775b797ca5bb76e..00c414bc877a02b409269253cca68ff3c995aa17 100644 (file)
@@ -22,7 +22,7 @@ RedactorPlugins.wutil = function() {
                 */
                init: function() {
                        // convert HTML to BBCode upon submit
-                       this.$textarea.parents('form').submit($.proxy(this.submit, this));
+                       this.$textarea.parents('form').submit($.proxy(this.wutil.submit, this));
                        
                        if (this.wutil.getOption('wautosave').active) {
                                this.wutil.autosaveEnable();
@@ -151,18 +151,33 @@ RedactorPlugins.wutil = function() {
                 */
                getText: function() {
                        if (this.inWysiwygMode()) {
-                               this.wSync();
+                               this.code.startSync();
+                               this.$textarea.val(this.wbbcode.convertFromHtml(this.$textarea.val()));
                        }
                        
                        return this.$textarea.val();
                },
                
+               /**
+                * Returns true if editor is empty.
+                * 
+                * @return      boolean
+                */
+               isEmptyEditor: function() {
+                       if (this.opts.visual) {
+                               return this.utils.isEmpty(this.$editor.html());
+                       }
+                       
+                       return (!$.trim(this.$textarea.val()));
+               },
+               
                /**
                 * Converts HTML to BBCode upon submit.
                 */
                submit: function() {
-                       if (this.inWysiwygMode()) {
-                               this.wSync();
+                       if (this.wutil.inWysiwygMode()) {
+                               this.code.startSync();
+                               this.$textarea.val(this.wbbcode.convertFromHtml(this.$textarea.val()));
                        }
                        
                        this.autosavePurge();
@@ -172,14 +187,12 @@ RedactorPlugins.wutil = function() {
                 * Resets the editor's contents.
                 */
                reset: function() {
-                       if (this.inWysiwygMode()) {
+                       if (this.opts.visual) {
                                this.$editor.html('<p>' + this.opts.invisibleSpace + '</p>');
-                               this.sync();
-                       }
-                       else {
-                               this.$textarea.val('');
                        }
                        
+                       this.$textarea.val('');
+                       
                        WCF.System.Event.fireEvent('com.woltlab.wcf.redactor', 'reset', { wysiwygContainerID: this.$textarea.wcfIdentify() });
                },
                
@@ -300,14 +313,6 @@ RedactorPlugins.wutil = function() {
                        return $string;
                },
                
-               /**
-                * Synchronizes editor's source textarea.
-                */
-               wSync: function() {
-                       this.sync(undefined, true);
-                       this.$textarea.val(this.convertFromHtml(this.cleanHtml(this.$textarea.val())));
-               },
-               
                /**
                 * Returns source textarea object.
                 * 
@@ -442,21 +447,26 @@ RedactorPlugins.wutil = function() {
                 * @param       string          value
                 */
                replaceText: function(value) {
+                       var $document = $(document);
+                       var $offsetTop = $document.scrollTop();
                        var $wasInWysiwygMode = false;
-                       var $offsetTop = $(document).scrollTop();
-                       if (this.inWysiwygMode()) {
-                               this.toggle();
+                       
+                       if (this.wutil.inWysiwygMode()) {
+                               this.code.toggle();
                                $wasInWysiwygMode = true;
                        }
                        
                        this.$textarea.val(value);
                        
                        if ($wasInWysiwygMode) {
-                               this.toggle();
+                               this.code.toggle();
                                
                                // restore scrolling since editor receives the focus
-                               $(document).scrollTop($offsetTop);
+                               $document.scrollTop($offsetTop);
                        }
+                       
+                       // trigger resize event to rebuild message tab menu
+                       $document.trigger('resize');
                },
                
                setCaretBefore: function(element) {
index 28435c86006bd0887a2e89791b8230b54ca695f2..d0369355909a3bf5746e07dcaa149155310136ee 100644 (file)
@@ -699,7 +699,7 @@ WCF.Message.Smilies = Class.extend({
                this._wysiwygSelector = wysiwygSelector;
                
                WCF.System.Dependency.Manager.register('Redactor_' + this._wysiwygSelector, $.proxy(function() {
-                       this._redactor = $('#' + this._wysiwygSelector).redactor('getObject');
+                       this._redactor = $('#' + this._wysiwygSelector).redactor('core.getObject');
                        
                        $('.messageTabMenu[data-wysiwyg-container-id=' + this._wysiwygSelector + ']').on('click', '.jsSmiley', $.proxy(this._smileyClick, this));
                }, this));
@@ -716,7 +716,7 @@ WCF.Message.Smilies = Class.extend({
                var $smileyPath = $target.data('smileyPath');
                
                // register smiley
-               this._redactor.insertSmiley($smileyCode, $smileyPath, true);
+               this._redactor.wbbcode.insertSmiley($smileyCode, $smileyPath, true);
        }
 });
 
@@ -834,8 +834,7 @@ WCF.Message.QuickReply = Class.extend({
                                var $empty = true;
                                if ($.browser.redactor) {
                                        if (this._messageField.data('redactor')) {
-                                               $empty = (!$.trim(this._messageField.redactor('getText')));
-                                               this._editorCallback($empty);
+                                               this._editorCallback(this._messageField.redactor('wutil.isEmptyEditor'));
                                        }
                                }
                                else {
@@ -861,7 +860,7 @@ WCF.Message.QuickReply = Class.extend({
                }
                
                if ($.browser.redactor) {
-                       this._messageField.redactor('focus');
+                       this._messageField.redactor('focus.setEnd');
                }
                else {
                        this._messageField.focus();
@@ -983,7 +982,7 @@ WCF.Message.QuickReply = Class.extend({
                this._revertQuickReply(true);
                
                if ($.browser.redactor) {
-                       this._messageField.redactor('reset');
+                       this._messageField.redactor('wutil.reset');
                }
                else {
                        this._messageField.val('');
@@ -3352,11 +3351,9 @@ WCF.Message.UserMention = Class.extend({
         */
        init: function(wysiwygSelector) {
                this._textarea = $('#' + wysiwygSelector);
-               this._redactor = this._textarea.redactor('getObject');
+               this._redactor = this._textarea.redactor('core.getObject');
                
-               this._redactor.setOption('keyupCallback', $.proxy(this._keyup, this));
-               
-               this._dropdown = this._textarea.redactor('getEditor');
+               this._dropdown = this._textarea.redactor('core.getEditor');
                this._dropdownMenu = $('<ul class="dropdownMenu userSuggestionList" />').appendTo(this._textarea.parent());
                WCF.Dropdown.initDropdownFragment(this._dropdown, this._dropdownMenu);
                
@@ -3365,6 +3362,7 @@ WCF.Message.UserMention = Class.extend({
                });
                
                WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'keydown_' + wysiwygSelector, $.proxy(this._keydown, this));
+               WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'keyup_' + wysiwygSelector, $.proxy(this._keyup, this));
        },
        
        /**
@@ -3383,7 +3381,7 @@ WCF.Message.UserMention = Class.extend({
         */
        _click: function(event) {
                // restore caret position
-               this._redactor.replaceRangesWith(this._caretPosition);
+               this._redactor.wutil.replaceRangesWith(this._caretPosition);
                
                this._setUsername($(event.currentTarget).data('username'));
        },
@@ -3415,7 +3413,7 @@ WCF.Message.UserMention = Class.extend({
                $newRange.setStart($orgRange.startContainer, $orgRange.startOffset - (this._mentionStart.length + 1));
                $newRange.setEnd($orgRange.startContainer, $orgRange.startOffset);
                
-               this._redactor.replaceRangesWith($newRange);
+               this._redactor.wutil.replaceRangesWith($newRange);
                
                // get the offsets of the bounding box of current text selection
                var $range = getSelection().getRangeAt(0);
@@ -3431,7 +3429,7 @@ WCF.Message.UserMention = Class.extend({
                }
                
                // restore caret position
-               this._redactor.replaceRangesWith($orgRange);
+               this._redactor.wutil.replaceRangesWith($orgRange);
                this._caretPosition = $orgRange;
                
                return $offsets;
@@ -3444,13 +3442,13 @@ WCF.Message.UserMention = Class.extend({
                var $orgRange = getSelection().getRangeAt(0).cloneRange();
                
                // allow redactor to undo this
-               this._redactor.bufferSet();
+               this._redactor.buffer.set();
                
                var $newRange = document.createRange();
                $newRange.setStart($orgRange.startContainer, $orgRange.startOffset - (this._mentionStart.length + 1));
                $newRange.setEnd($orgRange.startContainer, $orgRange.startOffset);
                
-               this._redactor.replaceRangesWith($newRange);
+               this._redactor.wutil.replaceRangesWith($newRange);
                
                var $range = getSelection().getRangeAt(0);
                $range.deleteContents();
@@ -3473,7 +3471,7 @@ WCF.Message.UserMention = Class.extend({
                $newRange.setStart($text, username.length + 1);
                $newRange.setEnd($text, username.length + 1);
                
-               this._redactor.replaceRangesWith($newRange);
+               this._redactor.wutil.replaceRangesWith($newRange);
                
                this._hideList();
        },
@@ -3499,11 +3497,11 @@ WCF.Message.UserMention = Class.extend({
         */
        _getTextLineInFrontOfCaret: function() {
                // if text is marked, user suggestions are disabled
-               if (this._redactor.getSelectionHtml().length) {
+               if (this._redactor.selection.getHtml().length) {
                        return '';
                }
                
-               var $range = this._redactor.getSelection().getRangeAt(0);
+               var $range = getSelection().getRangeAt(0);
                var $text = $range.startContainer.textContent.substr(0, $range.startOffset);
                
                // remove unicode zero width space and non-breaking space
@@ -3542,7 +3540,7 @@ WCF.Message.UserMention = Class.extend({
         * @param       object          data
         */
        _keydown: function(data) {
-               if (this._redactor.inPlainMode()) {
+               if (this._redactor.wutil.inPlainMode()) {
                        return;
                }
                
@@ -3550,53 +3548,42 @@ WCF.Message.UserMention = Class.extend({
                        switch (data.event.which) {
                                case $.ui.keyCode.ENTER:
                                        data.cancel = true;
-                                       data.event.preventDefault();
                                        
                                        this._dropdownMenu.children('li').eq(this._itemIndex).trigger('click');
-                                       
-                                       return;
                                break;
                                
                                case $.ui.keyCode.UP:
                                        data.cancel = true;
-                                       data.event.preventDefault();
                                        
                                        this._selectItem(this._itemIndex - 1);
-                                       
-                                       return;
                                break;
                                
                                case $.ui.keyCode.DOWN:
                                        data.cancel = true;
-                                       data.event.preventDefault();
                                        
                                        this._selectItem(this._itemIndex + 1);
-                                       
-                                       return;
                                break;
                        }
                }
-               
-               return true;
        },
        
        /**
         * Handles the keyup event to check if the user starts mentioning someone.
         * 
-        * @param       object          event
+        * @param       object          data
         */
-       _keyup: function(event) {
-               if (this._redactor.inPlainMode()) {
+       _keyup: function(data) {
+               if (this._redactor.wutil.inPlainMode()) {
                        return true;
                }
                
                // ignore enter key up event
-               if (event.which === $.ui.keyCode.ENTER) {
+               if (data.event.which === $.ui.keyCode.ENTER) {
                        return;
                }
                
                // ignore event if suggestion list and user pressed enter, arrow up or arrow down
-               if (this._dropdownMenu.is(':visible') && event.which in { 13:1, 38:1, 40:1 }) {
+               if (this._dropdownMenu.is(':visible') && data.event.which in { 13:1, 38:1, 40:1 }) {
                        return;
                }
                
index da8066cfebdb19f17e03c02c4f2f11daa83f1b86..4e5610c1e2f8f2108498bb058d41fb2cde0209cb 100644 (file)
        display: block;
        line-height: 1.5;
        
-       > div:not(.messageFooter):not(.redactor_box):not(.messageTabMenu) {
+       > div:not(.messageFooter):not(.redactor-box):not(.messageTabMenu) {
                overflow: hidden;
                padding-bottom: @wcfGapMedium;
        }
@@ -519,7 +519,7 @@ html[dir='rtl'] {
        }
 }
 
-.messageHeader + .messageBody > div:first-child:not(.redactor_box),
+.messageHeader + .messageBody > div:first-child:not(.redactor-box),
 .messageBody > div:not(.messageFooter):not(.messageTabMenu):not(:first-child) {
        border-top: 1px dotted @wcfContainerBorderColor;
        padding: @wcfGapMedium 0;
index f47e0446e0960a68cdd11465784ab40e01eb51b2..59973ce89021614b20a15153a15fe21915671307 100644 (file)
        }
 }
 
+.redactor-toolbar-tooltip {
+       .balloonTooltip;
+}
+
 .redactorAttachmentContainer {
        background-color: rgba(255, 255, 255, 1);
        border: 1px solid rgba(238, 238, 238, 1);