From: Alexander Ebert Date: Wed, 26 Mar 2014 15:54:41 +0000 (+0100) Subject: Updated quick reply feature X-Git-Tag: 2.1.0_Alpha_1~958 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=747ace92bac9783e3c0e5a6bd300fad79e1f3bf1;p=GitHub%2FWoltLab%2FWCF.git Updated quick reply feature --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbutton.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbutton.js index 53176913ec..6b3e771cac 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbutton.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbutton.js @@ -49,7 +49,7 @@ RedactorPlugins.wbutton = { break; case 'spoiler': - $iconName = 'fa-shield'; + $iconName = 'fa-eye-slash'; break; case 'tt': diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js index d38fff76b4..e85bb0bb6a 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js @@ -41,6 +41,27 @@ RedactorPlugins.wutil = { return true; }, + /** + * Inserts content into the editor depending if it is in wysiwyg or plain mode. If 'plainValue' is + * null or undefined, the value from 'html' will be taken instead. + * + * @param string html + * @param string plainValue + */ + insertDynamic: function(html, plainValue) { + if (plainValue === undefined || plainValue === null) { + // shortcut if both 'html' and 'html' are the same + plainValue = html; + } + + if (this.inWysiwygMode()) { + this.insertHtml(html); + } + else { + this.insertAtCaret(plainValue); + } + }, + /** * Sets an option value after initialization. */ @@ -100,5 +121,18 @@ RedactorPlugins.wutil = { this._convertFromHtml(); } + }, + + /** + * Resets the editor's contents. + */ + reset: function() { + if (this.inWysiwygMode()) { + this.$editor.empty(); + this.sync(); + } + else { + this.$source.val(''); + } } }; diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index 42f65c7ad7..e39176b070 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -179,7 +179,7 @@ WCF.Message.Preview = Class.extend({ _click: function(event) { var $message = this._getMessage(); if ($message === null) { - console.debug("[WCF.Message.Preview] Unable to access ckEditor instance of '" + this._messageFieldID + "'"); + console.debug("[WCF.Message.Preview] Unable to access Redactor instance of '" + this._messageFieldID + "'"); return; } @@ -225,7 +225,7 @@ WCF.Message.Preview = Class.extend({ }, /** - * Returns parsed message from ckEditor or null if editor was not accessible. + * Returns parsed message from Redactor or null if editor was not accessible. * * @return string */ @@ -448,16 +448,8 @@ WCF.Message.SmileyCategories = Class.extend({ */ _proxy: null, - /** - * ckEditor element - * @var jQuery - */ - _ckEditor: null, - /** * Initializes the smiley loader. - * - * @param string ckEditorID */ init: function() { this._cache = [ ]; @@ -649,6 +641,7 @@ WCF.Message.QuickReply = Class.extend({ this._container.toggle(); if (this._container.is(':visible')) { + // TODO: Scrolling is anything but smooth, better use the init callback this._scroll.scrollTo(this._container, true); WCF.Message.Submit.registerButton('text', this._container.find('.formSubmit button[data-type=save]')); @@ -656,17 +649,15 @@ WCF.Message.QuickReply = Class.extend({ if (this._quoteManager) { // check if message field is empty var $empty = true; - if ($.browser.ckeditor) { - var self = this; - this._messageField.ckeditor(function() { - $empty = (!$.trim(this.getData()).length); - self._ckeditorCallback($empty); - }); - + if ($.browser.redactor) { + if (this._messageField.data('redactor')) { + $empty = (!$.trim(this._messageField.redactor('getText'))); + this._editorCallback($empty); + } } else { $empty = (!this._messageField.val().length); - this._ckeditorCallback($empty); + this._editorCallback($empty); } } } @@ -678,13 +669,16 @@ WCF.Message.QuickReply = Class.extend({ } }, - _ckeditorCallback: function(isEmpty) { + /** + * Inserts quotes and focuses the editor. + */ + _editorCallback: function(isEmpty) { if (isEmpty) { this._quoteManager.insertQuotes(this._getClassName(), this._getObjectID(), $.proxy(this._insertQuotes, this)); } - if ($.browser.ckeditor) { - this._messageField.ckeditorGet().ui.editor.focus(); + if ($.browser.redactor) { + this._messageField.redactor('focus'); } else { this._messageField.focus(); @@ -710,18 +704,8 @@ WCF.Message.QuickReply = Class.extend({ return; } - if ($.browser.ckeditor) { - var $ckEditor = this._messageField.ckeditorGet(); - - // work-around for a strange selection bug in Firefox: http://www.woltlab.com/forum/index.php/Thread/220522-Zitat-Fehler/ - if ($ckEditor.getSelection().getStartElement() === null) { - // range is broken, set it to end of text: http://stackoverflow.com/a/16308194 - var $range = $ckEditor.createRange(); - $range.moveToPosition($range.root, CKEDITOR.POSITION_BEFORE_END); - $ckEditor.getSelection().selectRanges([ $range ]); - } - - $ckEditor.insertText(data.returnValues.template); + if ($.browser.redactor) { + this._messageField.redactor('insertDynamic', data.returnValues.template); } else { this._messageField.val(data.returnValues.template); @@ -737,10 +721,8 @@ WCF.Message.QuickReply = Class.extend({ } var $message = ''; - - if ($.browser.ckeditor) { - var $ckEditor = this._messageField.ckeditorGet(); - $message = $.trim($ckEditor.getData()); + if ($.browser.redactor) { + $message = this._messageField.redactor('getText'); } else { $message = $.trim(this._messageField.val()); @@ -770,10 +752,10 @@ WCF.Message.QuickReply = Class.extend({ }); this._proxy.sendRequest(); - // show spinner and hide CKEditor + // show spinner and hide Redactor var $messageBody = this._container.find('.messageQuickReplyContent .messageBody'); $('').appendTo($messageBody); - $messageBody.children('#cke_text').hide().end().next().hide(); + $messageBody.children('.redactor_box').hide().end().next().hide(); }, /** @@ -805,9 +787,8 @@ WCF.Message.QuickReply = Class.extend({ _cancel: function() { this._revertQuickReply(true); - if ($.browser.ckeditor) { - // revert CKEditor - this._messageField.ckeditorGet().setData(''); + if ($.browser.redactor) { + this._messageField.redactor('reset'); } else { this._messageField.val(''); @@ -829,9 +810,9 @@ WCF.Message.QuickReply = Class.extend({ $messageBody.children('small.innerError').remove(); } - // display CKEditor + // display Redactor $messageBody.children('.icon-spinner').remove(); - $messageBody.children('#cke_text').show(); + $messageBody.children('.redactor_box').show(); // display form submit $messageBody.next().show(); @@ -849,10 +830,8 @@ WCF.Message.QuickReply = Class.extend({ } var $message = ''; - - if ($.browser.ckeditor) { - var $ckEditor = this._messageField.ckeditorGet(); - $message = $ckEditor.getData(); + if ($.browser.redactor) { + $message = this._messageField.redactor('getText'); } else { $message = this._messageField.val(); @@ -912,9 +891,8 @@ WCF.Message.QuickReply = Class.extend({ this._notification.show(undefined, 5000, WCF.Language.get($message)); } - if ($.browser.ckeditor) { - // remove CKEditor contents - this._messageField.ckeditorGet().setData(''); + if ($.browser.redactor) { + this._messageField.redactor('reset'); } else { this._messageField.val('');