Automatic removal of editor event handlers
authorAlexander Ebert <ebert@woltlab.com>
Wed, 7 Sep 2016 13:26:41 +0000 (15:26 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 7 Sep 2016 13:26:49 +0000 (15:26 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabEvent.js
wcfsetup/install/files/js/WoltLabSuite/Core/Event/Handler.js

index f2930f04a327239d307637611714cd70b783ec08..64399729ddc56369005352ff23ef7638b098f00f 100644 (file)
@@ -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));
                        
index 8b591f6529f0ce499acbda7d6c9a8e84e8cd55a4..698731e2bdccd73d9fedd240a00ad0aabf7e7b35 100644 (file)
@@ -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));
                }
        };
 });