Guests will now be served a proper user menu
authorAlexander Ebert <ebert@woltlab.com>
Fri, 26 Feb 2016 16:29:22 +0000 (17:29 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 26 Feb 2016 16:29:22 +0000 (17:29 +0100)
Just showing the login dialog is rather lame, especially since it does
not provide the ability to change the UI language.

com.woltlab.wcf/templates/pageHeaderUser.tpl
com.woltlab.wcf/templates/pageMenuMobile.tpl
wcfsetup/install/files/js/WCF.User.js
wcfsetup/install/files/js/WoltLab/WCF/Ui/Page/Menu/Abstract.js
wcfsetup/install/files/js/WoltLab/WCF/Ui/Page/Menu/User.js

index 22fbe3e4f3283b3d9648db5adb5f761cce399176..13e45b60f829e75140b5c31b286655664d5df45e 100644 (file)
                        {if $__wcf->getLanguage()->getLanguages()|count > 1}
                                <li id="pageLanguageContainer">
                                        <script data-relocate="true">
-                                               require(['WoltLab/WCF/Language/Chooser'], function(LanguageChooser) {
+                                               require(['EventHandler', 'WoltLab/WCF/Language/Chooser'], function(EventHandler, LanguageChooser) {
                                                        var languages = {
                                                                {implode from=$__wcf->getLanguage()->getLanguages() item=__language}
                                                                        '{@$__language->languageID}': {
                                                                {/implode}
                                                        };
                                                        
-                                                       LanguageChooser.init('pageLanguageContainer', 'languageID', {@$__wcf->getLanguage()->languageID}, languages, function(listItem) {
+                                                       var callback = function(listItem) {
                                                                var location = window.location.toString().replace(/#.*/, '').replace(/(\?|&)l=[0-9]+/g, '');
                                                                var delimiter = (location.indexOf('?') == -1) ? '?' : '&';
                                                                
                                                                window.location = location + delimiter + 'l=' + elData(listItem, 'language-id') + window.location.hash;
+                                                       };
+                                                       
+                                                       LanguageChooser.init('pageLanguageContainer', 'languageID', {@$__wcf->getLanguage()->languageID}, languages, callback);
+                                                       EventHandler.add('com.woltlab.wcf.UserMenuMobile', 'more', function(data) {
+                                                               if (data.identifier === 'com.woltlab.wcf.language') {
+                                                                       callback(data.parent);
+                                                               }
                                                        });
                                                });
                                        </script>
index e9a388a8008dd41192e65040b07d0e5075ba35ee..e73ed15dcf9439801f5d8e503817cbabf10ebc28 100644 (file)
 </div>
 
 {* user menu *}
-{if $__wcf->user->userID}
-       <div id="pageUserMenuMobile" class="pageUserMenuMobile menuOverlayMobile" data-page-logo="{$__wcf->getPath()}images/default-logo.png">
-               <ol class="menuOverlayItemList" data-title="TODO: user menu">
+<div id="pageUserMenuMobile" class="pageUserMenuMobile menuOverlayMobile" data-page-logo="{$__wcf->getPath()}images/default-logo.png">
+       <ol class="menuOverlayItemList" data-title="TODO: user menu">
+               {if $__wcf->user->userID}
+                       {* logged-in *}
                        <li class="menuOverlayTitle">{lang}wcf.user.controlPanel{/lang}</li>
                        <li class="menuOverlayItem">
                                <a href="{link controller='User' object=$__wcf->user}{/link}" class="menuOverlayItemLink box24">
                                        <span class="menuOverlayItemTitle">{lang}wcf.user.notification.notifications{/lang}</span>
                                </a>
                        </li>
-                       <li class="menuOverlayItem">
+                       <li class="menuOverlayItem" data-more="com.woltlab.wcf.moderation">
                                <a href="#" class="menuOverlayItemLink box24">
                                        <span class="icon icon24 fa-exclamation-triangle"></span>
                                        <span class="menuOverlayItemTitle">{lang}wcf.moderation.moderation{/lang}</span>
                                        <span class="menuOverlayItemTitle">{lang}wcf.user.logout{/lang}</span>
                                </a>
                        </li>
-               </ol>
-       </div>
-{/if}
+               {else}
+                       {* guest *}
+                       <li class="menuOverlayTitle">TODO: user menu</li>
+                       <li class="menuOverlayItem" data-more="com.woltlab.wcf.login">
+                               <a href="#" class="menuOverlayItemLink box24">
+                                       <span class="icon icon24 fa-sign-in"></span>
+                                       <span class="menuOverlayItemTitle">{lang}wcf.user.login{/lang}</span>
+                               </a>
+                       </li>
+                       <li class="menuOverlayItem">
+                               <a href="{link controller='Register'}{/link}" class="menuOverlayItemLink box24">
+                                       <span class="icon icon24 fa-asterisk"></span>
+                                       <span class="menuOverlayItemTitle">{lang}wcf.user.register{/lang}</span>
+                               </a>
+                       </li>
+                       
+                       {event name='guestUserMenuItems'}
+               
+                       {if $__wcf->getLanguage()->getLanguages()|count > 1}
+                               <li class="menuOverlayItemSpacer"></li>
+                               <li class="menuOverlayTitle">{lang}wcf.user.language{/lang}</li>
+                               <li class="menuOverlayItem">
+                                       <a href="#" class="menuOverlayItemLink box24">
+                                               <img src="{$__wcf->getLanguage()->getIconPath()}">
+                                               <span class="menuOverlayItemTitle">{$__wcf->getLanguage()}</span>
+                                       </a>
+                                       <ol class="menuOverlayItemList" data-title="{lang}wcf.user.language{/lang}">
+                                               {foreach from=$__wcf->getLanguage()->getLanguages() item=__language}
+                                                       <li class="menuOverlayItem" data-more="com.woltlab.wcf.language" data-language-id="{@$__language->languageID}">
+                                                               <a href="#" class="menuOverlayItemLink box24">
+                                                                       <img src="{$__language->getIconPath()}">
+                                                                       <span class="menuOverlayItemTitle">{$__language}</span>
+                                                               </a>
+                                                       </li>
+                                               {/foreach}
+                                       </ol>
+                               </li>
+                       {/if}
+               {/if}
+       </ol>
+</div>
index 4c393c8ff57aae31fd25be53aed76c0d04baf347..0031b347aad816e17dfb9eaf1ecfb132eacc5c30 100644 (file)
@@ -595,7 +595,13 @@ WCF.User.QuickLogin = {
                                input.setAttribute('value', window.location.protocol + '//' + window.location.host + input.getAttribute('value'));
                        }
                        
-                       EventHandler.add('com.woltlab.wcf.UserMenuMobile', 'showLogin', callbackOpen);
+                       EventHandler.add('com.woltlab.wcf.UserMenuMobile', 'more', function(data) {
+                               if (data.identifier === 'com.woltlab.wcf.login') {
+                                       data.handler.close(true);
+                                       
+                                       callbackOpen();
+                               }
+                       });
                });
        }
 };
index 284cd5ed799fdd244dc77f7d8727ab7851ac85c0..46ad9b68a6b4d80e0859dd1ff81d21162c432794 100644 (file)
@@ -135,14 +135,17 @@ define(['Environment', 'EventHandler', 'ObjectMap', 'Dom/Traverse', 'Ui/Screen']
                        var isLink = (elAttr(item, 'href') !== '#');
                        var parent = item.parentNode;
                        var parentItemList = parent.parentNode;
-                       var itemTitle = DomTraverse.childByClass(item, 'menuOverlayItemTitle').textContent;
+                       var itemTitle = elData(itemList, 'title');
                        
                        this._items.set(item, {
                                itemList: itemList,
                                parentItemList: parentItemList
                        });
                        
-                       elData(itemList, 'title', itemTitle);
+                       if (itemTitle === '') {
+                               itemTitle = DomTraverse.childByClass(item, 'menuOverlayItemTitle').textContent
+                               elData(itemList, 'title', itemTitle);
+                       }
                        
                        var callbackLink = this._showItemList.bind(this, item), wrapper;
                        if (isLink) {
index 4fb19468c1dabf78fbecca8a9af12c5a5823767f..e816776c88e110cb83433feedc6204f6d0900bc9 100644 (file)
@@ -18,18 +18,6 @@ define(['Core', 'EventHandler', './Abstract'], function(Core, EventHandler, UiPa
                 * Initializes the touch-friendly fullscreen user menu.
                 */
                init: function() {
-                       // check if user menu is present, as it is absent when not logged-in
-                       if (elById('pageUserMenuMobile') === null) {
-                               elBySel('#pageHeader .userPanel').addEventListener(WCF_CLICK_EVENT, function(event) {
-                                       event.preventDefault();
-                                       event.stopPropagation();
-                                       
-                                       EventHandler.fire('com.woltlab.wcf.UserMenuMobile', 'showLogin');
-                               });
-                               
-                               return;
-                       }
-                       
                        UiPageMenuUser._super.prototype.init.call(
                                this,
                                'com.woltlab.wcf.UserMenuMobile',
@@ -47,7 +35,8 @@ define(['Core', 'EventHandler', './Abstract'], function(Core, EventHandler, UiPa
                 */
                _initItem: function(item) {
                        // check if it should contain a 'more' link w/ an external callback
-                       var more = elData(item.parentNode, 'more');
+                       var parent = item.parentNode;
+                       var more = elData(parent, 'more');
                        if (more) {
                                item.addEventListener(WCF_CLICK_EVENT, (function(event) {
                                        event.preventDefault();
@@ -55,7 +44,9 @@ define(['Core', 'EventHandler', './Abstract'], function(Core, EventHandler, UiPa
                                        
                                        EventHandler.fire(this._eventIdentifier, 'more', {
                                                handler: this,
-                                               identifier: more
+                                               identifier: more,
+                                               item: item,
+                                               parent: parent
                                        });
                                }).bind(this));