From 37c8092585ec22b40063f2bcbf6401407d1a6651 Mon Sep 17 00:00:00 2001 From: Faiez waseem <78906502+FaiezWaseem@users.noreply.github.com> Date: Mon, 20 Feb 2023 21:31:29 +0500 Subject: [PATCH] v 0.2 #bug fixed --- index.html | 33 +++- readme.md | 2 + src/css/style.css | 6 +- src/images/Button-Refresh-icon.png | Bin 0 -> 2185 bytes src/js/index.js | 6 +- src/js/init.js | 293 +++++++++++++++++------------ 6 files changed, 208 insertions(+), 132 deletions(-) create mode 100644 src/images/Button-Refresh-icon.png diff --git a/index.html b/index.html index 1765c12..76479e6 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,28 @@ - Code Editor + + Code Editor — Preview, Edit , Upload and Download + + + + + + + + + + + + + + + + + @@ -14,12 +35,12 @@
- +
-
- Terminal - -
+
+ Terminal + +
diff --git a/readme.md b/readme.md index 0780b65..76e0b74 100644 --- a/readme.md +++ b/readme.md @@ -31,4 +31,6 @@ Simply put it in the public Directory and enjoy. ## logs -- added Terminal (Feb 15 2023) +-- Added Reload Button - Fixed Bugs (Feb 20 2023) + diff --git a/src/css/style.css b/src/css/style.css index 0c2b948..0f4bb48 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -10,7 +10,7 @@ } .container .sidebar{ width: 20%; - background-color: black; + background-color: #1D1F21; height: 100vh; overflow: scroll; transition: all 1s ease 0s; @@ -83,8 +83,10 @@ display: flex; justify-content: space-between; } + .container .sidebar ul li{ margin: 4px 0px; + list-style: none; } .container .sidebar ul li a , .container .sidebar a{ text-decoration: none; @@ -93,7 +95,7 @@ justify-content: flex-start; align-items: center; } -.container .sidebar ul li a img{ +.container .sidebar ul li a img , .container .file-options div img{ width: 20px; margin-right: 4px; } diff --git a/src/images/Button-Refresh-icon.png b/src/images/Button-Refresh-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..831704aabbbd660bbe088fbf58acb6aa0323fe39 GIT binary patch literal 2185 zcmb_e`8yMi10Hi^n9XdC$u;MkGiL|6LanistDKRei=t@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7*wI4jsulku9Js+825B zc2eTf^{w9VD~5@iB}+MT6p!wyR?6oia=#>a*P=p0X`C*JG~1qlmPLl*@q&)xy9UC0 zclK1MLcBeR;*%?Oox#N?M>6$y^dZ~PK2HJsRRpeOt#H8CZ1b%D%&_gEohARB=P3P0i`h7zph=&ACSfQ^7Z_f-i5g5AA>2;dn(T};usxPouisu()8H>8z( z=`T_K2*q~`kq*^u_W6Nnnk;^C$Z#Uc4_1+6Z8FmD zt&NqUHg|KtN3P->Kp9Oj2^dSOiFxs05zxpGi`v|=Q5vMY3*v$63RxKF#FcRUAe_f_ z>`>d zOB3Z@_O8Um7QR%kxdAUT_y*r#=)*EPwcT;M%795Vk`ix2yGD}@mMsXF3; z7tv*(_%*9p-^7V+Zd~682k|;ays(B+hw<8IrC8qi^D>s$gB$+!C nVY_tjR$i@DJoCot&X%&u9lZ~baiJIgy$NRrynThOf71T|; icon icon + icon
`) document.getElementById("sidebar").innerHTML += (`
    `) @@ -26,7 +27,10 @@ ace.config.set('basePath', 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.14/') editor.setOptions({ theme: 'ace/theme/tomorrow_night', - mode: 'ace/mode/javascript' + mode: 'ace/mode/javascript', + enableBasicAutocompletion: true, + enableSnippets: true, + enableLiveAutocompletion: false }) themes.addEventListener('change', function(e){ editor.setOptions({ diff --git a/src/js/init.js b/src/js/init.js index 756ccc4..3405494 100644 --- a/src/js/init.js +++ b/src/js/init.js @@ -2,7 +2,7 @@ import db from "./tinylib.js" const codeEditor = { // To add a custom path edit currentDir key EX : "/var/user/home/" // leave null to auto detect server root path - currentDir: "C:/xampp/htdocs/php/CodeEditor", + currentDir: null, rootPath: null, selectedFile: null, fileIcon: (ext, name = null) => { @@ -87,7 +87,7 @@ const codeEditor = { db.getFolder(path).then(res => { // directory files recieved if (res.status === 200) { - codeEditor.loadfiles(res.data) + window.codeEditor.loadfiles(res.data) this.loader(false) } @@ -96,6 +96,13 @@ const codeEditor = { this.alert(err, "red") }) } else { + this.selectedFile = e.name; + let temp = e.name.split("."); + if (this.isValidFile(temp[temp.length - 1])) { + editor.setOptions({ + mode: 'ace/mode/' + temp[temp.length - 1] + }) + } db.getFile(path).then(res => { if (res.status === 200) { editor.setValue(res.data, -1) @@ -120,7 +127,7 @@ const codeEditor = { db.getFolder(path.data).then(res => { // directory files recieved if (res.status === 200) { - codeEditor.loadfiles(res.data) + window.codeEditor.loadfiles(res.data) this.loader(false); } @@ -144,22 +151,33 @@ const codeEditor = { this.loader(true) // Prevent the Save dialog to open e.preventDefault(); + if (editor.currentfile) { + + db.putFile(editor.currentfile, editor.getValue()).then(res => { + if (res.status === 200) { + this.alert("File Saved") + this.loader(false) + } + }) + } else { + this.alert("No File Selected !") + this.loader(false) + } + } + }); + document.querySelector(".save").onclick = () => { + this.loader(true) + if (editor.currentfile) { db.putFile(editor.currentfile, editor.getValue()).then(res => { if (res.status === 200) { this.alert("File Saved") this.loader(false) } }) + } else { + this.alert("No File Selected") + this.loader(false) } - }); - document.querySelector(".save").onclick = () => { - this.loader(true) - db.putFile(editor.currentfile, editor.getValue()).then(res => { - if (res.status === 200) { - this.alert("File Saved") - this.loader(false) - } - }) } document.querySelector("#cfolder").onclick = () => { @@ -215,12 +233,17 @@ const codeEditor = { close_modals.forEach((btn) => { btn.addEventListener("click", () => { const modal = btn.closest(".modal"); - modal.classList.remove("active"); + try { + modal.classList.remove("active"); + } catch (error) { + + } }); }); - document.addEventListener('long-press', function (e) { - codeEditor.selectedFile = e.target.getAttribute("data"); + document.addEventListener('long-press', (e) => { + console.log(e.target.getAttribute("data")) + this.selectedFile = e.target.getAttribute("data"); var menu = document.querySelector('.menu2'); console.log(e.detail.clientX, e.detail.clientY) menu.style.left = e.detail.clientX + 'px'; @@ -231,19 +254,19 @@ const codeEditor = { document.querySelector('.menu2').classList.remove('menu-show'); }) document.getElementById("shareFolder").onclick = () => { - const path = codeEditor.currentDir + "/" + codeEditor.selectedFile; + const path = window.codeEditor.currentDir + "/" + window.codeEditor.selectedFile; const a = document.createElement("a") a.href = "./src/php/index.php?dw=" + path; document.body.appendChild(a) a.click(); } document.getElementById("openFolder").onclick = () => { - db.getFolder(codeEditor.currentDir + "/" + codeEditor.selectedFile).then(res => { + db.getFolder(window.codeEditor.currentDir + "/" + window.codeEditor.selectedFile).then(res => { // directory files recieved if (res.status === 200) { - codeEditor.loadfiles(res.data) + window.codeEditor.loadfiles(res.data) this.loader(false); - this.currentDir = codeEditor.currentDir + "/" + codeEditor.selectedFile; + this.currentDir = window.codeEditor.currentDir + "/" + window.codeEditor.selectedFile; } }).catch(err => { @@ -253,56 +276,56 @@ const codeEditor = { } document.getElementById("folderDelete").onclick = () => { this.loader(true); - db.deleteFile(codeEditor.currentDir + "/" + codeEditor.selectedFile) + db.deleteFile(this.currentDir + "/" + this.selectedFile) .then(res => { if (res.status === 200) { this.reload() this.loader(false); - this.alert(codeEditor.selectedFile + " Removed !"); - codeEditor.selectedFile = null; + this.alert(this.selectedFile + " Removed !"); + this.selectedFile = null; } }) } - const dropArea = document.body; + const dropArea = document.body; // drag and drop - dropArea.addEventListener("dragover", (event)=>{ + dropArea.addEventListener("dragover", (event) => { event.preventDefault(); //preventing from default behaviour document.body.style.border = "4px dashed green" }); - + //If user leave dragged File from DropArea - dropArea.addEventListener("dragleave", (event)=>{ - console.log(event) - document.body.style.border = "0px solid green" - }); - dropArea.addEventListener("drop", (event)=>{ + dropArea.addEventListener("dragleave", (event) => { + console.log(event) + document.body.style.border = "0px solid green" + }); + dropArea.addEventListener("drop", (event) => { event.preventDefault(); //preventing from default behaviour document.body.style.border = "0px solid green" let files = event.dataTransfer.files; this.upload(files) - }); - - - let isClosed = false; + }); + + + let isClosed = false; document.getElementById("close-shell").onclick = () => { - if(!isClosed){ - document.querySelector('#terminal').style.display = "none"; - document.querySelector('#close-shell').innerHTML = "⇈"; - isClosed = true; - }else{ - document.querySelector('#close-shell').innerHTML = "×"; - document.querySelector('#terminal').style.display = "block"; - isClosed = false; + if (!isClosed) { + document.querySelector('#terminal').style.display = "none"; + document.querySelector('#close-shell').innerHTML = "⇈"; + isClosed = true; + } else { + document.querySelector('#close-shell').innerHTML = "×"; + document.querySelector('#terminal').style.display = "block"; + isClosed = false; } } - - + + }, previousDir: function () { this.loader(true); - var temp = codeEditor.currentDir; - let str = codeEditor.currentDir.split("/") + var temp = window.codeEditor.currentDir; + let str = window.codeEditor.currentDir.split("/") str.pop(); str = str.toString(); str = str.replaceAll(",", "/"); @@ -310,7 +333,7 @@ const codeEditor = { db.getFolder(str).then(res => { // directory files recieved if (res.status === 200) { - codeEditor.loadfiles(res.data) + window.codeEditor.loadfiles(res.data) this.loader(false); } else { this.loader(false); @@ -346,7 +369,7 @@ const codeEditor = { db.getFolder(this.currentDir).then(res => { // directory files recieved if (res.status === 200) { - codeEditor.loadfiles(res.data) + window.codeEditor.loadfiles(res.data) this.loader(false); } @@ -355,104 +378,128 @@ const codeEditor = { this.alert(err, "red") }) }, - upload : function (files = []) { + upload: function (files = []) { $.fcup({ upId: 'upid', //Upload the id of the dom - + upShardSize: '3', //Slice size, (maximum per upload) in unit M, default 3M - + upMaxSize: '9216', //Upload file size, unit M, no setting no limit supported 9GB - + upUrl: './src/php/file.php?p=' + this.currentDir, //File upload interface - - files : files, - - + + files: files, + + //The interface returns a result callback, which is judged according to the // data returned by the result, and can return a string or json for judgment processing - upCallBack: function (res,id) { - - // 状态 - var status = res.status; - // 信息 - var msg = res.message; - // url - var url = res.url + "?" + Math.random(); - - // Already done - if (status == 2) { - console.log("Done Id = Size : "+id); - alert("File Done "+id); - // document.getElementById("f"+id).innerText = "Done"; - } - - // still uploading - if (status == 1) { - console.log( msg); - alert( msg); - } - - // The interface returns an error - if (status == 0) { - // Stop uploading trigger $.upStop function - $.upErrorMsg(msg); - } - - if (status == 3) { - alert(100); - console.log(msg) - alert(msg) - jQuery.upErrorMsg(msg); - } + upCallBack: function (res, id) { + + // 状态 + var status = res.status; + // 信息 + var msg = res.message; + // url + var url = res.url + "?" + Math.random(); + + // Already done + if (status == 2) { + console.log("Done Id = Size : " + id); + alert("File Done " + id); + // document.getElementById("f"+id).innerText = "Done"; + } + + // still uploading + if (status == 1) { + console.log(msg); + alert(msg); + } + + // The interface returns an error + if (status == 0) { + // Stop uploading trigger $.upStop function + $.upErrorMsg(msg); + } + + if (status == 3) { + alert(100); + console.log(msg) + alert(msg) + jQuery.upErrorMsg(msg); + } }, - - upEvent: function (num,id) { - console.log(num+"%"); - alert(num+"%"); + + upEvent: function (num, id) { + console.log(num + "%"); + alert(num + "%"); }, - + upStop: function (errmsg) { - console.log("Uploading Failed .... " + errmsg); + console.log("Uploading Failed .... " + errmsg); }, - + upStart: function () { - console.log(0+"%"); - console.log("Uploading Started ...."); - alert("Uploading Started ...."); + console.log(0 + "%"); + console.log("Uploading Started ...."); + alert("Uploading Started ...."); }, - listfiles : function(files){ + listfiles: function (files) { console.log(files) - // for (let i = 0; i < files.length; i++) { - // const element = files[i]; - // document.getElementById("filesbdy").innerHTML += ` - // - // ${i+1} - // ${element.name} - // ${humanFileSize(element.size)} - // 0% - // - // ` - - // } + // for (let i = 0; i < files.length; i++) { + // const element = files[i]; + // document.getElementById("filesbdy").innerHTML += ` + // + // ${i+1} + // ${element.name} + // ${humanFileSize(element.size)} + // 0% + // + // ` + + // } } - - }); - function alert( message , color = "green") { + + }); + function alert(message, color = "green") { document.querySelector(".alert").style.display = "block" document.querySelector(".alert").innerText = message document.querySelector(".alert").style.backgroundColor = `var(--${color})` - + setTimeout(() => { document.querySelector(".alert").innerText = message document.querySelector(".alert").style.display = "none" document.querySelector(".alert").style.backgroundColor = `var(--${color})` }, 3000) - } - function humanFileSize(size) { - var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024)); - return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]; - } - } + } + function humanFileSize(size) { + var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024)); + return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]; + } + }, + isValidFile: function (ext) { + switch (ext) { + case "js": + return true; + case "html": + return true; + case "css": + return true; + case "php": + return true; + case "java": + return true; + case "ini": + return true; + case "fortran": + return true; + case "ejs": + return true; + case "sql": + return true; + default: + return false; + } + } } export default codeEditor; \ No newline at end of file