Added prototype for WCF.Collapsible.Sidebar
authorAlexander Ebert <ebert@woltlab.com>
Mon, 22 Oct 2012 13:08:58 +0000 (15:08 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 22 Oct 2012 13:08:58 +0000 (15:08 +0200)
wcfsetup/install/files/js/WCF.js

index a86a5ebcf42206bcc7b4c2eb96d11f3dca1942c1..5f1839afc94502cbbe35741bc11fbd80df172763 100755 (executable)
@@ -3450,6 +3450,56 @@ WCF.Collapsible.SimpleRemote = WCF.Collapsible.Remote.extend({
        }
 });
 
+WCF.Collapsible.Sidebar = Class.extend({
+       _button: null,
+       _isOpen: false,
+       _proxy: null,
+       _sidebar: null,
+       _sidebarName: '',
+       
+       init: function() {
+               this._sidebar = $('.sidebar:eq(0)');
+               if (!this._sidebar.length) {
+                       console.debug("[WCF.Collapsible.Sidebar] Could not find sidebar, aborting.");
+                       return;
+               }
+               
+               this._isOpen = (this._sidebar.data('isOpen') === 'false') ? false : true;
+               this._sidebarName = this._sidebar.data('sidebarName');
+               
+               // add toggle button
+               this._button = $('<a class="collapsibleButton jsTooltip" title="' + WCF.Language.get('wcf.global.button.collapsible') + '" />').prependTo(this._sidebar);
+               this._button.click($.proxy(this._click, this));
+               
+               this._proxy = new WCF.Action.Proxy({
+                       url: 'index.php/CollapsibleSidebar/?t=' + SECURITY_TOKEN + SID_2ND
+               });
+               
+               this._renderSidebar();
+       },
+       
+       _click: function() {
+               this._isOpen = (this._isOpen) ? false : true;
+               
+               this._proxy.setOption('data', {
+                       isOpen: (this._isOpen ? 1 : 0),
+                       sidebarName: this._sidebarName
+               });
+               this._proxy.sendRequest();
+               
+               this._renderSidebar();
+       },
+       
+       _renderSidebar: function() {
+               if (this._isOpen) {
+                       this._sidebar.addClass('sidebarCollapsed');
+               }
+               else {
+                       this._sidebar.removeClass('sidebarCollapsed');
+               }
+       }
+});
+
 /**
  * Holds userdata of the current user
  */