2
0

folding.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>CodeMirror: Code Folding Demo</title>
  6. <link rel="stylesheet" href="../lib/codemirror.css">
  7. <script src="../lib/codemirror.js"></script>
  8. <script src="../addon/fold/foldcode.js"></script>
  9. <script src="../addon/fold/brace-fold.js"></script>
  10. <script src="../addon/fold/xml-fold.js"></script>
  11. <script src="../mode/javascript/javascript.js"></script>
  12. <script src="../mode/xml/xml.js"></script>
  13. <link rel="stylesheet" href="../doc/docs.css">
  14. <style type="text/css">
  15. .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
  16. .CodeMirror-foldmarker {
  17. color: blue;
  18. text-shadow: #b9f 1px 1px 2px, #b9f -1px -1px 2px, #b9f 1px -1px 2px, #b9f -1px 1px 2px;
  19. font-family: arial;
  20. line-height: .3;
  21. cursor: pointer;
  22. }
  23. </style>
  24. </head>
  25. <body>
  26. <h1>CodeMirror: Code Folding Demo</h1>
  27. <p>Demonstration of code folding using the code
  28. in <a href="../addon/fold/foldcode.js"><code>foldcode.js</code></a>.
  29. Press ctrl-q or click on the gutter to fold a block, again
  30. to unfold.</p>
  31. <form>
  32. <div style="max-width: 50em; margin-bottom: 1em">JavaScript:<br><textarea id="code" name="code"></textarea></div>
  33. <div style="max-width: 50em">HTML:<br><textarea id="code-html" name="code-html"></textarea></div>
  34. </form>
  35. <script id="script">
  36. window.onload = function() {
  37. var te = document.getElementById("code");
  38. var sc = document.getElementById("script");
  39. te.value = (sc.textContent || sc.innerText || sc.innerHTML).replace(/^\s*/, "");
  40. sc.innerHTML = "";
  41. var te_html = document.getElementById("code-html");
  42. te_html.value = "<html>\n " + document.documentElement.innerHTML + "\n</html>";
  43. var foldFunc = CodeMirror.newFoldFunction(CodeMirror.braceRangeFinder);
  44. window.editor = CodeMirror.fromTextArea(te, {
  45. mode: "javascript",
  46. lineNumbers: true,
  47. lineWrapping: true,
  48. extraKeys: {"Ctrl-Q": function(cm){foldFunc(cm, cm.getCursor().line);}}
  49. });
  50. editor.on("gutterClick", foldFunc);
  51. foldFunc(editor, 9);
  52. var foldFunc_html = CodeMirror.newFoldFunction(CodeMirror.tagRangeFinder);
  53. window.editor_html = CodeMirror.fromTextArea(te_html, {
  54. mode: "text/html",
  55. lineNumbers: true,
  56. lineWrapping: true,
  57. extraKeys: {"Ctrl-Q": function(cm){foldFunc_html(cm, cm.getCursor().line);}}
  58. });
  59. editor_html.on("gutterClick", foldFunc_html);
  60. foldFunc_html(editor_html, 11);
  61. foldFunc_html(editor_html, 1);
  62. };
  63. </script>
  64. </body>
  65. </html>