From 80d717b4dc7dd1c431ec1c7c954da4de3b587e70 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Sun, 30 Sep 2012 14:55:59 +0100 Subject: [PATCH] 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 --- lib/coder.js | 74 ++++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/lib/coder.js b/lib/coder.js index a3b57fb..823f132 100644 --- a/lib/coder.js +++ b/lib/coder.js @@ -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