From 216826471af13fe5d346ca1e1a5a7de1c0d4c413 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 5 Oct 2014 16:23:11 +0200 Subject: [PATCH] Fixed a few issues related to editor API access --- .../js/3rdParty/redactor/plugins/wbbcode.js | 6 +- .../3rdParty/redactor/plugins/wmonkeypatch.js | 7 +-- .../js/3rdParty/redactor/plugins/wutil.js | 54 +++++++++++------- wcfsetup/install/files/js/WCF.Message.js | 57 +++++++------------ wcfsetup/install/files/style/message.less | 4 +- wcfsetup/install/files/style/redactor.less | 4 ++ 6 files changed, 65 insertions(+), 67 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index cb1322e93d..60cf3cb55b 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -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); diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index 3e04b68233..eb1f198168 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -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 diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js index 5a61101238..00c414bc87 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js @@ -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('

' + this.opts.invisibleSpace + '

'); - 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) { diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index 28435c8600..d036935590 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -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 = $('