file-attach: Reset file_input after each trigger.

The file input used for attaching files and images was not being reset
after each use. This resulted in irregular behaviour (sometimes failure)
in attaching the same file consecutively.
This fixes the bug in the reset method.

Fixes #5074.
This commit is contained in:
Tejas Kasetty 2017-06-04 17:40:14 +05:30 committed by Tim Abbott
parent ec673c739c
commit 4487899099
1 changed files with 7 additions and 4 deletions

View File

@ -17,7 +17,7 @@ exports.all_everyone_warn_threshold = 15;
var uploads_domain = document.location.protocol + '//' + document.location.host;
var uploads_path = '/user_uploads';
var uploads_re = new RegExp("\\]\\(" + uploads_domain + "(" + uploads_path + "[^\\)]+)\\)", 'g');
var clone_file_input;
function make_upload_absolute(uri) {
if (uri.indexOf(uploads_path) === 0) {
// Rewrite the URI to a usable link
@ -34,9 +34,9 @@ function make_uploads_relative(content) {
// This function resets an input type="file". Pass in the
// jquery object.
function clear_out_file_list(jq_file_list) {
var clone_for_ie_sake = jq_file_list.clone(true);
jq_file_list.replaceWith(clone_for_ie_sake);
if (clone_file_input !== undefined) {
jq_file_list.replaceWith(clone_file_input.clone(true));
}
// Hack explanation:
// IE won't let you do this (untested, but so says StackOverflow):
// $("#file_input").val("");
@ -745,6 +745,9 @@ $(function () {
$("#compose").on("click", "#attach_files", function (e) {
e.preventDefault();
if (clone_file_input === undefined) {
clone_file_input = $('#file_input').clone(true);
}
$("#compose #file_input").trigger("click");
} );