Clear iceRoot from checked path and check locNest

These couple of bug fixes ensure paths aren't compounded and also handle
empty dirs correctly
This commit is contained in:
Matt Pass
2015-10-03 17:40:19 +01:00
parent f4762fbaf3
commit 592c8ccda4
2 changed files with 15 additions and 11 deletions

View File

@@ -1589,6 +1589,10 @@ var ICEcoder = {
var xhr, statusObj, timeStart;
path = path.replace(/\|/g,"/");
// Clear any prefixed iceRoot from path
if (path.indexOf(top.iceRoot) === 0) {
path = path.replace(top.iceRoot,"");
}
// Start a seperate XHR call. We run seperately rather than add into the serverQueue because we may need to run
// immediately, eg need to if a file/dir exists mid flow in 'Save As' function, so can't go into queue
@@ -1718,8 +1722,8 @@ var ICEcoder = {
' if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {top.ICEcoder.openFile()}}" style="position: relative; left:-22px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span id="'+location.replace(/\/$/, "").replace(/\//g,"|")+"|"+file+'">'+file+'</span> <span style="'+permColors+'; font-size: 8px" id="'+location.replace(/\/$/, "").replace(/\//g,"|")+"|"+file+'_perms">'+perms+'</span></a>';
// If we don't have at least 3 DOM items in here, it's an empty folder
if(locNest.childNodes.length<3) {
// If we don't have a locNest or at least 3 DOM items in there, it's an empty folder
if(!locNest || locNest.childNodes.length<3) {
// We now need to begin a new UL list
newUL = document.createElement("ul");
locNest = targetElem.parentNode.parentNode;

18
lib/ice-coder.min.js vendored
View File

@@ -65,15 +65,15 @@ a=a?a:top.ICEcoder.selectedFiles;b=a.toString().replace(/\|/g,"/").replace(/,/g,
pasteFiles:function(a){if(top.ICEcoder.copiedFiles)for(var b=0;b<top.ICEcoder.copiedFiles.length;b++)"|"!=top.ICEcoder.copiedFiles[b]?(top.ICEcoder.serverQueue("add","lib/file-control-xhr.php?action=paste&location="+a+"&csrf="+top.ICEcoder.csrf,top.ICEcoder.copiedFiles[b]),top.ICEcoder.serverMessage("<b>"+top.t["Pasting File"]+"</b><br>"+top.ICEcoder.copiedFiles[b].toString().replace(/\|/g,"/").replace(/,/g,"\n"))):top.ICEcoder.message(top.t["Sorry cannot paste..."]);else top.ICEcoder.message(top.t["Nothing to paste..."])},
duplicateFiles:function(a){var b;top.ICEcoder.copiedFiles&&(b=top.ICEcoder.copiedFiles);top.ICEcoder.copyFiles(a,"dontShowPaste","dontHide");a=a[0].substr(0,a[0].lastIndexOf("|"));top.ICEcoder.pasteFiles(a);"undefined"!=typeof b&&(top.ICEcoder.copiedFiles=b)},uploadFilesSelect:function(a){top.get("uploadDir").value=a;top.get("fileInput").click()},uploadFilesSubmit:function(a){""!=top.get("fileInput").value&&(top.ICEcoder.showHide("show",top.get("loadingMask")),top.get("uploadFilesForm").submit(),
event.preventDefault())},showHideFileNav:function(a,b){var c=["optionsFile","optionsEdit","optionsSource","optionsHelp"];if("hide"==a)fileNavInt=setTimeout(function(){for(var a=0;a<c.length;a++)top.ICEcoder.showHide("hide",top.get(c[a])),top.get(c[a]+"Nav").style.color=""},150);else for(var d=0;d<c.length;d++)top.ICEcoder.showHide("hide",top.get(c[d])),top.get(c[d]+"Nav").style.color="";get("fileOptions").style.opacity=0;"show"==a&&("undefined"!=typeof fileNavInt&&clearTimeout(fileNavInt),top.ICEcoder.showHide(a,
top.get(b)),top.get(b+"Nav").style.color="#fff",get("fileOptions").style.opacity=1)},isPathFolder:function(a){a=top.ICEcoder.filesFrame.contentDocument.getElementsByClassName("pft-directory");for(var b=top.ICEcoder.selectedFiles[0],c,d=0;d<a.length;d++)if(c=a[d],"underfined"!=typeof c&&(c=c.childNodes[0],"undefined"!=typeof c&&(c=c.childNodes[1],"undefined"!=typeof c&&b===c.getAttribute("id"))))return!0;return!1},checkExists:function(a){var b,c,d;a=a.replace(/\|/g,"/");b=top.ICEcoder.xhrObj();b.onreadystatechange=
function(){4==b.readyState&&(c=JSON.parse(b.responseText),c.action.timeEnd=(new Date).getTime(),c.action.timeTaken=c.action.timeEnd-c.action.timeStart,0<=["raw","both"].indexOf(top.ICEcoder.fileDirResOutput)&&console.log(b.responseText),0<=["object","both"].indexOf(top.ICEcoder.fileDirResOutput)&&console.log(c),top.ICEcoder.lastFileDirCheckStatusObj=c,200==b.status?c.status.error?(top.ICEcoder.message(c.status.errorMsg),console.log("ICEcoder error info for your request..."),console.log(c),top.ICEcoder.serverMessage(),
top.ICEcoder.serverQueue("del",0)):eval(c.action.doNext):(top.ICEcoder.message(top.t["Sorry there was..."]),console.log("ICEcoder error info for your request..."),console.log(c),top.ICEcoder.serverMessage(),top.ICEcoder.serverQueue("del",0)))};b.open("POST","lib/file-control-xhr.php?action=checkExists&csrf="+top.ICEcoder.csrf,!0);b.setRequestHeader("Content-type","application/x-www-form-urlencoded");d=(new Date).getTime();b.send("timeStart="+d+"&file="+a)},showMenu:function(a){var b,c;0!=top.ICEcoder.selectedFiles.length&&
-1!=top.ICEcoder.selectedFiles.indexOf(top.ICEcoder.selectedFiles[top.ICEcoder.selectedFiles.length-1].replace(/\//g,"|"))||top.ICEcoder.selectFileFolder(a);a=129;c=window.innerHeight;"undefined"!=typeof top.ICEcoder.thisFileFolderLink&&""!=top.ICEcoder.thisFileFolderLink&&(b=this.isPathFolder(top.ICEcoder.selectedFiles[0])?"folder":"file",top.get("folderMenuItems").style.display="folder"==b&&1==top.ICEcoder.selectedFiles.length?"block":"none","folder"==b&&1==top.ICEcoder.selectedFiles.length&&(a+=
67,"block"==top.get("fmMenuPasteOption").style.display&&(a+=19)),top.get("singleFileMenuItems").style.display=1<top.ICEcoder.selectedFiles.length?"none":"block",1==top.ICEcoder.selectedFiles.length&&(a+=43),top.get("fileMenu").style.display="inline-block",setTimeout(function(){top.get("fileMenu").style.opacity="1"},4),top.get("fileMenu").style.left=top.ICEcoder.mouseX+20+"px",b=top.ICEcoder.mouseY-top.ICEcoder.filesFrame.contentWindow.document.body.scrollTop-10,b+a>c&&(b-=b+a-c),top.get("fileMenu").style.top=
b+"px");return!1},showFileMenu:function(){top.get("fileMenu").style.display="inline-block";setTimeout(function(){top.get("fileMenu").style.opacity="1"},4)},hideFileMenu:function(){top.get("fileMenu").style.display="none";top.get("fileMenu").style.opacity="0"},updateFileManagerList:function(a,b,c,d,e,f,g){var h,k,l,p,n,m,q;if("add"==a&&!top.get("filesFrame").contentWindow.document.getElementById(b.replace(top.iceRoot,"").replace(/\/$/,"").replace(/\//g,"|")+"|"+c)){h="file"==g?"pft-file ext-"+c.substr(c.indexOf(".")+
1):"pft-directory";d="file"==g?top.ICEcoder.newFilePerms:top.ICEcoder.newDirPerms;b||(b="/");b=b.replace(top.iceRoot,"/");b=b.replace("//","/");k=top.get("filesFrame").contentWindow.document.getElementById(b.replace(/\//g,"|"));l=k.parentNode.parentNode.nextSibling;p=document.createTextNode("\n");n=777==d?"background: #800; color: #eee":"color: #888";n='<a nohref title="'+b.replace(/\/$/,"")+"/"+c+'" onMouseOver="parentNode.draggable=true;top.ICEcoder.overFileFolder(\''+g+"',this.childNodes[1].id)\" onMouseOut=\"parentNode.draggable=false;top.ICEcoder.overFileFolder('"+
g+"','')\" "+("folder"==g?"ondragover=\"if(parentNode.nextSibling && parentNode.nextSibling.tagName != 'UL' && top.ICEcoder.thisFileFolderLink != this.childNodes[1].id) {top.ICEcoder.openCloseDir(this,true);}\"":"")+' onClick="if(!event.ctrlKey && !top.ICEcoder.cmdKey) {'+("folder"==g?"top.ICEcoder.openCloseDir(this,"+("folder"==g?"true":"false")+");":"")+' if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {top.ICEcoder.openFile()}}" style="position: relative; left:-22px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span id="'+
b.replace(/\/$/,"").replace(/\//g,"|")+"|"+c+'">'+c+'</span> <span style="'+n+'; font-size: 8px" id="'+b.replace(/\/$/,"").replace(/\//g,"|")+"|"+c+'_perms">'+d+"</span></a>";if(3>l.childNodes.length)m=document.createElement("ul"),l=k.parentNode.parentNode,l.parentNode.insertBefore(m,l.nextSibling),m=document.createElement("li"),m.className=h,m.draggable=!1,m.ondrag=function(a){top.ICEcoder.draggingWithKeyTest(a);top.ICEcoder.getcMInstance()&&(-1==top.ICEcoder.editorFocusInstance.indexOf("diff")?
top.get(b)),top.get(b+"Nav").style.color="#fff",get("fileOptions").style.opacity=1)},isPathFolder:function(a){a=top.ICEcoder.filesFrame.contentDocument.getElementsByClassName("pft-directory");for(var b=top.ICEcoder.selectedFiles[0],c,d=0;d<a.length;d++)if(c=a[d],"underfined"!=typeof c&&(c=c.childNodes[0],"undefined"!=typeof c&&(c=c.childNodes[1],"undefined"!=typeof c&&b===c.getAttribute("id"))))return!0;return!1},checkExists:function(a){var b,c,d;a=a.replace(/\|/g,"/");0===a.indexOf(top.iceRoot)&&
(a=a.replace(top.iceRoot,""));b=top.ICEcoder.xhrObj();b.onreadystatechange=function(){4==b.readyState&&(c=JSON.parse(b.responseText),c.action.timeEnd=(new Date).getTime(),c.action.timeTaken=c.action.timeEnd-c.action.timeStart,0<=["raw","both"].indexOf(top.ICEcoder.fileDirResOutput)&&console.log(b.responseText),0<=["object","both"].indexOf(top.ICEcoder.fileDirResOutput)&&console.log(c),top.ICEcoder.lastFileDirCheckStatusObj=c,200==b.status?c.status.error?(top.ICEcoder.message(c.status.errorMsg),console.log("ICEcoder error info for your request..."),
console.log(c),top.ICEcoder.serverMessage(),top.ICEcoder.serverQueue("del",0)):eval(c.action.doNext):(top.ICEcoder.message(top.t["Sorry there was..."]),console.log("ICEcoder error info for your request..."),console.log(c),top.ICEcoder.serverMessage(),top.ICEcoder.serverQueue("del",0)))};b.open("POST","lib/file-control-xhr.php?action=checkExists&csrf="+top.ICEcoder.csrf,!0);b.setRequestHeader("Content-type","application/x-www-form-urlencoded");d=(new Date).getTime();b.send("timeStart="+d+"&file="+
a)},showMenu:function(a){var b,c;0!=top.ICEcoder.selectedFiles.length&&-1!=top.ICEcoder.selectedFiles.indexOf(top.ICEcoder.selectedFiles[top.ICEcoder.selectedFiles.length-1].replace(/\//g,"|"))||top.ICEcoder.selectFileFolder(a);a=129;c=window.innerHeight;"undefined"!=typeof top.ICEcoder.thisFileFolderLink&&""!=top.ICEcoder.thisFileFolderLink&&(b=this.isPathFolder(top.ICEcoder.selectedFiles[0])?"folder":"file",top.get("folderMenuItems").style.display="folder"==b&&1==top.ICEcoder.selectedFiles.length?
"block":"none","folder"==b&&1==top.ICEcoder.selectedFiles.length&&(a+=67,"block"==top.get("fmMenuPasteOption").style.display&&(a+=19)),top.get("singleFileMenuItems").style.display=1<top.ICEcoder.selectedFiles.length?"none":"block",1==top.ICEcoder.selectedFiles.length&&(a+=43),top.get("fileMenu").style.display="inline-block",setTimeout(function(){top.get("fileMenu").style.opacity="1"},4),top.get("fileMenu").style.left=top.ICEcoder.mouseX+20+"px",b=top.ICEcoder.mouseY-top.ICEcoder.filesFrame.contentWindow.document.body.scrollTop-
10,b+a>c&&(b-=b+a-c),top.get("fileMenu").style.top=b+"px");return!1},showFileMenu:function(){top.get("fileMenu").style.display="inline-block";setTimeout(function(){top.get("fileMenu").style.opacity="1"},4)},hideFileMenu:function(){top.get("fileMenu").style.display="none";top.get("fileMenu").style.opacity="0"},updateFileManagerList:function(a,b,c,d,e,f,g){var h,k,l,p,n,m,q;if("add"==a&&!top.get("filesFrame").contentWindow.document.getElementById(b.replace(top.iceRoot,"").replace(/\/$/,"").replace(/\//g,
"|")+"|"+c)){h="file"==g?"pft-file ext-"+c.substr(c.indexOf(".")+1):"pft-directory";d="file"==g?top.ICEcoder.newFilePerms:top.ICEcoder.newDirPerms;b||(b="/");b=b.replace(top.iceRoot,"/");b=b.replace("//","/");k=top.get("filesFrame").contentWindow.document.getElementById(b.replace(/\//g,"|"));l=k.parentNode.parentNode.nextSibling;p=document.createTextNode("\n");n=777==d?"background: #800; color: #eee":"color: #888";n='<a nohref title="'+b.replace(/\/$/,"")+"/"+c+'" onMouseOver="parentNode.draggable=true;top.ICEcoder.overFileFolder(\''+
g+"',this.childNodes[1].id)\" onMouseOut=\"parentNode.draggable=false;top.ICEcoder.overFileFolder('"+g+"','')\" "+("folder"==g?"ondragover=\"if(parentNode.nextSibling && parentNode.nextSibling.tagName != 'UL' && top.ICEcoder.thisFileFolderLink != this.childNodes[1].id) {top.ICEcoder.openCloseDir(this,true);}\"":"")+' onClick="if(!event.ctrlKey && !top.ICEcoder.cmdKey) {'+("folder"==g?"top.ICEcoder.openCloseDir(this,"+("folder"==g?"true":"false")+");":"")+' if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {top.ICEcoder.openFile()}}" style="position: relative; left:-22px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span id="'+
b.replace(/\/$/,"").replace(/\//g,"|")+"|"+c+'">'+c+'</span> <span style="'+n+'; font-size: 8px" id="'+b.replace(/\/$/,"").replace(/\//g,"|")+"|"+c+'_perms">'+d+"</span></a>";if(!l||3>l.childNodes.length)m=document.createElement("ul"),l=k.parentNode.parentNode,l.parentNode.insertBefore(m,l.nextSibling),m=document.createElement("li"),m.className=h,m.draggable=!1,m.ondrag=function(a){top.ICEcoder.draggingWithKeyTest(a);top.ICEcoder.getcMInstance()&&(-1==top.ICEcoder.editorFocusInstance.indexOf("diff")?
top.ICEcoder.getcMInstance().focus():top.ICEcoder.getcMdiffInstance().focus())},m.ondragend=function(){top.ICEcoder.dropFile(this)},m.innerHTML=n,l.nextSibling.appendChild(m),l.nextSibling.appendChild(p);else for(k=0;k<l.childNodes.length;k++)if(l.childNodes[k].className&&(m=0<l.childNodes[k].className.indexOf("directory")?"folder":"file",q=l.childNodes[k].getElementsByTagName("span")[0].innerHTML,m==g&&q>c||"folder"==g&&"file"==m||k==l.childNodes.length-1)){m=document.createElement("li");m.className=
h;m.draggable=!1;m.ondrag=function(a){top.ICEcoder.draggingWithKeyTest(a);top.ICEcoder.getcMInstance()&&(-1==top.ICEcoder.editorFocusInstance.indexOf("diff")?top.ICEcoder.getcMInstance().focus():top.ICEcoder.getcMdiffInstance().focus())};m.ondragend=function(){top.ICEcoder.dropFile(this)};m.innerHTML=n;k==l.childNodes.length-1?(l.appendChild(m),l.appendChild(p)):(l.insertBefore(m,l.childNodes[k]),l.insertBefore(p,l.childNodes[k+1]));break}"file"!=g||f||(top.ICEcoder.openFiles[top.ICEcoder.selectedTab-
1]=b+c)}"rename"==a&&(f=e.replace(/\//g,"|"),k=top.get("filesFrame").contentWindow.document.getElementById(f),k.innerHTML=c,k.id=b.replace(/\//g,"|")+"|"+c,k.parentNode.title=k.id.replace(/\|/g,"/"),targetElemPerms=top.get("filesFrame").contentWindow.document.getElementById(f+"_perms"),targetElemPerms.id=b.replace(/\//g,"|")+"|"+c+"_perms",top.ICEcoder.renameInChildren(k,e,b,c));"move"==a&&(top.ICEcoder.updateFileManagerList("add",b,c,!1,!1,!1,g),top.ICEcoder.updateFileManagerList("delete",e.substr(0,