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">
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;}
19 <h1>CodeMirror: Inline Widget Demo</h1>
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]);
29 JSHINT(editor.getValue());
30 for (var i = 0; i < JSHINT.errors.length; ++i) {
31 var err = JSHINT.errors[i];
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}));
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);
48 window.onload = function() {
49 var sc = document.getElementById("script");
50 var content = sc.textContent || sc.innerText || sc.innerHTML;
52 window.editor = CodeMirror(document.getElementById("code"), {
59 editor.on("change", function() {
60 clearTimeout(waiting);
61 waiting = setTimeout(updateHints, 500);
64 setTimeout(updateHints, 100);
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";
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>