mirror of
https://github.com/icecoder/ICEcoder.git
synced 2026-03-04 15:54:00 +01:00
Simplifying and condensing code
No need to return cM in getcMInstance, just return the ternary value Shortened a few comments for clarity & byte saving No need to add length as 2nd param on substrs in a couple of places newTab setup as string to be used in a couple of places Ternary shortening on elemType Converted ternary statement back to if else to byte save on 2 ternaries Reversing bool on codeAssist var by using ! instead break is shorter & better too, than increasing i's value to escape
This commit is contained in:
42
lib/coder.js
42
lib/coder.js
@@ -1021,14 +1021,11 @@ var ICEcoder = {
|
||||
|
||||
// Determine the CodeMirror instance we're using on demand
|
||||
getcMInstance: function(newTab) {
|
||||
var cM;
|
||||
|
||||
cM = top.ICEcoder.content.contentWindow[
|
||||
return top.ICEcoder.content.contentWindow[
|
||||
newTab=="new"||(newTab!="new" && ICEcoder.openFiles.length>0)
|
||||
? 'cM'+ICEcoder.cMInstances[ICEcoder.selectedTab-1]
|
||||
: 'cM1'
|
||||
];
|
||||
return cM;
|
||||
},
|
||||
|
||||
// Start running plugin intervals according to given specifics
|
||||
@@ -1145,13 +1142,13 @@ var ICEcoder = {
|
||||
|
||||
// Update the file manager tree list on demand
|
||||
updateFileManagerList: function(action,location,file,perms,oldName) {
|
||||
var actionElemType, cssStyle, perms, targetElem, locNest, newText, newUL, newLI, nameLI, shortURL, newMouseOver;
|
||||
var actionElemType, cssStyle, perms, targetElem, locNest, newText, newTab, newUL, newLI, elemType, 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
|
||||
// Is this is a file or folder and based on that, set the CSS styling & link
|
||||
actionElemType = file.indexOf(".")>-1 ? "file" : "folder";
|
||||
cssStyle = actionElemType=="file" ? "pft-file ext-" + file.substr(file.indexOf(".")+1,file.length) : "pft-directory";
|
||||
cssStyle = actionElemType=="file" ? "pft-file ext-" + file.substr(file.indexOf(".")+1) : "pft-directory";
|
||||
perms = actionElemType=="file" ? 664 : 705;
|
||||
|
||||
// Identify our target element & the first child element in it's location
|
||||
@@ -1161,6 +1158,7 @@ var ICEcoder = {
|
||||
locNest = targetElem.parentNode.parentNode.nextSibling;
|
||||
if (locNest.nextSibling) {locNest = locNest.nextSibling}
|
||||
newText = document.createTextNode("\n");
|
||||
newTab = '<a nohref 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">'+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) {
|
||||
@@ -1169,10 +1167,10 @@ var ICEcoder = {
|
||||
locNest = targetElem.parentNode.parentNode;
|
||||
locNest.parentNode.insertBefore(newUL,locNest.nextSibling);
|
||||
|
||||
// Finally we can add the first list item for this file/folder we're adding
|
||||
// Now we can add the first LI for this file/folder we're adding
|
||||
newLI = document.createElement("li");
|
||||
newLI.className = cssStyle;
|
||||
newLI.innerHTML = '<a nohref 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">'+perms+'</span></a>';
|
||||
newLI.innerHTML = newTab
|
||||
locNest.nextSibling.appendChild(newLI);
|
||||
locNest.nextSibling.appendChild(newText);
|
||||
|
||||
@@ -1181,23 +1179,25 @@ var ICEcoder = {
|
||||
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";
|
||||
elemType = locNest.childNodes[i].className.indexOf('directory')>0 ? "folder" : "file";
|
||||
|
||||
// Get the name of the item
|
||||
nameLI = locNest.childNodes[i].getElementsByTagName('span')[0].innerHTML;
|
||||
|
||||
// If it's of the same type & the name is greater, or we're adding a folder and it's a file or if we're at the end of the list
|
||||
// then we can add in here
|
||||
if ((elemType==actionElemType && nameLI > file) || (actionElemType=="folder" && elemType=="file") || i==locNest.childNodes.length-1) {
|
||||
newLI = document.createElement("li");
|
||||
newLI.className = cssStyle;
|
||||
newLI.innerHTML = '<a nohref 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">'+perms+'</span></a>';
|
||||
newLI.innerHTML = newTab;
|
||||
// Append or insert depending on which of the above if statements is true
|
||||
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;
|
||||
if (i==locNest.childNodes.length-1) {
|
||||
locNest.appendChild(newLI);
|
||||
locNest.appendChild(newText);
|
||||
} else {
|
||||
locNest.insertBefore(newLI,locNest.childNodes[i]);
|
||||
locNest.insertBefore(newLI,locNest.childNodes[i+1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1210,14 +1210,14 @@ var ICEcoder = {
|
||||
|
||||
// Renaming files
|
||||
if (action=="rename") {
|
||||
// Identify a shortened URL for our right clicked file and get our target element based on this
|
||||
// Get short URL of our right clicked file and get target elem based on this
|
||||
shortURL = oldName;
|
||||
targetElem = document.getElementById('filesFrame').contentWindow.document.getElementById(shortURL.replace(/\//g,"|"));
|
||||
// Set the name to be as per our new file/folder name
|
||||
targetElem.innerHTML = file;
|
||||
// Finally, update the ID of the target & set a new mouseover function for the parent too
|
||||
targetElem.id = location.replace(/\//g,"|") + "|" + file;
|
||||
newMouseOver = targetElem.parentNode.onmouseover.toString().replace(shortURL.substring(shortURL.lastIndexOf("|")+1,shortURL.length),file).split('\'');
|
||||
newMouseOver = targetElem.parentNode.onmouseover.toString().replace(shortURL.substring(shortURL.lastIndexOf("|")+1),file).split('\'');
|
||||
eval("targetElem.parentNode.onmouseover = function() { top.ICEcoder.overFileFolder('"+newMouseOver[1]+"','"+newMouseOver[3]+"');}");
|
||||
targetElemPerms = document.getElementById('filesFrame').contentWindow.document.getElementById(shortURL.replace(/\//g,"|")+"_perms");
|
||||
targetElemPerms.id = location.replace(/\//g,"|") + "|" + file + "_perms";
|
||||
@@ -1225,7 +1225,7 @@ var ICEcoder = {
|
||||
|
||||
// Chmod on files
|
||||
if (action=="chmod") {
|
||||
// Identify a shortened URL for our file and get our target element based on this
|
||||
// Get short URL for our file and get our target elem based on this
|
||||
shortURL = top.ICEcoder.rightClickedFile.replace(/\|/g,"/");
|
||||
targetElem = document.getElementById('filesFrame').contentWindow.document.getElementById(shortURL.replace(/\//g,"|")+"_perms");
|
||||
// Set the new perms
|
||||
@@ -1245,7 +1245,7 @@ var ICEcoder = {
|
||||
var cM;
|
||||
|
||||
cM = ICEcoder.getcMInstance();
|
||||
top.ICEcoder.codeAssist = top.ICEcoder.codeAssist ? false : true;
|
||||
top.ICEcoder.codeAssist = !top.ICEcoder.codeAssist;
|
||||
top.ICEcoder.cssColorPreview();
|
||||
cM.focus();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user