uploader_dropzone.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # Dropzone multiple file uploader
  4. *
  5. * Demo JS code for uploader_dropzone.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var DropzoneUploader = function() {
  11. //
  12. // Setup module components
  13. //
  14. // Dropzone file uploader
  15. var _componentDropzone = function() {
  16. if (typeof Dropzone == 'undefined') {
  17. console.warn('Warning - dropzone.min.js is not loaded.');
  18. return;
  19. }
  20. // Multiple files
  21. Dropzone.options.dropzoneMultiple = {
  22. paramName: "file", // The name that will be used to transfer the file
  23. dictDefaultMessage: 'Drop files to upload <span>or CLICK</span>',
  24. maxFilesize: 0.1 // MB
  25. };
  26. // Single files
  27. Dropzone.options.dropzoneSingle = {
  28. paramName: "file", // The name that will be used to transfer the file
  29. maxFilesize: 1, // MB
  30. maxFiles: 1,
  31. dictDefaultMessage: 'Drop file to upload <span>or CLICK</span>',
  32. autoProcessQueue: false,
  33. init: function() {
  34. this.on('addedfile', function(file){
  35. if (this.fileTracker) {
  36. this.removeFile(this.fileTracker);
  37. }
  38. this.fileTracker = file;
  39. });
  40. }
  41. };
  42. // Accepted files
  43. Dropzone.options.dropzoneAcceptedFiles = {
  44. paramName: "file", // The name that will be used to transfer the file
  45. dictDefaultMessage: 'Drop files to upload <span>or CLICK</span>',
  46. maxFilesize: 1, // MB
  47. acceptedFiles: 'image/*'
  48. };
  49. // Removable thumbnails
  50. Dropzone.options.dropzoneRemove = {
  51. paramName: "file", // The name that will be used to transfer the file
  52. dictDefaultMessage: 'Drop files to upload <span>or CLICK</span>',
  53. maxFilesize: 1, // MB
  54. addRemoveLinks: true
  55. };
  56. // File limitations
  57. Dropzone.options.dropzoneFileLimits = {
  58. paramName: "file", // The name that will be used to transfer the file
  59. dictDefaultMessage: 'Drop files to upload <span>or CLICK</span>',
  60. maxFilesize: 0.4, // MB
  61. maxFiles: 4,
  62. maxThumbnailFilesize: 1,
  63. addRemoveLinks: true
  64. };
  65. };
  66. //
  67. // Return objects assigned to module
  68. //
  69. return {
  70. init: function() {
  71. _componentDropzone();
  72. }
  73. }
  74. }();
  75. // Initialize module
  76. // ------------------------------
  77. DropzoneUploader.init();