Condensing code & new deselectAllFiles func

Syntax format improvements on fileManager function
selectFileFolder improvements:
- Removed a load of vars we no longer need & new tgtFile var added
- 2 x areas where we deselect files/folders now done via new function
- tgtFile now avail to avoid duplicate setup
- Other much more efficient and clearer processes setup to achieve same
result
New function added to deselect all files
Ternary shortening on colouring of selected/deselected files & folders
Swapped var order around
This commit is contained in:
Matt Pass
2012-09-30 14:55:59 +01:00
parent e14a8df6a0
commit 80d717b4dc

View File

@@ -597,9 +597,9 @@ var ICEcoder = {
submenu[j].onclick = function() {
var node = this.parentNode.nextSibling.nextSibling;
if (node && node.tagName=="UL") {
var d=(node.style.display=="none");
node.style.display=(d) ? "block" : "none";
this.parentNode.className=this.className=(d) ? "pft-directory dirOpen" : "pft-directory";
var d = node.style.display=="none";
node.style.display = d ? "block" : "none";
this.parentNode.className=this.className = d ? "pft-directory dirOpen" : "pft-directory";
}
return false;
}
@@ -624,59 +624,38 @@ var ICEcoder = {
// Select file or folder on demand
selectFileFolder: function() {
var resetFile, shortURL, foundSelectedFile, foundShortURL, foundFile;
var tgtFile, shortURL;
// If we've clicked somewhere other than a file/folder
if (top.ICEcoder.thisFileFolderLink=="") {
if (!top.ICEcoder.ctrlKeyDown) {
// Deselect all files
for (var i=0;i<=top.ICEcoder.selectedFiles.length;i++) {
if (top.ICEcoder.selectedFiles[i]) {
resetFile = top.ICEcoder.filesFrame.contentWindow.document.getElementById(top.ICEcoder.selectedFiles[i]);
ICEcoder.selectDeselectFile('deselect',resetFile);
}
}
// Set our array to contain 0 items
top.ICEcoder.selectedFiles.length = 0;
top.ICEcoder.deselectAllFiles();
}
} else if (top.ICEcoder.thisFileFolderLink) {
// We clicked a file/folder. Work out a shortened URL for the file, with pipes instead of slashes
// Get file URL, with pipes instead of slashes & target DOM elem
shortURL = top.ICEcoder.thisFileFolderLink.replace(/\//g,"|");
tgtFile = ICEcoder.filesFrame.contentWindow.document.getElementById(shortURL);
// If we have the CTRL key down
if (top.ICEcoder.ctrlKeyDown) {
foundSelectedFile=false;
// Deselect previously selected file?
for (i=0;i<=top.ICEcoder.selectedFiles.length;i++) {
if (top.ICEcoder.selectedFiles[i]==shortURL) {
resetFile = ICEcoder.filesFrame.contentWindow.document.getElementById(top.ICEcoder.selectedFiles[i]);
ICEcoder.selectDeselectFile('deselect',resetFile);
top.ICEcoder.selectedFiles.splice(i);
foundSelectedFile=true;
}
}
if (!foundSelectedFile) {
foundFile = ICEcoder.filesFrame.contentWindow.document.getElementById(shortURL);
ICEcoder.selectDeselectFile('select',foundFile);
// Deselect or select file
if (top.ICEcoder.selectedFiles.indexOf(shortURL)>-1) {
ICEcoder.selectDeselectFile('deselect',tgtFile);
top.ICEcoder.selectedFiles.splice(top.ICEcoder.selectedFiles.indexOf(shortURL),1);
} else {
ICEcoder.selectDeselectFile('select',tgtFile);
top.ICEcoder.selectedFiles.push(shortURL);
}
// We are single clicking
} else {
// First deselect all files
for (i=0;i<top.ICEcoder.selectedFiles.length;i++) {
resetFile = ICEcoder.filesFrame.contentWindow.document.getElementById(top.ICEcoder.selectedFiles[i]);
ICEcoder.selectDeselectFile('deselect',resetFile);
}
// Set our arrray to contain 0 items
top.ICEcoder.selectedFiles.length = 0;
top.ICEcoder.deselectAllFiles();
// Add our URL and highlight the file
ICEcoder.selectDeselectFile('select',tgtFile);
top.ICEcoder.selectedFiles.push(shortURL);
foundFile = ICEcoder.filesFrame.contentWindow.document.getElementById(shortURL);
ICEcoder.selectDeselectFile('select',foundFile);
}
}
// Adjust the file & replace select values depending on if we have files selected
// Adjust the file & replace select dropdown values accordingly
document.findAndReplace.target[2].innerHTML = !top.ICEcoder.selectedFiles[0] ? "all files" : "selected files";
document.findAndReplace.target[3].innerHTML = !top.ICEcoder.selectedFiles[0] ? "all filenames" : "selected filenames";
@@ -690,6 +669,17 @@ var ICEcoder = {
top.document.getElementById('fileMenu').style.display = "none";
},
// Deselect all files
deselectAllFiles: function() {
var tgtFile;
for (var i=0;i<top.ICEcoder.selectedFiles.length;i++) {
tgtFile = top.ICEcoder.filesFrame.contentWindow.document.getElementById(top.ICEcoder.selectedFiles[i]);
ICEcoder.selectDeselectFile('deselect',tgtFile);
}
top.ICEcoder.selectedFiles.length = 0;
},
// Select or deselect file
selectDeselectFile: function(action,file) {
var isOpen;
@@ -699,11 +689,9 @@ var ICEcoder = {
if (top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1] == file.id.replace(/\|/g,"/")) {
file.style.backgroundColor="#49d";
} else {
if (action=="select") {
file.style.backgroundColor="#888";
} else {
file.style.backgroundColor = isOpen ? "rgba(255,255,255,0.15)" : "transparent";
}
file.style.backgroundColor = action=="select"
? "#888" : file.style.backgroundColor = isOpen
? "rgba(255,255,255,0.15)" : "transparent";
}
file.style.color= action=="select" ? "#fff" : "#eee";
},
@@ -716,7 +704,7 @@ var ICEcoder = {
// Create a new folder
newFolder: function() {
var newFolder, shortURL;
var shortURL, newFolder;
shortURL = top.ICEcoder.rightClickedFile.replace(/\|/g,"/");
newFolder = top.ICEcoder.getInput('Enter New Folder Name at '+shortURL,'');