From 8c043393980be0dad6294efde62f02c0f17b7fc9 Mon Sep 17 00:00:00 2001 From: Maxim Stewart Date: Sat, 7 Jul 2018 15:32:45 -0500 Subject: [PATCH] Cleaned up code... --- index.html | 4 +- resources/js/ajax.js | 16 ++++---- resources/js/filesystemActions.js | 35 ++++++++---------- resources/js/uiActions.js | 61 +++++++++++-------------------- resources/js/uiEvents.js | 10 ++--- 5 files changed, 53 insertions(+), 73 deletions(-) diff --git a/index.html b/index.html index f08ecbd..59c7eb9 100644 --- a/index.html +++ b/index.html @@ -14,14 +14,14 @@ - +

- +     Path:   diff --git a/resources/js/ajax.js b/resources/js/ajax.js index 221a02c..99c19b1 100644 --- a/resources/js/ajax.js +++ b/resources/js/ajax.js @@ -13,10 +13,10 @@ if(typeof(EventSource) !== "undefined") { } function getDir(query) { - var formUlPth = document.getElementById("DIRPATHUL"); - var path = ""; - var cookies = ""; - var dirCookie = ""; + var formUlPth = document.getElementById("DIRPATHUL"); + var path = ""; + var cookies = ""; + var dirCookie = ""; // push or pop to path list if (query === "/") { @@ -50,15 +50,15 @@ function getDir(query) { path += pathNode; } - formUlPth.value = path; // Setup upload path for form - path = "dirQuery=" + encodeURIComponent(path); + formUlPth.value = path; // Setup upload path for form + path = "dirQuery=" + encodeURIComponent(path); process(path); } // Get dir info... function process(path) { - var mergeType = document.getElementById("MergeType"); - var xhttp = new XMLHttpRequest(); // Create the xhttp object + var mergeType = document.getElementById("MergeType"); + var xhttp = new XMLHttpRequest(); // Create the xhttp object // This is actually run after open and send are done xhttp.onreadystatechange = function() { diff --git a/resources/js/filesystemActions.js b/resources/js/filesystemActions.js index 6d6f61c..752338f 100644 --- a/resources/js/filesystemActions.js +++ b/resources/js/filesystemActions.js @@ -5,27 +5,23 @@ function renameItem(obj) { var oldName = encodeURIComponent(formerFileName); var newName = encodeURIComponent(obj.value); var formData = "renameItem=true&oldName=" + oldName + "&newName=" + newName + "&path=" + path; - var xhttp = new XMLHttpRequest(); console.log("Old name: " + oldName); console.log("New name: " + newName); - xhttp.open("POST", "resources/php/filesystemActions.php", true); - xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhttp.send(formData); + doFSAction("resources/php/filesystemActions.php", + formData); } function createItem(type) { var path = document.getElementById("path").innerHTML; var newItem = document.getElementById("NewItem"); var fullPth = path + newItem.value; - var xhttp = new XMLHttpRequest(); newItem.value = ""; fullPth = encodeURIComponent(fullPth); - xhttp.open("POST", "resources/php/filesystemActions.php", true); - xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhttp.send("createItem=true&item=" + fullPth + "&type=" + type); + doFSAction("resources/php/filesystemActions.php", + "createItem=true&item=" + fullPth + "&type=" + type); } function startDeleteItem(item) { @@ -39,13 +35,10 @@ function deleteItem() { if (itemObj != undefined && itemObj != null) { var fullPth = path + itemObj; fullPth = encodeURIComponent(fullPth); - var answer = confirm("Are you sure you want to delete: " + fullPth); + var answer = confirm("Are you sure you want to delete: " + fullPth); if (answer == true) { - var xhttp = new XMLHttpRequest(); - - xhttp.open("POST", "resources/php/filesystemActions.php", true); - xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhttp.send("deleteItem=true&item=" + fullPth); + doFSAction("resources/php/filesystemActions.php", + "deleteItem=true&item=" + fullPth); console.log("Deleted: " + fullPth); itemObj = null; @@ -54,9 +47,13 @@ function deleteItem() { } function openInLocalProg(media) { - var xhttp = new XMLHttpRequest(); - - xhttp.open("POST", "resources/php/filesystemActions.php", true); - xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhttp.send("media=" + media); + doFSAction("resources/php/filesystemActions.php", + "media=" + media); +} + +function doFSAction(actionPath, data) { + var xhttp = new XMLHttpRequest(); + xhttp.open("POST", actionPath, true); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.send(data); } diff --git a/resources/js/uiActions.js b/resources/js/uiActions.js index e543df1..c39e8fb 100644 --- a/resources/js/uiActions.js +++ b/resources/js/uiActions.js @@ -1,37 +1,28 @@ var formerFileName = ""; -function showOptions() { - var popOutControls = document.getElementById("popOutControls"); - if (popOutControls.style.display == "none") { - popOutControls.style.display = "block"; +function tgglElmView(id) { + var elm = document.getElementById(id); + if (elm.style.display == "none") { + elm.style.display = "block"; } else { - popOutControls.style.display = "none"; - } -} - -function tgglServerMsgView() { - var serverMsgView = document.getElementById("toggleServerMsg"); - if (serverMsgView.style.display == "none") { - serverMsgView.style.display = "block"; - } else { - serverMsgView.style.display = "none"; + elm.style.display = "none"; } } function enableEdit(obj) { - obj.style.backgroundColor = "#ffffffff"; - obj.style.color = '#000000ff'; - obj.readOnly = ''; - formerFileName = obj.value; + obj.style.backgroundColor = "#ffffffff"; + obj.style.color = '#000000ff'; + obj.readOnly = ''; + formerFileName = obj.value; } function disableEdits() { // this references the passed object from // addEventListener than us passing it - this.style.backgroundColor = "#ffffff00"; - this.style.color = '#ffffff'; - this.value = formerFileName; - this.readOnly = "true"; + this.style.backgroundColor = "#ffffff00"; + this.style.color = '#ffffff'; + this.value = formerFileName; + this.readOnly = "true"; } function showImg(imgLoc) { @@ -61,9 +52,9 @@ function showMedia(media) { var popButton = "
"; var CloseBttn = "
X
"; - mediaView.style.display = "block"; - mediaView.innerHTML = CloseBttn + popButton + toPlayerButton; - mediaView.innerHTML += ""; + mediaView.style.display = "block"; + mediaView.innerHTML = CloseBttn + popButton + toPlayerButton; + mediaView.innerHTML += ""; dragContainer(mediaView); // Set for dragging events } else { @@ -72,13 +63,13 @@ function showMedia(media) { } function closeImg() { - var imgView = document.getElementById("imgView"); + var imgView = document.getElementById("imgView"); imgView.style.display = "none"; } function closeMedia() { - var mediaView = document.getElementById("fileView"); - mediaView.style.display = "none"; + var mediaView = document.getElementById("fileView"); + mediaView.style.display = "none"; mediaView.children[3].src = ""; } @@ -88,14 +79,6 @@ function clearDirCookie() { getDir("/"); } -function clearDlList() { - document.getElementById("CLEARBTTN").click(); -} - -function onloadSetBG() { - updateBG("resources/images/backgrounds/000.jpg"); -} - -function updateBG(bgImg) { - document.getElementById("bg").src = bgImg; -} +function clearDlList() { document.getElementById("CLEARBTTN").click(); } +function onloadSetBG() { updateBG("resources/images/backgrounds/000.jpg"); } +function updateBG(bgImg) { document.getElementById("bg").src = bgImg; } diff --git a/resources/js/uiEvents.js b/resources/js/uiEvents.js index 67e1883..3e6dbcb 100644 --- a/resources/js/uiEvents.js +++ b/resources/js/uiEvents.js @@ -1,8 +1,8 @@ // ondblclick document.ondblclick = function (event) { - var obj = event.target; + var obj = event.target; var callingID = obj.id; - var classNM = obj.className; + var classNM = obj.className; // Left click detect if (event.which == 1) { @@ -50,8 +50,8 @@ document.ondblclick = function (event) { // Mainly for rename event document.onkeydown = function (event) { - var obj = event.target; - var callingID = event.target.id; + var obj = event.target; + var callingID = event.target.id; var keyCodeVal = event.keyCode; // If keycode == Enter @@ -65,7 +65,7 @@ document.onkeydown = function (event) { // Drage event for the poped out image and media container function dragContainer(elmnt) { var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0; - elmnt.onmousedown = dragMouseDown; + elmnt.onmousedown = dragMouseDown; function dragMouseDown(e) { e = e || window.event;