Adds recalculation of dropdown position each time
authorMatthias Schmidt <gravatronics@live.com>
Fri, 26 Jul 2013 06:49:24 +0000 (08:49 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 26 Jul 2013 06:49:24 +0000 (08:49 +0200)
This avoids multiple issues like when an inserted/removed node changes the height of the page.

wcfsetup/install/files/js/WCF.js

index b66e44fbf2b0e4a01502ab821d811cc934c77d52..8fe0c8f2ed47116ff6277b9d27af201bc1fd020d 100755 (executable)
@@ -736,18 +736,6 @@ WCF.Dropdown = {
                        WCF.CloseOverlayHandler.addCallback('WCF.Dropdown', $.proxy(this._closeAll, this));
                        WCF.DOMNodeInsertedHandler.addCallback('WCF.Dropdown', $.proxy(this.init, this));
                }
-               
-               $(window).resize($.proxy(this._resize, this));
-       },
-       
-       /**
-        * Handles resizing the window by making sure that the menu positions are
-        * recalculated.
-        */
-       _resize: function() {
-               for (var $containerID in this._dropdowns) {
-                       this._menus[$containerID].removeData('orientationX');
-               }
        },
        
        /**
@@ -938,54 +926,31 @@ WCF.Dropdown = {
                        $dropdownDimensions = $button.getDimensions('outer');
                }
                
-               // validate if current alignment is still fine, prevents "jumping"
-               var $align = null;
-               switch (dropdownMenu.data('orientationX')) {
-                       case 'left':
-                               if (($dropdownOffsets.left + $menuDimensions.width) > $windowWidth) {
-                                       $align = 'right';
-                               }
-                       break;
-                       
-                       case 'right':
-                               if (($dropdownOffsets.left + $dropdownDimensions.width - $menuDimensions.width) < 0) {
-                                       $align = 'left';
-                               }
-                       break;
-                       
-                       default:
-                               $align = 'left';
-                               
-                               if (($dropdownOffsets.left + $menuDimensions.width) > $windowWidth) {
-                                       $align = 'right';
-                               }
-                       break;
+               // get alignment
+               var $align = 'left';
+               if (($dropdownOffsets.left + $menuDimensions.width) > $windowWidth) {
+                       $align = 'right';
                }
                
-               // alignment has changed
-               if ($align !== null) {
-                       dropdownMenu.data('orientationX', $align);
-                       
-                       var $left = 'auto';
-                       var $right = 'auto';
+               // calculate offsets
+               var $left = 'auto';
+               var $right = 'auto';
+               if ($align === 'left') {
+                       dropdownMenu.removeClass('dropdownArrorRight');
                        
-                       if ($align === 'left') {
-                               dropdownMenu.removeClass('dropdownArrorRight');
-                               
-                               $left = $dropdownOffsets.left + 'px';
-                       }
-                       else {
-                               dropdownMenu.addClass('dropdownArrowRight');
-                               
-                               $right = ($windowWidth - ($dropdownOffsets.left + $dropdownDimensions.width)) + 'px';
-                       }
+                       $left = $dropdownOffsets.left + 'px';
+               }
+               else {
+                       dropdownMenu.addClass('dropdownArrowRight');
                        
-                       dropdownMenu.css({
-                               left: $left,
-                               right: $right,
-                               top: $dropdownOffsets.top + $dropdownDimensions.height + 7 + 'px'
-                       });
+                       $right = ($windowWidth - ($dropdownOffsets.left + $dropdownDimensions.width)) + 'px';
                }
+               
+               dropdownMenu.css({
+                       left: $left,
+                       right: $right,
+                       top: $dropdownOffsets.top + $dropdownDimensions.height + 7 + 'px'
+               });
        },
        
        /**