Guest User

Untitled

a guest
Feb 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. <input type="file" id="0" name="photos[]" multiple hidden required class="photos">
  2.  
  3. $('form').submit(function () {
  4. $('input.photos').val(photos);
  5. }
  6.  
  7. var ids = [0];
  8. var photoNames = [];
  9. var append = false;
  10.  
  11. $('span#photo-uploader').click(function (e) {
  12. $('input.photos#' + ids[ids.length - 1]).click();
  13. });
  14.  
  15. $('body').on('change', 'input.photos', function () {
  16.  
  17. var input = this;
  18. var photoList = $('div.photo-list');
  19.  
  20. for (var i = 0; i < input.files.length; i++) {
  21. var file = input.files[i];
  22.  
  23. if (photoNames.indexOf(file.name) !== -1) continue;
  24.  
  25. append = true;
  26.  
  27. photoNames.push(file.name);
  28.  
  29. var reader = new FileReader();
  30.  
  31. reader.onloadstart = (function (file, i) {
  32. return function (e) {
  33. photoList.append(photoItem(e, file, i));
  34. }
  35. }) (file, i + photoNames.length);
  36.  
  37. reader.onload = (function (i) {
  38. return function (e) {
  39. $('div#' + i + '.photo-item img').attr('src', e.target.result);
  40. }
  41. }) (i + photoNames.length);
  42.  
  43. reader.onprogress = function (e) {
  44. if (e.lengthComputable) {
  45. var progress = Math.round(e.loaded / e.total * 100);
  46. $('div#' + i + '.photo-item div.progress-bar').css('width', progress + '%');
  47. }
  48. };
  49.  
  50. reader.readAsDataURL(file);
  51. }
  52.  
  53. if (append) {
  54. $('div.kek').append('<input type="file" id="' + (ids[ids.length - 1] + 1) + '" name="photos[]" multiple class="photos">');
  55. ids.push(ids[ids.length - 1] + 1);
  56. append = false;
  57. }
  58.  
  59. });
  60.  
  61. function photoItem(e, file, i) {
  62.  
  63. return ''; // рендерит фотку
  64. }
Add Comment
Please, Sign In to add comment