Commit 1766bc55 authored by Jean-Romain Prévost's avatar Jean-Romain Prévost Committed by Felix Paul Kühne
Browse files

Fix before unload check

parent ad8767d9
...@@ -4,10 +4,10 @@ $(function(){ ...@@ -4,10 +4,10 @@ $(function(){
}); });
$(document).bind('dragover', function () { $(document).bind('dragover', function () {
$('.main').addClass('drop'); $('.main').addClass('drop');
}) });
$(document).bind('dragexit dragleave dragend drop', function () { $(document).bind('dragexit dragleave dragend drop', function () {
$('.main').removeClass('drop'); $('.main').removeClass('drop');
}) });
var fileupload = $('#fileupload').fileupload({ var fileupload = $('#fileupload').fileupload({
dataType: 'json', dataType: 'json',
...@@ -22,13 +22,11 @@ $(function(){ ...@@ -22,13 +22,11 @@ $(function(){
fileupload.bind('fileuploadprogress', progress); fileupload.bind('fileuploadprogress', progress);
$(window).bind('beforeunload', function (e) { $(window).bind('beforeunload', function (e) {
var confirmationMessage = null; if (xhrCache.length) {
var confirmationMessage = 'There are transfers in progress, navigating away will abort them.';
if ($('.uploads > ul > li').not('.done').not('.fail').length > 0) { (e || window.event).returnValue = confirmationMessage; // Gecko + IE
confirmationMessage = 'There are transfers in progress, navigating away will abort them.'; return confirmationMessage; // Webkit, Safari, Chrome etc.
} }
(e || window.event).returnValue = confirmationMessage; // Gecko + IE
return confirmationMessage; // Webkit, Safari, Chrome etc.
}); });
var xhrCache = []; var xhrCache = [];
...@@ -72,6 +70,7 @@ $(function(){ ...@@ -72,6 +70,7 @@ $(function(){
function done (e, data) { function done (e, data) {
$.each(data.files, function (index, file) { $.each(data.files, function (index, file) {
xhrCache.splice(file._ID, 1);
$('li[data-file-id=' + file._ID + ']').addClass('done'); $('li[data-file-id=' + file._ID + ']').addClass('done');
}); });
} }
...@@ -86,6 +85,7 @@ $(function(){ ...@@ -86,6 +85,7 @@ $(function(){
function fail (e, data) { function fail (e, data) {
console.log('File transfer failed', data.errorThrown, data.textStatus); console.log('File transfer failed', data.errorThrown, data.textStatus);
$.each(data.files, function (index, file) { $.each(data.files, function (index, file) {
xhrCache.splice(file._ID, 1);
$('li[data-file-id=' + file._ID + ']').addClass('fail'); $('li[data-file-id=' + file._ID + ']').addClass('fail');
}); });
} }
...@@ -96,6 +96,7 @@ $(function(){ ...@@ -96,6 +96,7 @@ $(function(){
var li = $(e.currentTarget).parent('li'); var li = $(e.currentTarget).parent('li');
var id = li.data('file-id'); var id = li.data('file-id');
xhrCache[id].abort(); xhrCache[id].abort();
xhrCache.splice(id, 1);
li.addClass('fail'); li.addClass('fail');
} }
}); });
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment