/** * JavaScript for mod/cloud */ $(document).ready(function () { // call initialization file if (window.File && window.FileList && window.FileReader) { UploadInit(); } }); // // initialize function UploadInit() { var fileselect = $("#files-upload"); var filedrag = $("#cloud-drag-area"); var submit = $("#upload-submit"); // is XHR2 available? var xhr = new XMLHttpRequest(); if (xhr.upload) { // file select fileselect.on("change", UploadFileSelectHandler); // file submit submit.on("click", fileselect, UploadFileSelectHandler); // file drop filedrag.on("dragover", DragDropUploadFileHover); filedrag.on("dragleave", DragDropUploadFileHover); filedrag.on("drop", DragDropUploadFileSelectHandler); } window.filesToUpload = 0; window.fileUploadsCompleted = 0; } // file drag hover function DragDropUploadFileHover(e) { e.stopPropagation(); e.preventDefault(); e.currentTarget.className = (e.type == "dragover" ? "hover" : ""); } // file selection via drag/drop function DragDropUploadFileSelectHandler(e) { // cancel event and hover styling DragDropUploadFileHover(e); // fetch FileList object var files = e.target.files || e.originalEvent.dataTransfer.files; $('.new-upload').remove(); // process all File objects for (var i = 0, f; f = files[i]; i++) { prepareHtml(f, i); UploadFile(f, i); } } // file selection via input function UploadFileSelectHandler(e) { // fetch FileList object if(e.type === 'click') { e.preventDefault(); var files = e.data[0].files; } else { var files = e.target.files; } $('.new-upload').remove(); // process all File objects for (var i = 0, f; f = files[i]; i++) { prepareHtml(f, i); if(e.type === 'click') UploadFile(f, i); } } function prepareHtml(f, i) { $("#cloud-index").prepend( "