From: Alexander Ebert Date: Tue, 12 May 2015 10:55:54 +0000 (+0200) Subject: Overhauled WCF.Sitemap and fixed a few issues X-Git-Tag: 3.0.0_Beta_1~2405 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0127caf7318f76a1d612664929dd84011b9f7130;p=GitHub%2FWoltLab%2FWCF.git Overhauled WCF.Sitemap and fixed a few issues --- diff --git a/com.woltlab.wcf/templates/headIncludeJavaScript.tpl b/com.woltlab.wcf/templates/headIncludeJavaScript.tpl index c6ddd51940..698d51ed80 100644 --- a/com.woltlab.wcf/templates/headIncludeJavaScript.tpl +++ b/com.woltlab.wcf/templates/headIncludeJavaScript.tpl @@ -181,7 +181,6 @@ //getStyleHandler()->countStyles() > 1}new WCF.Style.Chooser();{/if} WCF.System.PageNavigation.init('.pageNavigation'); WCF.Date.Picker.init(); diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 18663caedc..e2b3a767da 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -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 = $('
').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. * diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Bootstrap.js b/wcfsetup/install/files/js/WoltLab/WCF/Bootstrap.js index e0629c73ce..642eda0c8f 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Bootstrap.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Bootstrap.js @@ -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 index 0000000000..5a3516d03d --- /dev/null +++ b/wcfsetup/install/files/js/WoltLab/WCF/Controller/Sitemap.js @@ -0,0 +1,93 @@ +/** + * Provides the sitemap dialog. + * + * @author Alexander Ebert + * @copyright 2001-2015 WoltLab GmbH + * @license GNU Lesser General Public License + * @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} 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(); +}); diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Event/Handler.js b/wcfsetup/install/files/js/WoltLab/WCF/Event/Handler.js index b3a946edad..47f8ae3b5c 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Event/Handler.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Event/Handler.js @@ -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); } diff --git a/wcfsetup/install/files/js/WoltLab/WCF/UI/Dialog.js b/wcfsetup/install/files/js/WoltLab/WCF/UI/Dialog.js index 13f11e5bb0..e4e9c03186 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/UI/Dialog.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/UI/Dialog.js @@ -6,12 +6,13 @@ * @license GNU Lesser General Public License * @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} options list of options, is completely ignored if the dialog already exists + * @return {object} 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'); + } + } }, /** diff --git a/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu.js b/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu.js index e7303e8966..f2e005f063 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu.js @@ -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)); }, /** diff --git a/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu/Simple.js b/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu/Simple.js index e2b2d0a182..c1163bc769 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu/Simple.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu/Simple.js @@ -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 + "')."); } } diff --git a/wcfsetup/install/files/js/require.config.js b/wcfsetup/install/files/js/require.config.js index 0da554d115..c311007e76 100644 --- a/wcfsetup/install/files/js/require.config.js +++ b/wcfsetup/install/files/js/require.config.js @@ -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' } } });