Fix: merge conflict
[myslice.git] / to-be-integrated / third-party / codemirror-3.15 / demo / xmlcomplete.html
1 <!doctype html>
2 <html>
3   <head>
4     <meta charset="utf-8">
5     <title>CodeMirror: XML Autocomplete Demo</title>
6     <link rel="stylesheet" href="../lib/codemirror.css">
7     <script src="../lib/codemirror.js"></script>
8     <script src="../addon/hint/show-hint.js"></script>
9     <link rel="stylesheet" href="../addon/hint/show-hint.css">
10     <script src="../addon/hint/xml-hint.js"></script>
11     <script src="../mode/xml/xml.js"></script>
12     <link rel="stylesheet" href="../doc/docs.css">
13     <style type="text/css">
14       .CodeMirror { border: 1px solid #eee; }
15     </style>
16   </head>
17   <body>
18     <h1>CodeMirror: XML Autocomplete demo</h1>
19
20     <form><textarea id="code" name="code"><!-- write some xml below -->
21 </textarea></form>
22
23     <p>Press <strong>ctrl-space</strong>, or type a '<' character to
24     activate autocompletion. This demo defines a simple schema that
25     guides completion. The schema can be customized—see
26     the <a href="../doc/manual.html#addon_xml-hint">manual</a>.</p>
27
28     <p>Development of the <code>xml-hint</code> addon was kindly
29     sponsored
30     by <a href="http://www.xperiment.mobi">www.xperiment.mobi</a>.</p>
31
32     <script>
33       var dummy = {
34         attrs: {
35           color: ["red", "green", "blue", "purple", "white", "black", "yellow"],
36           size: ["large", "medium", "small"],
37           description: null
38         },
39         children: []
40       };
41
42       var tags = {
43         "!top": ["top"],
44         top: {
45           attrs: {
46             lang: ["en", "de", "fr", "nl"],
47             freeform: null
48           },
49           children: ["animal", "plant"]
50         },
51         animal: {
52           attrs: {
53             name: null,
54             isduck: ["yes", "no"]
55           },
56           children: ["wings", "feet", "body", "head", "tail"]
57         },
58         plant: {
59           attrs: {name: null},
60           children: ["leaves", "stem", "flowers"]
61         },
62         wings: dummy, feet: dummy, body: dummy, head: dummy, tail: dummy,
63         leaves: dummy, stem: dummy, flowers: dummy
64       };
65
66       function completeAfter(cm, pred) {
67         var cur = cm.getCursor();
68         if (!pred || pred()) setTimeout(function() {
69           if (!cm.state.completionActive)
70             CodeMirror.showHint(cm, CodeMirror.hint.xml, {schemaInfo: tags, completeSingle: false});
71         }, 100);
72         return CodeMirror.Pass;
73       }
74
75       function completeIfAfterLt(cm) {
76         return completeAfter(cm, function() {
77           var cur = cm.getCursor();
78           return cm.getRange(CodeMirror.Pos(cur.line, cur.ch - 1), cur) == "<";
79         });
80       }
81
82       function completeIfInTag(cm) {
83         return completeAfter(cm, function() {
84           var tok = cm.getTokenAt(cm.getCursor());
85           if (tok.type == "string" && (!/['"]/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length == 1)) return false;
86           var inner = CodeMirror.innerMode(cm.getMode(), tok.state).state;
87           return inner.tagName;
88         });
89       }
90
91       var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
92         mode: "xml",
93         lineNumbers: true,
94         extraKeys: {
95           "'<'": completeAfter,
96           "'/'": completeIfAfterLt,
97           "' '": completeIfInTag,
98           "'='": completeIfInTag,
99           "Ctrl-Space": function(cm) {
100             CodeMirror.showHint(cm, CodeMirror.hint.xml, {schemaInfo: tags});
101           }
102         }
103       });
104     </script>
105   </body>
106 </html>