Overhauled WCF.Style.Chooser
authorAlexander Ebert <ebert@woltlab.com>
Tue, 12 May 2015 13:25:11 +0000 (15:25 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 12 May 2015 13:25:11 +0000 (15:25 +0200)
com.woltlab.wcf/templates/headIncludeJavaScript.tpl
com.woltlab.wcf/templates/styleChooser.tpl
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/js/WoltLab/WCF/BootstrapFrontend.js
wcfsetup/install/files/js/WoltLab/WCF/Controller/Style/Changer.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu.js

index a519805d9943bc74d2cb27e5a5e5e58ef1ec9d67..e81deb7864dd91071c8ef6771076594f48f0768b 100644 (file)
        
        $.holdReady(true);
        require(['WoltLab/WCF/BootstrapFrontend'], function(BootstrapFrontend) {
-               BootstrapFrontend.setup();
+               BootstrapFrontend.setup({
+                       styleChanger: {if $__wcf->getStyleHandler()->countStyles() > 1}true{else}false{/if}
+               });
        });
 </script>
 
        //<![CDATA[
        $(function() {
                new WCF.Effect.SmoothScroll();
-               {if $__wcf->getStyleHandler()->countStyles() > 1}new WCF.Style.Chooser();{/if}
+               
                WCF.System.PageNavigation.init('.pageNavigation');
                WCF.Date.Picker.init();
                new WCF.User.ProfilePreview();
index aa6a71c0882758e3f47e7b629daf0509df431a6b..a3c4bb96f552aa7f26ccb3eca3c650f695afdab3 100644 (file)
@@ -1,19 +1,17 @@
-<div class="container">
-       <ol class="containerList styleList{if $styleList|count > 4} doubleColumned{/if}">
-               {foreach from=$styleList item=style}
-                       <li data-style-id="{@$style->styleID}">
-                               <div class="box64">
-                                       <span class="framed">
-                                               <img src="{@$style->getPreviewImage()}" alt="" />
-                                       </span>
-                                       <div class="details">
-                                               <div class="containerHeadline">
-                                                       <h3>{$style->styleName}{if $style->styleID == $__wcf->getStyleHandler()->getStyle()->styleID} <span class="icon icon16 icon-ok-sign" title="{lang}wcf.style.currentStyle{/lang}"></span>{/if}</h3>
-                                               </div>
-                                               {if $style->styleDescription}<small>{lang}{@$style->styleDescription}{/lang}</small>{/if}
+<ol class="containerList styleList{if $styleList|count > 4} doubleColumned{/if}">
+       {foreach from=$styleList item=style}
+               <li data-style-id="{@$style->styleID}">
+                       <div class="box64">
+                               <span class="framed">
+                                       <img src="{@$style->getPreviewImage()}" alt="" />
+                               </span>
+                               <div class="details">
+                                       <div class="containerHeadline">
+                                               <h3>{$style->styleName}{if $style->styleID == $__wcf->getStyleHandler()->getStyle()->styleID} <span class="icon icon16 icon-ok-sign" title="{lang}wcf.style.currentStyle{/lang}"></span>{/if}</h3>
                                        </div>
+                                       {if $style->styleDescription}<small>{lang}{@$style->styleDescription}{/lang}</small>{/if}
                                </div>
-                       </li>
-               {/foreach}
-       </ol>
-</div>
\ No newline at end of file
+                       </div>
+               </li>
+       {/foreach}
+</ol>
\ No newline at end of file
index e2b3a767dac1509dad01cca812e356258fd0f139..ec7153c0026db71cb09a8e2fab87f623a3fa5d94 100755 (executable)
@@ -9574,99 +9574,6 @@ WCF.Language.Chooser = Class.extend({
  */
 WCF.Style = { };
 
-/**
- * Provides a visual style chooser.
- */
-WCF.Style.Chooser = Class.extend({
-       /**
-        * dialog overlay
-        * @var jQuery
-        */
-       _dialog: null,
-       
-       /**
-        * action proxy
-        * @var WCF.Action.Proxy
-        */
-       _proxy: null,
-       
-       /**
-        * Initializes the style chooser class.
-        */
-       init: function() {
-               $('<li class="styleChooser"><a href="#">' + WCF.Language.get('wcf.style.changeStyle') + '</a></li>').appendTo($('#footerNavigation > ul.navigationItems')).click($.proxy(this._showDialog, this));
-               
-               this._proxy = new WCF.Action.Proxy({
-                       success: $.proxy(this._success, this)
-               });
-       },
-       
-       /**
-        * Displays the style chooser dialog.
-        * 
-        * @param       object          event
-        */
-       _showDialog: function(event) {
-               if (event !== null) {
-                       event.preventDefault();
-               }
-               
-               if (this._dialog === null) {
-                       this._dialog = $('<div id="styleChooser" />').hide().appendTo(document.body);
-                       this._loadDialog();
-               }
-               else {
-                       this._dialog.wcfDialog({
-                               title: WCF.Language.get('wcf.style.changeStyle')
-                       });
-               }
-       },
-       
-       /**
-        * Loads the style chooser dialog.
-        */
-       _loadDialog: function() {
-               this._proxy.setOption('data', {
-                       actionName: 'getStyleChooser',
-                       className: 'wcf\\data\\style\\StyleAction'
-               });
-               this._proxy.sendRequest();
-       },
-       
-       /**
-        * Handles successful AJAX requests.
-        * 
-        * @param       object          data
-        * @param       string          textStatus
-        * @param       jQuery          jqXHR
-        */
-       _success: function(data, textStatus, jqXHR) {
-               if (data.actionName === 'changeStyle') {
-                       window.location.reload();
-                       return;
-               }
-               
-               this._dialog.html(data.returnValues.template);
-               this._dialog.find('li').addClass('pointer').click($.proxy(this._click, this));
-               
-               this._showDialog(null);
-       },
-       
-       /**
-        * Changes user style.
-        * 
-        * @param       object          event
-        */
-       _click: function(event) {
-               this._proxy.setOption('data', {
-                       actionName: 'changeStyle',
-                       className: 'wcf\\data\\style\\StyleAction',
-                       objectIDs: [ $(event.currentTarget).data('styleID') ]
-               });
-               this._proxy.sendRequest();
-       }
-});
-
 /**
  * Converts static user panel items into interactive dropdowns.
  * 
index 764a27c4b35d01c10dc453f1f9de0d4deab70b3a..024ea6dd74abf5ddc97f01baffa6af38de3820b2 100644 (file)
@@ -6,7 +6,7 @@
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @module     WoltLab/WCF/BootstrapFrontend
  */
-define(['WoltLab/WCF/Bootstrap', 'WoltLab/WCF/Controller/Sitemap'], function(Bootstrap, ControllerSitemap) {
+define(['WoltLab/WCF/Bootstrap', 'WoltLab/WCF/Controller/Sitemap', 'WoltLab/WCF/Controller/Style/Changer'], function(Bootstrap, ControllerSitemap, ControllerStyleChanger) {
        "use strict";
        
        /**
@@ -16,12 +16,19 @@ define(['WoltLab/WCF/Bootstrap', 'WoltLab/WCF/Controller/Sitemap'], function(Boo
        BootstrapFrontend.prototype = {
                /**
                 * Bootstraps general modules and frontend exclusive ones.
+                * 
+                * @param       {object<string, *>}     options         bootstrap options
                 */
-               setup: function() {
+               setup: function(options) {
                        Bootstrap.setup();
+                       
                        ControllerSitemap.setup();
+                       
+                       if (options.styleChanger) {
+                               ControllerStyleChanger.setup();
+                       }
                }
        };
        
        return new BootstrapFrontend();
-});
\ No newline at end of file
+});
diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Controller/Style/Changer.js b/wcfsetup/install/files/js/WoltLab/WCF/Controller/Style/Changer.js
new file mode 100644 (file)
index 0000000..000b59d
--- /dev/null
@@ -0,0 +1,95 @@
+/**
+ * Dialog based style changer.
+ * 
+ * @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/Style/Changer
+ */
+define(['UI/Dialog'], function(UIDialog) {
+       "use strict";
+       
+       /**
+        * @constructor
+        */
+       function ControllerStyleChanger() {};
+       ControllerStyleChanger.prototype = {
+               /**
+                * Adds the style changer to the bottom navigation.
+                */
+               setup: function() {
+                       var list = document.querySelector('#footerNavigation > ul.navigationItems');
+                       if (list === null) {
+                               return;
+                       }
+                       
+                       var listItem = document.createElement('li');
+                       listItem.classList.add('styleChanger');
+                       listItem.addEventListener('click', this.showDialog.bind(this));
+                       
+                       var link = document.createElement('a');
+                       link.setAttribute('href', '#');
+                       link.textContent = WCF.Language.get('wcf.style.changeStyle');
+                       listItem.appendChild(link);
+                       
+                       list.appendChild(listItem);
+               },
+               
+               /**
+                * Loads and displays the style change dialog.
+                * 
+                * @param       {object}        event   event object
+                */
+               showDialog: function(event) {
+                       event.preventDefault();
+                       
+                       if (UIDialog.getDialog('styleChanger') === null) {
+                               new WCF.Action.Proxy({
+                                       autoSend: true,
+                                       data: {
+                                               actionName: 'getStyleChooser',
+                                               className: 'wcf\\data\\style\\StyleAction'
+                                       },
+                                       success: (function(data) {
+                                               var dialog = UIDialog.open('styleChanger', data.returnValues.template, {
+                                                       disableContentPadding: true,
+                                                       title: WCF.Language.get('wcf.style.changeStyle')
+                                               });
+                                               
+                                               var styles = dialog.content.querySelectorAll('.styleList > li');
+                                               for (var i = 0, length = styles.length; i < length; i++) {
+                                                       var style = styles[i];
+                                                       
+                                                       style.classList.add('pointer');
+                                                       style.addEventListener('click', this._click.bind(this));
+                                               }
+                                       }).bind(this)
+                               });
+                       }
+                       else {
+                               UIDialog.open('styleChanger');
+                       }
+               },
+               
+               /**
+                * Changes the style and reloads current page.
+                * 
+                * @param       {object}        event   event object
+                */
+               _click: function(event) {
+                       event.preventDefault();
+                       
+                       new WCF.Action.Proxy({
+                               autoSend: true,
+                               data: {
+                                       actionName: 'changeStyle',
+                                       className: 'wcf\\data\\style\\StyleAction',
+                                       objectIDs: [ event.currentTarget.getAttribute('data-style-id') ]
+                               },
+                               success: function() { window.location.reload(); }
+                       });
+               }
+       };
+       
+       return new ControllerStyleChanger();
+});
index f2e005f06390753d58a363c2809ecf223d136424..057b2cc915bb57d6f894e5af547223c0597f9be5 100644 (file)
@@ -22,7 +22,6 @@ define(['Dictionary', 'DOM/Util', './TabMenu/Simple'], function(Dictionary, DOMU
                setup: function() {
                        this._init();
                        
-                       // TODO: use WCF.DOMNodeInsertedHandler
                        WCF.DOMNodeInsertedHandler.addCallback('WoltLab/WCF/UI/TabMenu', this._init.bind(this));
                },