Adds an own button selector for toggle actions
authorMatthias Schmidt <gravatronics@live.com>
Sun, 25 Dec 2011 10:53:50 +0000 (11:53 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 25 Dec 2011 10:53:50 +0000 (11:53 +0100)
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

index 5f0d94271171a96708abcaafc70f327784871ec5..09c081502eccbb59593bc7bc6eafbd2cb7e44c28 100644 (file)
@@ -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));
        }
 };