Skip to content

Instantly share code, notes, and snippets.

@h0jeZvgoxFepBQ2C
Created December 21, 2017 10:49
Show Gist options
  • Save h0jeZvgoxFepBQ2C/7dcbd62f74b697adf4d1094e6bd82e4d to your computer and use it in GitHub Desktop.
Save h0jeZvgoxFepBQ2C/7dcbd62f74b697adf4d1094e6bd82e4d to your computer and use it in GitHub Desktop.
$(function () {
$('#fileupload').fileupload({
dropzone: $("#fileupload"),
dataType: 'json',
add: function (e, data) {
data.context = $('<p/>').html(""+
"<div class='upload_item'> "+
" <div class='progress' style='margin-bottom:5px;'>"+
" <div class='bar' style='width: 0%'></div>"+
" </div>"+
" <div class='text'><i class='fa fa-spinner fa-spin'></i> Uploading \"" +
data.files[0].name +
"\"...</div>"+
"</div>").prependTo($("#upload_items"));
data.submit();
},
done: function (e, data) {
data.context.find('.text').html("<i class='fa fa-check'></i> Upload of \""+
data.files[0].name +
"\" finished.");
//setTimeout(function() {
// data.context.slideUp()
//}, 5000)
},
progress: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
console.log(progress)
data.context.find(".progress .bar").css(
'width',
progress + '%'
).text(progress + " %");
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
if(progress == 100)
window.location = window.location
}
});
$(document).bind('dragover', function (e) {
var dropZone = $('#dropzone'),
timeout = window.dropZoneTimeout;
if (!timeout) {
dropZone.addClass('in');
} else {
clearTimeout(timeout);
}
var found = false,
node = e.target;
do {
if (node === dropZone[0]) {
found = true;
break;
}
node = node.parentNode;
} while (node != null);
if (found) {
dropZone.addClass('hover');
} else {
dropZone.removeClass('hover');
}
window.dropZoneTimeout = setTimeout(function () {
window.dropZoneTimeout = null;
dropZone.removeClass('in hover');
}, 100);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment