From: Alexander Ebert Date: Wed, 7 Sep 2016 13:26:41 +0000 (+0200) Subject: Automatic removal of editor event handlers X-Git-Tag: 3.0.0_Beta_1~268 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8b9ce1d9005ca2a290d682978e94d134a30d1409;p=GitHub%2FWoltLab%2FWCF.git Automatic removal of editor event handlers --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabEvent.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabEvent.js index f2930f04a3..64399729dd 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabEvent.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabEvent.js @@ -11,8 +11,8 @@ $.Redactor.prototype.WoltLabEvent = function() { require(['EventHandler'], (function(EventHandler) { this.WoltLabEvent._setEvents(EventHandler); - var uuid = EventHandler.add('com.woltlab.wcf.redactor2', 'showEditor', (function (data) { - + EventHandler.add('com.woltlab.wcf.redactor2', 'destroy_' + this._elementId, (function () { + EventHandler.removeAllBySuffix('com.woltlab.wcf.redactor2', this._elementId); }).bind(this)) }).bind(this)); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Event/Handler.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Event/Handler.js index 8b591f6529..698731e2bd 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Event/Handler.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Event/Handler.js @@ -109,6 +109,29 @@ define(['Core', 'Dictionary'], function(Core, Dictionary) { else { actions['delete'](action); } + }, + + /** + * Removes all listeners registered for an identifer and ending with a special suffix. + * This is commonly used to unbound event handlers for the editor. + * + * @param {string} identifier event identifier + * @param {string} suffix action suffix + */ + removeAllBySuffix: function (identifier, suffix) { + var actions = _listeners.get(identifier); + if (actions === undefined) { + return; + } + + suffix = '_' + suffix; + var length = suffix.length * -1; + actions.forEach((function (callbacks, action) { + //noinspection JSUnresolvedFunction + if (action.substr(length) === suffix) { + this.removeAll(identifier, action); + } + }).bind(this)); } }; });