diff --git a/json/ctx.json b/json/ctx.json
index af81f7c..e721e3c 100755
--- a/json/ctx.json
+++ b/json/ctx.json
@@ -2,6 +2,7 @@
[
{"name": "New Folder", "id": "ctx-new-folder", "onclick": "newfolder"},
{"name": "Compress", "id": "ctx-compress", "onclick": "compress"},
+ {"name": "Compress Selected", "id": "ctx-compress-selected", "onclick": "compress-selected"},
{"name": "Decompress", "id": "ctx-decompress", "onclick": "decompress"}
],
[
diff --git a/scripts/contextmenu/compress-selected.js b/scripts/contextmenu/compress-selected.js
new file mode 100644
index 0000000..d0bf126
--- /dev/null
+++ b/scripts/contextmenu/compress-selected.js
@@ -0,0 +1,5 @@
+const path = require('path');
+
+module.exports = () => {
+ return require('./compress')(undefined, path.join(window.kade.cpath, window.kade.currentFolder));
+};
\ No newline at end of file
diff --git a/scripts/contextmenu/compress.js b/scripts/contextmenu/compress.js
index 9fe804c..ba3124e 100644
--- a/scripts/contextmenu/compress.js
+++ b/scripts/contextmenu/compress.js
@@ -11,8 +11,9 @@ const clearModals = require('../modal/clearmodals');
const newToast = require('../toast/createtoast');
const refresh = require('../fileview/refresh');
-module.exports = () => {
+module.exports = (event, pathToCompress) => {
let zip = new az();
+ if (!pathToCompress) {pathToCompress = window.kade.cpath;}
if (window.kade.modal) {return;}
preModal('compress-folder-modal-container');
let modalOut = document.createElement('div');
@@ -32,7 +33,7 @@ module.exports = () => {
cont.className = 'button-container';
modal.appendChild(cont);
let input = document.createElement('input');
- input.placeholder = window.kade.cpath.split(/\\+|\/+/gm).reverse()[0];
+ input.placeholder = pathToCompress.split(/\\+|\/+/gm).reverse()[0];
input.value = input.placeholder;
input.id = 'compress-folder-input';
let lastIn = '';
@@ -46,8 +47,9 @@ module.exports = () => {
conf.onclick = () => {
try {
input.value = input.value.trim();
+ if (input.value.endsWith('.zip')) {input.value = input.value.slice(0, input.value.length - 4);}
if (!input.value.length) {return;}
- if (fs.existsSync(path.join(window.kade.cpath, input.value))) {
+ if (fs.existsSync(path.join(window.kade.cpath, `${input.value}.zip`))) {
if (!input.value.match(/^.+\(\d\)$/gm)) {input.value += ' (1)';}
else {
let tempstr = input.value.split('');
@@ -60,10 +62,10 @@ module.exports = () => {
conf.style.display = 'none';
cont.style.display = 'none';
text.innerHTML = "Please wait a moment...";
- zip.addLocalFolderPromise(window.kade.cpath).then(() => {
+ closeWrap.style.display = 'none';
+ zip.addLocalFolderPromise(pathToCompress).then(() => {
title.innerHTML += " - In Progress..."
text.innerHTML = "Your folder is being compressed. Please wait a moment.
This may take some time...";
- closeWrap.style.display = 'none';
let bar = document.createElement('div');
bar.className = "loading-bar";
modal.appendChild(bar);
@@ -71,7 +73,7 @@ module.exports = () => {
newToast("Folder compressed", [`The current folder was compressed into "${input.value}" successfully`, `${window.kade.cpath}/${input.value}`], undefined, false, 5);
lightRefresh();
modalOut.remove();
- postModal(modalOut.id);
+ postModal(modalOut.id);
});
});
} catch {
diff --git a/scripts/contextmenu/createcontext.js b/scripts/contextmenu/createcontext.js
index 097f076..8307667 100755
--- a/scripts/contextmenu/createcontext.js
+++ b/scripts/contextmenu/createcontext.js
@@ -4,14 +4,20 @@ module.exports = (e, target, window) => {
let ctx = document.getElementById('ctx');
ctx.style.display = 'block';
const ctxf = document.getElementById('ctx-folder');
+ const compress = document.getElementById('ctx-compress');
+ const compsel = document.getElementById('ctx-compress-selected');
if (target.classList.contains('folder') || (target.parentElement && target.parentElement.classList.contains('folder'))) {
ctxf.style.display = 'block';
ctxf.previousElementSibling.style.display = 'block';
if (target.classList.contains('folder')) {window.kade.currentFolder = target.children[1].innerHTML.trim();}
else {window.kade.currentFolder = target.parentElement.children[1].innerHTML.trim();}
+ compress.style.display = 'none';
+ compsel.style.display = 'block';
} else {
ctxf.style.display = 'none';
ctxf.previousElementSibling.style.display = 'none';
+ compress.style.display = 'block';
+ compsel.style.display = 'none';
}
document.getElementById('ctx-decompress').style.display = 'none';
ctx.style.left = `${Math.min(e.pageX, (window.innerWidth - (ctx.clientWidth + 2)))}px`;