|
135 | 135 | };
|
136 | 136 |
|
137 | 137 | Search.prototype.documentKeydown = function (e) {
|
138 |
| - if (e.keyCode === 191) { |
| 138 | + if (e.key === '/') { |
139 | 139 | e.preventDefault();
|
140 | 140 | e.stopPropagation();
|
141 | 141 | this.triggerSearch();
|
|
190 | 190 | relevance += 2048;
|
191 | 191 | }
|
192 | 192 |
|
193 |
| - relevance += Math.max(0, 255 - result.entry.key.length); |
| 193 | + relevance += Math.max(0, 255 - result.key.length); |
194 | 194 |
|
195 | 195 | return relevance;
|
196 | 196 | }
|
|
214 | 214 | if (/^[\d.]*$/.test(searchString)) {
|
215 | 215 | results = this.biblio.clauses
|
216 | 216 | .filter(clause => clause.number.substring(0, searchString.length) === searchString)
|
217 |
| - .map(clause => ({ entry: clause })); |
| 217 | + .map(clause => ({ key: getKey(clause), entry: clause })); |
218 | 218 | } else {
|
219 | 219 | results = [];
|
220 | 220 |
|
221 | 221 | for (let i = 0; i < this.biblio.entries.length; i++) {
|
222 | 222 | let entry = this.biblio.entries[i];
|
223 |
| - if (!entry.key) { |
| 223 | + let key = getKey(entry); |
| 224 | + if (!key) { |
224 | 225 | // biblio entries without a key aren't searchable
|
225 | 226 | continue;
|
226 | 227 | }
|
227 | 228 |
|
228 |
| - let match = fuzzysearch(searchString, entry.key); |
| 229 | + let match = fuzzysearch(searchString, key); |
229 | 230 | if (match) {
|
230 |
| - results.push({ entry, match }); |
| 231 | + results.push({ key, entry, match }); |
231 | 232 | }
|
232 | 233 | }
|
233 | 234 |
|
|
276 | 277 | let html = '<ul>';
|
277 | 278 |
|
278 | 279 | results.forEach(result => {
|
| 280 | + let key = result.key; |
279 | 281 | let entry = result.entry;
|
280 | 282 | let id = entry.id;
|
281 | 283 | let cssClass = '';
|
282 | 284 | let text = '';
|
283 | 285 |
|
284 | 286 | if (entry.type === 'clause') {
|
285 | 287 | let number = entry.number ? entry.number + ' ' : '';
|
286 |
| - text = number + entry.key; |
| 288 | + text = number + key; |
287 | 289 | cssClass = 'clause';
|
288 | 290 | id = entry.id;
|
289 | 291 | } else if (entry.type === 'production') {
|
290 |
| - text = entry.key; |
| 292 | + text = key; |
291 | 293 | cssClass = 'prod';
|
292 | 294 | id = entry.id;
|
293 | 295 | } else if (entry.type === 'op') {
|
294 |
| - text = entry.key; |
| 296 | + text = key; |
295 | 297 | cssClass = 'op';
|
296 | 298 | id = entry.id || entry.refId;
|
297 | 299 | } else if (entry.type === 'term') {
|
298 |
| - text = entry.key; |
| 300 | + text = key; |
299 | 301 | cssClass = 'term';
|
300 | 302 | id = entry.id || entry.refId;
|
301 | 303 | }
|
|
315 | 317 | }
|
316 | 318 | };
|
317 | 319 |
|
| 320 | +function getKey(item) { |
| 321 | + if (item.key) { |
| 322 | + return item.key; |
| 323 | + } |
| 324 | + switch (item.type) { |
| 325 | + case 'clause': |
| 326 | + return item.title || item.titleHTML; |
| 327 | + case 'production': |
| 328 | + return item.name; |
| 329 | + case 'op': |
| 330 | + return item.aoid; |
| 331 | + case 'term': |
| 332 | + return item.term; |
| 333 | + case 'table': |
| 334 | + case 'figure': |
| 335 | + case 'example': |
| 336 | + case 'note': |
| 337 | + return item.caption; |
| 338 | + case 'step': |
| 339 | + return item.id; |
| 340 | + default: |
| 341 | + throw new Error("Can't get key for " + item.type); |
| 342 | + } |
| 343 | +} |
| 344 | +
|
318 | 345 | function Menu() {
|
319 | 346 | this.$toggle = document.getElementById('menu-toggle');
|
320 | 347 | this.$menu = document.getElementById('menu');
|
|
507 | 534 | // prettier-ignore
|
508 | 535 | this.$pinList.innerHTML += `<li><a href="${makeLinkToId(entry.id)}">${prefix}${entry.titleHTML}</a></li>`;
|
509 | 536 | } else {
|
510 |
| - this.$pinList.innerHTML += `<li><a href="${makeLinkToId(entry.id)}">${entry.key}</a></li>`; |
| 537 | + this.$pinList.innerHTML += `<li><a href="${makeLinkToId(entry.id)}">${getKey(entry)}</a></li>`; |
511 | 538 | }
|
512 | 539 |
|
513 | 540 | if (Object.keys(this._pinnedIds).length === 0) {
|
|
782 | 809 | this.$headerRefId.textContent = '#' + entry.id;
|
783 | 810 | this.$headerRefId.setAttribute('href', makeLinkToId(entry.id));
|
784 | 811 | this.$headerRefId.style.display = 'inline';
|
785 |
| - entry.referencingIds |
| 812 | + (entry.referencingIds || []) |
786 | 813 | .map(id => {
|
787 | 814 | let cid = menu.search.biblio.refParentClause[id];
|
788 | 815 | let clause = menu.search.biblio.byId[cid];
|
|
913 | 940 | },
|
914 | 941 |
|
915 | 942 | updateReferences() {
|
916 |
| - this.$refsLink.textContent = `References (${this.entry.referencingIds.length})`; |
| 943 | + this.$refsLink.textContent = `References (${(this.entry.referencingIds || []).length})`; |
917 | 944 | },
|
918 | 945 |
|
919 | 946 | activateIfMouseOver(e) {
|
|
1034 | 1061 | if (name === 'textarea' || name === 'input' || name === 'select' || target.isContentEditable) {
|
1035 | 1062 | return;
|
1036 | 1063 | }
|
1037 |
| - if (e.key === 'm' && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey && usesMultipage) { |
| 1064 | + if (e.altKey || e.ctrlKey || e.metaKey) { |
| 1065 | + return; |
| 1066 | + } |
| 1067 | + if (e.key === 'm' && usesMultipage) { |
1038 | 1068 | let pathParts = location.pathname.split('/');
|
1039 | 1069 | let hash = location.hash;
|
1040 | 1070 | if (pathParts[pathParts.length - 2] === 'multipage') {
|
|
1051 | 1081 | } else {
|
1052 | 1082 | location = 'multipage/' + hash;
|
1053 | 1083 | }
|
| 1084 | + } else if (e.key === 'u') { |
| 1085 | + document.documentElement.classList.toggle('show-ao-annotations'); |
| 1086 | + } else if (e.key === '?') { |
| 1087 | + document.getElementById('shortcuts-help').classList.toggle('active'); |
1054 | 1088 | }
|
1055 | 1089 | }
|
1056 | 1090 |
|
|
1066 | 1100 | document.addEventListener(
|
1067 | 1101 | 'keydown',
|
1068 | 1102 | debounce(e => {
|
1069 |
| - if (e.code === 'Escape' && Toolbox.active) { |
1070 |
| - Toolbox.deactivate(); |
| 1103 | + if (e.code === 'Escape') { |
| 1104 | + if (Toolbox.active) { |
| 1105 | + Toolbox.deactivate(); |
| 1106 | + } |
| 1107 | + document.getElementById('shortcuts-help').classList.remove('active'); |
1071 | 1108 | }
|
1072 | 1109 | })
|
1073 | 1110 | );
|
|
1112 | 1149 | });
|
1113 | 1150 |
|
1114 | 1151 | let sdoMap = JSON.parse(`{}`);
|
1115 |
| -let biblio = JSON.parse(`{"refsByClause":{"sec-demo-clause":["_ref_0"]},"entries":[{"type":"clause","id":"sec-demo-clause","aoid":null,"titleHTML":"This is an emu-clause","number":"1","referencingIds":[],"key":"This is an emu-clause"},{"type":"clause","id":"sec-copyright-and-software-license","aoid":null,"titleHTML":"Copyright & Software License","number":"A","referencingIds":[],"key":"Copyright & Software License"}]}`); |
| 1152 | +let biblio = JSON.parse(`{"refsByClause":{},"entries":[{"type":"clause","id":"sec-demo-clause","titleHTML":"This is an emu-clause","number":"1"},{"type":"clause","id":"sec-copyright-and-software-license","title":"Copyright & Software License","titleHTML":"Copyright & Software License","number":"A"}]}`); |
1116 | 1153 | ;let usesMultipage = false</script><style>body {
|
1117 | 1154 | display: flex;
|
1118 | 1155 | font-size: 18px;
|
|
1150 | 1187 | color: #239dee;
|
1151 | 1188 | }
|
1152 | 1189 |
|
| 1190 | +a.e-user-code, |
| 1191 | +span.e-user-code { |
| 1192 | + white-space: nowrap; |
| 1193 | +} |
| 1194 | +
|
| 1195 | +a.e-user-code::before, |
| 1196 | +span.e-user-code::before { |
| 1197 | + display: none; |
| 1198 | + color: brown; |
| 1199 | + background-color: white; |
| 1200 | + border: 2pt solid brown; |
| 1201 | + padding: 0.3ex; |
| 1202 | + margin: 0 0.25em 0 0; |
| 1203 | + line-height: 1; |
| 1204 | + vertical-align: text-top; |
| 1205 | + text-transform: uppercase; |
| 1206 | + font-family: 'Comic Code', sans-serif; |
| 1207 | + font-weight: 900; |
| 1208 | + font-size: x-small; |
| 1209 | +} |
| 1210 | +
|
| 1211 | +a.e-user-code:hover::before, |
| 1212 | +span.e-user-code:hover::before { |
| 1213 | + background-color: brown; |
| 1214 | + color: white; |
| 1215 | +} |
| 1216 | +
|
| 1217 | +html.show-ao-annotations a.e-user-code::before, |
| 1218 | +html.show-ao-annotations span.e-user-code::before { |
| 1219 | + display: inline-block; |
| 1220 | +} |
| 1221 | +
|
| 1222 | +a.e-user-code::before, |
| 1223 | +span.e-user-code::before { |
| 1224 | + content: 'UC'; |
| 1225 | +} |
| 1226 | +
|
1153 | 1227 | code {
|
1154 | 1228 | font-weight: bold;
|
1155 | 1229 | font-family: Consolas, Monaco, monospace;
|
|
2290 | 2364 | .clause-attributes-tag a {
|
2291 | 2365 | color: #884400;
|
2292 | 2366 | }
|
2293 |
| -</style></head><body><div id="menu-toggle">☰</div><div id="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins</div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-demo-clause" title="This is an emu-clause"><span class="secnum">1</span> This is an emu-clause</a></li><li><span class="item-toggle-none"></span><a href="#sec-copyright-and-software-license" title="Copyright & Software License"><span class="secnum">A</span> Copyright & Software License</a></li></ol></div></div><div id="spec-container"><h1 class="version">Stage -1 Draft / April 8, 2022</h1><h1 class="title">Proposal Title Goes Here</h1> |
| 2367 | +
|
| 2368 | +/* Shortcuts help dialog */ |
| 2369 | +
|
| 2370 | +#shortcuts-help { |
| 2371 | + position: fixed; |
| 2372 | + left: 5%; |
| 2373 | + margin: 0 auto; |
| 2374 | + right: 5%; |
| 2375 | + z-index: 10; |
| 2376 | + top: 10%; |
| 2377 | + top: calc(5vw + 5vh); |
| 2378 | + padding: 30px 90px; |
| 2379 | + max-width: 500px; |
| 2380 | + outline: solid 10000px rgba(255, 255, 255, 0.6); |
| 2381 | + border-radius: 5px; |
| 2382 | + border-width: 1px 1px 0 1px; |
| 2383 | + background-color: #ddd; |
| 2384 | + display: none; |
| 2385 | +} |
| 2386 | +
|
| 2387 | +#shortcuts-help.active { |
| 2388 | + display: block; |
| 2389 | +} |
| 2390 | +
|
| 2391 | +#shortcuts-help ul { |
| 2392 | + padding: 0; |
| 2393 | +} |
| 2394 | +
|
| 2395 | +#shortcuts-help li { |
| 2396 | + display: flex; |
| 2397 | + justify-content: space-between; |
| 2398 | +} |
| 2399 | +
|
| 2400 | +#shortcuts-help code { |
| 2401 | + padding: 3px 10px; |
| 2402 | + border-radius: 3px; |
| 2403 | + border-width: 1px 1px 0 1px; |
| 2404 | + border-color: #bbb; |
| 2405 | + background-color: #eee; |
| 2406 | + box-shadow: inset 0 -1px 0 #ccc; |
| 2407 | +} |
| 2408 | +</style></head><body><div id="shortcuts-help"> |
| 2409 | +<ul> |
| 2410 | + <li><span>Toggle shortcuts help</span><code>?</code></li> |
| 2411 | + <li><span>Toggle "can call user code" annotations</span><code>u</code></li> |
| 2412 | + |
| 2413 | + <li><span>Jump to search box</span><code>/</code></li> |
| 2414 | +</ul></div><div id="menu-toggle"><svg xmlns="http://www.w3.org/2000/svg" style="width:100%; height:100%; stroke:currentColor" viewBox="0 0 120 120"> |
| 2415 | + <title>Menu</title> |
| 2416 | + <path stroke-width="10" stroke-linecap="round" d="M30,60 h60 M30,30 m0,5 h60 M30,90 m0,-5 h60"></path> |
| 2417 | + </svg></div><div id="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins</div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-demo-clause" title="This is an emu-clause"><span class="secnum">1</span> This is an emu-clause</a></li><li><span class="item-toggle-none"></span><a href="#sec-copyright-and-software-license" title="Copyright & Software License"><span class="secnum">A</span> Copyright & Software License</a></li></ol></div></div><div id="spec-container"><h1 class="version">Stage -1 Draft / April 8, 2022</h1><h1 class="title">Proposal Title Goes Here</h1> |
2294 | 2418 |
|
2295 | 2419 | <emu-clause id="sec-demo-clause">
|
2296 | 2420 | <h1><span class="secnum">1</span> This is an emu-clause</h1>
|
2297 | 2421 | <p>This is an algorithm:</p>
|
2298 |
| - <emu-alg><ol><li>Let <var>proposal</var> be <emu-val>undefined</emu-val>.</li><li>If IsAccepted(<var>proposal</var>), then<ol><li>Let <var>stage</var> be <emu-val>0</emu-val><sub>ℤ</sub>.</li></ol></li><li>Else,<ol><li>Let <var>stage</var> be <emu-val>-1</emu-val><sub>ℤ</sub>.</li></ol></li><li>Return ? <emu-xref aoid="ToString" id="_ref_0"><a href="https://tc39.es/ecma262/#sec-tostring">ToString</a></emu-xref>(<var>proposal</var>).</li></ol></emu-alg> |
| 2422 | + <emu-alg><ol><li>Let <var>proposal</var> be <emu-val>undefined</emu-val>.</li><li>If IsAccepted(<var>proposal</var>), then<ol><li>Let <var>stage</var> be <emu-val>0</emu-val><sub>ℤ</sub>.</li></ol></li><li>Else,<ol><li>Let <var>stage</var> be <emu-val>-1</emu-val><sub>ℤ</sub>.</li></ol></li><li>Return ? <emu-xref aoid="ToString"><a href="https://tc39.es/ecma262/#sec-tostring">ToString</a></emu-xref>(<var>proposal</var>).</li></ol></emu-alg> |
2299 | 2423 | </emu-clause><emu-annex id="sec-copyright-and-software-license">
|
2300 | 2424 | <h1><span class="secnum">A</span> Copyright & Software License</h1>
|
2301 | 2425 |
|
|
0 commit comments