Overhauled WCF.Sitemap and fixed a few issues
authorAlexander Ebert <ebert@woltlab.com>
Tue, 12 May 2015 10:55:54 +0000 (12:55 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 12 May 2015 10:55:54 +0000 (12:55 +0200)
com.woltlab.wcf/templates/headIncludeJavaScript.tpl
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/js/WoltLab/WCF/Bootstrap.js
wcfsetup/install/files/js/WoltLab/WCF/Controller/Sitemap.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLab/WCF/Event/Handler.js
wcfsetup/install/files/js/WoltLab/WCF/UI/Dialog.js
wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu.js
wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu/Simple.js
wcfsetup/install/files/js/require.config.js

index c6ddd51940189dd102af20c76ba0c2159bc76f68..698d51ed80e131557f1dc13e10f9ee788e3682e5 100644 (file)
        //<![CDATA[
        $(function() {
                new WCF.Effect.SmoothScroll();
-               new WCF.Sitemap();
                {if $__wcf->getStyleHandler()->countStyles() > 1}new WCF.Style.Chooser();{/if}
                WCF.System.PageNavigation.init('.pageNavigation');
                WCF.Date.Picker.init();
index 18663caedcfffb844d00774ecc52c3a599e2482c..e2b3a767dac1509dad01cca812e356258fd0f139 100755 (executable)
@@ -9448,136 +9448,6 @@ WCF.EditableItemList = Class.extend({
        }
 });
 
-/**
- * Provides a generic sitemap.
- */
-WCF.Sitemap = Class.extend({
-       /**
-        * sitemap name cache
-        * @var array
-        */
-       _cache: [ ],
-       
-       /**
-        * dialog overlay
-        * @var jQuery
-        */
-       _dialog: null,
-       
-       /**
-        * initialization state
-        * @var boolean
-        */
-       _didInit: false,
-       
-       /**
-        * action proxy
-        * @var WCF.Action.Proxy
-        */
-       _proxy: null,
-       
-       /**
-        * Initializes the generic sitemap.
-        */
-       init: function() {
-               $('#sitemap').click($.proxy(this._click, this));
-               
-               this._cache = [ ];
-               this._dialog = null;
-               this._didInit = false;
-               this._proxy = new WCF.Action.Proxy({
-                       success: $.proxy(this._success, this)
-               });
-       },
-       
-       /**
-        * Handles clicks on the sitemap icon.
-        */
-       _click: function(event) {
-               event.preventDefault();
-               
-               if (this._dialog === null) {
-                       this._dialog = $('<div id="sitemapDialog" />').appendTo(document.body);
-                       
-                       this._proxy.setOption('data', {
-                               actionName: 'getSitemap',
-                               className: 'wcf\\data\\sitemap\\SitemapAction'
-                       });
-                       this._proxy.sendRequest();
-               }
-               else {
-                       this._dialog.wcfDialog('open');
-                       
-                       $(document).trigger('resize');
-               }
-       },
-       
-       /**
-        * Handles successful AJAX responses.
-        * 
-        * @param       object          data
-        * @param       string          textStatus
-        * @param       jQuery          jqXHR
-        */
-       _success: function(data, textStatus, jqXHR) {
-               if (this._didInit) {
-                       this._cache.push(data.returnValues.sitemapName);
-                       
-                       this._dialog.find('#sitemap_' + data.returnValues.sitemapName).html(data.returnValues.template);
-                       
-                       // redraw dialog
-                       this._dialog.wcfDialog('render');
-               }
-               else {
-                       // mark sitemap name as loaded
-                       this._cache.push(data.returnValues.sitemapName);
-                       
-                       // insert sitemap template
-                       this._dialog.html(data.returnValues.template);
-                       
-                       // bind event listener
-                       this._dialog.find('.sitemapNavigation').click($.proxy(this._navigate, this));
-                       
-                       // select active item
-                       this._dialog.find('.tabMenuContainer').wcfTabs('select', 'sitemap_' + data.returnValues.sitemapName);
-                       
-                       // show dialog
-                       this._dialog.wcfDialog({
-                               title: WCF.Language.get('wcf.page.sitemap')
-                       });
-                       
-                       this._didInit = true;
-               }
-               
-               $(document).trigger('resize');
-       },
-       
-       /**
-        * Navigates between different sitemaps.
-        * 
-        * @param       object          event
-        */
-       _navigate: function(event) {
-               var $sitemapName = $(event.currentTarget).data('sitemapName');
-               if (WCF.inArray($sitemapName, this._cache)) {
-                       this._dialog.find('.tabMenuContainer').wcfTabs('select', 'sitemap_' + $sitemapName);
-                       
-                       // redraw dialog
-                       this._dialog.wcfDialog('render');
-               }
-               else {
-                       this._proxy.setOption('data', {
-                               actionName: 'getSitemap',
-                               className: 'wcf\\data\\sitemap\\SitemapAction',
-                               parameters: {
-                                       sitemapName: $sitemapName
-                               }
-                       });
-                       this._proxy.sendRequest();
-               }
-       }
-});
-
 /**
  * Provides a language chooser.
  * 
index e0629c73ced17325ce0189e0e49d2ebf2244568a..642eda0c8fb4f79f96a986eceb346853f39568a7 100644 (file)
@@ -9,8 +9,16 @@
  * @module     WoltLab/WCF/Bootstrap
  */
 define(
-       [       'jquery', 'favico', 'enquire', 'WoltLab/WCF/Date/Time/Relative', 'UI/SimpleDropdown', 'WoltLab/WCF/UI/Mobile', 'WoltLab/WCF/UI/TabMenu', 'WoltLab/WCF/UI/FlexibleMenu', 'UI/Dialog', 'WoltLab/WCF/UI/Tooltip'], 
-       function($,        favico,   enquire,   relativeTime,                     simpleDropdown,      UIMobile,                UITabMenu,                UIFlexibleMenu,                UIDialog,    UITooltip)
+       [
+               'jquery',            'favico',                 'enquire',                'WoltLab/WCF/Date/Time/Relative',
+               'UI/SimpleDropdown', 'WoltLab/WCF/UI/Mobile',  'WoltLab/WCF/UI/TabMenu', 'WoltLab/WCF/UI/FlexibleMenu',
+               'UI/Dialog',         'WoltLab/WCF/UI/Tooltip', 'WoltLab/WCF/Controller/Sitemap'
+       ], 
+       function(
+                $,                   favico,                   enquire,                  relativeTime,
+                simpleDropdown,      UIMobile,                 UITabMenu,                UIFlexibleMenu,
+                UIDialog,            UITooltip,                ControllerSitemap
+       )
 {
        "use strict";
        
@@ -34,6 +42,8 @@ define(
                        UIDialog.setup();
                        UITooltip.setup();
                        
+                       ControllerSitemap.setup();
+                       
                        $.holdReady(false);
                }
        };
diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Controller/Sitemap.js b/wcfsetup/install/files/js/WoltLab/WCF/Controller/Sitemap.js
new file mode 100644 (file)
index 0000000..5a3516d
--- /dev/null
@@ -0,0 +1,93 @@
+/**
+ * Provides the sitemap dialog.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2015 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module     WoltLab/WCF/Controller/Sitemap
+ */
+define(['EventHandler', 'DOM/Util', 'UI/Dialog', 'UI/TabMenu'], function(EventHandler, DOMUtil, UIDialog, UITabMenu) {
+       "use strict";
+       
+       var _cache = [];
+       var _dialog = null;
+       
+       /**
+        * @constructor
+        */
+       function ControllerSitemap() {};
+       ControllerSitemap.prototype = {
+               /**
+                * Binds click handler.
+                */
+               setup: function() {
+                       document.getElementById('sitemap').addEventListener('click', this._click.bind(this));
+               },
+               
+               /**
+                * Handles clicks on the sitemap button.
+                * 
+                * @param       {object}        event   event object
+                */
+               _click: function(event) {
+                       event.preventDefault();
+                       
+                       if (UIDialog.getDialog('sitemapDialog') === null) {
+                               new WCF.Action.Proxy({
+                                       autoSend: true,
+                                       data: {
+                                               actionName: 'getSitemap',
+                                               className: 'wcf\\data\\sitemap\\SitemapAction'
+                                       },
+                                       success: (function(data) {
+                                               _cache.push(data.returnValues.sitemapName);
+                                               
+                                               _dialog = UIDialog.open('sitemapDialog', data.returnValues.template, {
+                                                       disableContentPadding: true,
+                                                       title: WCF.Language.get('wcf.page.sitemap')
+                                               });
+                                               
+                                               var tabMenuContainer = _dialog.content.querySelector('.tabMenuContainer');
+                                               var menuId = DOMUtil.identify(tabMenuContainer);
+                                               
+                                               UITabMenu.getTabMenu(menuId).select('sitemap_' + data.returnValues.sitemapName);
+                                               
+                                               EventHandler.add('com.woltlab.wcf.simpleTabMenu_' + menuId, 'select', this.showTab.bind(this));
+                                       }).bind(this)
+                               });
+                       }
+                       else {
+                               UIDialog.open('sitemapDialog');
+                       }
+               },
+               
+               /**
+                * Callback for tab links, lazy loads content.
+                * 
+                * @param       {object<string, Element>}       tabData         tab data
+                */
+               showTab: function(tabData) {
+                       var name = tabData.active.getAttribute('data-name').replace(/^sitemap_/, '');
+                       
+                       if (_cache.indexOf(name) === -1) {
+                               new WCF.Action.Proxy({
+                                       autoSend: true,
+                                       data: {
+                                               actionName: 'getSitemap',
+                                               className: 'wcf\\data\\sitemap\\SitemapAction',
+                                               parameters: {
+                                                       sitemapName: name
+                                               }
+                                       },
+                                       success: function(data) {
+                                               _cache.push(data.returnValues.sitemapName);
+                                               
+                                               document.getElementById('sitemap_' + data.returnValues.sitemapName).innerHTML = data.returnValues.template;
+                                       }
+                               });
+                       }
+               } 
+       };
+       
+       return new ControllerSitemap();
+});
index b3a946edad42f705d9f18f7ee0a446b0a2704be8..47f8ae3b5c1e91f08113a75ac143034155b0d9b5 100644 (file)
@@ -31,13 +31,13 @@ define(['Dictionary'], function(Dictionary) {
                        
                        var actions = _listeners.get(identifier);
                        if (actions === null) {
-                               actions = dictionary.create();
+                               actions = new Dictionary();
                                _listeners.set(identifier, actions);
                        }
                        
                        var callbacks = actions.get(action);
                        if (callbacks === null) {
-                               callbacks = dictionary.create();
+                               callbacks = new Dictionary();
                                actions.set(action, callbacks);
                        }
                        
index 13f11e5bb074dbbbda935c2d2d16a2089bb0a880..e4e9c031869d816415d4c1732fed96d2af3b34cf 100644 (file)
@@ -6,12 +6,13 @@
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @module     WoltLab/WCF/UI/Dialog
  */
-define(['jquery', 'Core', 'Dictionary', 'DOM/Util'], function($, Core, Dictionary, DOMUtil) {
+define(['jquery', 'enquire', 'Core', 'Dictionary', 'DOM/Util'], function($, enquire, Core, Dictionary, DOMUtil) {
        "use strict";
        
        var _activeDialog = null;
        var _container = null;
        var _dialogs = null;
+       var _dialogFullHeight = false;
        var _keyupListener = null;
        
        /**
@@ -43,6 +44,13 @@ define(['jquery', 'Core', 'Dictionary', 'DOM/Util'], function($, Core, Dictionar
                                
                                return true;
                        }).bind(this);
+                       
+                       enquire.register('screen and (max-width: 800px)', {
+                               match: function() { _dialogFullHeight = true; },
+                               unmatch: function() { _dialogFullHeight = false; },
+                               setup: function() { _dialogFullHeight = true; },
+                               deferSetup: true
+                       });
                },
                
                /**
@@ -55,6 +63,7 @@ define(['jquery', 'Core', 'Dictionary', 'DOM/Util'], function($, Core, Dictionar
                 * @param       {string}                id              element id, if exists the html parameter is ignored in favor of the existing element
                 * @param       {?string}               html            content html
                 * @param       {object<string, *>}     options         list of options, is completely ignored if the dialog already exists
+                * @return      {object<string, *>}     dialog data
                 */
                open: function(id, html, options) {
                        if (_dialogs.has(id)) {
@@ -89,6 +98,8 @@ define(['jquery', 'Core', 'Dictionary', 'DOM/Util'], function($, Core, Dictionar
                                
                                this._createDialog(id, html, options);
                        }
+                       
+                       return _dialogs.get(id);
                },
                
                /**
@@ -175,7 +186,11 @@ define(['jquery', 'Core', 'Dictionary', 'DOM/Util'], function($, Core, Dictionar
                                content = element;
                        }
                        
-                       contentContainer.appendChild(element);
+                       contentContainer.appendChild(content);
+                       
+                       if (content.style.getPropertyValue('display') === 'none') {
+                               content.style.removeProperty('display');
+                       }
                        
                        _dialogs.set(id, {
                                backdropCloseOnClick: options.backdropCloseOnClick,
@@ -262,13 +277,6 @@ define(['jquery', 'Core', 'Dictionary', 'DOM/Util'], function($, Core, Dictionar
                                return;
                        }
                        
-                       // fix for a calculation bug in Chrome causing the scrollbar to overlap the border
-                       if ($.browser.chrome) {
-                               if (data.content.scrollHeight > data.content.clientHeight) {
-                                       data.content.style.setProperty('margin-right', '-1px');
-                               }
-                       }
-                       
                        var contentContainer = data.content.parentNode;
                        
                        var formSubmit = data.content.querySelector('.formSubmit');
@@ -286,8 +294,18 @@ define(['jquery', 'Core', 'Dictionary', 'DOM/Util'], function($, Core, Dictionar
                        
                        unavailableHeight += DOMUtil.outerHeight(data.header);
                        
-                       var maximumHeight = (window.innerHeight * 0.8) - unavailableHeight;
+                       var maximumHeight = (window.innerHeight * (_dialogFullHeight ? 1 : 0.8)) - unavailableHeight;
                        contentContainer.style.setProperty('max-height', ~~maximumHeight + 'px');
+                       
+                       // fix for a calculation bug in Chrome causing the scrollbar to overlap the border
+                       if ($.browser.chrome) {
+                               if (data.content.scrollHeight > maximumHeight) {
+                                       data.content.style.setProperty('margin-right', '-1px');
+                               }
+                               else {
+                                       data.content.style.removeProperty('margin-right');
+                               }
+                       }
                },
                
                /**
index e7303e896628dceb001b7a05a9cd5c4b317f6283..f2e005f06390753d58a363c2809ecf223d136424 100644 (file)
@@ -23,6 +23,7 @@ define(['Dictionary', 'DOM/Util', './TabMenu/Simple'], function(Dictionary, DOMU
                        this._init();
                        
                        // TODO: use WCF.DOMNodeInsertedHandler
+                       WCF.DOMNodeInsertedHandler.addCallback('WoltLab/WCF/UI/TabMenu', this._init.bind(this));
                },
                
                /**
index e2b2d0a182ea68c94da8eed5432b0236f376f842..c1163bc769c359c790297c80dca4a845c0d2390c 100644 (file)
@@ -168,7 +168,7 @@ define(['jquery', 'Dictionary', 'DOM/Util', 'EventHandler'], function($, Diction
                 * @param       {boolean=}              disableEvent    suppress event handling
                 */
                select: function(name, tab, disableEvent) {
-                       tab = tab || this._tabs.get(name);
+                       tab = tab || this._tabs.get(name) || null;
                        
                        if (tab === null) {
                                // check if name is an integer
@@ -186,7 +186,7 @@ define(['jquery', 'Dictionary', 'DOM/Util', 'EventHandler'], function($, Diction
                                }
                                
                                if (tab === null) {
-                                       throw new Error("Expected a valid tab name (tab menu id: '" + this._containerId + "').");
+                                       throw new Error("Expected a valid tab name, '" + name + "' given (tab menu id: '" + this._containerId + "').");
                                }
                        }
                        
index 0da554d1159a448075827dc6c57c44040d98bcae..c311007e76036d2b0a2d43bf92926877d3d9db69 100644 (file)
@@ -13,7 +13,8 @@ requirejs.config({
                        'EventHandler': 'WoltLab/WCF/Event/Handler',
                        'UI/Alignment': 'WoltLab/WCF/UI/Alignment',
                        'UI/Dialog': 'WoltLab/WCF/UI/Dialog',
-                       'UI/SimpleDropdown': 'WoltLab/WCF/UI/Dropdown/Simple'
+                       'UI/SimpleDropdown': 'WoltLab/WCF/UI/Dropdown/Simple',
+                       'UI/TabMenu': 'WoltLab/WCF/UI/TabMenu'
                }
        }
 });