From: Alexander Ebert Date: Sat, 17 Mar 2018 22:57:57 +0000 (+0100) Subject: Merge remote-tracking branch 'refs/remotes/origin/3.0' X-Git-Tag: 3.1.2~66 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=36c0379ace42ab9831fee857219387e281ea9ad6;p=GitHub%2FWoltLab%2FWCF.git Merge remote-tracking branch 'refs/remotes/origin/3.0' # Conflicts: # wcfsetup/install/files/js/WCF.Poll.js --- 36c0379ace42ab9831fee857219387e281ea9ad6 diff --cc wcfsetup/install/files/js/WCF.Poll.js index e5b6edada2,b37d25dbcc..e8cdb276eb --- a/wcfsetup/install/files/js/WCF.Poll.js +++ b/wcfsetup/install/files/js/WCF.Poll.js @@@ -9,259 -9,227 +9,261 @@@ */ WCF.Poll = { }; -/** - * Handles poll option management. - * - * @param string containerID - * @param array optionList - */ -WCF.Poll.Management = Class.extend({ - /** - * container object - * @var jQuery - */ - _container: null, - - /** - * number of options - * @var int - */ - _count: 0, - +if (COMPILER_TARGET_DEFAULT) { /** - * editor element id - * @var string + * Handles poll option management. + * + * @param string containerID + * @param array optionList */ - _editorId: '', - - /** - * maximum allowed number of options - * @var int - */ - _maxOptions: 0, - - /** - * Initializes the WCF.Poll.Management class. - * - * @param {string} containerID - * @param {Object[]} optionList - * @param {int} maxOptions - * @param {string} editorId - */ - init: function(containerID, optionList, maxOptions, editorId) { - this._count = 0; - this._maxOptions = maxOptions || -1; - this._container = $('#' + containerID).children('ol:eq(0)'); - if (!this._container.length) { - console.debug("[WCF.Poll.Management] Invalid container id given, aborting."); - return; - } + WCF.Poll.Management = Class.extend({ + /** + * container object + * @var jQuery + */ + _container: null, - optionList = optionList || []; - this._createOptionList(optionList); + /** + * number of options + * @var int + */ + _count: 0, - // bind event listener - if (editorId) { - this._editorId = editorId; - - WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'reset_' + editorId, this._reset.bind(this)); - WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'submit_' + editorId, this._submit.bind(this)); - WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'validate_' + editorId, this._validate.bind(this)); - } - else { - this._container.closest('form').submit($.proxy(this._submit, this)); - } + /** + * editor element id + * @var string + */ + _editorId: '', - // init sorting - require(['WoltLabSuite/Core/Ui/Sortable/List'], function (UiSortableList) { - new UiSortableList({ - containerId: containerID, - options: { - toleranceElement: '> div' - } - }); - }); - }, - - /** - * Creates the option list on init. - * - * @param array optionList - */ - _createOptionList: function(optionList) { - for (var $i = 0, $length = optionList.length; $i < $length; $i++) { - var $option = optionList[$i]; - this._createOption($option.optionValue, $option.optionID); - } - - // add an empty option, unless it would exceed the limit - if (optionList.length < this._maxOptions) { - this._createOption(); - } - }, - - /** - * Creates a new option element. - * - * @param string optionValue - * @param integer optionID - * @param jQuery insertAfter - */ - _createOption: function(optionValue, optionID, insertAfter) { - optionValue = optionValue || ''; - optionID = parseInt(optionID) || 0; - insertAfter = insertAfter || null; + /** + * maximum allowed number of options + * @var int + */ + _maxOptions: 0, - var $listItem = $('
  • ').data('optionID', optionID); - if (insertAfter === null) { - $listItem.appendTo(this._container); - } - else { - $listItem.insertAfter(insertAfter); - } - - // insert buttons - var $container = $('
    ').appendTo($listItem); - $('').appendTo($container); - $('').click($.proxy(this._addOption, this)).appendTo($container); - $('').click($.proxy(this._removeOption, this)).appendTo($container); - - // insert input field - var $input = $('').keydown($.proxy(this._keyDown, this)).appendTo($container); - $input.click(function() { - // work-around for some weird focus issue on iOS/Android - if (document.activeElement !== this) { - this.focus(); + /** + * Initializes the WCF.Poll.Management class. + * + * @param {string} containerID + * @param {Object[]} optionList + * @param {int} maxOptions + * @param {string} editorId + */ + init: function (containerID, optionList, maxOptions, editorId) { + this._count = 0; + this._maxOptions = maxOptions || -1; + this._container = $('#' + containerID).children('ol:eq(0)'); + if (!this._container.length) { + console.debug("[WCF.Poll.Management] Invalid container id given, aborting."); + return; } - }); - - if (insertAfter !== null) { - $input.focus(); - } - - WCF.DOMNodeInsertedHandler.execute(); - - this._count++; - if (this._count === this._maxOptions) { - this._container.find('span.jsAddOption').removeClass('pointer').addClass('disabled'); - } - }, - - /** - * Handles key down events for option input field. - * - * @param object event - */ - _keyDown: function(event) { - // ignore every key except for [Enter] - if (event.which !== 13) { - return; - } - - $(event.currentTarget).parent().children('.jsAddOption').trigger('click'); + + optionList = optionList || []; + this._createOptionList(optionList); + + // bind event listener + if (editorId) { + this._editorId = editorId; + + WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'reset_' + editorId, this._reset.bind(this)); + WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'submit_' + editorId, this._submit.bind(this)); + WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'validate_' + editorId, this._validate.bind(this)); + } + else { + this._container.closest('form').submit($.proxy(this._submit, this)); + } + + // init sorting + require(['WoltLabSuite/Core/Ui/Sortable/List'], function (UiSortableList) { + new UiSortableList({ + containerId: containerID, + options: { + toleranceElement: '> div' + } + }); + }); + }, - event.preventDefault(); - }, - - /** - * Adds a new option after current one. - * - * @param object event - */ - _addOption: function(event) { - if (this._count === this._maxOptions) { - return false; - } + /** + * Creates the option list on init. + * + * @param array optionList + */ + _createOptionList: function (optionList) { + for (var $i = 0, $length = optionList.length; $i < $length; $i++) { + var $option = optionList[$i]; + this._createOption($option.optionValue, $option.optionID); + } + - // add empty option - this._createOption(); ++ // add an empty option, unless it would exceed the limit ++ if (optionList.length < this._maxOptions) { ++ this._createOption(); ++ } + }, - var $listItem = $(event.currentTarget).closest('li', this._container[0]); + /** + * Creates a new option element. + * + * @param string optionValue + * @param integer optionID + * @param jQuery insertAfter + */ + _createOption: function (optionValue, optionID, insertAfter) { + optionValue = optionValue || ''; + optionID = parseInt(optionID) || 0; + insertAfter = insertAfter || null; + + var $listItem = $('
  • ').data('optionID', optionID); + if (insertAfter === null) { + $listItem.appendTo(this._container); + } + else { + $listItem.insertAfter(insertAfter); + } + + // insert buttons + var $container = $('
    ').appendTo($listItem); + $('').appendTo($container); + $('').click($.proxy(this._addOption, this)).appendTo($container); + $('').click($.proxy(this._removeOption, this)).appendTo($container); + + // insert input field + var $input = $('').keydown($.proxy(this._keyDown, this)).appendTo($container); + $input.click(function () { + // work-around for some weird focus issue on iOS/Android + if (document.activeElement !== this) { + this.focus(); + } + }); + + if (insertAfter !== null) { + $input.focus(); + } + + WCF.DOMNodeInsertedHandler.execute(); + + this._count++; + if (this._count === this._maxOptions) { + this._container.find('span.jsAddOption').removeClass('pointer').addClass('disabled'); + } + }, - this._createOption(undefined, undefined, $listItem); - }, - - /** - * Removes an option. - * - * @param object event - */ - _removeOption: function(event) { - $(event.currentTarget).closest('li', this._container[0]).remove(); + /** + * Handles key down events for option input field. + * + * @param object event + */ + _keyDown: function (event) { + // ignore every key except for [Enter] + if (event.which !== 13) { + return; + } + + $(event.currentTarget).parent().children('.jsAddOption').trigger('click'); + + event.preventDefault(); + }, - this._count--; - this._container.find('span.jsAddOption').addClass('pointer').removeClass('disabled'); + /** + * Adds a new option after current one. + * + * @param object event + */ + _addOption: function (event) { + if (this._count === this._maxOptions) { + return false; + } + + var $listItem = $(event.currentTarget).closest('li', this._container[0]); + + this._createOption(undefined, undefined, $listItem); + }, - if (this._container.children('li').length == 0) { - this._createOption(); - } - }, - - /** - * Inserts hidden input elements storing the option values. - * - * @param {(Event|Object)} event - */ - _submit: function(event) { - var $options = []; - this._container.children('li').each(function (index, listItem) { - var $listItem = $(listItem); - var $optionValue = $.trim($listItem.find('input').val()); + /** + * Removes an option. + * + * @param object event + */ + _removeOption: function (event) { + $(event.currentTarget).closest('li', this._container[0]).remove(); - // ignore empty values - if ($optionValue != '') { - $options.push($listItem.data('optionID') + '_' + $optionValue); + this._count--; + this._container.find('span.jsAddOption').addClass('pointer').removeClass('disabled'); + + if (this._container.children('li').length == 0) { + this._createOption(); } - }); + }, - if (typeof event.originalEvent === 'object' && event.originalEvent instanceof Event) { - // create hidden input fields - if ($options.length) { - var $formSubmit = this._container.parents('form').find('.formSubmit'); + /** + * Inserts hidden input elements storing the option values. + * + * @param {(Event|Object)} event + */ + _submit: function (event) { + var $options = []; + this._container.children('li').each(function (index, listItem) { + var $listItem = $(listItem); + var $optionValue = $.trim($listItem.find('input').val()); - for (var $i = 0, $length = $options.length; $i < $length; $i++) { - $('').val($options[$i]).appendTo($formSubmit); + // ignore empty values + if ($optionValue != '') { + $options.push($listItem.data('optionID') + '_' + $optionValue); + } + }); + + if (typeof event.originalEvent === 'object' && event.originalEvent instanceof Event) { + // create hidden input fields + if ($options.length) { + var $formSubmit = this._container.parents('form').find('.formSubmit'); + + for (var $i = 0, $length = $options.length; $i < $length; $i++) { + $('').val($options[$i]).appendTo($formSubmit); + } } } - } - else { - event.poll = { pollOptions: $options }; + else { + event.poll = {pollOptions: $options}; + + // get form input fields + var parentContainer = this._container.parents('.messageTabMenuContent:eq(0)'); + parentContainer.find('input').each(function (index, input) { + if (input.name) { + if (input.type !== 'checkbox' || input.checked) { + event.poll[input.name] = input.value; + } + } + }); + } + }, + + /** + * Resets the poll option form. + * + * @private + */ + _reset: function () { + // reset options + /** @type Element */ + var container = this._container[0]; + while (container.childElementCount > 1) { + container.removeChild(container.children[1]); + } + + elBySel('input', container.children[0]).value = ''; - // get form input fields + // reset input fields and checkboxes var parentContainer = this._container.parents('.messageTabMenuContent:eq(0)'); - parentContainer.find('input').each(function(index, input) { + parentContainer.find('input').each(function (index, input) { if (input.name) { - if (input.type !== 'checkbox' || input.checked) { - event.poll[input.name] = input.value; + if (input.type === 'checkbox') { + input.checked = false; + } + else if (input.type === 'text') { + input.value = ''; + } + else if (input.type === 'number') { + input.value = input.min; } } });