From 168a9753893ce2f20f1aa46ec56f6f456a8fc8b5 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 22 Oct 2012 16:05:41 +0200 Subject: [PATCH] Supporting collapsible sidebar persistence --- wcfsetup/install/files/js/WCF.js | 40 ++++++++++++++++++- .../UserCollapsibleSidebarHandler.class.php | 37 +++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleSidebarHandler.class.php diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 3e7cfbd141..c8f722735d 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -3491,13 +3491,43 @@ WCF.Collapsible.SimpleRemote = WCF.Collapsible.Remote.extend({ } }); +/** + * Provides collapsible sidebars with persistency support. + */ WCF.Collapsible.Sidebar = Class.extend({ + /** + * trigger button object + * @var jQuery + */ _button: null, + + /** + * sidebar state + * @var boolean + */ _isOpen: false, + + /** + * action proxy + * @var WCF.Action.Proxy + */ _proxy: null, + + /** + * sidebar object + * @var jQuery + */ _sidebar: null, + + /** + * sidebar identifier + * @var string + */ _sidebarName: '', + /** + * Creates a new WCF.Collapsible.Sidebar object. + */ init: function() { this._sidebar = $('.sidebar:eq(0)'); if (!this._sidebar.length) { @@ -3513,16 +3543,21 @@ WCF.Collapsible.Sidebar = Class.extend({ this._button.click($.proxy(this._click, this)); this._proxy = new WCF.Action.Proxy({ - url: 'index.php/CollapsibleSidebar/?t=' + SECURITY_TOKEN + SID_2ND + url: 'index.php/AJAXInvoke/?t=' + SECURITY_TOKEN + SID_2ND }); this._renderSidebar(); }, + /** + * Handles clicks on the trigger button. + */ _click: function() { this._isOpen = (this._isOpen) ? false : true; this._proxy.setOption('data', { + actionName: 'toggle', + className: 'wcf\\system\\user\\collapsible\\content\\UserCollapsibleSidebarHandler', isOpen: (this._isOpen ? 1 : 0), sidebarName: this._sidebarName }); @@ -3531,6 +3566,9 @@ WCF.Collapsible.Sidebar = Class.extend({ this._renderSidebar(); }, + /** + * Renders the sidebar state. + */ _renderSidebar: function() { if (this._isOpen) { this._sidebar.addClass('sidebarCollapsed'); diff --git a/wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleSidebarHandler.class.php b/wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleSidebarHandler.class.php new file mode 100644 index 0000000000..8534fb0f8a --- /dev/null +++ b/wcfsetup/install/files/lib/system/user/collapsible/content/UserCollapsibleSidebarHandler.class.php @@ -0,0 +1,37 @@ + + * @package com.woltlab.wcf + * @subpackage system.user.collapsible.content + * @category Community Framework + */ +class UserCollapsibleSidebarHandler extends SingletonFactory implements IAJAXInvokeAction { + /** + * Toggles a sidebar. + */ + public function toggle() { + $isOpen = (isset($_POST['isOpen'])) ? intval($_POST['isOpen']) : 1; + $objectID = (isset($_POST['sidebarName'])) ? StringUtil::trim($_POST['sidebarName']) : ''; + if (empty($objectID)) { + throw new UserInputException('sidebarName'); + } + + $objectTypeID = UserCollapsibleContentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.collapsibleSidebar'); + if ($isOpen) { + UserCollapsibleContentHandler::getInstance()->markAsOpened($objectTypeID, $objectID); + } + else { + UserCollapsibleContentHandler::getInstance()->markAsCollapsed($objectTypeID, $objectID); + } + } +} -- 2.20.1