瀏覽代碼

WIP: toolbars

master
KaiSD 5 年之前
父節點
當前提交
bb9f10c4ca
共有 1 個文件被更改,包括 86 次插入100 次删除
  1. +86
    -100
      ace/index.html

+ 86
- 100
ace/index.html 查看文件

@@ -1,113 +1,99 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<meta name="HandheldFriendly" content="True" />
<title>Editor</title>
<style type="text/css" media="screen">
body {
overflow: hidden;
}
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<meta name="HandheldFriendly" content="True" />
<title>Editor</title>
<style type="text/css" media="screen">
body {
overflow: hidden;
}

#editor {
margin: 0;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>
#editor {
margin: 0;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>

<pre id="editor"></pre>
<pre id="editor"></pre>
<script src="src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
var buildDom = ace.require("ace/lib/dom").buildDom;
var editor = ace.edit("editor");
editor.setOptions({
mode: "ace/mode/text",
theme: "ace/theme/twilight",
showPrintMargin: false,
wrap: true,
indentedSoftWrap: true,
showFoldWidgets: false,
showLineNumbers: true,
showGutter: false,
autoScrollEditorIntoView: true
});
var refs = {};

<script src="src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
var buildDom = ace.require("ace/lib/dom").buildDom;
var editor = ace.edit();
editor.setOptions({
mode: "ace/mode/text",
theme: "ace/theme/twilight",
showPrintMargin: false,
wrap: true,
indentedSoftWrap: true,
showFoldWidgets: false,
showLineNumbers: true,
showGutter: false,
autoScrollEditorIntoView: true
});
var refs = {};
function updateToolbar() {
refs.undoButton.disabled = !editor.session.getUndoManager().hasUndo();
refs.redoButton.disabled = !editor.session.getUndoManager().hasRedo();
}
editor.on("input", updateToolbar);

function updateToolbar() {
refs.undoButton.disabled = !editor.session.getUndoManager().hasUndo();
refs.redoButton.disabled = !editor.session.getUndoManager().hasRedo();
}
editor.on("input", updateToolbar);
if (localStorage.getItem("acetest") !== null) {
editor.setValue(localStorage.getItem("acetest"));
editor.clearSelection();
}

if (localStorage.getItem("acetest") !== null) {
editor.setValue(localStorage.getItem("acetest"));
editor.clearSelection();
}
editor.getSession().on('change', function () {
localStorage.setItem("acetest", editor.getSession().getValue());
});

editor.getSession().on('change', function () {
localStorage.setItem("acetest", editor.getSession().getValue());
});
function save() {
alert("not yet implemented");
}

function save() {
alert("not yet implemented");
}
editor.commands.addCommand({
name: "save",
exec: save,
bindKey: {
win: "ctrl-s",
mac: "cmd-s"
}
});

editor.commands.addCommand({
name: "save",
exec: save,
bindKey: {
win: "ctrl-s",
mac: "cmd-s"
}
});

buildDom(["div", {
class: "toolbar"
},
["button", {
ref: "saveButton",
onclick: save
}, "save"],
["button", {
ref: "undoButton",
onclick: function() {
editor.undo();
}
}, "undo"],
["button", {
ref: "redoButton",
onclick: function() {
editor.redo();
}
}, "redo"],
["button", {
style: "font-weight: bold",
onclick: function() {
editor.insertSnippet("**${1:$SELECTION}**");
editor.renderer.scrollCursorIntoView()
}
}, "bold"],
["button", {
style: "font-style: italic",
onclick: function() {
editor.insertSnippet("*${1:$SELECTION}*");
editor.renderer.scrollCursorIntoView()
}
}, "Italic"],
], document.body, refs);
document.body.appendChild(editor.container)
buildDom(["div", {
class: "toolbar"
},
["button", {
ref: "saveButton",
onclick: save
}, "save"],
["button", {
ref: "undoButton",
onclick: function() {
editor.undo();
}
}, "undo"],
["button", {
ref: "redoButton",
onclick: function() {
editor.redo();
}
}, "redo"]
], document.body, refs);
document.body.appendChild(editor.container)

window.editor = editor;
</script>
window.editor = editor;
</script>

</body>
</body>
</html>

Loading…
取消
儲存