mirror of
https://github.com/icecoder/ICEcoder.git
synced 2026-03-03 15:24:00 +01:00
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.
This commit is contained in:
38
lib/coder.js
38
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 = '<a '+hrefLink+' onMouseOver="top.ICEcoder.overFileFolder(\''+actionElemType+'\',\''+location+'/'+file+'\')" onMouseOut="top.ICEcoder.overFileFolder(\''+actionElemType+'\',\'\')" style="position: relative; left:-22px"> <span id="'+location.replace(/\//g,"|")+'|'+file+'">'+file+'</a>';
|
||||
locNest.appendChild(newLI,locNest.childNodes[0]);
|
||||
newLI.innerHTML = '<a href="#" title="'+location+'/'+file+'" onMouseOver="top.ICEcoder.overFileFolder(\''+actionElemType+'\',\''+location.replace(/\//g,"|")+'|'+file+'\')" onMouseOut="top.ICEcoder.overFileFolder(\''+actionElemType+'\',\'\')" style="position: relative; left:-22px"> <span id="'+location.replace(/\//g,"|")+'|'+file+'">'+file+'</span> <span style="color: #888; font-size: 8px" id="'+location.replace(/\//g,"|")+'|'+file+'_perms">705</span></a>';
|
||||
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 = '<a '+hrefLink+' onMouseOver="top.ICEcoder.overFileFolder(\''+elemType+'\',\''+location+'/'+file+'\')" onMouseOut="top.ICEcoder.overFileFolder(\''+elemType+'\',\'\')" style="position: relative; left:-22px"> <span id="'+location.replace(/\//g,"|")+'|'+file+'">'+file+'</a>';
|
||||
|
||||
newLI.innerHTML = '<a href="#" title="'+location+'/'+file+'" onMouseOver="top.ICEcoder.overFileFolder(\''+actionElemType+'\',\''+location.replace(/\//g,"|")+'|'+file+'\')" onMouseOut="top.ICEcoder.overFileFolder(\''+actionElemType+'\',\'\')" style="position: relative; left:-22px"> <span id="'+location.replace(/\//g,"|")+'|'+file+'">'+file+'</span> <span style="color: #888; font-size: 8px" id="'+location.replace(/\//g,"|")+'|'+file+'_perms">705</span></a>';
|
||||
// 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";
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user