Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

118 строки
3.6KB

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
  6. <meta name="HandheldFriendly" content="True" />
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <title>Editor</title>
  9. <style type="text/css" media="screen">
  10. .ace_editor,
  11. .toolbar {
  12. border: 1px solid lightgray;
  13. margin: auto;
  14. width: 80%;
  15. }
  16. .ace_editor {
  17. height: 200px;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <script>
  23. // setup paths
  24. require.config({
  25. paths: {
  26. "ace": "src-min-noconflict/"
  27. }
  28. });
  29. // load ace and extensions
  30. require(["ace/ace", "ace/ext/language_tools"], function(ace) {
  31. var buildDom = require("ace/lib/dom").buildDom;
  32. var editor = ace.edit();
  33. editor.setOptions({
  34. theme: "ace/theme/twilight",
  35. showPrintMargin: false,
  36. wrap: true,
  37. indentedSoftWrap: true,
  38. showFoldWidgets: false,
  39. showLineNumbers: true,
  40. showGutter: false,
  41. autoScrollEditorIntoView: true
  42. });
  43. var refs = {};
  44. function updateToolbar() {
  45. refs.undoButton.disabled = !editor.session.getUndoManager().hasUndo();
  46. refs.redoButton.disabled = !editor.session.getUndoManager().hasRedo();
  47. }
  48. editor.on("input", updateToolbar);
  49. if (localStorage.getItem("acetest") !== null) {
  50. editor.setValue(localStorage.getItem("acetest"));
  51. editor.clearSelection();
  52. }
  53. editor.getSession().on('change', function () {
  54. localStorage.setItem("acetest", editor.getSession().getValue());
  55. });
  56. function save() {
  57. alert("not yet implemented");
  58. }
  59. editor.commands.addCommand({
  60. name: "save",
  61. exec: save,
  62. bindKey: {
  63. win: "ctrl-s",
  64. mac: "cmd-s"
  65. }
  66. });
  67. buildDom(["div", {
  68. class: "toolbar"
  69. },
  70. ["button", {
  71. ref: "saveButton",
  72. onclick: save
  73. }, "save"],
  74. ["button", {
  75. ref: "undoButton",
  76. onclick: function() {
  77. editor.undo();
  78. }
  79. }, "undo"],
  80. ["button", {
  81. ref: "redoButton",
  82. onclick: function() {
  83. editor.redo();
  84. }
  85. }, "redo"],
  86. ["button", {
  87. style: "font-weight: bold",
  88. onclick: function() {
  89. editor.insertSnippet("**${1:$SELECTION}**");
  90. editor.renderer.scrollCursorIntoView()
  91. }
  92. }, "bold"],
  93. ["button", {
  94. style: "font-style: italic",
  95. onclick: function() {
  96. editor.insertSnippet("*${1:$SELECTION}*");
  97. editor.renderer.scrollCursorIntoView()
  98. }
  99. }, "Italic"],
  100. ], document.body, refs);
  101. document.body.appendChild(editor.container)
  102. window.editor = editor;
  103. });
  104. </script>
  105. </body>
  106. </html>