From 32a9e8a4eb600d5f41b8c8bcdf634c4fd7209a8e Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 25 Dec 2011 11:53:50 +0100 Subject: [PATCH] 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. --- wcfsetup/install/files/js/WCF.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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)); } }; -- 2.20.1