1- /*===
2- * CODEYOURCLOUD
3- *
4- * editor.js built by Michael Kaminsky
5- * manages the editor + options
6- *
7- * contents:
8- ===*/
9-
101/**
112* FIND/REPLACE
123* find and replace for editors
@@ -45,28 +36,25 @@ function setMode(id,mode){
4536 editors [ index ] . editor . setOption ( "lint" , CodeMirror . lint . javascript ) ;
4637 startTern ( index ) ;
4738 }
48- else if ( mode === "text/x-coffeescript" ) {
49- }
5039 else if ( mode === "text/html" ) {
51- startHtml ( index ) ;
52- }
53- else if ( mode === "text/x-markdown" || mode === "gfm" ) {
40+ editors [ index ] . editor . setOption ( "extraKeys" , { "Ctrl-Space" : "autocomplete" } ) ;
41+ editors [ index ] . editor . on ( "inputRead" , function ( cm , change ) {
42+ if ( change . text [ 0 ] === "/" || change . text [ 0 ] === "<" ) {
43+ CodeMirror . showHint ( editors [ index ] . editor , CodeMirror . hint . html ) ;
44+ }
45+ } ) ;
5446 }
5547 else if ( mode === "text/css" ) {
5648 editors [ index ] . editor . setOption ( "gutters" , [ "CodeMirror-lint-markers" ] ) ;
5749 editors [ index ] . editor . setOption ( "lint" , CodeMirror . lint . css ) ;
58- startCss ( index ) ;
50+ editors [ index ] . editor . setOption ( "extraKeys" , { "Ctrl-Space" : "autocomplete" } ) ;
5951 }
6052 else if ( mode === "application/json" ) {
6153 editors [ index ] . editor . setOption ( "gutters" , [ "CodeMirror-lint-markers" ] ) ;
6254 editors [ index ] . editor . setOption ( "lint" , CodeMirror . lint . json ) ;
6355 }
64- else if ( mode === "text/x-python" ) {
65- startPython ( index ) ;
66- }
67- else if ( mode === "text/x-sql" ) {
68- startSql ( index ) ;
69- }
56+ else if ( mode === "text/x-python" ) { editors [ index ] . editor . setOption ( "extraKeys" , { "Ctrl-Space" : "autocomplete" } ) ; }
57+ else if ( mode === "text/x-sql" ) { editors [ index ] . editor . setOption ( "extraKeys" , { "Ctrl-Space" : "autocomplete" } ) ; }
7058 editors [ index ] . editor . setOption ( "mode" , mode ) ; //finally, set the mode
7159
7260 adjust ( ) ; //adjust the ide
@@ -76,27 +64,23 @@ function extension(fileName){
7664 var ext = "txt" ;
7765 var hidden = false ;
7866
79- if ( fileName . charAt ( 0 ) === "." ) {
80- hidden = true ;
81- } else {
82- var array = fileName . split ( "." ) ;
83- ext = array [ array . length - 1 ] ;
67+ if ( fileName . charAt ( 0 ) === "." ) { hidden = true ; }
68+ else {
69+ ext = fileName . split ( "." ) . reverse ( ) [ 0 ]
8470 }
8571 return { ext : ext , hidden : hidden } ; //hidden like .DS_STORE or .vimrc
8672}
8773//get the mode for a given filename
88- function check_mode ( id , fileName ) {
74+ function checkMode ( id , fileName ) {
8975 var ext_info = extension ( fileName ) ;
90- var hidden = ext_info . hidden ;
91- var ext = ext_info . ext ;
9276 var mode_to_use = "text" ; //default
93- if ( hidden === false ) {
77+ if ( ext_info . hidden === false ) {
9478 for ( var i = 0 ; i < modes . length ; i ++ ) {
9579 var possible_mime = modes [ i ] . mime ;
9680 var exts = modes [ i ] . ext ;
9781
9882 try {
99- if ( exts . indexOf ( ext ) !== - 1 ) {
83+ if ( exts . indexOf ( ext_info . ext ) !== - 1 ) {
10084 mode_to_use = possible_mime ;
10185 }
10286 }
@@ -111,21 +95,17 @@ function modeChange(){
11195}
11296//populates the mode select
11397for ( var i = 0 ; i < modes . length ; i ++ ) {
114- var name = modes [ i ] . name ;
115- var the_mode = modes [ i ] . mime ;
116-
117- var sel = "<option value='" + the_mode + "'>" + name + "</option>" ;
118- $ ( "#mode-select" ) . html ( $ ( "#mode-select" ) . html ( ) + sel ) ;
98+ $ ( "#mode-select" ) . html ( $ ( "#mode-select" ) . html ( ) + "<option value='" + modes [ i ] . mime + "'>" + modes [ i ] . name + "</option>" ) ;
11999}
120100
121101
122102/**
123103* UNDO/REDO
124104**/
125- function editor_undo ( ) {
105+ function editorUndo ( ) {
126106 editor ( ) . getDoc ( ) . undo ( ) ;
127107}
128- function editor_redo ( ) {
108+ function editorRedo ( ) {
129109 editor ( ) . getDoc ( ) . redo ( ) ;
130110}
131111
@@ -138,23 +118,17 @@ function editor_redo() {
138118function themeChange ( ) {
139119 setTheme ( $ ( "#theme-select" ) . val ( ) ) ;
140120}
141- function setTheme ( theme ) {
142-
143- //$(".mini").css("background-color",$(".CodeMirror").css("background-color"));
144-
121+ function setTheme ( theme ) {
122+ //$(".mini").css("background-color",$(".CodeMirror").css("background-color"));
145123 localStorage . setItem ( "theme" , theme ) ;
146124 for ( var i = 0 ; i < editors . length ; i ++ ) {
147125 editors [ i ] . editor . setOption ( "theme" , theme ) ;
148126 }
149127 editor_theme = theme ;
150128}
151129//populates theme select
152- for ( var j = 0 ; j < themes . length ; j ++ ) {
153- var the_name = themes [ j ] ;
154- var the_theme = the_name . split ( " " ) . join ( "-" ) . toLowerCase ( ) ;
155-
156- var sel = "<option value='" + the_theme + "'>" + the_name + "</option>" ;
157- $ ( "#theme-select" ) . html ( $ ( "#theme-select" ) . html ( ) + sel ) ;
130+ for ( var j = 0 ; j < themes . length ; j ++ ) {
131+ $ ( "#theme-select" ) . html ( $ ( "#theme-select" ) . html ( ) + "<option value='" + themes [ j ] . split ( " " ) . join ( "-" ) . toLowerCase ( ) + "'>" + themes [ j ] + "</option>" ) ;
158132}
159133
160134/**
@@ -167,8 +141,7 @@ function fontChange(){
167141
168142//populates the font select
169143for ( var k = 2 ; k <= 30 ; k ++ ) {
170- var sel = "<option value='" + k + "'>" + k + "</option>" ;
171- $ ( "#font-select" ) . html ( $ ( "#font-select" ) . html ( ) + sel ) ;
144+ $ ( "#font-select" ) . html ( $ ( "#font-select" ) . html ( ) + "<option value='" + k + "'>" + k + "</option>" ) ;
172145}
173146
174147//sets default settings
@@ -180,7 +153,7 @@ $("#font-select").val("12");
180153* OPTIONS
181154* line numbers, line wrap, font size
182155**/
183- function line_number_switch ( ) {
156+ function lineNumber ( ) {
184157 if ( line_number ) {
185158 for ( var i = 0 ; i < editors . length ; i ++ ) {
186159 editors [ i ] . editor . setOption ( "lineNumbers" , false ) ;
@@ -194,7 +167,7 @@ function line_number_switch() {
194167 line_number = true ;
195168 }
196169}
197- function line_wrap_switch ( ) {
170+ function lineWrap ( ) {
198171 if ( editor ( ) . getOption ( "lineWrapping" ) ) {
199172 for ( var i = 0 ; i < editors . length ; i ++ ) {
200173 editors [ i ] . editor . setOption ( "lineWrapping" , false ) ;
@@ -230,28 +203,6 @@ function getHint(){
230203 CodeMirror . showHint ( editor ( ) , CodeMirror . hint . sql ) ;
231204 }
232205}
233-
234- //HTML
235- function startHtml ( index ) {
236- editors [ index ] . editor . setOption ( "extraKeys" , { "Ctrl-Space" : "autocomplete" } ) ;
237- editors [ index ] . editor . on ( "inputRead" , function ( cm , change ) {
238- if ( change . text [ 0 ] === "/" || change . text [ 0 ] === "<" ) {
239- CodeMirror . showHint ( editors [ index ] . editor , CodeMirror . hint . html ) ;
240- }
241- } ) ;
242- }
243- //CSS
244- function startCss ( index ) {
245- editors [ index ] . editor . setOption ( "extraKeys" , { "Ctrl-Space" : "autocomplete" } ) ;
246- }
247- //SQL
248- function startSql ( index ) {
249- editors [ index ] . editor . setOption ( "extraKeys" , { "Ctrl-Space" : "autocomplete" } ) ;
250- }
251- //PYTHON
252- function startPython ( index ) {
253- editors [ index ] . editor . setOption ( "extraKeys" , { "Ctrl-Space" : "autocomplete" } ) ;
254- }
255206//JAVASCRIPT
256207function getURL ( url , c ) {
257208 var xhr = new XMLHttpRequest ( ) ;
0 commit comments