"; loadZip(base64); var selectFormatter = function (item) { var index = item.text.indexOf("("); if (index > -1) { var name = item.text.substring(0, index); return name + '' + item.text.substring(index - 1) + ""; } else { return item.text; } }; $(".no-propagate").on("click", function (el) { el.stopPropagation(); }); function loadZip(file) { setIsLoading(true); resetTableList(); setTimeout(function () { JSZip.loadAsync(file, {base64: true}).then(function(zip) { currentZip = zip; var firstFolderName = null; var tableList = $("#tables"); var rootFileCount = getFilesForRoot(zip).length; if (rootFileCount > 0) { rowCounts['/'] = rootFileCount; firstFolderName = '/'; } zip.forEach(function (relativePath, zipEntry) { if (!zipEntry.dir) { return; } var name = zipEntry.name; if (firstFolderName === null) { firstFolderName = name; } var rowCount = getFilesForFolder(zip, name).length; rowCounts[name] = rowCount; }); if (firstFolderName === null) { // some zip files do not declare directories explicitly rowCounts[''] = 0; firstFolderName = ''; } for (var rowName in rowCounts) { var rowCount = rowCounts[rowName]; tableList.append(''); } //Select first table and show It tableList.select2("val", firstFolderName); renderQuery(firstFolderName); $("#output-box").fadeIn(); $("#success-box").show(); setIsLoading(false); }, function (ex) { setIsLoading(false); alert(ex); }); }, 50); } function resetTableList() { var tables = $("#tables"); rowCounts = []; tables.empty(); tables.append(""); tables.select2({ placeholder: "Select a folder", formatSelection: selectFormatter, formatResult: selectFormatter }); tables.on("change", function (e) { renderQuery(e.val); }); } function setIsLoading(isLoading) { var dropText = $("#drop-text"); var loading = $("#drop-loading"); if (isLoading) { dropText.hide(); loading.show(); } else { dropText.show(); loading.hide(); } } function extractFileNameWithoutExt(filename) { var dotIndex = filename.lastIndexOf("."); if (dotIndex > -1) { return filename.substr(0, dotIndex); } else { return filename; } } function showError(msg) { $("#data").hide(); $("#bottom-bar").hide(); errorBox.show(); errorBox.text(msg); } function renderQuery(folder) { var dataBox = $("#data"); var thead = dataBox.find("thead").find("tr"); var tbody = dataBox.find("tbody"); thead.empty(); tbody.empty(); errorBox.hide(); dataBox.show(); var columnNames = ["Name", "Date", "Comment", "Permissions (DOS / UNIX)"]; var files; if (folder === '/') { files = getFilesForRoot(currentZip); } else { files = getFilesForFolder(currentZip, folder); } var addedColums = false; for (var fileName in files) { var file = files[fileName]; if (file.dir) { continue; } if (!addedColums) { addedColums = true; for (var i = 0; i < columnNames.length; i++) { var columnName = columnNames[i]; thead.append('' + columnName + ""); } } var columnValues = []; columnValues.push(file.name.replace(folder, '')); columnValues.push(file.date); columnValues.push(file.column); columnValues.push(file.dosPermissions + ' / ' + file.unixPermissions); var tr = $(''); for (var i = 0; i < columnValues.length; i++) { var columnValue = columnValues[i]; var fileElement = tr.append('' + columnValue + ''); registerFileClickListener(file, fileElement); } tbody.append(tr); } $('[data-toggle="tooltip"]').tooltip({html: true}); } function registerFileClickListener(file, element) { element.click(function() { if (showFileClickExplanation) { showFileClickExplanation = false; console.log('right click object in console and "Store as global variable". afterwards do something like "temp1.async(\'string\').then(console.log)"'); console.log('more information here: https://stuk.github.io/jszip/documentation/api_zipobject/async.html'); console.log('for example: "temp1.async(\'base64\').then(function (content) { window.open(\'data:;base64,\' + content)})"'); } if (lastShownFile === file) { return; } lastShownFile = file; file.async("base64").then(function (base) { window.paragraphListener.sendFile(base); }); console.log(file); }); } function getFilesForRoot(zip) { return zip.filter(function(relativePath, file) { return relativePath.indexOf('/') < 0; }); } function getFilesForFolder(zip, folder) { var isNoFolderZip = false; if (folder !== '') { // some zip files do not declare directories explicitly zip = zip.folder(folder); } else { isNoFolderZip = true; } return zip.filter(function(relativePath, file) { if (isNoFolderZip) { return true; } else { return relativePath.replace(folder, '').indexOf('/') < 0; } }); }