From e7f87db12640160452eb23fc7a70ff61098aaa56 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 18 Jan 2012 14:54:17 +0100 Subject: [PATCH] Prototype implementation for inline editors --- wcfsetup/install/files/js/WCF.js | 226 +++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index b17dbc11f0..f20de77230 100644 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -3402,6 +3402,232 @@ WCF.System.Notification = Class.extend({ } }); +/** + * Default implementation for inline editors. + */ +WCF.InlineEditor = Class.extend({ + /** + * list of registered callbacks + * @var array + */ + _callbacks: [ ], + + /** + * list of container elements + * @var object + */ + _elements: { }, + + /** + * list of dropdown selections + * @var object + */ + _dropdowns: { }, + + /** + * element jQuery selector + * @var string + */ + _elementSelector: '', + + /** + * list of known options + * @var array + */ + _options: [ ], + + /** + * action proxy + * @var WCF.Action.Proxy + */ + _proxy: null, + + /** + * Initializes a new inline editor. + */ + init: function() { + if (!this._elementSelector) { + return; + } + + var $elements = $(this._elementSelector); + if (!$elements.length) { + return; + } + + var self = this; + $elements.each(function(index, element) { + var $element = $(element); + var $elementID = $element.wcfIdentify(); + + // find trigger element + var $trigger = this._getTriggerElement($element); + if ($trigger === null || $trigger.length !== 1) { + return; + } + + $trigger.click(self._show).data('elementID', $elementID); + + // store reference + self._elements[$elementID] = $element; + }); + + this._proxy = new WCF.Action.Proxy({ + success: self._success + }); + }, + + /** + * 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) { + var $elementID = $(event.currentTarget).data('elementID'); + + // build drop down + if (!this._dropdowns[$elementID]) { + this._elements[$elementID].wrap(''); + this._dropdowns[$elementID] = $('