Fix handling of reaction to objects with multiple containers
authorJoshua Rüsweg <ruesweg@woltlab.com>
Wed, 3 Jul 2019 20:42:18 +0000 (22:42 +0200)
committerJoshua Rüsweg <ruesweg@woltlab.com>
Wed, 3 Jul 2019 20:42:18 +0000 (22:42 +0200)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/CountButtons.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Handler.js

index d2211e2283d37ffc8233929a53c6d5993ba989dd..4e5afd715250ac0830e490de651a7812779e6ed0 100644 (file)
@@ -110,6 +110,9 @@ define(
                                this._objects.get(objectId).forEach(function(elementData) {
                                        var summaryList = elBySel(this._options.summaryListSelector, elementData.element);
                                        
+                                       // summary list for the object not found; abort
+                                       if (summaryList === null) return; 
+                                       
                                        var sortedElements = {}, elements = elBySelAll('li', summaryList);
                                        for (var i = 0, length = elements.length; i < length; i++) {
                                                if (data[elData(elements[i], 'reaction-type-id')] !== undefined) {
index a9b7b701a94b80566d2ca90b722ec642ef0e1862..eb6bdf2dbead710b0a3091e26168a6421371aa9d 100644 (file)
@@ -186,19 +186,29 @@ define(
                        
                        _updateReactButton: function(objectID, reactionTypeID) {
                                this._objects.get(objectID).forEach(function (elementData) {
-                                       if (reactionTypeID) {
-                                               elementData.reactButton.classList.add('active');
-                                               elData(elementData.reactButton, 'reaction-type-id', reactionTypeID);
-                                       }
-                                       else {
-                                               elData(elementData.reactButton, 'reaction-type-id', 0);
-                                               elementData.reactButton.classList.remove('active');
+                                       if (elementData.reactButton !== null) {
+                                               if (reactionTypeID) {
+                                                       elementData.reactButton.classList.add('active');
+                                                       elData(elementData.reactButton, 'reaction-type-id', reactionTypeID);
+                                               } else {
+                                                       elData(elementData.reactButton, 'reaction-type-id', 0);
+                                                       elementData.reactButton.classList.remove('active');
+                                               }
                                        }
                                });
                        },
                        
                        _markReactionAsActive: function() {
-                               var reactionTypeID = elData(this._objects.get(this._popoverCurrentObjectId)[0].reactButton, 'reaction-type-id');
+                               var reactionTypeID;
+                               this._objects.get(this._popoverCurrentObjectId).forEach(function (element) {
+                                       if (element.reactButton !== null) {
+                                               reactionTypeID = elData(element.reactButton, 'reaction-type-id');
+                                       }
+                               });
+                               
+                               if (reactionTypeID === undefined) {
+                                       throw new Error("Unable to find react button for current popover.");
+                               }
                                
                                //  clear old active state
                                var elements = elBySelAll('.reactionTypeButton.active', this._getPopover());