From 5dd8bc73eea34c8556ec693044d9153a59d729f2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Magnus=20K=C3=BChn?= Date: Wed, 2 Jan 2013 14:31:58 +0100 Subject: [PATCH] Changed WCF.Action.Toggle to work with inserted content --- wcfsetup/install/files/js/WCF.js | 61 +++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index ff6434b8a1..dbf722053d 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -1825,18 +1825,40 @@ WCF.Action.Delete = Class.extend({ * @param string toggleButtonSelector */ WCF.Action.Toggle = Class.extend({ + /** + * action class name + * @var string + */ + _className: '', + + /** + * container selector + * @var string + */ + _containerSelector: '', + + /** + * list of known container ids + * @var array + */ + _containers: [ ], + + /** + * toogle button selector + * @var string + */ + _toggleButtonSelector: '.jsToggleButton', + /** * Initializes 'toggle'-Proxy * * @param string className - * @param jQuery containerList + * @param string containerSelector + * @param string toggleButtonSelector */ - init: function(className, containerList, toggleButtonSelector) { - if (!containerList.length) return; - this.containerList = containerList; - this.className = className; - - this.toggleButtonSelector = '.jsToggleButton'; + init: function(className, containerSelector, toggleButtonSelector) { + this._containerSelector = containerSelector; + this._className = className; if (toggleButtonSelector) { this.toggleButtonSelector = toggleButtonSelector; } @@ -1848,8 +1870,21 @@ WCF.Action.Toggle = Class.extend({ this.proxy = new WCF.Action.Proxy(options); // bind event listener - this.containerList.each($.proxy(function(index, container) { - $(container).find(this.toggleButtonSelector).bind('click', $.proxy(this._click, this)); + WCF.DOMNodeInsertedHandler.addCallback('WCF.Action.Delete' + this._className.hashCode(), $.proxy(this._initElements, this)); + }, + + /** + * Initializes available element containers. + */ + _initElements: function() { + $(this._containerSelector).each($.proxy(function(index, container) { + var $container = $(container); + var $containerID = $container.wcfIdentify(); + + if (!WCF.inArray($containerID, this._containers)) { + this._containers.push($containerID); + $container.find('.jsDeleteButton').click($.proxy(this._click, this)); + } }, this)); }, @@ -1861,7 +1896,7 @@ WCF.Action.Toggle = Class.extend({ _click: function(event) { this.proxy.setOption('data', { actionName: 'toggle', - className: this.className, + className: this._className, interfaceName: 'wcf\\data\\IToggleAction', objectIDs: [ $(event.target).data('objectID') ] }); @@ -1886,14 +1921,14 @@ WCF.Action.Toggle = Class.extend({ * @param array objectIDs */ triggerEffect: function(objectIDs) { - this.containerList.each($.proxy(function(index, container) { - var $container = $(container); + for (var $index in this._containers) { + var $container = $('#' + this._containers[$index]); var $toggleButton = $container.find(this.toggleButtonSelector); if (WCF.inArray($toggleButton.data('objectID'), objectIDs)) { $container.wcfHighlight(); this._toggleButton($container, $toggleButton); } - }, this)); + } }, /** -- 2.20.1