var ICEcoder = { // Define settings filesW: 250, // Initial width of the files pane minFilesW: 14, // Min width of the files pane maxFilesW: 250, // Max width of the files pane selectedTab: 0, // The tab that's currently selected changedContent: [], // Binary array to indicate which tabs have changed ctrlKeyDown: false, // Indicates if CTRL keydown shiftKeyDown: false, // Indicates if Shift keydown delKeyDown: false, // Indicates if DEL keydown canSwitchTabs: true, // Stops switching of tabs when trying to close openFiles: [], // Array of open file URLs openFileMDTs: [], // Array of open file modification datetimes cMInstances: [], // List of CodeMirror instance no's nextcMInstance: 1, // Next available CodeMirror instance no selectedFiles: [], // Array of selected files findMode: false, // States if we're in find/replace mode lockedNav: true, // Nav is locked or not htmlTagArray: [], // Array storing the nest of tags codeAssist: true, // Assist user with their coding mouseDown: false, // If the mouse is down or not draggingFilesW: false, // If we're dragging the file manager width or not serverQueueItems: [], // Array of URLs to call in order stickyTab: false, // If we have a sticky tab open or not stickyTabWindow: false, // Target variable for the sticky tab window pluginIntervalRefs: [], // Array of plugin interval refs dragSrcEl: null, // Tab element being dragged ready: false, // Indicates if ICEcoder is ready for action // Don't consider these tags as part of nesting as they're singles, JS, PHP or Ruby code blocks tagNestExceptions: ["!DOCTYPE","meta","link","img","br","hr","input","script","?php","?","%"], // Set our aliases initAliases: function() { var aliasArray = ["header","files","account","fmLock","filesFrame","editor","tabsBar","findBar","content","footer","nestValid","nestDisplay","charDisplay"]; // Create our ID aliases for (var i=0;i value fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1]; if (["js","coffee","rb","css","less"].indexOf(fileName.split(".")[1])<0) { cM = ICEcoder.getcMInstance(); content = cM.getValue(); content = content.replace(//g,''); // Then set the content in the editor & clear the history cM.setValue(content); cM.clearHistory(); } }, // Work out the nesting depth location on demand and update our display if required getNestLocation: function(updateNestDisplay) { var cM, nestCheck, state, cx, startPos, fileName; cM = ICEcoder.getcMInstance(); nestCheck = cM.getValue(); // Set up array to store nest data state = cM.getTokenAt(cM.getCursor()).state; if ("undefined" != typeof state.curState) { ICEcoder.htmlTagArray = []; for (cx = state.curState.context; cx; cx = cx.prev) { ICEcoder.htmlTagArray.unshift(cx.tagName); } } ICEcoder.tagString = ICEcoder.htmlTagArray[ICEcoder.htmlTagArray.length-1]; if (ICEcoder.caretLocType=="JavaScript") { ICEcoder.tagString = "script"; } // Now we've built up our nest depth array, if we're due to show it in the display if (updateNestDisplay && !top.ICEcoder.dontUpdateNest) { // Clear the display ICEcoder.nestDisplay.innerHTML = ""; if ("undefined" != typeof ICEcoder.openFiles[ICEcoder.selectedTab-1]) { fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1]; if (["js","coffee","rb","css","less"].indexOf(fileName.split(".")[1])<0 && (nestCheck.indexOf("include(")==-1)&&(nestCheck.indexOf("include_once(")==-1)&& (nestCheck.indexOf("-1||nestCheck.indexOf("-1)) { // Then for all the array items, output as the nest display for (var i=0;i'+ICEcoder.htmlTagArray[i]+''; if(i ICEcoder.minFilesW+1 ? ICEcoder.filesW -= Math.ceil((ICEcoder.filesW-ICEcoder.minFilesW)/2) : ICEcoder.filesW = ICEcoder.minFilesW; } if ((expandContract=="expand" && ICEcoder.filesW == ICEcoder.maxFilesW)||(expandContract=="contract" && ICEcoder.filesW == ICEcoder.minFilesW)) { clearInterval(ICEcoder.changeFilesInt); } // Redo the layout to match ICEcoder.setLayout(); }, // Can click-drag file manager width? canResizeFilesW: function() { // If we have the cursor set we must be able! if (top.document.body.style.cursor == "w-resize") { // If our mouse is down and we're within a 250-400px range if (top.ICEcoder.mouseDown) { top.ICEcoder.filesW = top.ICEcoder.maxFilesW = top.ICEcoder.mouseX >=250 && top.ICEcoder.mouseX <= 400 ? top.ICEcoder.mouseX : top.ICEcoder.mouseX <250 ? 250 : 400; // Set various widths based on the new width top.ICEcoder.files.style.width = top.ICEcoder.account.style.width = top.ICEcoder.filesFrame.style.width = top.ICEcoder.filesW + "px"; top.ICEcoder.setLayout(); top.ICEcoder.draggingFilesW = true; } } else { top.ICEcoder.draggingFilesW = false; } }, // Change tabs by switching visibility of instances switchTab: function(newTab,noFocus) { var cM; // Identify tab that's currently selected & get the instance ICEcoder.selectedTab = newTab; cM = ICEcoder.getcMInstance(); if (cM) { // Switch mode to HTML, PHP, CSS etc ICEcoder.switchMode(); // Set all cM instances to be hidden, then make our selected instance visible for (var i=0;i0 ? "#b00" : "rgba(255,255,255,0.3)"; } tColor = i==selectedTab ? "#000" : "#fff"; if ("undefined" != typeof top.ICEcoder.openFiles[i-1] && top.ICEcoder.openFiles[i-1] != "/[NEW]") { fileLink = top.ICEcoder.filesFrame.contentWindow.document.getElementById(top.ICEcoder.openFiles[i-1].replace(/\//g,"|")); if (fileLink) {fileLink.style.backgroundColor = i==selectedTab ? "#49d" : "rgba(255,255,255,0.15)";}; } document.getElementById('tab'+i).style.color = tColor; bgVPos = i==selectedTab ? -22 : 0; document.getElementById('tab'+i).style.backgroundPosition = "0 "+bgVPos+"px"; } top.ICEcoder.fMIconVis('fMSave',ICEcoder.changedContent[selectedTab-1]==1 ? 1 : 0.3); }, // Starts a new file by setting a few vars & creating a new cM instance newTab: function() { var cM; ICEcoder.cMInstances.push(ICEcoder.nextcMInstance); ICEcoder.selectedTab = ICEcoder.cMInstances.length; ICEcoder.content.style.visibility='visible'; ICEcoder.content.contentWindow.createNewCMInstance(ICEcoder.nextcMInstance); ICEcoder.setLayout(); ICEcoder.thisFileFolderType='file'; ICEcoder.thisFileFolderLink='/[NEW]'; ICEcoder.openFile(); cM = ICEcoder.getcMInstance('new'); ICEcoder.switchTab(ICEcoder.openFiles.length); cM.setLineClass(ICEcoder['cMActiveLine'+ICEcoder.selectedTab], null); ICEcoder['cMActiveLine'+ICEcoder.selectedTab] = cM.setLineClass(0, "cm-s-activeLine"); ICEcoder.nextcMInstance++; }, // Create a new tab for a file createNewTab: function() { var closeTabLink; // Push new file into array top.ICEcoder.openFiles.push(top.ICEcoder.shortURL); // Setup a new tab closeTabLink = ''; top.document.getElementById('tab'+(top.ICEcoder.openFiles.length)).style.display = "inline-block"; top.document.getElementById('tab'+(top.ICEcoder.openFiles.length)).innerHTML = top.ICEcoder.openFiles[top.ICEcoder.openFiles.length-1] + " " + closeTabLink; // Highlight it and state it's selected top.ICEcoder.redoTabHighlight(top.ICEcoder.openFiles.length); top.ICEcoder.selectedTab=top.ICEcoder.openFiles.length; // Add a new value ready to indicate if this content has been changed top.ICEcoder.changedContent.push(0); top.ICEcoder.setPreviousFiles(); }, // Cycle to next tab nextTab: function() { var goToTab; goToTab = top.ICEcoder.selectedTab+1 <= top.ICEcoder.openFiles.length ? top.ICEcoder.selectedTab+1 : 1; top.ICEcoder.switchTab(goToTab,'noFocus'); }, // Cycle to next tab previousTab: function() { var goToTab; goToTab = top.ICEcoder.selectedTab-1 >= 1 ? top.ICEcoder.selectedTab-1 : top.ICEcoder.openFiles.length; top.ICEcoder.switchTab(goToTab,'noFocus'); }, // Create a new tab for a file renameTab: function(tabNum,newName) { var closeTabLink; // Push new file into array top.ICEcoder.openFiles[tabNum-1] = newName; // Setup a new tab closeTabLink = ''; top.document.getElementById('tab'+tabNum).innerHTML = top.ICEcoder.openFiles[tabNum-1] + " " + closeTabLink; }, // Indicate if the nesting structure of the code is OK updateNestingIndicator: function () { var cM, nestOK, fileName; cM = ICEcoder.getcMInstance(); nestOK = true; fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1]; if (cM && ["js","coffee","rb","css","less"].indexOf(fileName.split(".")[1])==-1) { nestOK = cM.getTokenAt({line:cM.lineCount(),ch:cM.lineInfo(cM.lineCount()-1).text.length}).className != "error" ? true : false; } ICEcoder.nestValid.style.backgroundColor = nestOK ? "#0b0" : "#f00"; ICEcoder.nestValid.innerHTML = nestOK ? "Nesting OK" : "Nesting Broken"; }, // 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; for (var i=0;icaretChunk.lastIndexOf("")&&caretLocType=="Unknown") {caretLocType = "JavaScript"}; if (caretChunk.lastIndexOf("caretChunk.lastIndexOf("?>")&&caretLocType=="Unknown") {caretLocType = "PHP"}; if (caretChunk.lastIndexOf("<%")>caretChunk.lastIndexOf("%>")&&caretLocType=="Unknown") {caretLocType = "Ruby"}; if (caretChunk.lastIndexOf("<")>caretChunk.lastIndexOf(">")&&caretLocType=="Unknown") {caretLocType = "HTML"}; if (caretLocType=="Unknown") {caretLocType = "Content"}; fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1]; if (fileName.indexOf(".js")>0) {caretLocType="JavaScript"}; if (fileName.indexOf(".coffee")>0) {caretLocType="CoffeeScript"}; if (fileName.indexOf(".rb")>0) {caretLocType="Ruby"}; if (fileName.indexOf(".css")>0) {caretLocType="CSS"}; if (fileName.indexOf(".less")>0) {caretLocType="LESS"}; ICEcoder.caretLocType = caretLocType; // If we're in a JS, CoffeeScript PHP or Ruby code block, add that to the nest display if (["JavaScript","CoffeeScript","PHP","Ruby"].indexOf(caretLocType)>-1) { ICEcoder.nestDisplay.innerHTML += " > " + caretLocType; } }, // Alter array indicating which files have changed redoChangedContent: function(evt) { var key; key = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode; // Exclude a few keys such as Escape... if (top.ICEcoder.ctrlKeyDown==false && key!=27 && key!=20 && (key<16||key>19) && (key<37||key>40) && (key!=144||key!=145) && (key!=44||key!=45) && (key<33||key>36) && (key!=91||key!=92) && (key<112||key>123)) { ICEcoder.changedContent[ICEcoder.selectedTab-1] = 1; ICEcoder.redoTabHighlight(ICEcoder.selectedTab); } }, // Close the tab upon request closeTab: function(closeTabNum) { var cM, okToRemove, closeFileName; cM = ICEcoder.getcMInstance(); okToRemove = true; if (ICEcoder.changedContent[closeTabNum-1]==1) { okToRemove = top.ICEcoder.ask('You have made changes.\n\nAre you sure you want to close without saving?'); } if (okToRemove) { // Get the filename of tab we're closing closeFileName = top.ICEcoder.openFiles[closeTabNum-1]; // recursively copy over all tabs & data from the tab to the right, if there is one for (var i=closeTabNum;i0 ? ICEcoder.selectedTab-=1 : ICEcoder.selectedTab = 0; } if (ICEcoder.openFiles.length>0 && ICEcoder.selectedTab==0) {ICEcoder.selectedTab=1}; // grey out the view icon if (ICEcoder.openFiles.length==0) { top.ICEcoder.fMIconVis('fMView',0.3); } else { // Switch the mode & the tab ICEcoder.switchMode(); ICEcoder.switchTab(ICEcoder.selectedTab); } // Highlight the selected tab after splicing the change state out of the array top.ICEcoder.changedContent.splice(closeTabNum-1,1); top.parent.ICEcoder.redoTabHighlight(ICEcoder.selectedTab); // Remove any highlighting from the file manager top.ICEcoder.selectDeselectFile('deselect',top.ICEcoder.filesFrame.contentWindow.document.getElementById(closeFileName.replace(/\//g,"|"))); top.ICEcoder.setPreviousFiles(); } // Lastly, stop it from trying to also switch tab top.ICEcoder.canSwitchTabs=false; }, // Setup the file manager fileManager: function() { ICEcoder.filesFrame = top.document.getElementById('filesFrame'); if (!ICEcoder.filesFrame.contentWindow.document.getElementsByTagName) {return;}; var aMenus = ICEcoder.filesFrame.contentWindow.document.getElementsByTagName("LI"); for (var i=0; i-1) { var submenu=aMenus[i].childNodes; for (var j=0; j-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 { top.ICEcoder.deselectAllFiles(); // Add our URL and highlight the file ICEcoder.selectDeselectFile('select',tgtFile); top.ICEcoder.selectedFiles.push(shortURL); } } // 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"; // Finally, show or grey out the relevant file manager icons top.ICEcoder.fMIconVis('fMOpen',top.ICEcoder.selectedFiles.length == 1 ? 1 : 0.3); top.ICEcoder.fMIconVis('fMNewFile',top.ICEcoder.selectedFiles.length == 1 && top.ICEcoder.thisFileFolderType == "folder" ? 1 : 0.3); top.ICEcoder.fMIconVis('fMNewFolder',top.ICEcoder.selectedFiles.length == 1 && top.ICEcoder.thisFileFolderType == "folder" ? 1 : 0.3); top.ICEcoder.fMIconVis('fMDelete',top.ICEcoder.selectedFiles.length > 0 ? 1 : 0.3); top.ICEcoder.fMIconVis('fMRename',top.ICEcoder.selectedFiles.length == 1 ? 1 : 0.3); // Hide the file menu incase it's showing top.document.getElementById('fileMenu').style.display = "none"; }, // Deselect all files deselectAllFiles: function() { var tgtFile; for (var i=0;i -1 ? true : false; if (top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1] == file.id.replace(/\|/g,"/")) { file.style.backgroundColor="#49d"; } else { file.style.backgroundColor = action=="select" ? "#888" : file.style.backgroundColor = isOpen ? "rgba(255,255,255,0.15)" : "transparent"; } file.style.color= action=="select" ? "#fff" : "#eee"; }, // Create a new file (start & instant save) newFile: function() { top.ICEcoder.newTab(); top.ICEcoder.saveFile(); }, // Create a new folder newFolder: function() { var shortURL, newFolder; shortURL = top.ICEcoder.rightClickedFile.replace(/\|/g,"/"); newFolder = top.ICEcoder.getInput('Enter New Folder Name at '+shortURL,''); if (newFolder) { newFolder = (shortURL + "/" + newFolder).replace(/\/\//,"/"); top.ICEcoder.serverQueue("add","lib/file-control.php?action=newFolder&file="+newFolder.replace(/\//g,"|")); top.ICEcoder.serverMessage('Creating Folder
'+newFolder); } }, // Open a file on demand openFile: function(fileLink) { var shortURL, canOpenFile; if (fileLink) { top.ICEcoder.thisFileFolderLink=fileLink; top.ICEcoder.thisFileFolderType="file"; } if (top.ICEcoder.isOpen(top.ICEcoder.thisFileFolderLink)!==false) { top.ICEcoder.switchTab(top.ICEcoder.isOpen(top.ICEcoder.thisFileFolderLink)+1); } else if (top.ICEcoder.thisFileFolderLink!="" && top.ICEcoder.thisFileFolderType=="file") { // work out a shortened URL for the file shortURL = top.ICEcoder.thisFileFolderLink.replace(/\|/g,"/"); // 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 if (top.ICEcoder.openFiles.indexOf(shortURL)>-1 && shortURL!="/[NEW]") { // we have, so instead, switch to that tab canOpenFile = false; top.ICEcoder.switchTab(i+1); } } else { // show a message because we have 10 files open top.ICEcoder.message('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]") { 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('Opening File
'+top.ICEcoder.shortURL); } else { top.ICEcoder.createNewTab(); } top.ICEcoder.fMIconVis('fMView',1); } } }, // Save a file on demand saveFile: function(saveAs) { var saveType; saveType = saveAs ? "saveAs" : "save"; top.ICEcoder.serverQueue("add","lib/file-control.php?action=save&file="+ICEcoder.openFiles[ICEcoder.selectedTab-1].replace(top.iceRoot,"").replace(/\//g,"|")+"&fileMDT="+ICEcoder.openFileMDTs[ICEcoder.selectedTab-1]+"&saveType="+saveType); top.ICEcoder.serverMessage('Saving
'+ICEcoder.openFiles[ICEcoder.selectedTab-1].replace(top.iceRoot,"")); }, // Prompt a rename dialog on demand renameFile: function(oldName,newName) { var shortURL; if (!oldName) { shortURL = top.ICEcoder.rightClickedFile.replace(/\|/g,"/"); oldName = top.ICEcoder.rightClickedFile.replace(/\|/g,"/"); } else { shortURL = oldName.replace(/\|/g,"/"); } if (!newName) { newName = top.ICEcoder.getInput('Please enter the new name for',shortURL); } if (newName) { if(top.ICEcoder.openFiles.indexOf(shortURL.replace(/\|/g,"/"))>-1) { // rename array item and the tab top.ICEcoder.openFiles[i] = newName; closeTabLink = ''; top.document.getElementById('tab'+(i+1)).innerHTML = top.ICEcoder.openFiles[i] + " " + closeTabLink; } top.ICEcoder.serverQueue("add","lib/file-control.php?action=rename&file="+newName+"&oldFileName="+oldName.replace(/\|/g,"/")); top.ICEcoder.serverMessage('Renaming to
'+newName); top.ICEcoder.setPreviousFiles(); } }, // Delete a file on demand deleteFile: function() { var delFiles, selectedFilesList; delFiles = top.ICEcoder.ask('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;iDeleting File
'+top.ICEcoder.selectedFiles.toString().replace(/\|/g,"/").replace(/,/g,"\n")); }; }, // Show menu on right clicking in file manager showMenu: function() { var menuType, folderMenuItems; if ( top.ICEcoder.selectedFiles.length == 0 || top.ICEcoder.selectedFiles.indexOf(top.ICEcoder.rightClickedFile.replace(/\//g,"|")) == -1) { top.ICEcoder.selectFileFolder(); } if ("undefined" != typeof top.ICEcoder.thisFileFolderLink && top.ICEcoder.thisFileFolderLink!="") { menuType = top.ICEcoder.selectedFiles[0].indexOf(".")>-1 ? "file" : "folder"; folderMenuItems = top.document.getElementById('folderMenuItems'); folderMenuItems.style.display = menuType == "folder" && top.ICEcoder.selectedFiles.length == 1 ? "block" : "none"; singleFileMenuItems.style.display = top.ICEcoder.selectedFiles.length > 1 ? "none" : "block"; 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.ICEcoder.filesFrame.contentWindow.document.body.scrollTop-10) + "px"; } return false; }, // Show & hide target element showHide: function(doVis,elem) { elem.style.visibility = doVis=="show" ? 'visible' : 'hidden'; }, // Move current line up/down moveLine: function(dir) { var cM, line, swapLineNo, swapLine; cM = top.ICEcoder.getcMInstance(); line = cM.getCursor().line; if (dir=="up" && line>0) {swapLineNo = line-1} if (dir=="down" && line0 && document.findAndReplace.target.value=="this document") { cM = ICEcoder.getcMInstance(); content = cM.getValue(); // Find & replace the next instance, or all? if (document.findAndReplace.connector.value=="and") { if (document.findAndReplace.replaceAction.value=="replace" && cM.getSelection()==find) { cM.replaceSelection(replace); } else if (document.findAndReplace.replaceAction.value=="replace all" && buttonClick) { var rExp = new RegExp(find,"g"); cM.setValue(cM.getValue().replace(rExp,replace)); } } // Get the content again, as it might of changed content = cM.getValue(); if (!top.ICEcoder.findMode||find!=top.ICEcoder.lastsearch) { ICEcoder.results = []; for (var i=0;i0) { // Show results only if (resultsOnly) { results.innerHTML = ICEcoder.results.length + " results"; // We need to take action instead } else { lineCount=1; numChars=0; // Count the no of chars & lines previous to our cursor's line for (var i=0;iICEcoder.results.length-1) {ICEcoder.findResult=0}; results.innerHTML = "Highlighted result "+(ICEcoder.findResult+1)+" of "+ICEcoder.results.length+" results"; lineCount=0; for (var i=0;i=0) { targetQS = "&target="+document.findAndReplace.target.value.replace(/ /g,"-"); } find = find.replace(/\'/g, '''); find != encodeURIComponent(find) ? find = 'ICEcoder:'+encodeURIComponent(find) : find; top.document.getElementById('loadingMask').style.visibility = "visible"; top.document.getElementById('mediaContainer').innerHTML = ''; } } }, // Go to a specific line number goToLine: function(lineNo) { var cM; cM = ICEcoder.getcMInstance(); cM.setCursor(lineNo ? lineNo-1 : document.getElementById('goToLineNo').value-1); cM.focus(); return false; }, // Switch the CodeMirror mode on demand switchMode: function() { var cM; cM = ICEcoder.getcMInstance(); fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1]; if (fileName) { fileName.indexOf('.js')>0 ? cM.setOption("mode","javascript") : fileName.indexOf('.coffee')>0 ? cM.setOption("mode","coffeescript") : fileName.indexOf('.rb')>0 ? cM.setOption("mode","ruby") : fileName.indexOf('.css')>0 ? cM.setOption("mode","css") : fileName.indexOf('.less')>0 ? cM.setOption("mode","less") : cM.setOption("mode","application/x-httpd-php"); } }, // Lock & unlock the file manager navigation on demand lockUnlockNav: function() { var lockIcon; lockIcon = top.document.getElementById('fmLock'); ICEcoder.lockedNav = ICEcoder.lockedNav ? false : true; lockIcon.style.backgroundPosition = ICEcoder.lockedNav ? "-64px -16px" : "-80px -16px"; }, // Determine the CodeMirror instance we're using on demand getcMInstance: function(newTab) { var cM; cM = 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 startPluginIntervals: function(plugRef,plugURL,plugTarget,plugTimer) { top.ICEcoder['plugTimer'+plugRef] = // This window instances ["_parent","_top","_self",""].indexOf(plugTarget) > -1 ? top.ICEcoder['plugTimer'+plugRef] = setInterval('window.location=\''+plugURL+'\'',plugTimer*1000*60) // fileControl iframe instances : plugTarget.indexOf("fileControl") == 0 ? top.ICEcoder['plugTimer'+plugRef] = setInterval(function() { top.ICEcoder.serverQueue("add",plugURL);top.ICEcoder.serverMessage(plugTarget.split(":")[1]); },plugTimer*1000*60) // _blank or named target window instances : top.ICEcoder['plugTimer'+plugRef] = setInterval('window.open(\''+plugURL+'\',\''+plugTarget+'\')',plugTimer*1000*60); // push the plugin ref into our array top.ICEcoder.pluginIntervalRefs.push(plugRef); }, // Comment or uncomment line on keypress lineCommentToggle: function() { var cM, cursorPos, linePos, lineContent, lCLen, adjustCursor, startLine, endLine; cM = ICEcoder.getcMInstance(); cursorPos = cM.getCursor().ch; linePos = cM.getCursor().line; lineContent = cM.getLine(linePos); lCLen = lineContent.length; adjustCursor = 3; if (["JavaScript","CoffeeScript","PHP","Ruby","CSS"].indexOf(ICEcoder.caretLocType)>-1) { if (cM.somethingSelected()) { if (ICEcoder.caretLocType=="Ruby") { startLine = cM.getCursor(true).line; endLine = cM.getCursor().line; for (var i=startLine; i<=endLine; i++) { cM.setLine(i, cM.getLine(i).slice(0,2)!="# " ? "# " + cM.getLine(i) : cM.getLine(i).slice(2,cM.getLine(i).length)); } } else { cM.replaceSelection(cM.getSelection().slice(0,2)!="/*" ? "/*" + cM.getSelection() + "*/" : cM.getSelection().slice(2,cM.getSelection().length-2)); } } else { if (["CoffeeScript","CSS"].indexOf(ICEcoder.caretLocType)>-1) { cM.setLine(linePos, lineContent.slice(0,3)!="/* " ? "/* " + lineContent + " */" : lineContent.slice(3,lCLen).slice(0,lCLen-5)); if (lineContent.slice(0,3)=="/* ") {adjustCursor = -adjustCursor}; } else if (ICEcoder.caretLocType=="Ruby") { cM.setLine(linePos, lineContent.slice(0,2)!="# " ? "# " + lineContent : lineContent.slice(2,lCLen)); if (lineContent.slice(0,2)=="# ") {adjustCursor = -adjustCursor}; } else { cM.setLine(linePos, lineContent.slice(0,3)!="// " ? "// " + lineContent : lineContent.slice(3,lCLen)); if (lineContent.slice(0,3)=="// ") {adjustCursor = -adjustCursor}; } } } else { if (cM.somethingSelected()) { cM.replaceSelection(cM.getSelection().slice(0,4)!="" : cM.getSelection().slice(4,cM.getSelection().length-5)); } else { cM.setLine(linePos, lineContent.slice(0,4)!="" : lineContent.slice(4,lCLen).slice(0,lCLen-9)); adjustCursor = lineContent.slice(0,4)=="