From 6c181c87e8cb621e463c77d07d9fa7be399cbbd3 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 10 Nov 2011 03:07:18 +0100 Subject: [PATCH] Implemented persistent collapsible sidebar --- wcfsetup/install/files/js/WCF.js | 91 ++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index b6bda14825..576f2c40f5 100644 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -3062,6 +3062,97 @@ $.widget('ui.wcfSidebar', { } }); +/** + * Provides a toggleable sidebar with persistent visibility. + */ +$.widget('ui.wcfPersistentSidebar', $.ui.wcfSidebar, { + /** + * widget options + * @var object + */ + options: { + className: '', + collapsed: false, + objectTypeID: 0 + }, + + /** + * action proxy + * @var WCF.Action.Proxy + */ + _proxy: null, + + /** + * Creates a new toggleable sidebar. + */ + _create: function() { + if (this.options.className === '' || this.options.objectTypeID === 0) { + console.debug('[ui.wcfPersistentSidebar] Class name or object type id missing, aborting.'); + return; + } + + $.ui.dialog.prototype._init.apply(this, arguments); + + // collapse on init + if (this.options.collapsed) { + this.element.hide(); + this._visible = false; + } + + // init proxy + this._proxy = new WCF.Action.Proxy(); + }, + + /** + * Shows sidebar content. + */ + show: function() { + if (this._visible) { + return; + } + + $.ui.dialog.prototype._init.apply(this, arguments); + + // save state + this._save(); + }, + + /** + * Hides the sidebar content. + */ + hide: function() { + if (!this._visible) { + return; + } + + $.ui.dialog.prototype._init.apply(this, arguments); + + // save state + this._save(); + }, + + /** + * Save collapsible state + */ + _save: function() { + var $currentState = (!this._visible) ? 'close' : 'open'; + var $state = (this._visible) ? 'open' : 'close'; + + this._proxy.setOption('data', { + actionName: 'toggleSidebar', + className: this.options.className, + parameters: { + data: { + currentState: $currentState, + newState: $newState, + objectTypeID: this.options.objectTypeID + } + } + }); + this._proxy.sendRequest(); + } +}); + /** * Basic implementation for WCF dialogs. */ -- 2.20.1