From: Matthias Schmidt Date: Sun, 25 Dec 2011 10:53:50 +0000 (+0100) Subject: Adds an own button selector for toggle actions X-Git-Tag: 2.0.0_Beta_1~1456^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=32a9e8a4eb600d5f41b8c8bcdf634c4fd7209a8e;p=GitHub%2FWoltLab%2FWCF.git Adds an own button selector for toggle actions If you have nested containers, the simple selector for the toggle buttons doesn't work anymore since it selects all toggle buttons, also the ones from nested containers, though it should only select the toggle button of the parent container. With an own selector you're able to select the button of each parent container only - without an restriction of how you nest the containers. --- diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 5f0d942711..09c081502e 100644 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -1286,8 +1286,9 @@ WCF.Action.Delete.prototype = { * * @param string className * @param jQuery containerList + * @param string toggleButtonSelector */ -WCF.Action.Toggle = function(className, containerList) { this.init(className, containerList); }; +WCF.Action.Toggle = function(className, containerList, toggleButtonSelector) { this.init(className, containerList, toggleButtonSelector); }; WCF.Action.Toggle.prototype = { /** * Initializes 'toggle'-Proxy @@ -1295,11 +1296,16 @@ WCF.Action.Toggle.prototype = { * @param string className * @param jQuery containerList */ - init: function(className, containerList) { + init: function(className, containerList, toggleButtonSelector) { if (!containerList.length) return; this.containerList = containerList; this.className = className; + this.toggleButtonSelector = '.toggleButton'; + if (toggleButtonSelector) { + this.toggleButtonSelector = toggleButtonSelector; + } + // initialize proxy var options = { success: $.proxy(this._success, this) @@ -1308,7 +1314,7 @@ WCF.Action.Toggle.prototype = { // bind event listener this.containerList.each($.proxy(function(index, container) { - $(container).find('.toggleButton').bind('click', $.proxy(this._click, this)); + $(container).find(this.toggleButtonSelector).bind('click', $.proxy(this._click, this)); }, this)); }, @@ -1336,8 +1342,8 @@ WCF.Action.Toggle.prototype = { */ _success: function(data, textStatus, jqXHR) { // remove items - this.containerList.each(function(index, container) { - var $toggleButton = $(container).find('.toggleButton'); + this.containerList.each($.proxy(function(index, container) { + var $toggleButton = $(container).find(this.toggleButtonSelector); if (WCF.inArray($toggleButton.data('objectID'), data.objectIDs)) { $(container).wcfHighlight(); @@ -1360,7 +1366,7 @@ WCF.Action.Toggle.prototype = { } }); } - }); + }, this)); } };