Added support for smilies
authorAlexander Ebert <ebert@woltlab.com>
Fri, 27 May 2016 11:18:01 +0000 (13:18 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 27 May 2016 11:18:07 +0000 (13:18 +0200)
com.woltlab.wcf/templates/wysiwyg.tpl
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSmiley.js [new file with mode: 0644]
wcfsetup/install/files/js/WCF.Message.js

index 1529901c03f135b62b2f4d6010ca4a2e2d6e4cf1..2d2fb9963d32afff189290297c7205d1af2d51aa 100644 (file)
@@ -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);
index 75cc8f2e7528d354f09b8d8755502fde2c32be09..3cf57f9c093d5dc2dabb9fb83bd003c344952976 100644 (file)
@@ -26,7 +26,9 @@ $.Redactor.prototype.WoltLabButton = function() {
                                
                                // set icon
                                this.button.setIcon(button, '<span class="icon icon16 ' + buttonData.icon + '"></span>');
-                               
+                               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 (file)
index 0000000..8c35f5d
--- /dev/null
@@ -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('<img src="' + data.path + '" class="smiley" alt="' + data.code + '">');
+               }
+       }
+};
index 1cc7363254bf2010bd1d638dc39281c7b1fb9576..900fd94df7431d4153434abf2faf64552e1424cd 100644 (file)
@@ -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));
        }
 });