if (this._dropdownContainer === null) {
this._dropdownContainer = $('<div class="dropdownMenuContainer" />').appendTo(document.body);
WCF.CloseOverlayHandler.addCallback('WCF.Dropdown.Interactive.Handler', $.proxy(this.closeAll, this));
-
- window.addEventListener('scroll', (function (event) {
- if (!document.documentElement.classList.contains('pageOverlayActive')) {
- this.closeAll();
- }
- }).bind(this));
}
var $instance = new WCF.Dropdown.Interactive.Instance(this._dropdownContainer, triggerElement, identifier, options);
this._pointer = $('<span class="elementPointer"><span /></span>').appendTo(this._container);
- require(['Environment'], function(Environment) {
- if (Environment.platform() === 'desktop' && $itemContainer !== null) {
- // use jQuery scrollbar on desktop, mobile browsers have a similar display built-in
- $itemContainer.perfectScrollbar({
- suppressScrollX: true
- });
+ require(['Environment', 'EventHandler'], (function(Environment, EventHandler) {
+ if (Environment.platform() === 'desktop') {
+ EventHandler.add('com.woltlab.wcf.pageHeaderFixed', 'change', (function (data) {
+ this.render();
+ }).bind(this));
+
+ if ($itemContainer !== null) {
+ // use jQuery scrollbar on desktop, mobile browsers have a similar display built-in
+ $itemContainer.perfectScrollbar({
+ suppressScrollX: true
+ });
+ }
}
- });
+ }).bind(this));
this._container.appendTo(dropdownContainer);
},
* Renders the dropdown.
*/
render: function() {
- if (window.matchMedia('(max-width: 767px)').matches) {
- this._container.css({
- bottom: '',
- left: '',
- right: '',
- top: elById('pageHeader').clientHeight + 'px'
- });
- }
- else {
- require(['Ui/Alignment'], (function(UiAlignment) {
+ require(['Dom/Util', 'Ui/Alignment', 'Ui/Screen'], (function (DomUtil, UiAlignment, UiScreen) {
+ if (UiScreen.is('screen-lg')) {
+ this._container[0].classList.remove('interactiveDropdownFixed');
+
UiAlignment.set(this._container[0], this._triggerElement[0], {
horizontal: 'right',
pointer: true
});
- }).bind(this));
- }
+
+ if (DomUtil.getFixedParent(this._triggerElement[0]) !== null) {
+ this._container[0].classList.add('interactiveDropdownFixed');
+ this._container[0].style.setProperty('top', this._triggerElement[0].clientHeight + 'px', '');
+ }
+ }
+ else {
+ this._container.css({
+ bottom: '',
+ left: '',
+ right: '',
+ top: elById('pageHeader').clientHeight + 'px'
+ });
+ }
+ }).bind(this));
},
/**
*/
isAtNodeEnd: function(element, ancestor) {
return _isBoundaryNode(element, ancestor, 'next');
+ },
+
+ /**
+ * Returns the first ancestor element with position fixed or null.
+ *
+ * @param {Element} element target element
+ * @returns {(Element|null)} first ancestor with position fixed or null
+ */
+ getFixedParent: function (element) {
+ while (element && element !== document.body) {
+ if (window.getComputedStyle(element).getPropertyValue('position') === 'fixed') {
+ return element;
+ }
+
+ element = element.offsetParent;
+ }
+
+ return null;
}
};
_isFixed = (window.pageYOffset > _triggerHeight);
- _pageHeader.classList[_isFixed ? 'add' : 'remove']('sticky');
- _pageHeaderContainer.classList[_isFixed ? 'add' : 'remove']('stickyPageHeader');
-
- if (!_isFixed && wasFixed) {
- _pageHeader.classList.remove('searchBarOpen');
- ['bottom', 'left', 'right', 'top'].forEach(function(propertyName) {
- _searchInputContainer.style.removeProperty(propertyName);
- });
+ if (_isFixed !== wasFixed) {
+ _pageHeader.classList[_isFixed ? 'add' : 'remove']('sticky');
+ _pageHeaderContainer.classList[_isFixed ? 'add' : 'remove']('stickyPageHeader');
+
+ EventHandler.fire('com.woltlab.wcf.pageHeaderFixed', 'change', { isFixed: _isFixed });
+
+ if (!_isFixed && wasFixed) {
+ _pageHeader.classList.remove('searchBarOpen');
+ ['bottom', 'left', 'right', 'top'].forEach(function(propertyName) {
+ _searchInputContainer.style.removeProperty(propertyName);
+ });
+ }
}
}
};