From: Matthias Schmidt Date: Fri, 26 Jul 2013 06:49:24 +0000 (+0200) Subject: Adds recalculation of dropdown position each time X-Git-Tag: 2.0.0_Beta_5~11^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1635b5bd3510b8cd1b3ac87542c4e5b7b9783b27;p=GitHub%2FWoltLab%2FWCF.git Adds recalculation of dropdown position each time This avoids multiple issues like when an inserted/removed node changes the height of the page. --- diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index b66e44fbf2..8fe0c8f2ed 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -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' + }); }, /**