panel.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <!doctype html>
  2. <title>CodeMirror: Panel Demo</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/javascript/javascript.js"></script>
  8. <script src="../mode/xml/xml.js"></script>
  9. <script src="../mode/htmlmixed/htmlmixed.js"></script>
  10. <script src="../addon/display/panel.js"></script>
  11. <style>
  12. .border {
  13. border: 1px solid #f7f7f7;
  14. }
  15. .add-panel {
  16. background: orange;
  17. padding: 3px 6px;
  18. color: white !important;
  19. border-radius: 3px;
  20. }
  21. .add-panel, .remove-panel {
  22. cursor: pointer;
  23. }
  24. .remove-panel {
  25. float: right;
  26. }
  27. .panel {
  28. background: #f7f7f7;
  29. padding: 3px 7px;
  30. font-size: 0.85em;
  31. }
  32. .panel.top, .panel.after-top {
  33. border-bottom: 1px solid #ddd;
  34. }
  35. .panel.bottom, .panel.before-bottom {
  36. border-top: 1px solid #ddd;
  37. }
  38. </style>
  39. <div id=nav>
  40. <a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../doc/logo.png"></a>
  41. <ul>
  42. <li><a href="../index.html">Home</a>
  43. <li><a href="../doc/manual.html">Manual</a>
  44. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  45. </ul>
  46. <ul>
  47. <li><a class=active href="#">Panel</a>
  48. </ul>
  49. </div>
  50. <article>
  51. <h2>Panel Demo</h2>
  52. <div class="border">
  53. <textarea id="code" name="code"></textarea>
  54. </div>
  55. <p>
  56. The <a href="../doc/manual.html#addon_panel"><code>panel</code></a>
  57. addon allows you to display panels above or below an editor.
  58. <br>
  59. Click the links below to add panels at the given position:
  60. </p>
  61. <div id="demo">
  62. <p>
  63. <a class="add-panel" onclick="addPanel('top')">top</a>
  64. <a class="add-panel" onclick="addPanel('after-top')">after-top</a>
  65. <a class="add-panel" onclick="addPanel('before-bottom')">before-bottom</a>
  66. <a class="add-panel" onclick="addPanel('bottom')">bottom</a>
  67. </p>
  68. <p>
  69. You can also replace an existing panel:
  70. </p>
  71. <form onsubmit="return replacePanel(this);" name="replace_panel">
  72. <input type="submit" value="Replace panel n°" />
  73. <input type="number" name="panel_id" min="1" value="1" />
  74. </form>
  75. <script>
  76. var textarea = document.getElementById("code");
  77. var demo = document.getElementById("demo");
  78. var numPanels = 0;
  79. var panels = {};
  80. var editor;
  81. textarea.value = demo.innerHTML.trim();
  82. editor = CodeMirror.fromTextArea(textarea, {
  83. lineNumbers: true,
  84. mode: "htmlmixed"
  85. });
  86. function makePanel(where) {
  87. var node = document.createElement("div");
  88. var id = ++numPanels;
  89. var widget, close, label;
  90. node.id = "panel-" + id;
  91. node.className = "panel " + where;
  92. close = node.appendChild(document.createElement("a"));
  93. close.setAttribute("title", "Remove me!");
  94. close.setAttribute("class", "remove-panel");
  95. close.textContent = "✖";
  96. CodeMirror.on(close, "mousedown", function(e) {
  97. e.preventDefault()
  98. panels[node.id].clear();
  99. });
  100. label = node.appendChild(document.createElement("span"));
  101. label.textContent = "I'm panel n°" + id;
  102. return node;
  103. }
  104. function addPanel(where) {
  105. var node = makePanel(where);
  106. panels[node.id] = editor.addPanel(node, {position: where, stable: true});
  107. }
  108. addPanel("top");
  109. addPanel("bottom");
  110. function replacePanel(form) {
  111. var id = form.elements.panel_id.value;
  112. var panel = panels["panel-" + id];
  113. var node = makePanel("");
  114. panels[node.id] = editor.addPanel(node, {replace: panel, position: "after-top", stable: true});
  115. return false;
  116. }
  117. </script>
  118. </div>
  119. </article>