loadmode.html 1.5 KB

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