requirejs.html 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <!doctype html>
  2. <head>
  3. <title>CodeMirror: HTML completion demo</title>
  4. <meta charset="utf-8"/>
  5. <link rel=stylesheet href="../doc/docs.css">
  6. <link rel="stylesheet" href="../lib/codemirror.css">
  7. <link rel="stylesheet" href="../addon/hint/show-hint.css">
  8. <script src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js"></script>
  9. <style type="text/css">
  10. .CodeMirror {border-top: 1px solid #888; border-bottom: 1px solid #888;}
  11. </style>
  12. </head>
  13. <body>
  14. <div id=nav>
  15. <a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../doc/logo.png"></a>
  16. <ul>
  17. <li><a href="../index.html">Home</a>
  18. <li><a href="../doc/manual.html">Manual</a>
  19. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  20. </ul>
  21. <ul>
  22. <li><a class=active href="#">HTML completion</a>
  23. </ul>
  24. </div>
  25. <article>
  26. <h2>RequireJS module loading demo</h2>
  27. <p>This demo does the same thing as
  28. the <a href="html5complete.html">HTML5 completion demo</a>, but
  29. loads its dependencies
  30. with <a href="http://requirejs.org/">Require.js</a>, rather than
  31. explicitly. Press <strong>ctrl-space</strong> to activate
  32. completion.</p>
  33. <div id="code"></div>
  34. <button id="markdown">Dynamically load Markdown mode</button>
  35. <script type="text/javascript">
  36. require.config({
  37. packages: [{
  38. name: "codemirror",
  39. location: "../",
  40. main: "lib/codemirror"
  41. }]
  42. });
  43. require(["codemirror", "codemirror/mode/htmlmixed/htmlmixed",
  44. "codemirror/addon/hint/show-hint", "codemirror/addon/hint/html-hint",
  45. "codemirror/addon/mode/loadmode"], function(CodeMirror) {
  46. editor = CodeMirror(document.getElementById("code"), {
  47. mode: "text/html",
  48. extraKeys: {"Ctrl-Space": "autocomplete"},
  49. value: document.documentElement.innerHTML
  50. });
  51. CodeMirror.modeURL = "codemirror/mode/%N/%N";
  52. document.getElementById("markdown").addEventListener("click", function() {
  53. CodeMirror.requireMode("markdown", function() {
  54. editor.replaceRange("This is **Markdown**.\n\n", {line: 0, ch: 0});
  55. editor.setOption("mode", "markdown");
  56. });
  57. });
  58. });
  59. </script>
  60. </article>
  61. </body>