"; 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('