Skip to content

Commit b971460

Browse files
authored
Add shortcuts help dialog (#400)
1 parent f34a045 commit b971460

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+386
-62
lines changed

css/elements.css

+41
Original file line numberDiff line numberDiff line change
@@ -1212,3 +1212,44 @@ li.menu-search-result-term:before {
12121212
.clause-attributes-tag a {
12131213
color: #884400;
12141214
}
1215+
1216+
/* Shortcuts help dialog */
1217+
1218+
#shortcuts-help {
1219+
position: fixed;
1220+
left: 5%;
1221+
margin: 0 auto;
1222+
right: 5%;
1223+
z-index: 10;
1224+
top: 10%;
1225+
top: calc(5vw + 5vh);
1226+
padding: 30px 90px;
1227+
max-width: 500px;
1228+
outline: solid 10000px rgba(255, 255, 255, 0.6);
1229+
border-radius: 5px;
1230+
border-width: 1px 1px 0 1px;
1231+
background-color: #ddd;
1232+
display: none;
1233+
}
1234+
1235+
#shortcuts-help.active {
1236+
display: block;
1237+
}
1238+
1239+
#shortcuts-help ul {
1240+
padding: 0;
1241+
}
1242+
1243+
#shortcuts-help li {
1244+
display: flex;
1245+
justify-content: space-between;
1246+
}
1247+
1248+
#shortcuts-help code {
1249+
padding: 3px 10px;
1250+
border-radius: 3px;
1251+
border-width: 1px 1px 0 1px;
1252+
border-color: #bbb;
1253+
background-color: #eee;
1254+
box-shadow: inset 0 -1px 0 #ccc;
1255+
}

js/menu.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Search.prototype.loadBiblio = function () {
4747
};
4848

4949
Search.prototype.documentKeydown = function (e) {
50-
if (e.keyCode === 191) {
50+
if (e.key === '/') {
5151
e.preventDefault();
5252
e.stopPropagation();
5353
this.triggerSearch();
@@ -973,7 +973,7 @@ function doShortcut(e) {
973973
if (name === 'textarea' || name === 'input' || name === 'select' || target.isContentEditable) {
974974
return;
975975
}
976-
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
976+
if (e.altKey || e.ctrlKey || e.metaKey) {
977977
return;
978978
}
979979
if (e.key === 'm' && usesMultipage) {
@@ -995,6 +995,8 @@ function doShortcut(e) {
995995
}
996996
} else if (e.key === 'u') {
997997
document.documentElement.classList.toggle('show-ao-annotations');
998+
} else if (e.key === '?') {
999+
document.getElementById('shortcuts-help').classList.toggle('active');
9981000
}
9991001
}
10001002

@@ -1010,8 +1012,11 @@ function init() {
10101012
document.addEventListener(
10111013
'keydown',
10121014
debounce(e => {
1013-
if (e.code === 'Escape' && Toolbox.active) {
1014-
Toolbox.deactivate();
1015+
if (e.code === 'Escape') {
1016+
if (Toolbox.active) {
1017+
Toolbox.deactivate();
1018+
}
1019+
document.getElementById('shortcuts-help').classList.remove('active');
10151020
}
10161021
})
10171022
);

src/Spec.ts

+26-9
Original file line numberDiff line numberDiff line change
@@ -519,18 +519,22 @@ export default class Spec {
519519
this.setCharset();
520520
const wrapper = this.buildSpecWrapper();
521521

522-
let tocEles: HTMLElement[] = [];
522+
let commonEles: HTMLElement[] = [];
523523
let tocJs = '';
524524
if (this.opts.toc) {
525525
this.log('Building table of contents...');
526526

527527
if (this.opts.oldToc) {
528528
new Toc(this).build();
529529
} else {
530-
({ js: tocJs, eles: tocEles } = makeMenu(this));
530+
({ js: tocJs, eles: commonEles } = makeMenu(this));
531531
}
532532
}
533-
for (const ele of tocEles) {
533+
534+
this.log('Building shortcuts help dialog...');
535+
commonEles.push(this.buildShortcutsHelp());
536+
537+
for (const ele of commonEles) {
534538
this.doc.body.insertBefore(ele, this.doc.body.firstChild);
535539
}
536540

@@ -539,7 +543,7 @@ export default class Spec {
539543
const jsSha = sha(jsContents);
540544

541545
if (this.opts.multipage) {
542-
await this.buildMultipage(wrapper, tocEles, jsSha);
546+
await this.buildMultipage(wrapper, commonEles, jsSha);
543547
}
544548

545549
await this.buildAssets(jsContents, jsSha);
@@ -731,7 +735,7 @@ export default class Spec {
731735
return null;
732736
}
733737

734-
private async buildMultipage(wrapper: Element, tocEles: Element[], jsSha: string) {
738+
private async buildMultipage(wrapper: Element, commonEles: Element[], jsSha: string) {
735739
let stillIntro = true;
736740
const introEles = [];
737741
const sections: { name: string; eles: Element[] }[] = [];
@@ -864,9 +868,9 @@ ${await utils.readFile(path.join(__dirname, '../js/multipage.js'))}
864868
for (const { name, eles } of sections) {
865869
this.log(`Generating section ${name}...`);
866870
const headClone = head.cloneNode(true) as HTMLHeadElement;
867-
const tocClone = tocEles.map(e => e.cloneNode(true));
871+
const commonClone = commonEles.map(e => e.cloneNode(true));
868872
const clones = eles.map(e => e.cloneNode(true));
869-
const allClones = [headClone, ...tocClone, ...clones];
873+
const allClones = [headClone, ...commonClone, ...clones];
870874
// @ts-ignore
871875
const links = allClones.flatMap(e => [...e.querySelectorAll('a,link')]);
872876
for (const link of links) {
@@ -919,10 +923,10 @@ ${await utils.readFile(path.join(__dirname, '../js/multipage.js'))}
919923
}
920924

921925
// @ts-ignore
922-
const tocHTML = tocClone.map(e => e.outerHTML).join('\n');
926+
const commonHTML = commonClone.map(e => e.outerHTML).join('\n');
923927
// @ts-ignore
924928
const clonesHTML = clones.map(e => e.outerHTML).join('\n');
925-
const content = `<!doctype html>${htmlEle}\n${headClone.outerHTML}\n<body>${tocHTML}<div id='spec-container'>${clonesHTML}</div></body>`;
929+
const content = `<!doctype html>${htmlEle}\n${headClone.outerHTML}\n<body>${commonHTML}<div id='spec-container'>${clonesHTML}</div></body>`;
926930

927931
this.generatedFiles.set(path.join(this.opts.outfile!, `multipage/${name}.html`), content);
928932
}
@@ -1027,6 +1031,19 @@ ${await utils.readFile(path.join(__dirname, '../js/multipage.js'))}
10271031
return wrapper;
10281032
}
10291033

1034+
private buildShortcutsHelp() {
1035+
const shortcutsHelp = this.doc.createElement('div');
1036+
shortcutsHelp.setAttribute('id', 'shortcuts-help');
1037+
shortcutsHelp.innerHTML = `
1038+
<ul>
1039+
<li><span>Toggle shortcuts help</span><code>?</code></li>
1040+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
1041+
${this.opts.multipage ? `<li><span>Navigate to/from multipage</span><code>m</code></li>` : ''}
1042+
<li><span>Jump to search box</span><code>/</code></li>
1043+
</ul>`;
1044+
return shortcutsHelp;
1045+
}
1046+
10301047
private processMetadata() {
10311048
const block = this.doc.querySelector('pre.metadata');
10321049

test/baselines/generated-reference/algorithm-replacements.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"></head><body><div id="spec-container">
2+
<head><meta charset="utf-8"></head><body><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container">
39

410
<emu-clause id="test">
511
<h1><span class="secnum">1</span> Title</h1>

test/baselines/generated-reference/algorithms.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"></head><body><div id="spec-container">
2+
<head><meta charset="utf-8"></head><body><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container">
39
<emu-biblio href="./algorithmsBiblio.json"></emu-biblio>
410
<emu-alg><ol><li>Can call <emu-xref href="#sec-algorithm-conventions-abstract-operations"><a href="https://tc39.es/ecma262/#sec-algorithm-conventions-abstract-operations">abstract operations</a></emu-xref> in this spec: <emu-xref aoid="Internal" id="_ref_0"><a href="#sec-internal">Internal</a></emu-xref>();</li><li>Can call <emu-xref href="#sec-algorithm-conventions-abstract-operations"><a href="https://tc39.es/ecma262/#sec-algorithm-conventions-abstract-operations">abstract operations</a></emu-xref> in ES6: <emu-xref aoid="ReturnIfAbrupt" id="_ref_1"><a href="https://tc39.es/ecma262/#sec-returnifabrupt">ReturnIfAbrupt</a></emu-xref>(<var>completion</var>);</li><li>Can call <emu-xref href="#sec-algorithm-conventions-abstract-operations"><a href="https://tc39.es/ecma262/#sec-algorithm-conventions-abstract-operations">abstract operations</a></emu-xref> in a biblio file: <emu-xref aoid="Biblio"><a href="http://example.com/fooSite.html#sec-biblio">Biblio</a></emu-xref>();</li><li>Unfound <emu-xref href="#sec-algorithm-conventions-abstract-operations"><a href="https://tc39.es/ecma262/#sec-algorithm-conventions-abstract-operations">abstract operations</a></emu-xref> just don't link: Unfound();</li><li>Can prefix with !&nbsp;and ?.<ol><li>Let <var>foo</var> be ?&nbsp;<emu-xref aoid="Internal" id="_ref_2"><a href="#sec-internal">Internal</a></emu-xref>();</li><li>Set <var>foo</var> to !&nbsp;<emu-xref aoid="Internal" id="_ref_3"><a href="#sec-internal">Internal</a></emu-xref>();</li><li>Set <var>foo</var> to !&nbsp;SDO of <var>operation</var>.</li><li>Set <var>foo</var> to !&nbsp;<var>operation</var>.[[MOP]]().</li></ol></li></ol></emu-alg>
511

test/baselines/generated-reference/autolinking.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"></head><body><div id="spec-container">
2+
<head><meta charset="utf-8"></head><body><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container">
39
<emu-clause id="sec-foo">
410
<h1><span class="secnum">1</span> Autolinking</h1>
511
<p>Type, type, <emu-xref aoid="Type" id="_ref_0"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(), type()</p>

test/baselines/generated-reference/boilerplate-address.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"><title>test title!</title></head><body><div id="spec-container"><h1 class="title">test title!</h1>
2+
<head><meta charset="utf-8"><title>test title!</title></head><body><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container"><h1 class="title">test title!</h1>
39

410
<emu-annex id="sec-copyright-and-software-license">
511
<h1><span class="secnum">A</span> Copyright &amp; Software License</h1>

test/baselines/generated-reference/boilerplate-all.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"><title>test title!</title></head><body><div id="spec-container"><h1 class="title">test title!</h1>
2+
<head><meta charset="utf-8"><title>test title!</title></head><body><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container"><h1 class="title">test title!</h1>
39

410
<emu-annex id="sec-copyright-and-software-license">
511
<h1><span class="secnum">A</span> Copyright &amp; Software License</h1>

test/baselines/generated-reference/boilerplate-copyright.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"><title>test title!</title></head><body><div id="spec-container"><h1 class="title">test title!</h1>
2+
<head><meta charset="utf-8"><title>test title!</title></head><body><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container"><h1 class="title">test title!</h1>
39

410
<emu-annex id="sec-copyright-and-software-license">
511
<h1><span class="secnum">A</span> Copyright &amp; Software License</h1>

test/baselines/generated-reference/boilerplate-license.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"><title>test title!</title></head><body><div id="spec-container"><h1 class="title">test title!</h1>
2+
<head><meta charset="utf-8"><title>test title!</title></head><body><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container"><h1 class="title">test title!</h1>
39

410
<emu-annex id="sec-copyright-and-software-license">
511
<h1><span class="secnum">A</span> Copyright &amp; Software License</h1>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"></head><body><div id="spec-container">
2+
<head><meta charset="utf-8"></head><body><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container">
39
</div></body>
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
22
<head><meta charset="utf-8">
3-
</head><body><div id="spec-container">
3+
</head><body><div id="shortcuts-help">
4+
<ul>
5+
<li><span>Toggle shortcuts help</span><code>?</code></li>
6+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
7+
8+
<li><span>Jump to search box</span><code>/</code></li>
9+
</ul></div><div id="spec-container">
410

511
</div></body>

test/baselines/generated-reference/clauses.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"></head><body class=" oldtoc"><div id="spec-container">
2+
<head><meta charset="utf-8"></head><body class=" oldtoc"><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container">
39
<div><h2>Table of Contents</h2><ol class="toc"><li><a href="#sec-intro" title="Intro">Intro</a><ol class="toc"><li><a href="#sec-intro2" title="Sub Intro">Sub Intro</a></li></ol></li><li><a href="#sec-clause" title="Clause Foo(a, b)"><span class="secnum">1</span> Clause Foo(<var>a</var>, <var>b</var>)</a><ol class="toc"><li><a href="#Foo" title="Sub Clause"><span class="secnum">1.1</span> Sub Clause</a></li></ol></li><li><a href="#sec-annex" title="Annex"><span class="secnum">A</span> Annex</a><ol class="toc"><li><a href="#sec-annex2" title="Sub-annex"><span class="secnum">A.1</span> Sub-annex</a></li></ol></li></ol></div><emu-intro id="sec-intro">
410
<h1>Intro</h1>
511
<emu-intro id="sec-intro2">

test/baselines/generated-reference/code.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"></head><body><div id="spec-container">
2+
<head><meta charset="utf-8"></head><body><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container">
39
<link rel="stylesheet" href="css/elements.css">
410
<emu-clause id="foo">
511
<h1><span class="secnum">1</span> Test Clause</h1>

test/baselines/generated-reference/copyright.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"><title>test title!</title></head><body><div id="spec-container"><h1 class="version">Draft 1 / September 26, 2014</h1><h1 class="title">test title!</h1>
2+
<head><meta charset="utf-8"><title>test title!</title></head><body><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container"><h1 class="version">Draft 1 / September 26, 2014</h1><h1 class="title">test title!</h1>
39
<emu-clause id="sec-clause">
410
<h1><span class="secnum">1</span> Test Clause</h1>
511
</emu-clause><emu-annex id="sec-copyright-and-software-license">

test/baselines/generated-reference/date.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"><title>test title!</title></head><body><div id="spec-container"><h1 class="title">test title!</h1>
2+
<head><meta charset="utf-8"><title>test title!</title></head><body><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container"><h1 class="title">test title!</h1>
39

410
<p>Some body content</p>
511

test/baselines/generated-reference/dfn.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"></head><body><div id="spec-container">
2+
<head><meta charset="utf-8"></head><body><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container">
39
<emu-intro id="sec-intro">
410
<h1>Intro</h1>
511
<p>Forward references to <emu-xref href="#sec-dfn" id="_ref_0"><a href="#sec-dfn">dfn</a></emu-xref> work.</p>

test/baselines/generated-reference/duplicate-ids.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"></head><body><div id="spec-container">
2+
<head><meta charset="utf-8"></head><body><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container">
39
<emu-clause id="sec-a">
410
<h1><span class="secnum">1</span> A</h1>
511
<emu-clause id="sec-a">

test/baselines/generated-reference/duplicate-productions.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"></head><body><div id="spec-container">
2+
<head><meta charset="utf-8"></head><body><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container">
39
<emu-production name="Prod"><emu-nt><a href="#prod-Prod">Prod</a></emu-nt> <emu-geq>:</emu-geq> </emu-production>
410
<emu-grammar><emu-production name="GMD" type="lexical">
511
<emu-nt><a href="#prod-GMD">GMD</a></emu-nt> <emu-geq>::</emu-geq> <emu-rhs a="opbw7lol">

test/baselines/generated-reference/effect-user-code.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"></head><body><div id="spec-container">
2+
<head><meta charset="utf-8"></head><body><div id="shortcuts-help">
3+
<ul>
4+
<li><span>Toggle shortcuts help</span><code>?</code></li>
5+
<li><span>Toggle "can call user code" annotations</span><code>u</code></li>
6+
7+
<li><span>Jump to search box</span><code>/</code></li>
8+
</ul></div><div id="spec-container">
39

410
<emu-clause id="sec-user-code" type="abstract operation" aoid="UserCode">
511
<h1><span class="secnum">1</span> UserCode ( )</h1>

0 commit comments

Comments
 (0)