2
0

loadmode.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>CodeMirror: Lazy Mode Loading Demo</title>
  6. <link rel="stylesheet" href="../lib/codemirror.css">
  7. <script src="../lib/codemirror.js"></script>
  8. <script src="../addon/mode/loadmode.js"></script>
  9. <link rel="stylesheet" href="../doc/docs.css">
  10. <style type="text/css">
  11. .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
  12. </style>
  13. </head>
  14. <body>
  15. <h1>CodeMirror: Lazy Mode Loading</h1>
  16. <form><textarea id="code" name="code">This is the editor.
  17. // It starts out in plain text mode,
  18. # use the control below to load and apply a mode
  19. "you'll see the highlighting of" this text /*change*/.
  20. </textarea></form>
  21. <p><input type=text value=javascript id=mode> <button type=button onclick="change()">change mode</button></p>
  22. <script>
  23. CodeMirror.modeURL = "../mode/%N/%N.js";
  24. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  25. lineNumbers: true
  26. });
  27. var modeInput = document.getElementById("mode");
  28. CodeMirror.on(modeInput, "keypress", function(e) {
  29. if (e.keyCode == 13) change();
  30. });
  31. function change() {
  32. editor.setOption("mode", modeInput.value);
  33. CodeMirror.autoLoadMode(editor, modeInput.value);
  34. }
  35. </script>
  36. </body>
  37. </html>