From 1416d35be85b68d4f439594f055fde9b4279a12a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 27 May 2016 13:18:01 +0200 Subject: [PATCH] Added support for smilies --- com.woltlab.wcf/templates/wysiwyg.tpl | 5 +-- .../redactor2/plugins/WoltLabButton.js | 4 ++- .../redactor2/plugins/WoltLabSmiley.js | 15 ++++++++ wcfsetup/install/files/js/WCF.Message.js | 34 +++++++------------ 4 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSmiley.js diff --git a/com.woltlab.wcf/templates/wysiwyg.tpl b/com.woltlab.wcf/templates/wysiwyg.tpl index 1529901c03..2d2fb9963d 100644 --- a/com.woltlab.wcf/templates/wysiwyg.tpl +++ b/com.woltlab.wcf/templates/wysiwyg.tpl @@ -31,7 +31,7 @@ require(['WoltLab/WCF/Ui/Redactor/Metacode'], function(UiRedactorMetacode) { var config = { buttons: buttons, minHeight: 200, - plugins: ['alignment', 'source', 'table', 'WoltLabColor', 'WoltLabDropdown', 'WoltLabEvent', 'WoltLabLink', 'WoltLabQuote', 'WoltLabSize'], + plugins: ['alignment', 'source', 'table', 'WoltLabColor', 'WoltLabDropdown', 'WoltLabEvent', 'WoltLabLink', 'WoltLabQuote', 'WoltLabSize', 'WoltLabSmiley'], toolbarFixed: false, woltlab: { autosave: autosave, @@ -72,7 +72,8 @@ require(['WoltLab/WCF/Ui/Redactor/Metacode'], function(UiRedactorMetacode) { {if $__wcf->session->getPermission('admin.content.cms.canUseMedia')}'{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMedia.js?v={@LAST_UPDATE_TIME}',{/if} '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMention.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabQuote.js?v={@LAST_UPDATE_TIME}', - '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSize.js?v={@LAST_UPDATE_TIME}' + '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSize.js?v={@LAST_UPDATE_TIME}', + '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSmiley.js?v={@LAST_UPDATE_TIME}' ], function() { WCF.System.Dependency.Manager.invoke(callbackIdentifier); diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js index 75cc8f2e75..3cf57f9c09 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js @@ -26,7 +26,9 @@ $.Redactor.prototype.WoltLabButton = function() { // set icon this.button.setIcon(button, ''); - + if (!button[0]) { + console.debug(buttonName); + } // set title //noinspection JSUnresolvedVariable elAttr(button[0], 'title', buttonData.title); diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSmiley.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSmiley.js new file mode 100644 index 0000000000..8c35f5d08c --- /dev/null +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSmiley.js @@ -0,0 +1,15 @@ +$.Redactor.prototype.WoltLabSmiley = function() { + "use strict"; + + return { + init: function() { + require(['EventHandler'], (function(EventHandler) { + EventHandler.add('com.woltlab.wcf.redactor2', 'insertSmiley_' + this.$element[0].id, this.WoltLabSmiley._insertSmiley.bind(this)) + }).bind(this)); + }, + + _insertSmiley: function(data) { + this.insert.html('' + data.code + ''); + } + } +}; diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index 1cc7363254..900fd94df7 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -684,30 +684,20 @@ WCF.Message.SmileyCategories = Class.extend({ */ WCF.Message.Smilies = Class.extend({ /** - * redactor element - * @var $.Redactor - */ - _redactor: null, - - /** - * wysiwyg container id + * wysiwyg editor id * @var string */ - _wysiwygSelector: '', + _editorId: '', /** * Initializes the smiley handler. * - * @param {string} wysiwygSelector + * @param {string} editorId */ - init: function(wysiwygSelector) { - this._wysiwygSelector = wysiwygSelector; + init: function(editorId) { + this._editorId = editorId; - WCF.System.Dependency.Manager.register('Redactor_' + this._wysiwygSelector, $.proxy(function() { - this._redactor = $('#' + this._wysiwygSelector).redactor('core.getObject'); - - $('.messageTabMenu[data-wysiwyg-container-id=' + this._wysiwygSelector + ']').on('click', '.jsSmiley', $.proxy(this._smileyClick, this)); - }, this)); + $('.messageTabMenu[data-wysiwyg-container-id=' + this._editorId + ']').on('click', '.jsSmiley', this._smileyClick.bind(this)); }, /** @@ -718,12 +708,12 @@ WCF.Message.Smilies = Class.extend({ _smileyClick: function(event) { event.preventDefault(); - var $target = $(event.currentTarget); - var $smileyCode = $target.data('smileyCode'); - var $smileyPath = $target.data('smileyPath'); - - // register smiley - this._redactor.wbbcode.insertSmiley($smileyCode, $smileyPath, true); + require(['EventHandler'], (function(EventHandler) { + EventHandler.fire('com.woltlab.wcf.redactor2', 'insertSmiley_' + this._editorId, { + code: elData(event.currentTarget, 'smiley-code'), + path: elData(event.currentTarget, 'smiley-path') + }); + }).bind(this)); } }); -- 2.20.1