/** * JavaScript used by mod/photos */ $(document).ready(function() { // call initialization file if (window.File && window.FileList && window.FileReader) { UploadInit(); } $(".comment-edit-form textarea").editor_autocomplete(baseurl+"/acl?f=&n=1"); $('textarea').editor_autocomplete(baseurl+"/acl"); $('textarea').bbco_autocomplete('bbcode'); }); // initialize function UploadInit() { var nickname = $('#invisible-photos-file-upload').data('nickname'); var fileselect = $("#photos-upload-choose"); var filedrag = $("#photos-upload-form"); var submit = $("#dbtn-submit"); var idx = 0; var reload = false; $('#invisible-photos-file-upload').fileupload({ url: 'photos/' + nickname, dataType: 'json', dropZone: filedrag, maxChunkSize: 4 * 1024 * 1024, add: function(e,data) { idx++; data.files[0].idx = idx; prepareHtml(data.files[0]); var allow_cid = ($('#photos-upload-form').data('allow_cid') || []); var allow_gid = ($('#photos-upload-form').data('allow_gid') || []); var deny_cid = ($('#photos-upload-form').data('deny_cid') || []); var deny_gid = ($('#photos-upload-form').data('deny_gid') || []); $('.acl-field').remove(); $(allow_gid).each(function(i,v) { $('#photos-upload-form').append(""); }); $(allow_cid).each(function(i,v) { $('#photos-upload-form').append(""); }); $(deny_gid).each(function(i,v) { $('#photos-upload-form').append(""); }); $(deny_cid).each(function(i,v) { $('#photos-upload-form').append(""); }); data.formData = $('#photos-upload-form').serializeArray(); // trick it into not uploadiong all files at once $('#new-upload-' + data.files[0].idx).one('fileupload_trigger', function () { data.submit(); }); $('#new-upload-1').trigger('fileupload_trigger'); }, progress: function(e,data) { var id = data.files[0].idx; if(data.loaded == data.total) { if(id == data.originalFiles.length) { reload = true; } else { // trigger uploading the next file var next_id = id + 1; setTimeout(function(){ $('#new-upload-' + next_id).trigger('fileupload_trigger'); }, 1000); } } // Dynamically update the percentage complete displayed in the file upload list $('#upload-progress-' + id).html(Math.round(data.loaded / data.total * 100) + '%'); $('#upload-progress-bar-' + id).css('background-size', Math.round(data.loaded / data.total * 100) + '%'); }, stop: function(e,data) { if(reload) { console.log('Upload completed'); window.location.href = window.location.href; } } }); $('#dbtn-submit').click(function(event) { event.preventDefault(); $('#invisible-photos-file-upload').trigger('click'); return false;}); } function prepareHtml(f) { var num = f.idx - 1; var i = f.idx; $('#upload-index #new-upload-progress-bar-' + num.toString()).after( '