Improve sorting of reaction types in js
authorJoshua Rüsweg <josh@bastelstu.be>
Mon, 6 Aug 2018 14:40:20 +0000 (16:40 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Mon, 6 Aug 2018 14:40:20 +0000 (16:40 +0200)
See #2508

wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Handler.js

index bf322088a8afb1b9fa0031ccd124f0bfd7af6a8b..a599e4221f818c8d916abebb8b65ac6b150ae514 100644 (file)
@@ -305,13 +305,22 @@ define(
                        _getSortedReactionTypes: function() {
                                var sortedReactionTypes = [];
                                
+                               // convert our reaction type object to an array
                                for (var key in REACTION_TYPES) {
                                        if (!REACTION_TYPES.hasOwnProperty(key)) continue;
-                                       var reactionType = REACTION_TYPES[key];
-                                       
-                                       sortedReactionTypes[reactionType.showOrder] = reactionType;
+                                       sortedReactionTypes.push(REACTION_TYPES[key]);
                                }
                                
+                               // sort the array
+                               sortedReactionTypes.sort(function (a, b) { 
+                                       if (a.showOrder > b.showOrder) {
+                                               return 1;
+                                       }
+                                       else {
+                                               return -1;
+                                       }
+                               });
+                               
                                return sortedReactionTypes;
                        },