Extra nestTagException for ?php (not that it makes difference)

Removed ICEcoder.tD var as it was hardly used and theress no char saving really
Switched a few areas to ternary if statements
Code improvements, structure tidy up & improved commenting
Removed unnecessary code, stopped a few global vars
Also considering ?php as well as ?
Breaking tagEnd var on new lines to avoid nesting false errors
CTRL+I searches for highlighted word on Google in a context aware way
(ie, highlight 'echo' in a PHP block and it will search for 'PHP echo',
highlighting 'echo' in content area will search for just 'echo')
New function to select/deselect file/folder by changing CSS class
Only show New File and New Folder context menu options if we right clicked a folder
Simplified getcMInstance function
Improved commenting function to allow partial line commenting
Fixed issue with clicking plugin icons and server queue deletion on return
Fixed issue with CSS color blocks so they only show if they have a BG color
This commit is contained in:
Matt Pass
2012-04-01 12:43:18 +01:00
parent 215229d051
commit 77aaa16be4

View File

@@ -27,16 +27,15 @@ var ICEcoder = {
serverQueueItems: [], // Array of URLs to call in order
// Don't consider these tags as part of nesting as they're singles, JS or PHP code blocks
tagNestExceptions: ["!DOCTYPE","meta","link","img","br","hr","input","script","?"],
tagNestExceptions: ["!DOCTYPE","meta","link","img","br","hr","input","script","?php","?"],
// On load, set aliases, set the layout and get the nest location
init: function() {
var aliasArray = ["header","files","account","fmLock","filesFrame","editor","tabsBar","findBar","content","footer","nestValid","nestDisplay","charDisplay"];
ICEcoder.tD = top.document;
// Create our ID aliases
for (var i=0;i<aliasArray.length;i++) {
ICEcoder[aliasArray[i]] = ICEcoder.tD.getElementById(aliasArray[i]);
ICEcoder[aliasArray[i]] = top.document.getElementById(aliasArray[i]);
}
// Set layout & the nest location
@@ -46,18 +45,13 @@ var ICEcoder = {
top.document.getElementById('loadingMask').style.visibility = "hidden";
},
// Set out our layout according to the browser size
// Set our layout according to the browser size
setLayout: function(dontSetEditor) {
var winW, winH, headerH, footerH, accountH, tabsBarH, findBarH, cMCSS;
// Determin width & height available
if (window.innerWidth) {
var winW = window.innerWidth;
var winH = window.innerHeight;
} else {
var winW = document.body.clientWidth;
var winH = document.body.clientHeight;
}
window.innerWidth ? winW = window.innerWidth : winW = document.body.clientWidth;
window.innerHeight ? winH = window.innerHeight : winH = document.body.clientHeight;
// Apply sizes to various elements of the page
headerH = 40, footerH = 30, accountH = 50, tabsBarH = 21, findBarH = 28;
@@ -67,6 +61,7 @@ var ICEcoder = {
fmLock.style.marginLeft = (this.filesW-27) + "px";
filesFrame.style.height = (winH-headerH-accountH-footerH) + "px";
// If we need to set the editor sizes
if (!dontSetEditor) {
editor.style.width = ICEcoder.content.style.width = (winW-this.filesW) + "px";
ICEcoder.content.style.height = (winH-headerH-footerH-tabsBarH-findBarH) + "px";
@@ -82,11 +77,11 @@ var ICEcoder = {
// Clean up our loaded code
contentCleanUp: function() {
var fileName;
var fileName, cM, content;
// If it's not a JS or CSS file, replace & and our temp </textarea> value
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
if (fileName.indexOf(".js")<0&&fileName.indexOf(".css")<0) {
var cM, content;
cM = ICEcoder.getcMInstance();
content = cM.getValue();
if (top.ICEcoder.codeAssist) {content = content.replace(/ & /g,' &amp; ');};
@@ -101,6 +96,7 @@ var ICEcoder = {
// Work out the nesting depth location on demand and update our display if required
getNestLocation: function(updateNestDisplay) {
var cM, openTag, nestCheck, startPos, tagStart, canDoTheEndTag, tagEnd, tagEndJS, fileName;
cM = ICEcoder.getcMInstance();
nestCheck = cM.getValue();
@@ -117,7 +113,7 @@ var ICEcoder = {
// Get the tag name and if it's the start of a code block, set the var for that
tagStart=nestCheck.substr(startPos,nestCheck.length).split(" ")[0].split(">")[0].split("\n")[0];
if (tagStart=="script"||tagStart=="?") {ICEcoder.codeBlock=true}
if (tagStart=="script"||tagStart=="?php"||tagStart=="?") {ICEcoder.codeBlock=true}
if (tagStart!="") {ICEcoder.tagStart = tagStart}
};
@@ -145,6 +141,7 @@ var ICEcoder = {
tagEnd=tagEnd.substr(tagEnd.lastIndexOf('<')+1,tagEnd.length);
tagEnd=tagEnd.substr(tagEnd.lastIndexOf(' ')+1,tagEnd.length);
tagEnd=tagEnd.substr(tagEnd.lastIndexOf('\t')+1,tagEnd.length);
tagEnd=tagEnd.substr(tagEnd.lastIndexOf('\n')+1,tagEnd.length);
tagEnd=tagEnd.substr(tagEnd.lastIndexOf(';')+1,tagEnd.length);
if (!ICEcoder.codeBlock) {
@@ -159,7 +156,7 @@ var ICEcoder = {
}
} else if (
((ICEcoder.tagStart=="script"||ICEcoder.tagStart=="/script")&&tagEndJS=="</script")||
(ICEcoder.tagStart=="?"&&tagEnd=="?")) {
((ICEcoder.tagStart=="?php"||ICEcoder.tagStart=="?")&&tagEnd=="?")) {
ICEcoder.codeBlock=false;
}
}
@@ -191,6 +188,7 @@ var ICEcoder = {
// Detect keys/combos plus identify our area and set the vars, perform actions
interceptKeys: function(area, evt) {
var key;
key = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;
// DEL (Delete file)
@@ -215,13 +213,23 @@ var ICEcoder = {
top.ICEcoder.ctrlKeyDown = false;
return false;
// CTRL+G (Go to Line)
// CTRL+G (Go to line)
} else if(key==71 && top.ICEcoder.ctrlKeyDown==true) {
top.document.getElementById('goToLineNo').focus();
top.ICEcoder.ctrlKeyDown = false;
return false;
// CTRL+S (Save)
// CTRL+I (Get info)
} else if(key==73 && top.ICEcoder.ctrlKeyDown==true && area == "content") {
var searchPrefix = "";
if (top.ICEcoder.caretLocType!="Content") {
searchPrefix = top.ICEcoder.caretLocType.toLowerCase()+" ";
}
window.open("http://www.google.com/#output=search&q="+searchPrefix+top.ICEcoder.getcMInstance().getSelection());
top.ICEcoder.ctrlKeyDown = false;
return false;
// CTRL+S (Save), CTRL+Shift+S (Save As)
} else if(key==83 && top.ICEcoder.ctrlKeyDown==true) {
if(top.ICEcoder.shiftKeyDown==true) {
top.ICEcoder.saveFile('saveAs');
@@ -252,6 +260,7 @@ var ICEcoder = {
// Reset the state of keys back to the normal state
resetKeys: function(evt) {
var key;
key = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;
if (key==17) {top.ICEcoder.ctrlKeyDown = false;}
@@ -261,7 +270,6 @@ var ICEcoder = {
// Set the width of the file manager on demand
changeFilesW: function(expandContract) {
var expandContract;
if (!ICEcoder.lockedNav) {
if ("undefined" != typeof ICEcoder.changeFilesInt) {clearInterval(ICEcoder.changeFilesInt)};
@@ -306,15 +314,15 @@ var ICEcoder = {
}
},
// Change tabs by reloading content
// Change tabs by switching visibility of instances
switchTab: function(newTab) {
var cM;
// Identify tab that's currently selected & show the instance
// Identify tab that's currently selected & get the instance
ICEcoder.selectedTab = newTab;
cM = ICEcoder.getcMInstance();
// Switch mode
// Switch mode to HTML, PHP, CSS etc
ICEcoder.switchMode();
// Set all cM instances to be hidden, then make our selected instance visable
@@ -324,7 +332,6 @@ var ICEcoder = {
cM.setOption('theme','icecoder visible');
// Focus on & refresh our selected instance
cM = ICEcoder.getcMInstance();
cM.focus();
cM.refresh();
@@ -334,14 +341,16 @@ var ICEcoder = {
// Reset all tabs to be without a highlight and then highlight the selected
redoTabHighlight: function(selectedTab) {
for(var i=1;i<=10;i++) {
var bgVPos;
for(var i=1;i<=ICEcoder.changedContent.length;i++) {
ICEcoder.changedContent[i-1]==1 ? bgVPos = -44 : bgVPos = 0;
i==selectedTab ? ICEcoder.changedContent[selectedTab-1]==1 ? bgVPos = -33 : bgVPos = -22 : bgVPos = bgVPos;
document.getElementById('tab'+i).style.backgroundPosition = "0px "+bgVPos+"px";
}
},
// Starts a new file by setting a few vars & clearing the editor
// Starts a new file by setting a few vars & creating a new cM instance
newTab: function() {
var cM;
@@ -397,8 +406,8 @@ var ICEcoder = {
// Indicate if the nesting structure of the code is OK
updateNestingIndicator: function () {
var cM, fileName;
cM = ICEcoder.getcMInstance();
cM = ICEcoder.getcMInstance();
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
ICEcoder.caretPos=cM.getValue().length;
ICEcoder.getNestLocation();
@@ -415,9 +424,9 @@ var ICEcoder = {
// Get the caret position on demand
getCaretPosition: function() {
var cM, content, line, char, charPos, charCount;
cM = ICEcoder.getcMInstance();
content = cM.getValue();
line = cM.getCursor().line;
char = cM.getCursor().ch;
charPos = 0;
@@ -432,8 +441,8 @@ var ICEcoder = {
// Update the code type, line & character display
updateCharDisplay: function() {
var cM;
cM = ICEcoder.getcMInstance();
cM = ICEcoder.getcMInstance();
ICEcoder.caretLocationType();
ICEcoder.charDisplay.innerHTML = ICEcoder.caretLocType + ", Line: " + (cM.getCursor().line+1) + ", Char: " + cM.getCursor().ch;
},
@@ -441,8 +450,8 @@ var ICEcoder = {
// Determine which area of the document we're in
caretLocationType: function () {
var cM, caretLocType, caretChunk, fileName;
cM = ICEcoder.getcMInstance();
cM = ICEcoder.getcMInstance();
caretLocType = "Unknown";
caretChunk = cM.getValue().substr(0,ICEcoder.caretPos+1);
if (caretChunk.lastIndexOf("<script")>caretChunk.lastIndexOf("</script>")&&caretLocType=="Unknown") {caretLocType = "JavaScript"};
@@ -450,7 +459,6 @@ var ICEcoder = {
if (caretChunk.lastIndexOf("<")>caretChunk.lastIndexOf(">")&&caretLocType=="Unknown") {caretLocType = "HTML"};
if (caretLocType=="Unknown") {caretLocType = "Content"};
var fileName;
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
if (fileName.indexOf(".js")>0) {caretLocType="JavaScript"};
if (fileName.indexOf(".css")>0) {caretLocType="CSS"};
@@ -477,10 +485,9 @@ var ICEcoder = {
// Close the tab upon request
closeTab: function(closeTabNum) {
var cM, okToRemove;
cM = ICEcoder.getcMInstance();
cM = ICEcoder.getcMInstance();
okToRemove = true;
if (ICEcoder.changedContent[closeTabNum-1]==1) {
okToRemove = confirm('You have made changes.\n\nAre you sure you want to close without saving?');
@@ -489,11 +496,11 @@ var ICEcoder = {
if (okToRemove) {
// recursively copy over all tabs & data from the tab to the right, if there is one
for (var i=closeTabNum;i<ICEcoder.openFiles.length;i++) {
ICEcoder.tD.getElementById('tab'+i).innerHTML = ICEcoder.tD.getElementById('tab'+(i+1)).innerHTML;
top.document.getElementById('tab'+i).innerHTML = top.document.getElementById('tab'+(i+1)).innerHTML;
ICEcoder.openFiles[i-1] = ICEcoder.openFiles[i];
// reduce the tab reference number on the closeTab link by 1
ICEcoder.tD.getElementById('tab'+i).innerHTML = ICEcoder.tD.getElementById('tab'+i).innerHTML.replace(("closeTab("+(i+1)+")"),"closeTab("+i+")");
top.document.getElementById('tab'+i).innerHTML = top.document.getElementById('tab'+i).innerHTML.replace(("closeTab("+(i+1)+")"),"closeTab("+i+")");
}
// hide the instance we're closing by setting the hide class, clear the value & remove from the array
@@ -502,8 +509,8 @@ var ICEcoder = {
top.ICEcoder.cMInstances.splice(closeTabNum-1,1);
// clear the rightmost tab (or only one left in a 1 tab scenario) & remove from the array
ICEcoder.tD.getElementById('tab'+ICEcoder.openFiles.length).style.display = "none";
ICEcoder.tD.getElementById('tab'+ICEcoder.openFiles.length).innerHTML = "";
top.document.getElementById('tab'+ICEcoder.openFiles.length).style.display = "none";
top.document.getElementById('tab'+ICEcoder.openFiles.length).innerHTML = "";
ICEcoder.openFiles.pop();
// Determin the new selectedTab number, reduced by 1 if we have some tabs, 0 for a reset state
@@ -512,7 +519,7 @@ var ICEcoder = {
// hide the content area if we have no tabs open
if (ICEcoder.openFiles.length==0) {
ICEcoder.tD.getElementById('content').style.visibility = "hidden";
top.document.getElementById('content').style.visibility = "hidden";
} else {
// Switch the mode & the tab
ICEcoder.switchMode();
@@ -534,9 +541,9 @@ var ICEcoder = {
var aMenus = ICEcoder.filesFrame.contentWindow.document.getElementsByTagName("LI");
for (var i=0; i<aMenus.length; i++) {
var mclass = aMenus[i].className;
var mclass = aMenus[i].className;
if (mclass.indexOf("pft-directory") > -1) {
var submenu=aMenus[i].childNodes;
var submenu=aMenus[i].childNodes;
for (var j=0; j<submenu.length; j++) {
if (submenu[j].tagName == "A") {
submenu[j].onclick = function() {
@@ -558,8 +565,9 @@ var ICEcoder = {
}
submenu[j].className = (mclass.indexOf("open") > -1) ? "open" : "closed";
}
if (submenu[j].tagName == "UL")
if (submenu[j].tagName == "UL") {
submenu[j].style.display = (mclass.indexOf("open") > -1) ? "block" : "none";
}
}
}
}
@@ -576,69 +584,70 @@ var ICEcoder = {
selectFileFolder: function() {
var resetFile, shortURL, foundSelectedFile, foundShortURL, foundFile;
// 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]);
resetFile.style.backgroundColor="#dddddd";
resetFile.style.color="#000000";
// 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 arrray to contain 0 items
top.ICEcoder.selectedFiles.length = 0;
}
// Set our arrray to contain 0 items
top.ICEcoder.selectedFiles.length = 0;
}
} else {
// We clicked a file/folder. Work out a shortened URL for the file, with pipes instead of slashes
shortURL = top.ICEcoder.thisFileFolderLink.substr((top.ICEcoder.thisFileFolderLink.indexOf(shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.thisFileFolderLink.length).replace(/\//g,"|");
// If we have the CTRL key down
if (top.ICEcoder.ctrlKeyDown) {
foundSelectedFile=false;
// Reset all files to not be highlighted
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]);
resetFile.style.backgroundColor="#dddddd";
resetFile.style.color="#000000";
top.ICEcoder.selectedFiles.splice(i);
foundSelectedFile=true;
}
}
if (!foundSelectedFile) {
foundFile = ICEcoder.filesFrame.contentWindow.document.getElementById(shortURL);
foundFile.style.backgroundColor="#888888";
foundFile.style.color="#f8f8f8";
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]);
resetFile.style.backgroundColor="#dddddd";
resetFile.style.color="#000000";
}
// Set our arrray to contain 0 items
top.ICEcoder.selectedFiles.length = 0;
// We clicked a file/folder. Work out a shortened URL for the file, with pipes instead of slashes
shortURL = top.ICEcoder.thisFileFolderLink.substr((top.ICEcoder.thisFileFolderLink.indexOf(shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.thisFileFolderLink.length).replace(/\//g,"|");
// 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);
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;
// Add our URL and highlight the file
top.ICEcoder.selectedFiles.push(shortURL);
foundFile = ICEcoder.filesFrame.contentWindow.document.getElementById(shortURL);
foundFile.style.backgroundColor="#888888";
foundFile.style.color="#f8f8f8";
// Add our URL and highlight the file
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
if (!top.ICEcoder.selectedFiles[0]) {
document.findAndReplace.target[2].innerHTML = "all files";
document.findAndReplace.target[3].innerHTML = "all filenames";
} else {
document.findAndReplace.target[2].innerHTML = "selected files";
document.findAndReplace.target[3].innerHTML = "selected filenames";
}
// Adjust the file & replace select values depending on if we have files selected
if (!top.ICEcoder.selectedFiles[0]) {
document.findAndReplace.target[2].innerHTML = "all files";
document.findAndReplace.target[3].innerHTML = "all filenames";
} else {
document.findAndReplace.target[2].innerHTML = "selected files";
document.findAndReplace.target[3].innerHTML = "selected filenames";
}
},
// Select or deselect file
selectDeselectFile: function(action,file) {
action == "select" ? file.style.backgroundColor="#888888" : file.style.backgroundColor="#dddddd";
action == "select" ? file.style.color="#f8f8f8" : file.style.color="#000000";
},
// Create a new file (start & instant save)
@@ -652,9 +661,7 @@ var ICEcoder = {
var newFolder, shortURL;
shortURL = top.ICEcoder.rightClickedFile.substr((top.ICEcoder.rightClickedFile.indexOf(shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.rightClickedFile.length).replace(/\|/g,"/");
newFolder = prompt('Enter New Folder Name at '+shortURL+'/','');
if (newFolder) {
newFolder = shortURL + "/" + newFolder;
top.ICEcoder.serverQueue("add","lib/file-control.php?action=newFolder&file="+newFolder.replace(/\//g,"|"));
@@ -664,53 +671,53 @@ var ICEcoder = {
// Open a file on demand
openFile: function() {
if (top.ICEcoder.thisFileFolderLink!="" && top.ICEcoder.thisFileFolderType=="file") {
var shortURL, canOpenFile;
if (top.ICEcoder.thisFileFolderLink!="" && top.ICEcoder.thisFileFolderType=="file") {
var shortURL, canOpenFile;
// work out a shortened URL for the file
shortURL = top.ICEcoder.thisFileFolderLink.replace(/\|/g,"/");
shortURL = shortURL.substr((shortURL.indexOf(shortURLStarts)+shortURLStarts.length),shortURL.length);
// work out a shortened URL for the file
shortURL = top.ICEcoder.thisFileFolderLink.replace(/\|/g,"/");
shortURL = shortURL.substr((shortURL.indexOf(shortURLStarts)+shortURLStarts.length),shortURL.length);
// No reason why we can't open a file (so far)
canOpenFile = true;
// No reason why we can't open a file (so far)
canOpenFile = true;
// Limit to 10 files open at a time
if (top.ICEcoder.openFiles.length<10) {
// check if we've already got it in our array
for (var i=0;i<top.ICEcoder.openFiles.length;i++) {
if (top.ICEcoder.openFiles[i]==shortURL && shortURL!="/[NEW]") {
// we have, so don't bother opening again
canOpenFile = false;
// instead, switch to that tab
top.ICEcoder.switchTab(i+1);
// Limit to 10 files open at a time
if (top.ICEcoder.openFiles.length<10) {
// check if we've already got it in our array
for (var i=0;i<top.ICEcoder.openFiles.length;i++) {
if (top.ICEcoder.openFiles[i]==shortURL && shortURL!="/[NEW]") {
// we have, so don't bother opening again
canOpenFile = false;
// instead, switch to that tab
top.ICEcoder.switchTab(i+1);
}
}
} else {
// show a message because we have 10 files open
alert('Sorry, you can only have 10 files open at a time!');
canOpenFile = false;
}
// if we're still OK to open it...
if (canOpenFile) {
top.ICEcoder.shortURL = shortURL;
if (shortURL!="/[NEW]") {
// replace forward slashes with pipes so it get be placed in a querystring
top.ICEcoder.thisFileFolderLink = top.ICEcoder.thisFileFolderLink.replace(/\//g,"|");
top.ICEcoder.serverQueue("add","lib/file-control.php?action=load&file="+top.ICEcoder.thisFileFolderLink);
top.ICEcoder.serverMessage('<b>Opening File</b><br>'+top.ICEcoder.shortURL);
} else {
top.ICEcoder.createNewTab();
}
}
} else {
// show a message because we have 10 files open
alert('Sorry, you can only have 10 files open at a time!');
canOpenFile = false;
}
// if we're still OK to open it...
if (canOpenFile) {
top.ICEcoder.shortURL = shortURL;
if (shortURL!="/[NEW]") {
// replace forward slashes with pipes so it get be placed in a querystring
top.ICEcoder.thisFileFolderLink = top.ICEcoder.thisFileFolderLink.replace(/\//g,"|");
top.ICEcoder.serverQueue("add","lib/file-control.php?action=load&file="+top.ICEcoder.thisFileFolderLink);
top.ICEcoder.serverMessage('<b>Opening File</b><br>'+top.ICEcoder.shortURL);
} else {
top.ICEcoder.createNewTab();
}
}
}
},
// Save a file on demand
saveFile: function(saveAs) {
var saveType;
if (saveAs) {saveType = "saveAs"} else {saveType = "save"};
saveAs ? saveType = "saveAs" : saveType = "save";
top.ICEcoder.serverQueue("add","lib/file-control.php?action=save&file="+ICEcoder.openFiles[ICEcoder.selectedTab-1].replace(/\//g,"|")+"&saveType="+saveType);
top.ICEcoder.serverMessage('<b>Saving</b><br>'+ICEcoder.openFiles[ICEcoder.selectedTab-1]);
},
@@ -720,14 +727,10 @@ var ICEcoder = {
var renamedFile, shortURL;
shortURL = top.ICEcoder.rightClickedFile.substr((top.ICEcoder.rightClickedFile.indexOf(shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.rightClickedFile.length).replace(/\|/g,"/");
renamedFile = false;
renamedFile = prompt('Please enter the new name for',shortURL);
if (renamedFile) {
for (var i=0;i<top.ICEcoder.openFiles.length;i++) {
if(top.ICEcoder.openFiles[i]==shortURL.replace(/\|/g,"/")) {
// rename array item and the tab
top.ICEcoder.openFiles[i] = renamedFile;
closeTabLink = '<a nohref onClick="top.ICEcoder.files.contentWindow.closeTab('+(i+1)+')"><img src="images/nav-close.gif"></a>';
@@ -744,13 +747,12 @@ var ICEcoder = {
var delFiles, selectedFilesList;
delFiles = confirm('Delete:\n\n'+top.ICEcoder.selectedFiles.toString().replace(/\|/g,"/").replace(/,/g,"\n")+'?');
// Upon supply a new name, rename tabs and update filename on server
if (delFiles) {
selectedFilesList = "";
for (var i=0;i<top.ICEcoder.selectedFiles.length;i++) {
selectedFilesList += top.ICEcoder.selectedFiles[i];
if (i<top.ICEcoder.selectedFiles.length-1) {selectedFilesList+=";"}
if (i<top.ICEcoder.selectedFiles.length-1) {selectedFilesList+=";"};
}
top.ICEcoder.serverQueue("add","lib/file-control.php?action=delete&file="+selectedFilesList);
top.ICEcoder.serverMessage('<b>Deleting File</b><br>'+top.ICEcoder.selectedFiles.toString().replace(/\|/g,"/").replace(/,/g,"\n"));
@@ -759,7 +761,12 @@ var ICEcoder = {
// Show menu on right clicking in file manager
showMenu: function() {
var menuType, folderMenuItems;
if ("undefined" != typeof top.ICEcoder.thisFileFolderLink && top.ICEcoder.thisFileFolderLink!="") {
top.ICEcoder.selectedFiles[0].indexOf(".")>0 ? menuType = "file" : menuType = "folder";
folderMenuItems = top.document.getElementById('folderMenuItems');
menuType == "folder" ? folderMenuItems.style.display = "block" : folderMenuItems.style.display = "none";
document.getElementById('fileMenu').style.display = "inline-block";
document.getElementById('fileMenu').style.left = (top.ICEcoder.mouseX+20) + "px";
document.getElementById('fileMenu').style.top = (top.ICEcoder.mouseY-top.document.getElementById('filesFrame').contentWindow.document.body.scrollTop+80) + "px";
@@ -814,11 +821,9 @@ var ICEcoder = {
// If we have results
if (ICEcoder.results.length>0) {
// Show results only
if (resultsOnly) {
parent.parent.document.getElementById('results').innerHTML = ICEcoder.results.length + " results";
// We need to take action instead
} else {
lineCount=1;
@@ -874,8 +879,8 @@ var ICEcoder = {
// Go to a specific line number
goToLine: function() {
var cM;
cM = ICEcoder.getcMInstance();
cM = ICEcoder.getcMInstance();
cM.setCursor(document.getElementById('goToLineNo').value-1);
cM.focus();
return false;
@@ -884,10 +889,9 @@ var ICEcoder = {
// Switch the CodeMirror mode on demand
switchMode: function() {
var cM;
cM = ICEcoder.getcMInstance();
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
if (fileName.indexOf('.js')>0) {
cM.setOption("mode","javascript");
} else if (fileName.indexOf('.css')>0) {
@@ -900,6 +904,7 @@ var ICEcoder = {
// Lock & unlock the file manager navigation on demand
lockUnlockNav: function() {
var lockIcon;
lockIcon = top.document.getElementById('fmLock');
ICEcoder.lockedNav ? ICEcoder.lockedNav = false : ICEcoder.lockedNav = true;
ICEcoder.lockedNav ? lockIcon.src="images/file-manager-icons/padlock.png" : lockIcon.src="images/file-manager-icons/padlock-disabled.png";
@@ -909,12 +914,10 @@ var ICEcoder = {
getcMInstance: function(newTab) {
var cM;
if (newTab=="new") {
if (newTab=="new"||(newTab!="new" && ICEcoder.openFiles.length>0)) {
cM = top.ICEcoder.content.contentWindow['cM'+ICEcoder.cMInstances[ICEcoder.selectedTab-1]];
} else if (ICEcoder.openFiles.length==0) {
cM = top.ICEcoder.content.contentWindow['cM1'];
} else {
cM = top.ICEcoder.content.contentWindow['cM'+ICEcoder.cMInstances[ICEcoder.selectedTab-1]];
cM = top.ICEcoder.content.contentWindow['cM1'];
}
return cM;
},
@@ -925,7 +928,7 @@ var ICEcoder = {
if (plugTarget=="_parent"||plugTarget=="_top"||plugTarget=="_self"||plugTarget=="") {
setInterval('window.location=\''+plugURL+'\'',plugTimer*1000*60);
// for pluginActions iframe instances
// for fileControl iframe instances
} else if (plugTarget.indexOf("fileControl")==0) {
setInterval(function() {top.ICEcoder.serverQueue("add",plugURL);top.ICEcoder.serverMessage(plugTarget.split(":")[1]);},plugTimer*1000*60);
@@ -937,37 +940,44 @@ var ICEcoder = {
// Comment or uncomment line on keypress
lineCommentToggle: function() {
var cM, lineContent, cursorPos;
var cM, cursorPos, linePos, lineContent, lCLen, adjustCursor;
cM = ICEcoder.getcMInstance();
cursorPos = cM.getCursor().ch;
lineContent = cM.getLine(cM.getCursor().line);
linePos = cM.getCursor().line;
lineContent = cM.getLine(linePos);
lCLen = lineContent.length;
adjustCursor = 3;
if (ICEcoder.caretLocType=="JavaScript"||ICEcoder.caretLocType=="PHP") {
if (lineContent.slice(0,3)!="// ") {
cM.setLine(cM.getCursor().line, "// " + lineContent);
cM.setCursor(cM.getCursor().line, cursorPos+3);
if (ICEcoder.caretLocType=="JavaScript"||ICEcoder.caretLocType=="PHP"||ICEcoder.caretLocType=="CSS") {
if (cM.somethingSelected()) {
if (cM.getSelection().slice(0,2)!="/*") {
cM.replaceSelection("/*" + cM.getSelection() + "*/");
} else {
cM.replaceSelection(cM.getSelection().slice(2,cM.getSelection().length-2));
}
} else {
cM.setLine(cM.getCursor().line, lineContent.slice(3,lineContent.length));
cM.setCursor(cM.getCursor().line, cursorPos-3);
}
} else if (ICEcoder.caretLocType=="CSS") {
if (lineContent.slice(0,3)!="/* ") {
cM.setLine(cM.getCursor().line, "/* " + lineContent + " */");
cM.setCursor(cM.getCursor().line, cursorPos+3);
} else {
cM.setLine(cM.getCursor().line, lineContent.slice(3,lineContent.length).slice(0,lineContent.length-5));
cM.setCursor(cM.getCursor().line, cursorPos-3);
if (ICEcoder.caretLocType=="CSS") {
lineContent.slice(0,3)!="/* " ? cM.setLine(linePos, "/* " + lineContent + " */") : cM.setLine(linePos, lineContent.slice(3,lCLen).slice(0,lCLen-5));
if (lineContent.slice(0,3)=="/* ") {adjustCursor = -adjustCursor};
} else {
lineContent.slice(0,3)!="// " ? cM.setLine(linePos, "// " + lineContent) : cM.setLine(linePos, lineContent.slice(3,lCLen));
if (lineContent.slice(0,3)=="// ") {adjustCursor = -adjustCursor};
}
}
} else {
if (lineContent.slice(0,4)!="<!--") {
cM.setLine(cM.getCursor().line, "<!--" + lineContent + "//-->");
cM.setCursor(cM.getCursor().line, cursorPos+4);
if (cM.somethingSelected()) {
if (cM.getSelection().slice(0,4)!="<!--") {
cM.replaceSelection("<!--" + cM.getSelection() + "//-->");
} else {
cM.replaceSelection(cM.getSelection().slice(4,cM.getSelection().length-5));
}
} else {
cM.setLine(cM.getCursor().line, lineContent.slice(4,lineContent.length).slice(0,lineContent.length-9));
cM.setCursor(cM.getCursor().line, cursorPos-4);
lineContent.slice(0,4)!="<!--" ? cM.setLine(linePos, "<!--" + lineContent + "//-->") : cM.setLine(linePos, lineContent.slice(4,lCLen).slice(0,lCLen-9));
lineContent.slice(0,4)=="<!--" ? adjustCursor = -4 : adjustCursor = 4;
}
}
if (!cM.somethingSelected()) {cM.setCursor(linePos, cursorPos+adjustCursor)};
},
// Get the mouse position on demand
@@ -976,7 +986,6 @@ var ICEcoder = {
IE = document.all ? true : false;
if (!IE) {document.captureEvents(Event.MOUSEMOVE)};
if (IE) {
top.ICEcoder.mouseX = event.clientX + document.body.scrollLeft;
top.ICEcoder.mouseY = event.clientY + document.body.scrollTop;
@@ -992,7 +1001,6 @@ var ICEcoder = {
var winH;
window.innerWidth ? winH = window.innerHeight : winH = document.body.clientHeight;
if (!top.ICEcoder.mouseDown) {top.ICEcoder.draggingFilesW = false};
if ((top.ICEcoder.mouseX > top.ICEcoder.filesW-7 && top.ICEcoder.mouseX < top.ICEcoder.filesW+7 && top.ICEcoder.mouseY > 40+50 && top.ICEcoder.mouseY < winH-30-40) || top.ICEcoder.draggingFilesW) {
@@ -1011,13 +1019,8 @@ var ICEcoder = {
// Determin if this is a file or folder and based on that, set the CSS styling & link
file.indexOf(".")>0 ? actionElemType = "file" : actionElemType = "folder";
if (actionElemType=="file") {
cssStyle = "pft-file ext-" + file.substr(file.indexOf(".")+1,file.length);
hrefLink = "nohref";
} else {
cssStyle = "pft-directory";
hrefLink = "href=\"#\"";
}
actionElemType=="file" ? cssStyle = "pft-file ext-" + file.substr(file.indexOf(".")+1,file.length) : cssStyle = "pft-directory";
actionElemType=="file" ? hrefLink = "nohref" : hrefLink = "href=\"#\"";
// Identify our target element & the first child element in it's location
targetElem = document.getElementById('filesFrame').contentWindow.document.getElementById(location.replace(/\//g,"|"));
@@ -1043,13 +1046,10 @@ var ICEcoder = {
// There are items in that location, so add our new item in the right position
} else {
for (i=0;i<=locNest.childNodes.length-1;i++) {
for (var i=0;i<=locNest.childNodes.length-1;i++) {
// Identify if the item we're considering is a file or folder
if (locNest.childNodes[i].className.indexOf('directory')>0) {
elemType = "folder";
} else {
elemType = "file";
}
locNest.childNodes[i].className.indexOf('directory')>0 ? elemType = "folder" : elemType = "file";
// Get the name of the item
nameLI = locNest.childNodes[i].getElementsByTagName('span')[0].innerHTML;
@@ -1059,12 +1059,10 @@ var ICEcoder = {
newLI = document.createElement("li");
newLI.className = cssStyle;
newLI.innerHTML = '<a '+hrefLink+' onMouseOver="top.ICEcoder.overFileFolder(\''+elemType+'\',\''+fullPath+location+'/'+file+'\')" onMouseOut="top.ICEcoder.overFileFolder(\''+elemType+'\',\'\')" style="position: relative; left:-22px" class="closed">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span id="'+location.replace(/\//g,"|")+'|'+file+'">'+file+'</a>';
// Append or insert depending on which of the above if statements is true
if (i==locNest.childNodes.length-1) {
locNest.appendChild(newLI,locNest.childNodes[i]);
} else {
locNest.insertBefore(newLI,locNest.childNodes[i]);
}
i==locNest.childNodes.length-1 ? locNest.appendChild(newLI,locNest.childNodes[i]) : locNest.insertBefore(newLI,locNest.childNodes[i]);
// Escape from this loop now
i=locNest.childNodes.length;
}
@@ -1098,9 +1096,7 @@ var ICEcoder = {
var cM;
cM = ICEcoder.getcMInstance();
top.ICEcoder.codeAssist ? top.ICEcoder.codeAssist = false : top.ICEcoder.codeAssist = true;
top.ICEcoder.cssColorPreview();
cM.focus();
},
@@ -1110,12 +1106,8 @@ var ICEcoder = {
var serverMessage;
serverMessage = document.getElementById('serverMessage');
if (message) {
serverMessage.innerHTML = message;
serverMessage.style.opacity = 1;
} else {
serverMessage.style.opacity = 0;
}
if (message) {serverMessage.innerHTML = message};
message ? serverMessage.style.opacity = 1 : serverMessage.style.opacity = 0;
},
// Queue items up for processing in turn
@@ -1123,7 +1115,6 @@ var ICEcoder = {
var cM,nextSaveID,txtArea,topSaveID,element;
cM = ICEcoder.getcMInstance();
// Firstly, work out how many saves we have to carry out
nextSaveID=0;
for (i=0;i<ICEcoder.serverQueueItems.length;i++) {
@@ -1144,7 +1135,7 @@ var ICEcoder = {
}
}
if (action=="del") {
if (ICEcoder.serverQueueItems[0].indexOf('action=save')>0) {
if (ICEcoder.serverQueueItems[0] && ICEcoder.serverQueueItems[0].indexOf('action=save')>0) {
topSaveID = nextSaveID-1;
for (i=1;i<topSaveID;i++) {
document.getElementById('saveTemp'+i).value = document.getElementById('saveTemp'+(i+1)).value;
@@ -1167,7 +1158,6 @@ var ICEcoder = {
var cM,string,startPosAdj,endPosAdj,nextSpace,oldBlock,newBlock;
cM = ICEcoder.getcMInstance();
string = cM.getLine(cM.getCursor().line);
startPosAdj = string.slice(0,cM.getCursor().ch).length - string.slice(0,cM.getCursor().ch).lastIndexOf(' ') - 1;
nextSpace = string.slice(cM.getCursor().ch,string.length).indexOf(' ');
@@ -1184,6 +1174,7 @@ var ICEcoder = {
newBlock.style.display = "block";
newBlock.style.width = newBlock.style.height = "20px";
newBlock.style.backgroundColor = string;
if (newBlock.style.backgroundColor=="") {newBlock.style.display = "none"};
top.document.getElementById('header').appendChild(newBlock);
cM.addWidget(cM.getCursor(), top.document.getElementById('cssColor'), true);
}