From 92d6e80d57fa92217935cf66ff362f90ae6b6a67 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 8 May 2013 10:54:01 -0400 Subject: [PATCH] Fix bug with uploading the same file twice using the clip icon. See #1234 for details. When you upload files the old-school way (no drag&drop), there was a bug where you couldn't upload the same file twice, due to us intercepting the change event and not clearing out the file list when we were done. Tested on Chrome, but uses a known IE workaround. (imported from commit 8120c2e8bce41f3964f4f5c21aad3a85df0e433d) --- zephyr/static/js/compose.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/zephyr/static/js/compose.js b/zephyr/static/js/compose.js index ad5dd4d16a..cea0ab7570 100644 --- a/zephyr/static/js/compose.js +++ b/zephyr/static/js/compose.js @@ -5,6 +5,17 @@ var is_composing_message = false; var faded_to; var message_snapshot; +// 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); + + // Hack explanation: + // IE won't let you do this (untested, but so says StackOverflow): + // $("#file_input").val(""); +} + function show(tabname, focus_area) { if (tabname === "stream") { $('#private-message').hide(); @@ -623,6 +634,12 @@ $(function () { $("#compose-send-button").removeAttr("disabled"); $("#send-status").removeClass("alert-info") .hide(); + + // In order to upload the same file twice in a row, we need to clear out + // the #file_input element, so that the next time we use the file dialog, + // an actual change event is fired. This is extracted to a function + // to abstract away some IE hacks. + clear_out_file_list($("#file_input")); }, rawDrop: function (contents) { var textbox = $("#new_message_content");