From f1aa2014259ecfb70a82b94cf9923da24f46aff1 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Mon, 30 Jul 2012 07:56:06 +0100 Subject: [PATCH] Realigned and reworked adding & removing files Due to new DOM structure and relative paths how we add new files & folders, including how they're added into empty folders has been realigned and reworked. --- lib/coder.js | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/coder.js b/lib/coder.js index d45eeec..135c692 100644 --- a/lib/coder.js +++ b/lib/coder.js @@ -1147,41 +1147,38 @@ var ICEcoder = { // Update the file manager tree list on demand updateFileManagerList: function(action,location,file,perms,oldName) { - var actionElemType, cssStyle, hrefLink, targetElem, locNest, newUL, newLI, nameLI, shortURL, newMouseOver; + var actionElemType, cssStyle, targetElem, locNest, newText, newUL, newLI, nameLI, shortURL, newMouseOver; // Adding files if (action=="add") { - // Determin if this is a file or folder and based on that, set the CSS styling & link - file.indexOf(".")>-1 ? actionElemType = "file" : actionElemType = "folder"; - actionElemType=="file" ? cssStyle = "pft-file ext-" + file.substr(file.indexOf(".")+1,file.length) : cssStyle = "pft-directory"; - actionElemType=="file" ? hrefLink = "nohref" : hrefLink = "href=\"#\""; + actionElemType = file.indexOf(".")>-1 ? "file" : "folder"; + cssStyle = actionElemType=="file" ? "pft-file ext-" + file.substr(file.indexOf(".")+1,file.length) : "pft-directory"; // Identify our target element & the first child element in it's location targetElem = document.getElementById('filesFrame').contentWindow.document.getElementById(location.replace(/\//g,"|")); - locNest = targetElem.parentNode.parentNode.childNodes[1]; - - // If we don't have a nest location, it's an empty folder - if(!locNest) { + locNest = targetElem.parentNode.parentNode.nextSibling; + if (locNest.nextSibling) {locNest = locNest.nextSibling} + newText = document.createTextNode("\n"); + // If we don't have at least 3 DOM items in here, it's an empty folder + if(!locNest.childNodes.length<3) { // We now need to begin a new UL list newUL = document.createElement("ul"); locNest = targetElem.parentNode.parentNode; - locNest.appendChild(newUL); - - // Now we have a list to insert into, we can identify the first child element - locNest = targetElem.parentNode.parentNode.childNodes[1]; + locNest.parentNode.insertBefore(newUL,locNest.nextSibling); // Finally we can add the first list item for this file/folder we're adding newLI = document.createElement("li"); newLI.className = cssStyle; - newLI.innerHTML = '        '+file+''; - locNest.appendChild(newLI,locNest.childNodes[0]); + newLI.innerHTML = '        '+file+' 705'; + locNest.nextSibling.appendChild(newLI); + locNest.nextSibling.appendChild(newText); // There are items in that location, so add our new item in the right position } else { - for (var i=0;i<=locNest.childNodes.length-1;i++) { + if (locNest.childNodes[i].className) { // Identify if the item we're considering is a file or folder locNest.childNodes[i].className.indexOf('directory')>0 ? elemType = "folder" : elemType = "file"; @@ -1193,14 +1190,15 @@ var ICEcoder = { if ((elemType==actionElemType && nameLI > file) || (actionElemType=="folder" && elemType=="file") || i==locNest.childNodes.length-1) { newLI = document.createElement("li"); newLI.className = cssStyle; - newLI.innerHTML = '        '+file+''; - + newLI.innerHTML = '        '+file+' 705'; // Append or insert depending on which of the above if statements is true - i==locNest.childNodes.length-1 ? locNest.appendChild(newLI,locNest.childNodes[i]) : locNest.insertBefore(newLI,locNest.childNodes[i]); + i==locNest.childNodes.length-1 ? locNest.appendChild(newLI) : locNest.insertBefore(newLI,locNest.childNodes[i]); + i==locNest.childNodes.length-1 ? locNest.appendChild(newText) : locNest.insertBefore(newLI,locNest.childNodes[i+1]); // Escape from this loop now i=locNest.childNodes.length; } + } } } } @@ -1230,7 +1228,7 @@ var ICEcoder = { // Deleting files if (action=="delete") { // Simply get our target and make it dissapear - targetElem = document.getElementById('filesFrame').contentWindow.document.getElementById(location.replace(/\//g,"|")+file); + targetElem = document.getElementById('filesFrame').contentWindow.document.getElementById(location.replace(/\//g,"|")+"|"+file); targetElem.parentNode.parentNode.style.display = "none"; } },