From f5885eb2e46530678df20cbca2603ff202b4231a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joshua=20R=C3=BCsweg?= Date: Tue, 9 Apr 2019 20:12:12 +0200 Subject: [PATCH] Add missing support for JS loaded content in WCF.InlineEditor --- wcfsetup/install/files/js/WCF.js | 69 ++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index cf0ef7d57c..f49a57435e 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -5421,44 +5421,40 @@ WCF.InlineEditor = Class.extend({ */ _updateData: [ ], + /** + * element selector + * @var string + */ + _elementSelector: null, + + /** + * quick option for the inline editor + * @var string + */ + _quickOption: null, + /** * Initializes a new inline editor. */ init: function(elementSelector) { + this._elementSelector = elementSelector; + var $elements = $(elementSelector); if (!$elements.length) { return; } this._setOptions(); - var $quickOption = ''; for (var $i = 0, $length = this._options.length; $i < $length; $i++) { if (this._options[$i].isQuickOption) { - $quickOption = this._options[$i].optionName; + this._quickOption = this._options[$i].optionName; break; } } - var self = this; - $elements.each(function(index, element) { - var $element = $(element); - var $elementID = $element.wcfIdentify(); - - // find trigger element - var $trigger = self._getTriggerElement($element); - if ($trigger === null || $trigger.length !== 1) { - return; - } - - $trigger.on(WCF_CLICK_EVENT, $.proxy(self._show, self)).data('elementID', $elementID); - if ($quickOption) { - // simulate click on target action - $trigger.disableSelection().data('optionName', $quickOption).dblclick($.proxy(self._click, self)); - } - - // store reference - self._elements[$elementID] = $element; - }); + this.rebuild(); + + WCF.DOMNodeInsertedHandler.addCallback('WCF.InlineEditor' + this._elementSelector.hashCode(), $.proxy(this.rebuild, this)); this._proxy = new WCF.Action.Proxy({ success: $.proxy(this._success, this) @@ -5469,6 +5465,35 @@ WCF.InlineEditor = Class.extend({ this._notification = new WCF.System.Notification(WCF.Language.get('wcf.global.success'), 'success'); }, + /** + * Identify new elements and adds the event listeners to them. + */ + rebuild: function() { + var $elements = $(this._elementSelector); + var self = this; + $elements.each(function (index, element) { + var $element = $(element); + var $elementID = $element.wcfIdentify(); + + if (self._elements[$elementID] === undefined) { + // find trigger element + var $trigger = self._getTriggerElement($element); + if ($trigger === null || $trigger.length !== 1) { + return; + } + + $trigger.on(WCF_CLICK_EVENT, $.proxy(self._show, self)).data('elementID', $elementID); + if (this._quickOption) { + // simulate click on target action + $trigger.disableSelection().data('optionName', $quickOption).dblclick($.proxy(self._click, self)); + } + + // store reference + self._elements[$elementID] = $element; + } + }); + }, + /** * Closes all inline editors. */ -- 2.20.1