plupload.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. $(document).ready(function() {
  2. var uploader;
  3. $("#plupload_files").pluploadQueue({
  4. // General settings
  5. runtimes : 'gears, html5, html4',
  6. url : baseUrl+'Plupload/upload/format/json',
  7. chunk_size : '5mb',
  8. unique_names : 'true',
  9. multiple_queues : 'true',
  10. filters : [
  11. {title: "Audio Files", extensions: "ogg,mp3,oga,flac,wav,m4a,mp4,opus"}
  12. ],
  13. multipart_params : {
  14. "csrf_token" : $("#csrf").attr('value'),
  15. }
  16. });
  17. uploader = $("#plupload_files").pluploadQueue();
  18. uploader.bind('FileUploaded', function(up, file, json) {
  19. var j = jQuery.parseJSON(json.response);
  20. if(j.error !== undefined) {
  21. var row = $("<tr/>")
  22. .append('<td>' + file.name +'</td>')
  23. .append('<td>' + j.error.message + '</td>');
  24. $("#plupload_error").find("table").append(row);
  25. $("#plupload_error table").css("display", "inline-table");
  26. }else{
  27. var tempFileName = j.tempfilepath;
  28. $.get(baseUrl+'Plupload/copyfile/format/json/name/'+
  29. encodeURIComponent(file.name)+'/tempname/' +
  30. encodeURIComponent(tempFileName), function(jr){
  31. if(jr.error !== undefined) {
  32. var row = $("<tr/>")
  33. .append('<td>' + file.name +'</td>')
  34. .append('<td>' + jr.error.message + '</td>');
  35. $("#plupload_error").find("table").append(row);
  36. $("#plupload_error table").css("display", "inline-table");
  37. }
  38. });
  39. }
  40. });
  41. var uploadProgress = false;
  42. uploader.bind('QueueChanged', function(){
  43. uploadProgress = (uploader.files.length > 0)
  44. });
  45. uploader.bind('UploadComplete', function(){
  46. uploadProgress = false;
  47. });
  48. $(window).bind('beforeunload', function(){
  49. if(uploadProgress){
  50. return sprintf($.i18n._("You are currently uploading files. %sGoing to another screen will cancel the upload process. %sAre you sure you want to leave the page?"),
  51. "\n", "\n");
  52. }
  53. });
  54. });