Created
August 2, 2011 13:53
-
-
Save oferreiro/1120225 to your computer and use it in GitHub Desktop.
plupload custom example
This file contains 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
//= require plupload/plupload | |
//= require plupload/plupload.html4 | |
//= require plupload/plupload.html5 | |
$(function(){ | |
var atoken = $("input[name=authenticity_token]").val(); | |
var uploader = new plupload.Uploader({ | |
runtimes : 'html5', | |
browse_button : 'pickfiles', | |
container : 'uploader', | |
max_file_size : '10mb', | |
url : $('form#upload').attr('action'), | |
flash_swf_url : '/assets/plupload/plupload.flash.swf', | |
silverlight_xap_url : '/assets/plupload/plupload.silverlight.xap', | |
multipart: true, | |
multipart_params : {"authenticity_token" : atoken} | |
}); | |
uploader.bind('Init', function(up, params) { | |
$('#uploader').html('<a id="pickfiles" href="#">[Select files]</a><a id="uploadfiles" href="#">[Upload files]</a></div>'); | |
$('#uploadfiles').bind('click', function(e) { | |
uploader.start(); | |
e.preventDefault(); | |
}); | |
$('#upload-runtime').html('<div id="filelist"></div>'+"<div>Current runtime: " + params.runtime + "</div>"); | |
}); | |
uploader.init(); | |
uploader.bind('FilesAdded', function(up, files) { | |
$.each(files, function(i, file) { | |
$('#filelist').append( | |
'<div id="' + file.id + '">' + | |
file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' + | |
'</div>'); | |
}); | |
up.refresh(); // Reposition Flash/Silverlight | |
}); | |
uploader.bind('UploadProgress', function(up, file) { | |
$('#' + file.id + " b").html(file.percent + "%"); | |
}); | |
uploader.bind('Error', function(up, err) { | |
$('#filelist').append("<div>Error: " + err.code + | |
", Message: " + err.message + | |
(err.file ? ", File: " + err.file.name : "") + | |
"</div>" | |
); | |
up.refresh(); // Reposition Flash/Silverlight | |
}); | |
uploader.bind('FileUploaded', function(up, file) { | |
$('#' + file.id + " b").html("100%"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment