Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
CoffeeScript Support & Update Lang on Tab Switch
Browse files Browse the repository at this point in the history
CoffeeScript is now supported as a language by ICEcoder
When you switch tabs, the cursor display info also now changes
  • Loading branch information
mattpass committed May 25, 2012
1 parent 96df3ac commit d095e6a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
5 changes: 3 additions & 2 deletions editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<script src="<?php echo $codeMirrorDir; ?>/lib/codemirror.js"></script>
<script src="<?php echo $codeMirrorDir; ?>/mode/xml/xml.js"></script>
<script src="<?php echo $codeMirrorDir; ?>/mode/javascript/javascript.js"></script>
<script src="<?php echo $codeMirrorDir; ?>/mode/coffeescript/coffeescript.js"></script>
<script src="<?php echo $codeMirrorDir; ?>/mode/css/css.js"></script>
<script src="<?php echo $codeMirrorDir; ?>/mode/clike/clike.js"></script>
<script src="<?php echo $codeMirrorDir; ?>/mode/php/php.js"></script>
Expand Down Expand Up @@ -41,7 +42,7 @@
function createNewCMInstance(num) {
var fileName = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1];
var codeFold = CodeMirror.newFoldFunction(CodeMirror.tagRangeFinder,'<span style=\"display: inline-block; width: 13px; height: 13px; background-color: #b00; color: #fff; text-align: center; cursor: pointer\"><span style="position: relative; top: -1px">+</span></span> %N%');
var codeFold_JS_PHP_Ruby = CodeMirror.newFoldFunction(CodeMirror.braceRangeFinder,'<span style=\"display: inline-block; width: 13px; height: 13px; background-color: #b00; color: #fff; text-align: center; cursor: pointer\"><span style="position: relative; top: -1px">+</span></span> %N%');
var codeFold_JS_Coffee_PHP_Ruby = CodeMirror.newFoldFunction(CodeMirror.braceRangeFinder,'<span style=\"display: inline-block; width: 13px; height: 13px; background-color: #b00; color: #fff; text-align: center; cursor: pointer\"><span style="position: relative; top: -1px">+</span></span> %N%');

window['cM'+num] = CodeMirror(document.body, {
mode: "application/x-httpd-php",
Expand Down Expand Up @@ -122,7 +123,7 @@ function createNewCMInstance(num) {
};
lastKeyCode = e.keyCode;
},
onGutterClick: !fileName || (fileName && fileName.indexOf(".js") == -1 && fileName.indexOf(".php") && fileName.indexOf(".rb") == -1) ? codeFold : codeFold_JS_PHP_Ruby,
onGutterClick: !fileName || (fileName && fileName.indexOf(".js") == -1 && fileName.indexOf(".coffee") == -1 && fileName.indexOf(".php") && fileName.indexOf(".rb") == -1) ? codeFold : codeFold_JS_Coffee_PHP_Ruby,
extraKeys: {
"Tab": function(cm) {CodeMirror.commands[top.tabsIndent ? "defaultTab" : "insertTab"](cm);},
"Shift-Tab": "indentLess"
Expand Down
Binary file added images/file-manager-icons/coffee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 15 additions & 8 deletions lib/coder.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ var ICEcoder = {
contentCleanUp: function() {
var fileName, cM, content;

// If it's not a JS, Ruby or CSS file, replace & and our temp </textarea> value
// If it's not a JS, CoffeeScript Ruby or CSS file, replace & and our temp </textarea> value
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
if (fileName.indexOf(".js")<0&&fileName.indexOf(".rb")&&fileName.indexOf(".css")<0) {
if (fileName.indexOf(".js")<0 && fileName.indexOf(".coffee")<0 && fileName.indexOf(".rb")<0 && fileName.indexOf(".css")<0) {
cM = ICEcoder.getcMInstance();
content = cM.getValue();
content = content.replace(/<ICEcoder:\/:textarea>/g,'</textarea>');
Expand Down Expand Up @@ -182,7 +182,7 @@ var ICEcoder = {
ICEcoder.nestDisplay.innerHTML = "";
if ("undefined" != typeof ICEcoder.openFiles[ICEcoder.selectedTab-1]) {
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
if (fileName.indexOf(".js")<0&&fileName.indexOf(".rb")<0&&fileName.indexOf(".css")<0&&
if (fileName.indexOf(".js")<0 && fileName.indexOf(".coffee")<0 && fileName.indexOf(".rb")<0 && fileName.indexOf(".css")<0&&
(nestCheck.indexOf("include(")==-1)&&(nestCheck.indexOf("include_once(")==-1)&&
(nestCheck.indexOf("<html")>-1||nestCheck.indexOf("<body")>-1)) {

Expand Down Expand Up @@ -363,6 +363,10 @@ var ICEcoder = {
// Redo our find display
top.ICEcoder.findMode = false;
ICEcoder.findReplace('find',true,false);

// Finally, update the cursor display
top.ICEcoder.getCaretPosition();
top.ICEcoder.updateCharDisplay();
}
},

Expand Down Expand Up @@ -446,7 +450,7 @@ var ICEcoder = {
ICEcoder.caretPos=cM.getValue().length;
ICEcoder.getNestLocation();
// Nesting is OK if at the end of the file we have no nests left, or it's a JS, Ruby or CSS file
if (ICEcoder.htmlTagArray.length==0||fileName.indexOf(".js")>0||fileName.indexOf(".rb")>0||fileName.indexOf(".css")>0) {
if (ICEcoder.htmlTagArray.length==0||fileName.indexOf(".js")>0||fileName.indexOf(".coffee")>0||fileName.indexOf(".rb")>0||fileName.indexOf(".css")>0) {
ICEcoder.nestValid.style.backgroundColor="#0b0";
ICEcoder.nestValid.innerHTML = "Nesting OK";
} else {
Expand Down Expand Up @@ -496,13 +500,14 @@ var ICEcoder = {

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"};

ICEcoder.caretLocType = caretLocType;

// If we're in a JS, PHP or Ruby code block, add that to the nest display
if (caretLocType=="JavaScript"||caretLocType=="PHP"||caretLocType=="Ruby") {
// If we're in a JS, CoffeeScript PHP or Ruby code block, add that to the nest display
if (caretLocType=="JavaScript"||caretLocType=="CoffeeScript"||caretLocType=="PHP"||caretLocType=="Ruby") {
ICEcoder.nestDisplay.innerHTML += " &gt; " + caretLocType;
}
},
Expand Down Expand Up @@ -976,6 +981,8 @@ var ICEcoder = {
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) {
Expand Down Expand Up @@ -1037,7 +1044,7 @@ var ICEcoder = {
lCLen = lineContent.length;
adjustCursor = 3;

if (ICEcoder.caretLocType=="JavaScript"||ICEcoder.caretLocType=="PHP"||ICEcoder.caretLocType=="Ruby"||ICEcoder.caretLocType=="CSS") {
if (ICEcoder.caretLocType=="JavaScript"||ICEcoder.caretLocType=="CoffeeScript"||ICEcoder.caretLocType=="PHP"||ICEcoder.caretLocType=="Ruby"||ICEcoder.caretLocType=="CSS") {
if (cM.somethingSelected()) {
if (ICEcoder.caretLocType=="Ruby") {
startLine = cM.getCursor(true).line;
Expand All @@ -1053,7 +1060,7 @@ var ICEcoder = {
}
}
} else {
if (ICEcoder.caretLocType=="CSS") {
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 (lineContent.slice(0,3)=="/* ") {adjustCursor = -adjustCursor};
} else if (ICEcoder.caretLocType=="Ruby") {
Expand Down
1 change: 1 addition & 0 deletions lib/files.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ body {margin: 0px; overflow: auto}
.fileManager LI.pft-file { list-style-image: url(../images/file-manager-icons/file.png); }

/* Additional file types */
.fileManager LI.ext-coffee { list-style-image: url(../images/file-manager-icons/coffee.png); }
.fileManager LI.ext-css { list-style-image: url(../images/file-manager-icons/css.png); }
.fileManager LI.ext-doc { list-style-image: url(../images/file-manager-icons/doc.png); }
.fileManager LI.ext-gif { list-style-image: url(../images/file-manager-icons/gif.png); }
Expand Down

0 comments on commit d095e6a

Please sign in to comment.