Centralized method to handle active page overlays
authorAlexander Ebert <ebert@woltlab.com>
Thu, 31 Jan 2019 18:18:13 +0000 (19:18 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 31 Jan 2019 18:18:13 +0000 (19:18 +0100)
wcfsetup/install/files/js/WCF.ImageViewer.js
wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Clipboard.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Page/Menu/Abstract.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Screen.js

index fd4070e7ed26d3af0d11427ec616bef14ff8b441..16ef42154572567cecabe6e1305e2b6f9ce3957b 100644 (file)
@@ -392,7 +392,9 @@ $.widget('ui.wcfImageViewer', {
                
                this._bindListener();
                
-               document.documentElement.classList.add('pageOverlayActive');
+               require(['Ui/Screen'], function(UiScreen) {
+                       UiScreen.pageOverlayOpen();
+               });
                
                return true;
        },
@@ -427,7 +429,9 @@ $.widget('ui.wcfImageViewer', {
                WCF.System.DisableScrolling.enable();
                WCF.System.DisableZoom.enable();
                
-               document.documentElement.classList.remove('pageOverlayActive');
+               require(['Ui/Screen'], function(UiScreen) {
+                       UiScreen.pageOverlayClose();
+               });
                
                return true;
        },
index ad1e1eeb03203bce82e61293b1924e3bb841cf87..96fc52c2563d43b44b9594613fcfd03cb5f0e798 100644 (file)
@@ -11,13 +11,13 @@ define(
                'Ajax',         'Core',     'Dictionary',      'EventHandler',
                'Language',     'List',     'ObjectMap',       'Dom/ChangeListener',
                'Dom/Traverse', 'Dom/Util', 'Ui/Confirmation', 'Ui/SimpleDropdown',
-               'WoltLabSuite/Core/Ui/Page/Action'
+               'WoltLabSuite/Core/Ui/Page/Action', 'Ui/Screen'
        ],
        function(
                Ajax,            Core,       Dictionary,        EventHandler,
                Language,        List,       ObjectMap,         DomChangeListener,
                DomTraverse,     DomUtil,    UiConfirmation,    UiSimpleDropdown,
-               UiPageAction
+               UiPageAction,    UiScreen
        )
 {
        "use strict";
@@ -56,7 +56,6 @@ define(
        var _callbackItem = null;
        var _callbackUnmarkAll = null;
        
-       var _addPageOverlayActiveClass = false;
        var _specialCheckboxSelector = '.messageCheckboxLabel > input[type="checkbox"], .message .messageClipboardCheckbox > input[type="checkbox"], .messageGroupList .columnMark > label > input[type="checkbox"]';
        
        /**
@@ -708,11 +707,7 @@ define(
                hideEditor: function(objectType) {
                        UiPageAction.remove('wcfClipboard-' + objectType);
                        
-                       if (_addPageOverlayActiveClass) {
-                               _addPageOverlayActiveClass = false;
-                               
-                               document.documentElement.classList.add('pageOverlayActive');
-                       }
+                       UiScreen.pageOverlayOpen();
                },
                
                /**
@@ -721,11 +716,7 @@ define(
                showEditor: function() {
                        this._loadMarkedItems();
                        
-                       if (document.documentElement.classList.contains('pageOverlayActive')) {
-                               document.documentElement.classList.remove('pageOverlayActive');
-                               
-                               _addPageOverlayActiveClass = true;
-                       }
+                       UiScreen.pageOverlayClose();
                },
                
                /**
index 0a8222d160f2dfde446ac85d9d3a8e6213aa7942..246635693c28a6f22dac56ffba03f221e76024f1 100644 (file)
@@ -236,7 +236,7 @@ define(
                 * @return      {object<string, *>}             dialog data
                 */
                openStatic: function(id, html, options, createOnly) {
-                       document.documentElement.classList.add('pageOverlayActive');
+                       UiScreen.pageOverlayOpen();
                        
                        if (Environment.platform() !== 'desktop') {
                                if (!this.isOpen(id)) {
@@ -830,7 +830,8 @@ define(
                                if (data.closable) {
                                        window.removeEventListener('keyup', _keyupListener);
                                }
-                               document.documentElement.classList.remove('pageOverlayActive');
+                               
+                               UiScreen.pageOverlayClose();
                        }
                        else {
                                data = _dialogs.get(_activeDialog);
index 163abc0588fa1eacd4bd1664ef7fa97f00c0b3da..b05be21fe4df68a5e333b89c0431debc15b2606d 100644 (file)
@@ -121,7 +121,7 @@ define(['Core', 'Environment', 'EventHandler', 'Language', 'ObjectMap', 'Dom/Tra
                        
                        _pageContainer.classList.add('menuOverlay-' + this._menu.id);
                        
-                       document.documentElement.classList.add('pageOverlayActive');
+                       UiScreen.pageOverlayOpen();
                        
                        return true;
                },
@@ -141,11 +141,10 @@ define(['Core', 'Environment', 'EventHandler', 'Language', 'ObjectMap', 'Dom/Tra
                                this._menu.classList.remove('open');
                                
                                UiScreen.scrollEnable();
+                               UiScreen.pageOverlayClose();
                                
                                _pageContainer.classList.remove('menuOverlay-' + this._menu.id);
                                
-                               document.documentElement.classList.remove('pageOverlayActive');
-                               
                                return true;
                        }
                        
@@ -223,7 +222,7 @@ define(['Core', 'Environment', 'EventHandler', 'Language', 'ObjectMap', 'Dom/Tra
                                // break if no edge has been touched
                                if (!isLeftEdge && !isRightEdge) return;
                                // break if a different menu is open
-                               if (document.documentElement.classList.contains('pageOverlayActive')) {
+                               if (UiScreen.pageOverlayIsActive()) {
                                        var found = false;
                                        for (var i = 0; i < _pageContainer.classList.length; i++) {
                                                if (_pageContainer.classList[i] === 'menuOverlay-' + this._menu.id) {
index 3aa76597d835141225a01b2ac6033845245ee030..2bacb2c1c310a08865bae952c69c141fb969b0e6 100644 (file)
@@ -14,6 +14,7 @@ define(['Core', 'Dictionary', 'Environment'], function(Core, Dictionary, Environ
        var _scrollDisableCounter = 0;
        var _scrollOffsetFrom = null;
        var _scrollTop = 0;
+       var _pageOverlayCounter = 0;
        
        var _mqMap = Dictionary.fromObject({
                'screen-xs': '(max-width: 544px)',                              /* smartphone */
@@ -152,6 +153,39 @@ define(['Core', 'Dictionary', 'Environment'], function(Core, Dictionary, Environ
                        }
                },
                
+               /**
+                * Indicates that at least one page overlay is currently open.
+                */
+               pageOverlayOpen: function() {
+                       if (_pageOverlayCounter === 0) {
+                               document.documentElement.classList.add('pageOverlayActive');
+                       }
+                       
+                       _pageOverlayCounter++;
+               },
+               
+               /**
+                * Marks one page overlay as closed.
+                */
+               pageOverlayClose: function() {
+                       if (_pageOverlayCounter) {
+                               _pageOverlayCounter--;
+                               
+                               if (_pageOverlayCounter === 0) {
+                                       document.documentElement.classList.remove('pageOverlayActive');
+                               }
+                       }
+               },
+               
+               /**
+                * Returns true if at least one page overlay is currently open.
+                * 
+                * @returns {boolean}
+                */
+               pageOverlayIsActive: function() {
+                       return _pageOverlayCounter > 0;
+               },
+               
                /**
                 * Sets the dialog container element. This method is used to
                 * circumvent a possible circular dependency, due to `Ui/Dialog`