mirror of
https://github.com/icecoder/ICEcoder.git
synced 2026-03-03 07:13:59 +01:00
Lots of ternary & array check shortening
Shorting to ternary statements instead of if else statements in many places Checking indexOf on arrays to condense code here too
This commit is contained in:
86
lib/coder.js
86
lib/coder.js
@@ -1011,19 +1011,12 @@ var ICEcoder = {
|
||||
cM = ICEcoder.getcMInstance();
|
||||
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
|
||||
if (fileName) {
|
||||
if (fileName.indexOf('.js')>0) {
|
||||
cM.setOption("mode","javascript");
|
||||
} else if (fileName.indexOf('.coffee')>0) {
|
||||
cM.setOption("mode","coffeescript");
|
||||
} else if (fileName.indexOf('.rb')>0) {
|
||||
cM.setOption("mode","ruby");
|
||||
} else if (fileName.indexOf('.css')>0) {
|
||||
cM.setOption("mode","css");
|
||||
} else if (fileName.indexOf('.less')>0) {
|
||||
cM.setOption("mode","less");
|
||||
} else {
|
||||
cM.setOption("mode","application/x-httpd-php");
|
||||
}
|
||||
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");
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1050,18 +1043,17 @@ var ICEcoder = {
|
||||
|
||||
// Start running plugin intervals according to given specifics
|
||||
startPluginIntervals: function(plugRef,plugURL,plugTarget,plugTimer) {
|
||||
// For this window instances
|
||||
if (plugTarget=="_parent"||plugTarget=="_top"||plugTarget=="_self"||plugTarget=="") {
|
||||
top.ICEcoder['plugTimer'+plugRef] = setInterval('window.location=\''+plugURL+'\'',plugTimer*1000*60);
|
||||
|
||||
// for fileControl iframe instances
|
||||
} else if (plugTarget.indexOf("fileControl")==0) {
|
||||
top.ICEcoder['plugTimer'+plugRef] = setInterval(function() {top.ICEcoder.serverQueue("add",plugURL);top.ICEcoder.serverMessage(plugTarget.split(":")[1]);},plugTimer*1000*60);
|
||||
|
||||
// for _blank or named target window instances
|
||||
} else {
|
||||
top.ICEcoder['plugTimer'+plugRef] = setInterval('window.open(\''+plugURL+'\',\''+plugTarget+'\')',plugTimer*1000*60);
|
||||
}
|
||||
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);
|
||||
@@ -1078,43 +1070,49 @@ var ICEcoder = {
|
||||
lCLen = lineContent.length;
|
||||
adjustCursor = 3;
|
||||
|
||||
if (ICEcoder.caretLocType=="JavaScript"||ICEcoder.caretLocType=="CoffeeScript"||ICEcoder.caretLocType=="PHP"||ICEcoder.caretLocType=="Ruby"||ICEcoder.caretLocType=="CSS") {
|
||||
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.getLine(i).slice(0,2)!="# " ? cM.setLine(i, "# " + cM.getLine(i)) : cM.setLine(i, cM.getLine(i).slice(2,cM.getLine(i).length));
|
||||
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 {
|
||||
if (cM.getSelection().slice(0,2)!="/*") {
|
||||
cM.replaceSelection("/*" + cM.getSelection() + "*/");
|
||||
} else {
|
||||
cM.replaceSelection(cM.getSelection().slice(2,cM.getSelection().length-2));
|
||||
}
|
||||
cM.replaceSelection(cM.getSelection().slice(0,2)!="/*"
|
||||
? "/*" + cM.getSelection() + "*/"
|
||||
: cM.getSelection().slice(2,cM.getSelection().length-2));
|
||||
}
|
||||
} else {
|
||||
if (ICEcoder.caretLocType=="CSS"||ICEcoder.caretLocType=="CoffeeScript") {
|
||||
lineContent.slice(0,3)!="/* " ? cM.setLine(linePos, "/* " + lineContent + " */") : cM.setLine(linePos, lineContent.slice(3,lCLen).slice(0,lCLen-5));
|
||||
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") {
|
||||
lineContent.slice(0,2)!="# " ? cM.setLine(linePos, "# " + lineContent) : cM.setLine(linePos, lineContent.slice(2,lCLen));
|
||||
cM.setLine(linePos, lineContent.slice(0,2)!="# "
|
||||
? "# " + lineContent
|
||||
: lineContent.slice(2,lCLen));
|
||||
if (lineContent.slice(0,2)=="# ") {adjustCursor = -adjustCursor};
|
||||
} else {
|
||||
lineContent.slice(0,3)!="// " ? cM.setLine(linePos, "// " + lineContent) : cM.setLine(linePos, lineContent.slice(3,lCLen));
|
||||
cM.setLine(linePos, lineContent.slice(0,3)!="// "
|
||||
? "// " + lineContent
|
||||
: lineContent.slice(3,lCLen));
|
||||
if (lineContent.slice(0,3)=="// ") {adjustCursor = -adjustCursor};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (cM.somethingSelected()) {
|
||||
if (cM.getSelection().slice(0,4)!="<!--") {
|
||||
cM.replaceSelection("<!--" + cM.getSelection() + "//-->");
|
||||
} else {
|
||||
cM.replaceSelection(cM.getSelection().slice(4,cM.getSelection().length-5));
|
||||
}
|
||||
cM.replaceSelection(cM.getSelection().slice(0,4)!="<!--"
|
||||
? "<!--" + cM.getSelection() + "//-->"
|
||||
: cM.getSelection().slice(4,cM.getSelection().length-5));
|
||||
} else {
|
||||
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;
|
||||
cM.setLine(linePos, lineContent.slice(0,4)!="<!--"
|
||||
? "<!--" + lineContent + "//-->"
|
||||
: lineContent.slice(4,lCLen).slice(0,lCLen-9));
|
||||
adjustCursor = lineContent.slice(0,4)=="<!--" ? -4 : 4;
|
||||
}
|
||||
}
|
||||
if (!cM.somethingSelected()) {cM.setCursor(linePos, cursorPos+adjustCursor)};
|
||||
|
||||
Reference in New Issue
Block a user