|
13 | 13 |
|
14 | 14 | // Switch the CodeMirror mode on demand |
15 | 15 | top.ICEcoder.switchMode = function(mode) { |
16 | | - var cM, fileName; |
| 16 | + var cM, fileName, fileExt; |
17 | 17 |
|
18 | 18 | cM = top.ICEcoder.getcMInstance(); |
19 | 19 | fileName = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1]; |
20 | 20 | if (cM && mode) { |
21 | 21 | cM.setOption("mode",mode); |
22 | 22 | } else if (cM && fileName) { |
23 | | - fileName.indexOf('.js')>0 ? cM.setOption("mode","text/javascript") |
24 | | - : fileName.indexOf('.coffee')>0 ? cM.setOption("mode","text/x-coffeescript") |
25 | | - : fileName.indexOf('.rb')>0 ? cM.setOption("mode","text/x-ruby") |
26 | | - : fileName.indexOf('.py')>0 ? cM.setOption("mode","text/x-python") |
27 | | - : fileName.indexOf('.css')>0 ? cM.setOption("mode","text/css") |
28 | | - : fileName.indexOf('.less')>0 ? cM.setOption("mode","text/x-less") |
29 | | - : fileName.indexOf('.md')>0 ? cM.setOption("mode","text/x-markdown") |
30 | | - : fileName.indexOf('.xml')>0 ? cM.setOption("mode","application/xml") |
31 | | - : fileName.indexOf('.sql')>0 ? cM.setOption("mode","text/x-mysql") // also text/x-sql, text/x-mariadb, text/x-cassandra or text/x-plsql |
32 | | - : fileName.indexOf('.erl')>0 ? cM.setOption("mode","text/x-erlang") |
33 | | - : fileName.indexOf('.yaml')>0 ? cM.setOption("mode","text/x-yaml") |
34 | | - : fileName.indexOf('.java')>0 ? cM.setOption("mode","text/x-java") |
35 | | - : fileName.indexOf('.jl')>0 ? cM.setOption("mode","text/x-julia") |
36 | | - : fileName.indexOf('.c')>0 ? cM.setOption("mode","text/x-csrc") |
37 | | - : fileName.indexOf('.cpp')>0 ? cM.setOption("mode","text/x-c++src") |
38 | | - : fileName.indexOf('.cs')>0 ? cM.setOption("mode","text/x-csharp") |
39 | | - : fileName.indexOf('.go')>0 ? cM.setOption("mode","text/x-go") |
40 | | - : fileName.indexOf('.lua')>0 ? cM.setOption("mode","text/x-lua") |
41 | | - : fileName.indexOf('.pl')>0 ? cM.setOption("mode","text/x-perl") |
42 | | - : fileName.indexOf('.rs')>0 ? cM.setOption("mode","text/x-rustsrc") |
43 | | - : fileName.indexOf('.scss')>0 ? cM.setOption("mode","text/x-sass") |
44 | | - : cM.setOption("mode","application/x-httpd-php"); |
| 23 | + fileExt = fileName.split("."); |
| 24 | + fileExt = fileExt[fileExt.length-1]; |
| 25 | + cM.setOption("mode", |
| 26 | + fileExt == "js" ? "text/javascript" |
| 27 | + : fileExt == "coffee" ? "text/x-coffeescript" |
| 28 | + : fileExt == "rb" ? "text/x-ruby" |
| 29 | + : fileExt == "py" ? "text/x-python" |
| 30 | + : fileExt == "css" ? "text/css" |
| 31 | + : fileExt == "less" ? "text/x-less" |
| 32 | + : fileExt == "md" ? "text/x-markdown" |
| 33 | + : fileExt == "xml" ? "application/xml" |
| 34 | + : fileExt == "sql" ? "text/x-mysql" // also text/x-sql, text/x-mariadb, text/x-cassandra or text/x-plsql |
| 35 | + : fileExt == "erl" ? "text/x-erlang" |
| 36 | + : fileExt == "yaml" ? "text/x-yaml" |
| 37 | + : fileExt == "java" ? "text/x-java" |
| 38 | + : fileExt == "jl" ? "text/x-julia" |
| 39 | + : fileExt == "c" ? "text/x-csrc" |
| 40 | + : fileExt == "cpp" ? "text/x-c++src" |
| 41 | + : fileExt == "cs" ? "text/x-csharp" |
| 42 | + : fileExt == "go" ? "text/x-go" |
| 43 | + : fileExt == "lua" ? "text/x-lua" |
| 44 | + : fileExt == "pl" ? "text/x-perl" |
| 45 | + : fileExt == "rs" ? "text/x-rustsrc" |
| 46 | + : fileExt == "scss" ? "text/x-sass" |
| 47 | + : "application/x-httpd-php" |
| 48 | + ); |
45 | 49 | } |
46 | 50 | } |
47 | 51 |
|
|
112 | 116 |
|
113 | 117 | // Work out the nesting depth location on demand and update our display if required |
114 | 118 | top.ICEcoder.getNestLocationSub = function(nestCheck, fileName) { |
115 | | - var events; |
| 119 | + var events, fileExt; |
116 | 120 |
|
117 | | - if (["js","coffee","css","less","sql","erl","yaml","java","jl","c","cpp","cs","go","lua","pl","rs","scss"].indexOf(fileName.split(".")[1])<0 && |
| 121 | + fileExt = fileName.split("."); |
| 122 | + fileExt = fileExt[fileExt.length-1]; |
| 123 | + |
| 124 | + if (["js","coffee","css","less","sql","erl","yaml","java","jl","c","cpp","cs","go","lua","pl","rs","scss"].indexOf(fileExt)<0 && |
118 | 125 | (nestCheck.indexOf("include(")==-1)&&(nestCheck.indexOf("include_once(")==-1)) { |
119 | 126 |
|
120 | 127 | // Then for all the array items, output as the nest display |
|
134 | 141 |
|
135 | 142 | // Indicate if the nesting structure of the code is OK |
136 | 143 | top.ICEcoder.updateNestingIndicator = function() { |
137 | | - var cM, testToken, nestOK, fileName; |
| 144 | + var cM, testToken, nestOK, fileName, fileExt; |
138 | 145 |
|
139 | 146 | cM = top.ICEcoder.getcMInstance(); |
140 | 147 | nestOK = true; |
141 | 148 | fileName = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1]; |
142 | | - if (cM && fileName && ["js","coffee","css","less","sql","erl","yaml","java","jl","c","cpp","cs","go","lua","pl","rs","scss"].indexOf(fileName.split(".")[1])==-1) { |
| 149 | + if (fileName) { |
| 150 | + fileExt = fileName.split("."); |
| 151 | + fileExt = fileExt[fileExt.length-1]; |
| 152 | + } |
| 153 | + if (cM && fileName && ["js","coffee","css","less","sql","erl","yaml","java","jl","c","cpp","cs","go","lua","pl","rs","scss"].indexOf(fileExt)==-1) { |
143 | 154 | testToken = cM.getTokenAt({line:cM.lineCount(),ch:cM.lineInfo(cM.lineCount()-1).text.length}); |
144 | 155 | nestOK = testToken.type && testToken.type.indexOf("error") == -1 ? true : false; |
145 | 156 | } |
|
149 | 160 |
|
150 | 161 | // Determine which area of the document we're in |
151 | 162 | top.ICEcoder.caretLocationType = function() { |
152 | | - var cM, caretLocType, caretChunk, fileName; |
| 163 | + var cM, caretLocType, caretChunk, fileName, fileExt; |
153 | 164 |
|
154 | 165 | cM = top.ICEcoder.getcMInstance(); |
155 | 166 | caretLocType = "Unknown"; |
|
163 | 174 |
|
164 | 175 | fileName = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1]; |
165 | 176 | if (fileName) { |
166 | | - if (fileName.indexOf(".js")>0) {caretLocType="JavaScript"} |
167 | | - else if (fileName.indexOf(".coffee")>0) {caretLocType="CoffeeScript"} |
168 | | - else if (fileName.indexOf(".py")>0) {caretLocType="Python"} |
169 | | - else if (fileName.indexOf(".rb")>0) {caretLocType="Ruby"} |
170 | | - else if (fileName.indexOf(".css")>0) {caretLocType="CSS"} |
171 | | - else if (fileName.indexOf(".less")>0) {caretLocType="LESS"} |
172 | | - else if (fileName.indexOf(".md")>0) {caretLocType="Markdown"} |
173 | | - else if (fileName.indexOf(".xml")>0) {caretLocType="XML"} |
174 | | - else if (fileName.indexOf(".sql")>0) {caretLocType="SQL"} |
175 | | - else if (fileName.indexOf(".yaml")>0) {caretLocType="YAML"} |
176 | | - else if (fileName.indexOf(".java")>0) {caretLocType="Java"} |
177 | | - else if (fileName.indexOf(".erl")>0) {caretLocType="Erlang"} |
178 | | - else if (fileName.indexOf(".jl")>0) {caretLocType="Julia"} |
179 | | - else if (fileName.indexOf(".c")>0 && fileName.indexOf(".cpp")<0 && fileName.indexOf(".cs")<0) {caretLocType="C"} |
180 | | - else if (fileName.indexOf(".cpp")>0) {caretLocType="C++"} |
181 | | - else if (fileName.indexOf(".cs")>0) {caretLocType="C#"} |
182 | | - else if (fileName.indexOf(".go")>0) {caretLocType="Go"} |
183 | | - else if (fileName.indexOf(".lua")>0) {caretLocType="Lua"} |
184 | | - else if (fileName.indexOf(".pl")>0) {caretLocType="Perl"} |
185 | | - else if (fileName.indexOf(".rs")>0) {caretLocType="Rust"} |
186 | | - else if (fileName.indexOf(".scss")>0) {caretLocType="Sass"}; |
| 177 | + fileExt = fileName.split("."); |
| 178 | + fileExt = fileExt[fileExt.length-1]; |
| 179 | + caretLocType = |
| 180 | + fileExt == "js" ? "JavaScript" |
| 181 | + : fileExt == "coffee" ? "CoffeeScript" |
| 182 | + : fileExt == "py" ? "Python" |
| 183 | + : fileExt == "rb" ? "Ruby" |
| 184 | + : fileExt == "css" ? "CSS" |
| 185 | + : fileExt == "less" ? "LESS" |
| 186 | + : fileExt == "md" ? "Markdown" |
| 187 | + : fileExt == "xml" ? "XML" |
| 188 | + : fileExt == "sql" ? "SQL" |
| 189 | + : fileExt == "yaml" ? "YAML" |
| 190 | + : fileExt == "java" ? "Java" |
| 191 | + : fileExt == "erl" ? "Erlang" |
| 192 | + : fileExt == "jl" ? "Julia" |
| 193 | + : fileExt == "c" ? "C" |
| 194 | + : fileExt == "cpp" ? "C++" |
| 195 | + : fileExt == "cs" ? "C#" |
| 196 | + : fileExt == "go" ? "Go" |
| 197 | + : fileExt == "lua" ? "Lua" |
| 198 | + : fileExt == "pl" ? "Perl" |
| 199 | + : fileExt == "rs" ? "Rust" |
| 200 | + : fileExt == "scss" ? "Sass" |
| 201 | + : "Content"; |
187 | 202 | } |
188 | 203 |
|
189 | 204 | top.ICEcoder.caretLocType = caretLocType; |
|
0 commit comments