From: Joshua Rüsweg Date: Fri, 12 Apr 2019 21:28:09 +0000 (+0200) Subject: Merge branch '3.0' into master X-Git-Tag: 5.2.0_Alpha_1~19^2~31 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1a4fbd62d38de27e3f97b14f283e70adc274a1c5;p=GitHub%2FWoltLab%2FWCF.git Merge branch '3.0' into master --- 1a4fbd62d38de27e3f97b14f283e70adc274a1c5 diff --cc tmp_WCF.InlineEditor.js index 0000000000,0000000000..1bf0b8e6af new file mode 100644 --- /dev/null +++ b/tmp_WCF.InlineEditor.js @@@ -1,0 -1,0 +1,342 @@@ ++/** ++ * Default implementation for inline editors. ++ * ++ * @param string elementSelector ++ */ ++WCF.InlineEditor = Class.extend({ ++ /** ++ * list of registered callbacks ++ * @var array ++ */ ++ _callbacks: [], ++ ++ /** ++ * list of dropdown selections ++ * @var object ++ */ ++ _dropdowns: {}, ++ ++ /** ++ * list of container elements ++ * @var object ++ */ ++ _elements: {}, ++ ++ /** ++ * notification object ++ * @var WCF.System.Notification ++ */ ++ _notification: null, ++ ++ /** ++ * list of known options ++ * @var array ++ */ ++ _options: [], ++ ++ /** ++ * action proxy ++ * @var WCF.Action.Proxy ++ */ ++ _proxy: null, ++ ++ /** ++ * list of trigger elements by element id ++ * @var object ++ */ ++ _triggerElements: {}, ++ ++ /** ++ * list of data to update upon success ++ * @var array ++ */ ++ _updateData: [], ++ ++ /** ++ * Initializes a new inline editor. ++ */ ++ init: function (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; ++ 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._proxy = new WCF.Action.Proxy({ ++ success: $.proxy(this._success, this) ++ }); ++ ++ WCF.CloseOverlayHandler.addCallback('WCF.InlineEditor', $.proxy(this._closeAll, this)); ++ ++ this._notification = new WCF.System.Notification(WCF.Language.get('wcf.global.success'), 'success'); ++ }, ++ ++ /** ++ * Closes all inline editors. ++ */ ++ _closeAll: function () { ++ for (var $elementID in this._elements) { ++ this._hide($elementID); ++ } ++ }, ++ ++ /** ++ * Sets options for this inline editor. ++ */ ++ _setOptions: function () { ++ this._options = []; ++ }, ++ ++ /** ++ * Register an option callback for validation and execution. ++ * ++ * @param object callback ++ */ ++ registerCallback: function (callback) { ++ if ($.isFunction(callback)) { ++ this._callbacks.push(callback); ++ } ++ }, ++ ++ /** ++ * Returns the triggering element. ++ * ++ * @param jQuery element ++ * @return jQuery ++ */ ++ _getTriggerElement: function (element) { ++ return null; ++ }, ++ ++ /** ++ * Shows a dropdown menu if options are available. ++ * ++ * @param object event ++ */ ++ _show: function (event) { ++ event.preventDefault(); ++ var $elementID = $(event.currentTarget).data('elementID'); ++ ++ // build dropdown ++ var $trigger = null; ++ if (!this._dropdowns[$elementID]) { ++ this._triggerElements[$elementID] = $trigger = this._getTriggerElement(this._elements[$elementID]).addClass('dropdownToggle'); ++ var parent = $trigger[0].parentNode; ++ if (parent && parent.nodeName === 'LI' && parent.childElementCount === 1) { ++ // do not add a wrapper element if the trigger is the only child ++ parent.classList.add('dropdown'); ++ } ++ else { ++ $trigger.wrap(''); ++ } ++ ++ this._dropdowns[$elementID] = $('