You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.4 KiB

7 months ago
  1. <!doctype html>
  2. <title>CodeMirror: HTML5 preview</title>
  3. <meta charset="utf-8"/>
  4. <link rel=stylesheet href="../doc/docs.css">
  5. <link rel=stylesheet href=../lib/codemirror.css>
  6. <script src=../lib/codemirror.js></script>
  7. <script src=../mode/xml/xml.js></script>
  8. <script src=../mode/javascript/javascript.js></script>
  9. <script src=../mode/css/css.js></script>
  10. <script src=../mode/htmlmixed/htmlmixed.js></script>
  11. <style type=text/css>
  12. .CodeMirror {
  13. float: left;
  14. width: 50%;
  15. border: 1px solid black;
  16. }
  17. iframe {
  18. width: 49%;
  19. float: left;
  20. height: 300px;
  21. border: 1px solid black;
  22. border-left: 0px;
  23. }
  24. </style>
  25. <div id=nav>
  26. <a href="https://codemirror.net/5"><h1>CodeMirror</h1><img id=logo src="../doc/logo.png"></a>
  27. <ul>
  28. <li><a href="../index.html">Home</a>
  29. <li><a href="../doc/manual.html">Manual</a>
  30. <li><a href="https://github.com/codemirror/codemirror5">Code</a>
  31. </ul>
  32. <ul>
  33. <li><a class=active href="#">HTML5 preview</a>
  34. </ul>
  35. </div>
  36. <article>
  37. <h2>HTML5 preview</h2>
  38. <textarea id=code name=code>
  39. <!doctype html>
  40. <html>
  41. <head>
  42. <meta charset=utf-8>
  43. <title>HTML5 canvas demo</title>
  44. <style>p {font-family: monospace;}</style>
  45. </head>
  46. <body>
  47. <p>Canvas pane goes here:</p>
  48. <canvas id=pane width=300 height=200></canvas>
  49. <script>
  50. var canvas = document.getElementById('pane');
  51. var context = canvas.getContext('2d');
  52. context.fillStyle = 'rgb(250,0,0)';
  53. context.fillRect(10, 10, 55, 50);
  54. context.fillStyle = 'rgba(0, 0, 250, 0.5)';
  55. context.fillRect(30, 30, 55, 50);
  56. </script>
  57. </body>
  58. </html></textarea>
  59. <iframe id=preview></iframe>
  60. <script>
  61. var delay;
  62. // Initialize CodeMirror editor with a nice html5 canvas demo.
  63. var editor = CodeMirror.fromTextArea(document.getElementById('code'), {
  64. mode: 'text/html'
  65. });
  66. editor.on("change", function() {
  67. clearTimeout(delay);
  68. delay = setTimeout(updatePreview, 300);
  69. });
  70. function updatePreview() {
  71. var previewFrame = document.getElementById('preview');
  72. var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
  73. preview.open();
  74. preview.write(editor.getValue());
  75. preview.close();
  76. }
  77. setTimeout(updatePreview, 300);
  78. </script>
  79. </article>