xfrocks
Well-known member
Hi there,
I'm currently working on an add-on and I tried to use the XenForo.AutoInlineUploader. It's great! But there is one small problem with it: it doesn't support multiple file inputs very well. Let say I have 2 file inputs in my form, after the first inline upload, there will be 4 file inputs, after another upload, there will be 16 file inputs (because the replaceAll replace each file input with 2 file inputs, doh!).
I have worked through the problem so I'm just asking you guys to implement it in the next version of XenForo. Please do this... (otherwise I will have to remove the awesome inline upload feature or I will have to manually edit every upgrade). Here is the changed version (very little changes but it's hard to point them individually, I highlighted the changed lines)
Thank you very much!
I'm currently working on an add-on and I tried to use the XenForo.AutoInlineUploader. It's great! But there is one small problem with it: it doesn't support multiple file inputs very well. Let say I have 2 file inputs in my form, after the first inline upload, there will be 4 file inputs, after another upload, there will be 16 file inputs (because the replaceAll replace each file input with 2 file inputs, doh!).
I have worked through the problem so I'm just asking you guys to implement it in the next version of XenForo. Please do this... (otherwise I will have to remove the awesome inline upload feature or I will have to manually edit every upgrade). Here is the changed version (very little changes but it's hard to point them individually, I highlighted the changed lines)
Rich (BB code):
XenForo.AutoInlineUploader = function($form)
{
/**
* Fires when the contents of an input:file change.
* Submits the form into a temporary iframe.
*
* @param event e
*/
var $uploader = $form.find('input:file').each(function(){
var $target = $(this);
$target.change(function(e)
{
if ($(e.target).val() != '')
{
var $iframe,
$hiddenInput;
$iframe = $('<iframe src="about:blank" style="display:none; background-color: white" name="AutoInlineUploader"></iframe>')
.insertAfter($(e.target))
.load(function(e)
{
var $iframe = $(e.target),
ajaxData = $iframe.contents().text(),
eComplete = null;
// Opera fires this function when it's not done with no data
if (!ajaxData)
{
return false;
}
// alert the global progress indicator that the transfer is complete
$(document).trigger('PseudoAjaxStop');
$uploader = $uploaderOrig.clone(true).replaceAll($target);
// removing the iframe after a delay to prevent Firefox' progress indicator staying active
setTimeout(function() { $iframe.remove(); }, 500);
try
{
ajaxData = $.parseJSON(ajaxData);
console.info('Inline file upload completed successfully. Data: %o', ajaxData);
}
catch(e)
{
console.error(ajaxData);
return false;
}
if (XenForo.hasResponseError(ajaxData))
{
return false;
}
$('input:submit', this.$form).removeAttr('disabled');
eComplete = new $.Event('AutoInlineUploadComplete');
eComplete.$form = $form;
eComplete.ajaxData = ajaxData;
$form.trigger(eComplete);
console.log(ajaxData);
if (!eComplete.isDefaultPrevented() && ajaxData.message)
{
XenForo.alert(ajaxData.message, '', 2500);
}
});
(removed for easy reading)
}
});
var $uploaderOrig = $target.clone(true);
});
};
Thank you very much!
Upvote
3