diff options
author | Matt Friedman <maf675@gmail.com> | 2013-10-29 19:12:32 -0700 |
---|---|---|
committer | Matt Friedman <maf675@gmail.com> | 2013-10-29 19:12:32 -0700 |
commit | 16213c92fe71cb1029bdac3b797529c6c74f6e96 (patch) | |
tree | 2256b3b880d113b814cd8c8b42b415dd407f0ef1 /phpBB/assets | |
parent | 67beb97efec06c4a663c7eec8d54ab3194744f83 (diff) | |
parent | 2f1cf0d287f416f1c3b388d5d3e68d897f226aaf (diff) | |
download | forums-16213c92fe71cb1029bdac3b797529c6c74f6e96.tar forums-16213c92fe71cb1029bdac3b797529c6c74f6e96.tar.gz forums-16213c92fe71cb1029bdac3b797529c6c74f6e96.tar.bz2 forums-16213c92fe71cb1029bdac3b797529c6c74f6e96.tar.xz forums-16213c92fe71cb1029bdac3b797529c6c74f6e96.zip |
[ticket/11935] Merge remote-tracking branch 'upstream/develop'
PHPBB3-11935
Diffstat (limited to 'phpBB/assets')
-rw-r--r-- | phpBB/assets/javascript/core.js | 138 | ||||
-rw-r--r-- | phpBB/assets/javascript/plupload.js | 63 |
2 files changed, 179 insertions, 22 deletions
diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index ab0891e70c..efb945a117 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -27,12 +27,12 @@ phpbb.loadingAlert = function() { } else { loadingAlert.show(); dark.fadeIn(phpbb.alertTime, function() { - // Wait five seconds and display an error if nothing has been returned by then. + // Wait fifteen seconds and display an error if nothing has been returned by then. phpbbAlertTimer = setTimeout(function() { if (loadingAlert.is(':visible')) { phpbb.alert($('#phpbb_alert').attr('data-l-err'), $('#phpbb_alert').attr('data-l-timeout-processing-req')); } - }, 5000); + }, 15000); }); } @@ -830,12 +830,146 @@ phpbb.applyCodeEditor = function(textarea) { }; /** +* List of classes that toggle dropdown menu, +* list of classes that contain visible dropdown menu +* +* Add your own classes to strings with comma (probably you +* will never need to do that) +*/ +phpbb.dropdownHandles = '.dropdown-container.dropdown-visible .dropdown-toggle'; +phpbb.dropdownVisibleContainers = '.dropdown-container.dropdown-visible'; + +/** +* Dropdown toggle event handler +* This handler is used by phpBB.registerDropdown() and other functions +*/ +phpbb.toggleDropdown = function() { + var $this = $(this), + options = $this.data('dropdown-options'), + parent = options.parent, + visible = parent.hasClass('dropdown-visible'); + + if (!visible) { + // Hide other dropdown menus + $(phpbb.dropdownHandles).each(phpbb.toggleDropdown); + + // Figure out direction of dropdown + var direction = options.direction, + verticalDirection = options.verticalDirection, + offset = $this.offset(); + + if (direction == 'auto') { + if (($(window).width() - $this.outerWidth(true)) / 2 > offset.left) { + direction = 'right'; + } + else { + direction = 'left'; + } + } + parent.toggleClass(options.leftClass, direction == 'left').toggleClass(options.rightClass, direction == 'right'); + + if (verticalDirection == 'auto') { + var height = $(window).height(), + top = offset.top - $(window).scrollTop(); + + if (top < height * 0.7) { + verticalDirection = 'down'; + } + else { + verticalDirection = 'up'; + } + } + parent.toggleClass(options.upClass, verticalDirection == 'up').toggleClass(options.downClass, verticalDirection == 'down'); + } + + options.dropdown.toggle(); + parent.toggleClass(options.visibleClass, !visible).toggleClass('dropdown-visible', !visible); + + // Check dimensions when showing dropdown + // !visible because variable shows state of dropdown before it was toggled + if (!visible) { + options.dropdown.find('.dropdown-contents').each(function() { + var $this = $(this), + windowWidth = $(window).width(); + + $this.css({ + marginLeft: 0, + left: 0, + maxWidth: (windowWidth - 4) + 'px' + }); + + var offset = $this.offset().left, + width = $this.outerWidth(true); + + if (offset < 2) { + $this.css('left', (2 - offset) + 'px'); + } + else if ((offset + width + 2) > windowWidth) { + $this.css('margin-left', (windowWidth - offset - width - 2) + 'px'); + } + }); + } + + // Prevent event propagation + if (arguments.length > 0) { + try { + var e = arguments[0]; + e.preventDefault(); + e.stopPropagation(); + } + catch (error) { } + } + return false; +}; + +/** +* Register dropdown menu +* Shows/hides dropdown, decides which side to open to +* +* @param {jQuery} toggle Link that toggles dropdown. +* @param {jQuery} dropdown Dropdown menu. +* @param {Object} options List of options. Optional. +*/ +phpbb.registerDropdown = function(toggle, dropdown, options) +{ + var ops = { + parent: toggle.parent(), // Parent item to add classes to + direction: 'auto', // Direction of dropdown menu. Possible values: auto, left, right + verticalDirection: 'auto', // Vertical direction. Possible values: auto, up, down + visibleClass: 'visible', // Class to add to parent item when dropdown is visible + leftClass: 'dropdown-left', // Class to add to parent item when dropdown opens to left side + rightClass: 'dropdown-right', // Class to add to parent item when dropdown opens to right side + upClass: 'dropdown-up', // Class to add to parent item when dropdown opens above menu item + downClass: 'dropdown-down' // Class to add to parent item when dropdown opens below menu item + }; + if (options) { + ops = $.extend(ops, options); + } + ops.dropdown = dropdown; + + ops.parent.addClass('dropdown-container'); + toggle.addClass('dropdown-toggle'); + + toggle.data('dropdown-options', ops); + + toggle.click(phpbb.toggleDropdown); +}; + +/** * Apply code editor to all textarea elements with data-bbcode attribute */ $(document).ready(function() { $('textarea[data-bbcode]').each(function() { phpbb.applyCodeEditor(this); }); + + // Hide active dropdowns when click event happens outside + $('body').click(function(e) { + var parents = $(e.target).parents(); + if (!parents.is(phpbb.dropdownVisibleContainers)) { + $(phpbb.dropdownHandles).each(phpbb.toggleDropdown); + } + }); }); })(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/assets/javascript/plupload.js b/phpBB/assets/javascript/plupload.js index 32ff178896..1befb88eb6 100644 --- a/phpBB/assets/javascript/plupload.js +++ b/phpBB/assets/javascript/plupload.js @@ -62,6 +62,47 @@ function phpbb_plupload_clear_params(obj) { } } +/** + * Update hidden attachment inputs in posting form + * Pre-existing hidden inputs will be removed by comparing the old attachment + * data (old_data) to the new attachment data (data) that has been sent back + * by plupload. + * + * @param object form Posting form + * @param object data Current attachment_data + * @param object old_date Previous attachment_data (before submission) + * + * @return void + */ +phpbb.update_hidden_attachment_inputs = function(form, data, old_data) { + // Update already existing hidden inputs + for (var i = 0; i < form.length; i++) { + if (data.hasOwnProperty(form[i].name)) { + form[i].value = data[form[i].name]; + delete data[form[i].name]; + } else if (typeof old_data !== 'undefined' && old_data.hasOwnProperty(form[i].name)) { + var inputRegex = /\b^[a-z_]+[+[0-9]+]/; + var inputName = inputRegex.exec(form[i].name); + if (typeof inputName !== 'undefined' && inputName[0] !== '') { + $("input[type='hidden'][name^='" + inputName[0] + "']").remove(); + } + } + } + + // Append new inputs + for (var key in data) { + if (!data.hasOwnProperty(key)) { + continue; + } + + var input = $('<input />') + .attr('type', 'hidden') + .attr('name', key) + .attr('value', data[key]); + $(form).append(input); + } +} + jQuery(function($) { $(phpbb.plupload.config.element_hook).pluploadQueue(phpbb.plupload.config); var uploader = $(phpbb.plupload.config.element_hook).pluploadQueue(); @@ -208,26 +249,7 @@ jQuery(function($) { var form = $(phpbb.plupload.config.form_hook)[0]; var data = phpbb_plupload_attachment_data_serialize(); - // Update already existing hidden inputs - for (var i = 0; i < form.length; i++) { - if (data.hasOwnProperty(form[i].name)) { - form[i].value = data[form[i].name]; - delete data[form[i].name]; - } - } - - // Append new inputs - for (var key in data) { - if (!data.hasOwnProperty(key)) { - continue; - } - - var input = $('<input />') - .attr('type', 'hidden') - .attr('name', key) - .attr('value', data[key]); - $(form).append(input); - } + phpbb.update_hidden_attachment_inputs(form, data); files.forEach(function(file) { if (file.status !== plupload.DONE) { @@ -257,6 +279,7 @@ jQuery(function($) { var done = function(response) { up.removeFile(file); plupload.attachment_data = response; + phpbb.update_hidden_attachment_inputs(form, phpbb_plupload_attachment_data_serialize(), data); phpbb_plupload_clear_params(up.settings.multipart_params); up.settings.multipart_params = $.extend( up.settings.multipart_params, |