Debian Codegraph @

demo/toolbar.html

raw
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
6 <title>Editor</title>
7 <style type="text/css" media="screen">
8
9 .ace_editor, .toolbar {
10 border: 1px solid lightgray;
11 margin: auto;
12 width: 80%;
13 }
14 .ace_editor {
15 height: 200px;
16 }
17 </style>
18 </head>
19 <body>
20
21 <script src="kitchen-sink/require.js"></script>
22 <script>
23 // setup paths
24 require.config({paths: { "ace" : "../src"}});
25 // load ace and extensions
26 require(["ace/ace", "ace/ext/language_tools"], function(ace) {
27 var buildDom = require("ace/lib/dom").buildDom;
28 var editor = ace.edit();
29 editor.setOptions({
30 theme: "ace/theme/tomorrow_night_eighties",
31 mode: "ace/mode/markdown",
32 maxLines: 30,
33 minLines: 30,
34 autoScrollEditorIntoView: true,
35 });
36 var refs = {};
37 function updateToolbar() {
38 refs.saveButton.disabled = editor.session.getUndoManager().isClean();
39 refs.undoButton.disabled = !editor.session.getUndoManager().hasUndo();
40 refs.redoButton.disabled = !editor.session.getUndoManager().hasRedo();
41 }
42 editor.on("input", updateToolbar);
43 editor.session.setValue(localStorage.savedValue || "Welcome to ace Toolbar demo!")
44 function save() {
45 localStorage.savedValue = editor.getValue();
46 editor.session.getUndoManager().markClean();
47 updateToolbar();
48 }
49 editor.commands.addCommand({
50 name: "save",
51 exec: save,
52 bindKey: { win: "ctrl-s", mac: "cmd-s" }
53 });
54
55 buildDom(["div", { class: "toolbar" },
56 ["button", {
57 ref: "saveButton",
58 onclick: save
59 }, "save"],
60 ["button", {
61 ref: "undoButton",
62 onclick: function() {
63 editor.undo();
64 }
65 }, "undo"],
66 ["button", {
67 ref: "redoButton",
68 onclick: function() {
69 editor.redo();
70 }
71 }, "redo"],
72 ["button", {
73 style: "font-weight: bold",
74 onclick: function() {
75 editor.insertSnippet("**${1:$SELECTION}**");
76 editor.renderer.scrollCursorIntoView()
77 }
78 }, "bold"],
79 ["button", {
80 style: "font-style: italic",
81 onclick: function() {
82 editor.insertSnippet("*${1:$SELECTION}*");
83 editor.renderer.scrollCursorIntoView()
84 }
85 }, "Italic"],
86 ], document.body, refs);
87 document.body.appendChild(editor.container)
88
89 window.editor = editor;
90 });
91
92 </script>
93
94 </body>
95 </html>