Ingen beskrivning
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

dropzone.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import Dropzone from 'dropzone/dist/dropzone';
  2. Dropzone.autoDiscover = false;
  3. // File upload progress animation
  4. Dropzone.prototype.uploadFiles = function (files) {
  5. const minSteps = 6;
  6. const maxSteps = 60;
  7. const timeBetweenSteps = 100;
  8. const bytesPerStep = 100000;
  9. const isUploadSuccess = true;
  10. const self = this;
  11. for (let i = 0; i < files.length; i++) {
  12. const file = files[i];
  13. const totalSteps = Math.round(Math.min(maxSteps, Math.max(minSteps, file.size / bytesPerStep)));
  14. for (let step = 0; step < totalSteps; step++) {
  15. const duration = timeBetweenSteps * (step + 1);
  16. setTimeout(
  17. (function (file, totalSteps, step) {
  18. return function () {
  19. file.upload = {
  20. progress: (100 * (step + 1)) / totalSteps,
  21. total: file.size,
  22. bytesSent: ((step + 1) * file.size) / totalSteps
  23. };
  24. self.emit('uploadprogress', file, file.upload.progress, file.upload.bytesSent);
  25. if (file.upload.progress === 100) {
  26. if (isUploadSuccess) {
  27. file.status = Dropzone.SUCCESS;
  28. self.emit('success', file, 'success', null);
  29. } else {
  30. file.status = Dropzone.ERROR;
  31. self.emit('error', file, 'Some upload error', null);
  32. }
  33. self.emit('complete', file);
  34. self.processQueue();
  35. }
  36. };
  37. })(file, totalSteps, step),
  38. duration
  39. );
  40. }
  41. }
  42. };
  43. try {
  44. window.Dropzone = Dropzone;
  45. } catch (e) {}
  46. export { Dropzone };