Skip to content

Commit 29e5dc0

Browse files
committed
Language related items moved to seperate files
Makes it easier for users to customise languages supported
1 parent 949e579 commit 29e5dc0

6 files changed

Lines changed: 180 additions & 154 deletions

File tree

editor.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
.heading {color:#888}
5555
</style>
5656
<link rel="stylesheet" href="lib/file-types.css">
57+
<link rel="stylesheet" href="lib/file-type-icons.css">
5758
</head>
5859

5960
<body style="color: #fff; margin: 0" onKeyDown="return top.ICEcoder.interceptKeys('content', event);" onKeyUp="top.ICEcoder.resetKeys(event);" onBlur="parent.ICEcoder.resetKeys(event);">
@@ -150,13 +151,6 @@
150151
"Ctrl-Down" : false,
151152
fallthrough: ["default"]
152153
};
153-
CodeMirror.commands.autocomplete = function(cm) {
154-
var langType = top.ICEcoder.caretLocType;
155-
if (["JavaScript","CoffeeScript","SQL","CSS","HTML","XML","Content"].indexOf(langType)>-1) {
156-
if (langType=="XML"||langType=="Content") {langType="HTML"};
157-
CodeMirror.showHint(cm,CodeMirror.hint[langType.toLowerCase()]);
158-
}
159-
}
160154

161155
function createNewCMInstance(num) {
162156
var fileName = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1];
@@ -317,6 +311,8 @@ function createNewCMInstance(num) {
317311

318312
<div style="position: absolute; display: none; width: 5px; height: 100%; top: 0; right: 0; background: rgba(255,255,255,0.1); overflow: hidden; z-index: 2" id="resultsBar"></div>
319313

314+
<?php include_once("processes/on-editor-load.php"); ?>
315+
320316
</body>
321317

322318
</html>

files.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<meta name="robots" content="noindex, nofollow">
88
<link rel="stylesheet" type="text/css" href="lib/files.css">
99
<link rel="stylesheet" type="text/css" href="lib/file-types.css">
10+
<link rel="stylesheet" type="text/css" href="lib/file-type-icons.css">
1011
<script src="lib/ice-coder<?php if (!$ICEcoder['devMode']) {echo '.min';};?>.js" type="text/javascript"></script>
1112
</head>
1213

lib/file-type-icons.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Additional file types */
2+
.fileManager LI.ext-coffee:before {background-position: -48px 0}
3+
.fileManager LI.ext-css:before {background-position: -64px 0}
4+
.fileManager LI.ext-gif:before {background-position: -80px 0}
5+
.fileManager LI.ext-htm:before, .fileManager LI.ext-html:before {background-position: -96px 0}
6+
.fileManager LI.ext-jpg:before, .fileManager LI.ext-jpeg:before {background-position: -112px 0}
7+
.fileManager LI.ext-js:before, .fileManager LI.ext-json:before {background-position: -128px 0}
8+
.fileManager LI.ext-less:before {background-position: -144px 0}
9+
.fileManager LI.ext-md:before {background-position: -160px 0}
10+
.fileManager LI.ext-php:before {background-position: -176px 0}
11+
.fileManager LI.ext-png:before {background-position: -192px 0}
12+
.fileManager LI.ext-py:before {background-position: -208px 0}
13+
.fileManager LI.ext-rb:before, .fileManager LI.ext-ruby:before {background-position: -224px 0}
14+
.fileManager LI.ext-sql:before {background-position: -240px 0}
15+
.fileManager LI.ext-txt:before {background-position: -256px 0}
16+
.fileManager LI.ext-xml:before {background-position: -272px 0}
17+
.fileManager LI.ext-zip:before {background-position: -288px 0}

lib/file-types.css

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,4 @@
2222
margin-top: -19px;
2323
}
2424
}
25-
.fileManager LI.pft-file:before {background-position: -32px 0}
26-
27-
/* Additional file types */
28-
.fileManager LI.ext-coffee:before {background-position: -48px 0}
29-
.fileManager LI.ext-css:before {background-position: -64px 0}
30-
.fileManager LI.ext-gif:before {background-position: -80px 0}
31-
.fileManager LI.ext-htm:before, .fileManager LI.ext-html:before {background-position: -96px 0}
32-
.fileManager LI.ext-jpg:before, .fileManager LI.ext-jpeg:before {background-position: -112px 0}
33-
.fileManager LI.ext-js:before, .fileManager LI.ext-json:before {background-position: -128px 0}
34-
.fileManager LI.ext-less:before {background-position: -144px 0}
35-
.fileManager LI.ext-md:before {background-position: -160px 0}
36-
.fileManager LI.ext-php:before {background-position: -176px 0}
37-
.fileManager LI.ext-png:before {background-position: -192px 0}
38-
.fileManager LI.ext-py:before {background-position: -208px 0}
39-
.fileManager LI.ext-rb:before, .fileManager LI.ext-ruby:before {background-position: -224px 0}
40-
.fileManager LI.ext-sql:before {background-position: -240px 0}
41-
.fileManager LI.ext-txt:before {background-position: -256px 0}
42-
.fileManager LI.ext-xml:before {background-position: -272px 0}
43-
.fileManager LI.ext-zip:before {background-position: -288px 0}
25+
.fileManager LI.pft-file:before {background-position: -32px 0}

lib/ice-coder.js

Lines changed: 6 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -297,31 +297,9 @@ var ICEcoder = {
297297
return false;
298298
},
299299

300-
// Switch the CodeMirror mode on demand
301-
switchMode: function(mode) {
302-
var cM, fileName;
303-
304-
cM = ICEcoder.getcMInstance();
305-
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
306-
if (cM && mode) {
307-
cM.setOption("mode",mode);
308-
} else if (cM && fileName) {
309-
fileName.indexOf('.js')>0 ? cM.setOption("mode","javascript")
310-
: fileName.indexOf('.coffee')>0 ? cM.setOption("mode","coffeescript")
311-
: fileName.indexOf('.rb')>0 ? cM.setOption("mode","ruby")
312-
: fileName.indexOf('.py')>0 ? cM.setOption("mode","python")
313-
: fileName.indexOf('.css')>0 ? cM.setOption("mode","css")
314-
: fileName.indexOf('.less')>0 ? cM.setOption("mode","less")
315-
: fileName.indexOf('.md')>0 ? cM.setOption("mode","markdown")
316-
: fileName.indexOf('.xml')>0 ? cM.setOption("mode","xml")
317-
: fileName.indexOf('.sql')>0 ? cM.setOption("mode","text/x-mysql") // also text/x-sql, text/x-mariadb, text/x-cassandra or text/x-plsql
318-
: cM.setOption("mode","application/x-httpd-php");
319-
}
320-
},
321-
322300
// Comment/uncomment line or selected range on keypress
323301
lineCommentToggle: function() {
324-
var cM, cursorPos, linePos, lineContent, lCLen, adjustCursor, startLine, endLine;
302+
var cM, cursorPos, linePos, lineContent, lCLen, adjustCursor;
325303

326304
cM = ICEcoder.getcMInstance();
327305
cursorPos = cM.getCursor().ch;
@@ -330,51 +308,8 @@ var ICEcoder = {
330308
lCLen = lineContent.length;
331309
adjustCursor = 2;
332310

333-
if (["JavaScript","CoffeeScript","PHP","Python","Ruby","CSS","SQL"].indexOf(ICEcoder.caretLocType)>-1) {
334-
if (cM.somethingSelected()) {
335-
if (ICEcoder.caretLocType=="Ruby"||ICEcoder.caretLocType=="Python") {
336-
startLine = cM.getCursor(true).line;
337-
endLine = cM.getCursor().line;
338-
for (var i=startLine; i<=endLine; i++) {
339-
cM.setLine(i, cM.getLine(i).slice(0,1)!="#"
340-
? "#" + cM.getLine(i)
341-
: cM.getLine(i).slice(1,cM.getLine(i).length));
342-
}
343-
} else {
344-
cM.replaceSelection(cM.getSelection().slice(0,2)!="/*"
345-
? "/*" + cM.getSelection() + "*/"
346-
: cM.getSelection().slice(2,cM.getSelection().length-2));
347-
}
348-
} else {
349-
if (["CoffeeScript","CSS","SQL"].indexOf(ICEcoder.caretLocType)>-1) {
350-
cM.setLine(linePos, lineContent.slice(0,2)!="/*"
351-
? "/*" + lineContent + "*/"
352-
: lineContent.slice(2,lCLen).slice(0,lCLen-4));
353-
if (lineContent.slice(0,2)=="/*") {adjustCursor = -adjustCursor};
354-
} else if (ICEcoder.caretLocType=="Ruby") {
355-
cM.setLine(linePos, lineContent.slice(0,1)!="#"
356-
? "#" + lineContent
357-
: lineContent.slice(1,lCLen));
358-
if (lineContent.slice(0,1)=="#") {adjustCursor = -adjustCursor};
359-
} else {
360-
cM.setLine(linePos, lineContent.slice(0,2)!="//"
361-
? "//" + lineContent
362-
: lineContent.slice(2,lCLen));
363-
if (lineContent.slice(0,2)=="//") {adjustCursor = -adjustCursor};
364-
}
365-
}
366-
} else {
367-
if (cM.somethingSelected()) {
368-
cM.replaceSelection(cM.getSelection().slice(0,4)!="<\!--"
369-
? "<\!--" + cM.getSelection() + "//-->"
370-
: cM.getSelection().slice(4,cM.getSelection().length-5));
371-
} else {
372-
cM.setLine(linePos, lineContent.slice(0,4)!="<\!--"
373-
? "<\!--" + lineContent + "//-->"
374-
: lineContent.slice(4,lCLen).slice(0,lCLen-9));
375-
adjustCursor = lineContent.slice(0,4)=="<\!--" ? -4 : 4;
376-
}
377-
}
311+
ICEcoder.lineCommentToggleSub(cM, cursorPos, linePos, lineContent, lCLen, adjustCursor);
312+
378313
if (!cM.somethingSelected()) {cM.setCursor(linePos, cursorPos+adjustCursor)};
379314
},
380315

@@ -1337,7 +1272,7 @@ var ICEcoder = {
13371272

13381273
// Work out the nesting depth location on demand and update our display if required
13391274
getNestLocation: function(updateNestDisplay) {
1340-
var cM, nestCheck, state, cx, startPos, fileName, events;
1275+
var cM, nestCheck, state, cx, startPos, fileName;
13411276

13421277
cM = ICEcoder.getcMInstance();
13431278
if (cM) {
@@ -1376,41 +1311,13 @@ var ICEcoder = {
13761311
ICEcoder.nestDisplay.innerHTML = "";
13771312
if ("undefined" != typeof ICEcoder.openFiles[ICEcoder.selectedTab-1]) {
13781313
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
1379-
if (["js","coffee","css","less","sql"].indexOf(fileName.split(".")[1])<0 &&
1380-
(nestCheck.indexOf("include(")==-1)&&(nestCheck.indexOf("include_once(")==-1)) {
1381-
1382-
// Then for all the array items, output as the nest display
1383-
for (var i=0;i<ICEcoder.htmlTagArray.length;i++) {
1384-
events = 'onMouseover="top.ICEcoder.highlightBlock('+i+')" onMouseout="top.ICEcoder.highlightBlock('+i+',\'hide\')" onClick="top.ICEcoder.setPosition('+i+',top.ICEcoder.startPosLine,\''+ICEcoder.htmlTagArray[i]+'\')"';
1385-
if (i==0) {ICEcoder.nestDisplay.innerHTML += '<div '+events+' style="display: inline-block; width: 7px; margin-top: -5px; height: 30px; background-image: url(images/nest-tag-bg.gif)"></div>'};
1386-
ICEcoder.nestDisplay.innerHTML += '<a '+events+' style="display: inline-block; cursor: pointer; background: #333; padding: 7px 2px 7px 7px; margin-top: -5px; height: 30px">'+ICEcoder.htmlTagArray[i]+'</a>';
1387-
ICEcoder.nestDisplay.innerHTML += i<ICEcoder.htmlTagArray.length-1
1388-
? '<div '+events+' style="display: inline-block; width: 8px; margin-top: -5px; height: 30px; background-image: url(images/nest-tag-bg.gif); background-position: -7px 0; cursor: pointer"></div>'
1389-
: '<div '+events+' style="display: inline-block; width: 7px; margin-top: -5px; height: 30px; background-image: url(images/nest-tag-bg.gif); background-position: -15px 0; cursor: pointer"></div>';
1390-
}
1391-
if (ICEcoder.tagString != "script") {
1392-
ICEcoder.nestDisplay.innerHTML += '<a style="display: inline-block; cursor: default; padding: 7px 2px 7px 7px; margin-top: -5px; height: 30px; color: #666">content</a>';
1393-
}
1394-
}
1314+
1315+
ICEcoder.getNestLocationSub(nestCheck, fileName);
13951316
}
13961317
}
13971318
}
13981319
},
13991320

1400-
// Indicate if the nesting structure of the code is OK
1401-
updateNestingIndicator: function() {
1402-
var cM, nestOK, fileName;
1403-
1404-
cM = ICEcoder.getcMInstance();
1405-
nestOK = true;
1406-
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
1407-
if (cM && fileName && ["js","coffee","css","less","sql"].indexOf(fileName.split(".")[1])==-1) {
1408-
nestOK = cM.getTokenAt({line:cM.lineCount(),ch:cM.lineInfo(cM.lineCount()-1).text.length}).className != "error" ? true : false;
1409-
}
1410-
ICEcoder.nestValid.style.background = nestOK ? "#0b0" : "#f00";
1411-
ICEcoder.nestValid.title = nestOK ? "Nesting OK" : "Nesting Broken";
1412-
},
1413-
14141321
// Get the caret position
14151322
getCaretPosition: function() {
14161323
var cM, line, ch, chPos;
@@ -1446,35 +1353,6 @@ var ICEcoder = {
14461353
top.ICEcoder.charDisplay.style.display = show == "char" ? "inline-block" : "none";
14471354
},
14481355

1449-
// Determine which area of the document we're in
1450-
caretLocationType: function() {
1451-
var cM, caretLocType, caretChunk, fileName;
1452-
1453-
cM = ICEcoder.getcMInstance();
1454-
caretLocType = "Unknown";
1455-
caretChunk = cM.getValue().substr(0,ICEcoder.caretPos+1);
1456-
if (caretChunk.lastIndexOf("<script")>caretChunk.lastIndexOf("</script>")&&caretLocType=="Unknown") {caretLocType = "JavaScript"}
1457-
else if (caretChunk.lastIndexOf("<?")>caretChunk.lastIndexOf("?>")&&caretLocType=="Unknown") {caretLocType = "PHP"}
1458-
else if (caretChunk.lastIndexOf("<%")>caretChunk.lastIndexOf("%>")&&caretLocType=="Unknown") {caretLocType = "Ruby"}
1459-
else if (caretChunk.lastIndexOf("<")>caretChunk.lastIndexOf(">")&&caretLocType=="Unknown") {caretLocType = "HTML"}
1460-
else if (caretLocType=="Unknown") {caretLocType = "Content"};
1461-
1462-
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
1463-
if (fileName) {
1464-
if (fileName.indexOf(".js")>0) {caretLocType="JavaScript"}
1465-
else if (fileName.indexOf(".coffee")>0) {caretLocType="CoffeeScript"}
1466-
else if (fileName.indexOf(".py")>0) {caretLocType="Python"}
1467-
else if (fileName.indexOf(".rb")>0) {caretLocType="Ruby"}
1468-
else if (fileName.indexOf(".css")>0) {caretLocType="CSS"}
1469-
else if (fileName.indexOf(".less")>0) {caretLocType="LESS"}
1470-
else if (fileName.indexOf(".md")>0) {caretLocType="Markdown"}
1471-
else if (fileName.indexOf(".xml")>0) {caretLocType="XML"}
1472-
else if (fileName.indexOf(".sql")>0) {caretLocType="SQL"};
1473-
}
1474-
1475-
ICEcoder.caretLocType = caretLocType;
1476-
},
1477-
14781356
// Show & hide target element
14791357
showHide: function(doVis,elem) {
14801358
elem.style.visibility = doVis=="show" ? 'visible' : 'hidden';

0 commit comments

Comments
 (0)