4
<title>CodeMirror: Code Folding Demo</title>
5
<link rel="stylesheet" href="../lib/codemirror.css">
6
<script src="../lib/codemirror.js"></script>
7
<script src="../lib/util/foldcode.js"></script>
8
<script src="../mode/javascript/javascript.js"></script>
9
<script src="../mode/xml/xml.js"></script>
10
<link rel="stylesheet" href="../doc/docs.css">
12
<style type="text/css">
13
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
14
.CodeMirror-gutter {min-width: 2.6em; cursor: pointer;}
18
<h1>CodeMirror: Code Folding Demo</h1>
20
<p>Demonstration of code folding using the code
21
in <a href="../lib/util/foldcode.js"><code>foldcode.js</code></a>.
22
Press ctrl-q or click on the gutter to fold a block, again
25
<div style="max-width: 50em; margin-bottom: 1em">JavaScript:<br><textarea id="code" name="code"></textarea></div>
26
<div style="max-width: 50em">HTML:<br><textarea id="code-html" name="code-html"></textarea></div>
29
window.onload = function() {
30
var te = document.getElementById("code");
31
var sc = document.getElementById("script");
32
te.value = (sc.textContent || sc.innerText || sc.innerHTML).replace(/^\s*/, "");
34
var te_html = document.getElementById("code-html");
35
te_html.value = "<html>\n " + document.documentElement.innerHTML + "\n</html>";
37
var foldFunc = CodeMirror.newFoldFunction(CodeMirror.braceRangeFinder);
38
window.editor = CodeMirror.fromTextArea(te, {
42
onGutterClick: foldFunc,
43
extraKeys: {"Ctrl-Q": function(cm){foldFunc(cm, cm.getCursor().line);}}
48
var foldFunc_html = CodeMirror.newFoldFunction(CodeMirror.tagRangeFinder);
49
window.editor_html = CodeMirror.fromTextArea(te_html, {
53
onGutterClick: foldFunc_html,
54
extraKeys: {"Ctrl-Q": function(cm){foldFunc_html(cm, cm.getCursor().line);}}
56
foldFunc_html(editor_html, 1);
57
foldFunc_html(editor_html, 15);