From: Alexander Ebert Date: Mon, 26 Nov 2012 16:30:39 +0000 (+0100) Subject: Added abstract class for UserPanel items X-Git-Tag: 2.0.0_Beta_1~755^2~4 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=271dbf28a4d209548cc9837b4c254811c02efee1;p=GitHub%2FWoltLab%2FWCF.git Added abstract class for UserPanel items WCF.UserPanel supports the dynamic conversion from a static link into a dynamic dropdown menu with AJAX support. Using this class ensures that every menu item remains usable even if someone decides to cripple their browser with disabled JavaScript support. --- diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 6bb288df19..4d3f1b5928 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -7030,6 +7030,139 @@ WCF.Style.Chooser = Class.extend({ } }); +/** + * Converts static user panel items into interactive dropdowns. + * + * @param string containerID + */ +WCF.UserPanel = Class.extend({ + /** + * target container + * @var jQuery + */ + _container: null, + + /** + * initialization state + * @var boolean + */ + _didLoad: false, + + /** + * original link element + * @var jQuery + */ + _link: null, + + /** + * reverts to original link if return values are empty + * @var boolean + */ + _revertOnEmpty: true, + + /** + * Initialites the WCF.UserPanel class. + * + * @param string containerID + */ + init: function(containerID) { + this._container = $('#' + containerID); + this._didLoad = false; + this._revertOnEmpty = true; + + if (this._container.length != 1) { + console.debug("[WCF.UserPanel] Unable to find container identfied by '" + containerID + "', aborting."); + return; + } + + if (this._container.data('count')) { + this._convert(); + } + }, + + /** + * Converts link into an interactive dropdown menu. + */ + _convert: function() { + WCF.DOMNodeInsertedHandler.enable(); + + this._container.addClass('dropdown'); + this._link = this._container.children('a').remove(); + + $('' + this._link.html() + '').appendTo(this._container).click($.proxy(this._click, this)); + var $dropdownMenu = $('