Created
November 16, 2011 12:50
-
-
Save bsodmike/1370006 to your computer and use it in GitHub Desktop.
Remove files from the plupload file 'Queue'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uploader.bind('FilesAdded', function(up, files) { | |
//console.log (up); | |
//console.log (files); | |
$.each(files, function(i, file) { | |
$('#filelist').append( | |
'<div id="' + file.id + '">' + | |
file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' + | |
'<a href="" class="remove btn error">X</a></div>' | |
); | |
$('#uploadfiles').css('display', 'initial'); | |
$('#filelist').append('<br/>'); | |
$('#' + file.id + ' a.remove').first().click(function(e) { | |
e.preventDefault(); | |
up.removeFile(file); | |
$('#' + file.id).next("br").remove(); | |
$('#' + file.id).remove(); | |
if (up.files.length == 0) { | |
$('#uploadfiles').css('display', 'none'); | |
} | |
}); | |
}); | |
}); | |
// When the file is uploaded, parse the response JSON and show that URL. | |
// | |
uploader.bind('FileUploaded', function(up, file, response){ | |
var json_response = JSON.parse( response.response ) | |
if (json_response.redirect) { | |
window.location = json_response.redirect; | |
} | |
else { | |
$("#"+file.id).addClass("uploaded").html('<strong>'+file.name+'</strong>'); | |
$("#"+file.id).append(' <span class="label success">Successfully uploaded!</span><br/><br/>'); | |
if (json_response.meta) { | |
$("#"+file.id).append('<div class="meta"></div>'); | |
$('div.meta').append('<ul></ul>'); | |
$('div.meta ul:only-child').append('<li>Link: <a href="'+json_response.url+'" target="_blank">'+file.name+'</a></li>'); | |
$('div.meta ul:only-child').append('<li>Server: '+json_response.meta.server+'</li>'); | |
$('div.meta ul:only-child').append('<li>Content Length: '+json_response.meta.content_length+' bytes</li>'); | |
$('div.meta ul:only-child').append('<li>Content Type: '+json_response.meta.content_type+'</li>'); | |
$('div.meta ul:only-child').append('<li>Last Updated: '+json_response.meta.last_updated+'</li>'); | |
} | |
$('#filelist').append( | |
'<p>' + | |
'<a href="/admin" class="btn primary">Return to Dashboard!</a>' + | |
'</p>'); | |
} | |
}); | |
// When the upload button is clicked, upload! | |
// | |
$('#uploadfiles').click(function(e) { | |
$('#filelist > div').children("a").remove(); | |
$('#pickfiles').remove(); | |
$('#uploadfiles').remove(); | |
uploader.start(); | |
e.preventDefault(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm disabling the
#uploadfiles
DOM button via