Add keyboard shortcuts
This commit is contained in:
@@ -41,10 +41,23 @@
|
|||||||
hr: function () { wrap('\n\n---\n\n', '', ''); },
|
hr: function () { wrap('\n\n---\n\n', '', ''); },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var keyMap = {};
|
||||||
document.querySelectorAll('[data-action]').forEach(function (btn) {
|
document.querySelectorAll('[data-action]').forEach(function (btn) {
|
||||||
btn.addEventListener('click', function () {
|
btn.addEventListener('click', function () {
|
||||||
var action = actions[btn.dataset.action];
|
var action = actions[btn.dataset.action];
|
||||||
if (action) action();
|
if (action) action();
|
||||||
});
|
});
|
||||||
|
if (btn.dataset.key) {
|
||||||
|
keyMap[btn.dataset.key] = actions[btn.dataset.action];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('keydown', function (e) {
|
||||||
|
if (!e.altKey || !e.shiftKey) return;
|
||||||
|
var action = keyMap[e.key];
|
||||||
|
if (action) {
|
||||||
|
e.preventDefault();
|
||||||
|
action();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|||||||
11
assets/global-shortcuts.js
Normal file
11
assets/global-shortcuts.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
(function () {
|
||||||
|
document.addEventListener('keydown', function (e) {
|
||||||
|
if (!e.altKey || !e.shiftKey) return;
|
||||||
|
switch (e.key) {
|
||||||
|
case 'E':
|
||||||
|
e.preventDefault();
|
||||||
|
window.location.href = window.location.pathname + '?edit';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>{{.Title}}</title>
|
<title>{{.Title}}</title>
|
||||||
<link rel="stylesheet" href="/_/style.css" />
|
<link rel="stylesheet" href="/_/style.css" />
|
||||||
|
<script src="/_/global-shortcuts.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
@@ -13,27 +14,27 @@
|
|||||||
{{range .Crumbs}}<span class="sep">/</span
|
{{range .Crumbs}}<span class="sep">/</span
|
||||||
><a href="{{.URL}}">{{.Name}}</a>{{end}}
|
><a href="{{.URL}}">{{.Name}}</a>{{end}}
|
||||||
</nav>
|
</nav>
|
||||||
{{if .CanEdit}}<a class="edit-btn" href="?edit">EDIT</a>{{end}}
|
{{if .CanEdit}}<a class="edit-btn" href="?edit" title="Edit (E)">EDIT</a>{{end}}
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
{{if .EditMode}}
|
{{if .EditMode}}
|
||||||
<form class="edit-form" method="POST" action="{{.PostURL}}">
|
<form class="edit-form" method="POST" action="{{.PostURL}}">
|
||||||
<div class="editor-toolbar">
|
<div class="editor-toolbar">
|
||||||
<button type="button" class="btn-tool" data-action="bold" title="Bold">**</button>
|
<button type="button" class="btn-tool" data-action="bold" data-key="B" title="Bold (B)">**</button>
|
||||||
<button type="button" class="btn-tool" data-action="italic" title="Italic">*</button>
|
<button type="button" class="btn-tool" data-action="italic" data-key="I" title="Italic (I)">*</button>
|
||||||
<span class="toolbar-sep"></span>
|
<span class="toolbar-sep"></span>
|
||||||
<button type="button" class="btn-tool" data-action="h1" title="Heading 1">#</button>
|
<button type="button" class="btn-tool" data-action="h1" data-key="1" title="Heading 1 (1)">#</button>
|
||||||
<button type="button" class="btn-tool" data-action="h2" title="Heading 2">##</button>
|
<button type="button" class="btn-tool" data-action="h2" data-key="2" title="Heading 2 (2)">##</button>
|
||||||
<button type="button" class="btn-tool" data-action="h3" title="Heading 3">###</button>
|
<button type="button" class="btn-tool" data-action="h3" data-key="3" title="Heading 3 (3)">###</button>
|
||||||
<span class="toolbar-sep"></span>
|
<span class="toolbar-sep"></span>
|
||||||
<button type="button" class="btn-tool" data-action="code" title="Inline code">`</button>
|
<button type="button" class="btn-tool" data-action="code" data-key="C" title="Inline code (C)">`</button>
|
||||||
<button type="button" class="btn-tool" data-action="codeblock" title="Code block">```</button>
|
<button type="button" class="btn-tool" data-action="codeblock" data-key="K" title="Code block (K)">```</button>
|
||||||
<span class="toolbar-sep"></span>
|
<span class="toolbar-sep"></span>
|
||||||
<button type="button" class="btn-tool" data-action="link" title="Link">[]</button>
|
<button type="button" class="btn-tool" data-action="link" data-key="L" title="Link (L)">[]</button>
|
||||||
<button type="button" class="btn-tool" data-action="quote" title="Blockquote">></button>
|
<button type="button" class="btn-tool" data-action="quote" data-key="Q" title="Blockquote (Q)">></button>
|
||||||
<button type="button" class="btn-tool" data-action="ul" title="Unordered list">-</button>
|
<button type="button" class="btn-tool" data-action="ul" data-key="U" title="Unordered list (U)">-</button>
|
||||||
<button type="button" class="btn-tool" data-action="ol" title="Ordered list">1.</button>
|
<button type="button" class="btn-tool" data-action="ol" data-key="O" title="Ordered list (O)">1.</button>
|
||||||
<button type="button" class="btn-tool" data-action="hr" title="Horizontal rule">---</button>
|
<button type="button" class="btn-tool" data-action="hr" data-key="R" title="Horizontal rule (R)">---</button>
|
||||||
</div>
|
</div>
|
||||||
<textarea name="content" id="editor" autofocus>{{.RawContent}}</textarea>
|
<textarea name="content" id="editor" autofocus>{{.RawContent}}</textarea>
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
|
|||||||
Reference in New Issue
Block a user