CMIContent Marketing InstituteContent directory

News · General · Archive

Codemirror Lazy Mode Loading Demo

Home News

.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}

CodeMirror

Home Manual Code

Lazy Mode Loading

Lazy Mode Loading Demo

Current mode: text/plain

This is the editor. // It starts out in plain text mode, # use the control below to load and apply a mode "you'll see the highlighting of" this text /*change*/.

Filename, mime, or mode name: change mode

CodeMirror.modeURL = "../mode/%N/%N.js"; var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true }); var modeInput = document.getElementById("mode"); CodeMirror.on(modeInput, "keypress", function(e) { if (e.keyCode == 13) change(); }); function change() { var val = modeInput.value, m, mode, spec; if (m = /.+\.([^.]+)$/.exec(val)) { var info = CodeMirror.findModeByExtension(m[1]); if (info) { mode = info.mode; spec = info.mime; } } else if (/\//.test(val)) { var info = CodeMirror.findModeByMIME(val); if (info) { mode = info.mode; spec = val; } } else { mode = spec = val; } if (mode) { editor.setOption("mode", spec); CodeMirror.autoLoadMode(editor, mode); document.getElementById("modeinfo").textContent = spec; } else { alert("Could not find a mode corresponding to " + val); } }

More in Archive · More in General · More in News