Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

index.html 3.7KB

il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 src="require.js"></script>
  23. <script>
  24. // setup paths
  25. require.config({
  26. paths: {
  27. "ace": "src-min-noconflict"
  28. }
  29. });
  30. // load ace and extensions
  31. require(["ace/ace", "ace/ext-language_tools"], function(ace) {
  32. var buildDom = ace.require("ace/lib/dom").buildDom;
  33. var editor = ace.edit();
  34. editor.setOptions({
  35. mode: "ace/mode/text",
  36. theme: "ace/theme/twilight",
  37. showPrintMargin: false,
  38. wrap: true,
  39. indentedSoftWrap: true,
  40. showFoldWidgets: false,
  41. showLineNumbers: true,
  42. showGutter: false,
  43. autoScrollEditorIntoView: true
  44. });
  45. var refs = {};
  46. function updateToolbar() {
  47. refs.undoButton.disabled = !editor.session.getUndoManager().hasUndo();
  48. refs.redoButton.disabled = !editor.session.getUndoManager().hasRedo();
  49. }
  50. editor.on("input", updateToolbar);
  51. if (localStorage.getItem("acetest") !== null) {
  52. editor.setValue(localStorage.getItem("acetest"));
  53. editor.clearSelection();
  54. }
  55. editor.getSession().on('change', function () {
  56. localStorage.setItem("acetest", editor.getSession().getValue());
  57. });
  58. function save() {
  59. alert("not yet implemented");
  60. }
  61. editor.commands.addCommand({
  62. name: "save",
  63. exec: save,
  64. bindKey: {
  65. win: "ctrl-s",
  66. mac: "cmd-s"
  67. }
  68. });
  69. buildDom(["div", {
  70. class: "toolbar"
  71. },
  72. ["button", {
  73. ref: "saveButton",
  74. onclick: save
  75. }, "save"],
  76. ["button", {
  77. ref: "undoButton",
  78. onclick: function() {
  79. editor.undo();
  80. }
  81. }, "undo"],
  82. ["button", {
  83. ref: "redoButton",
  84. onclick: function() {
  85. editor.redo();
  86. }
  87. }, "redo"],
  88. ["button", {
  89. style: "font-weight: bold",
  90. onclick: function() {
  91. editor.insertSnippet("**${1:$SELECTION}**");
  92. editor.renderer.scrollCursorIntoView()
  93. }
  94. }, "bold"],
  95. ["button", {
  96. style: "font-style: italic",
  97. onclick: function() {
  98. editor.insertSnippet("*${1:$SELECTION}*");
  99. editor.renderer.scrollCursorIntoView()
  100. }
  101. }, "Italic"],
  102. ], document.body, refs);
  103. document.body.appendChild(editor.container)
  104. window.editor = editor;
  105. });
  106. </script>
  107. </body>
  108. </html>