Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <input type="file" id="0" name="photos[]" multiple hidden required class="photos">
- $('form').submit(function () {
- $('input.photos').val(photos);
- }
- var ids = [0];
- var photoNames = [];
- var append = false;
- $('span#photo-uploader').click(function (e) {
- $('input.photos#' + ids[ids.length - 1]).click();
- });
- $('body').on('change', 'input.photos', function () {
- var input = this;
- var photoList = $('div.photo-list');
- for (var i = 0; i < input.files.length; i++) {
- var file = input.files[i];
- if (photoNames.indexOf(file.name) !== -1) continue;
- append = true;
- photoNames.push(file.name);
- var reader = new FileReader();
- reader.onloadstart = (function (file, i) {
- return function (e) {
- photoList.append(photoItem(e, file, i));
- }
- }) (file, i + photoNames.length);
- reader.onload = (function (i) {
- return function (e) {
- $('div#' + i + '.photo-item img').attr('src', e.target.result);
- }
- }) (i + photoNames.length);
- reader.onprogress = function (e) {
- if (e.lengthComputable) {
- var progress = Math.round(e.loaded / e.total * 100);
- $('div#' + i + '.photo-item div.progress-bar').css('width', progress + '%');
- }
- };
- reader.readAsDataURL(file);
- }
- if (append) {
- $('div.kek').append('<input type="file" id="' + (ids[ids.length - 1] + 1) + '" name="photos[]" multiple class="photos">');
- ids.push(ids[ids.length - 1] + 1);
- append = false;
- }
- });
- function photoItem(e, file, i) {
- return ''; // рендерит фотку
- }
Add Comment
Please, Sign In to add comment