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/javascript/plupload.js | |
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/javascript/plupload.js')
-rw-r--r-- | phpBB/assets/javascript/plupload.js | 63 |
1 files changed, 43 insertions, 20 deletions
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, |