@@ -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