Fix: merge conflict
[myslice.git] / to-be-integrated / third-party / codemirror-3.15 / demo / widget.html
1 <!doctype html>
2 <html>
3   <head>
4     <meta charset="utf-8">
5     <title>CodeMirror: Inline Widget Demo</title>
6     <link rel="stylesheet" href="../lib/codemirror.css">
7     <script src="../lib/codemirror.js"></script>
8     <script src="../mode/javascript/javascript.js"></script>
9     <script src="http://ajax.aspnetcdn.com/ajax/jshint/r07/jshint.js"></script>
10     <link rel="stylesheet" href="../doc/docs.css">
11
12     <style type="text/css">
13       .CodeMirror {border: 1px solid black;}
14       .lint-error {font-family: arial; font-size: 70%; background: #ffa; color: #a00; padding: 2px 5px 3px; }
15       .lint-error-icon {color: white; background-color: red; font-weight: bold; border-radius: 50%; padding: 0 3px; margin-right: 7px;}
16     </style>
17   </head>
18   <body>
19     <h1>CodeMirror: Inline Widget Demo</h1>
20
21     <div id=code></div>
22     <script id="script">var widgets = []
23 function updateHints() {
24   editor.operation(function(){
25     for (var i = 0; i < widgets.length; ++i)
26       editor.removeLineWidget(widgets[i]);
27     widgets.length = 0;
28
29     JSHINT(editor.getValue());
30     for (var i = 0; i < JSHINT.errors.length; ++i) {
31       var err = JSHINT.errors[i];
32       if (!err) continue;
33       var msg = document.createElement("div");
34       var icon = msg.appendChild(document.createElement("span"));
35       icon.innerHTML = "!!";
36       icon.className = "lint-error-icon";
37       msg.appendChild(document.createTextNode(err.reason));
38       msg.className = "lint-error";
39       widgets.push(editor.addLineWidget(err.line - 1, msg, {coverGutter: false, noHScroll: true}));
40     }
41   });
42   var info = editor.getScrollInfo();
43   var after = editor.charCoords({line: editor.getCursor().line + 1, ch: 0}, "local").top;
44   if (info.top + info.clientHeight < after)
45     editor.scrollTo(null, after - info.clientHeight + 3);
46 }
47
48 window.onload = function() {
49   var sc = document.getElementById("script");
50   var content = sc.textContent || sc.innerText || sc.innerHTML;
51
52   window.editor = CodeMirror(document.getElementById("code"), {
53     lineNumbers: true,
54     mode: "javascript",
55     value: content
56   });
57
58   var waiting;
59   editor.on("change", function() {
60     clearTimeout(waiting);
61     waiting = setTimeout(updateHints, 500);
62   });
63
64   setTimeout(updateHints, 100);
65 };
66
67 "long line to create a horizontal scrollbar, in order to test whether the (non-inline) widgets stay in place when scrolling to the right";
68 </script>
69 <p>This demo runs <a href="http://jshint.com">JSHint</a> over the code
70 in the editor (which is the script used on this page), and
71 inserts <a href="../doc/manual.html#addLineWidget">line widgets</a> to
72 display the warnings that JSHint comes up with.</p>
73   </body>
74 </html>