on master help sign in
glossary before stdlib
8cb1066Matilde Park
static/scripts.js+91−89
@@ -4,42 +4,42 @@ function initHotKeys() {
4 var searchInput = document.getElementById('search');
4 var searchInput = document.getElementById('search');
5
5
6 document.addEventListener('keydown', function (event) {
6 document.addEventListener('keydown', function (event) {
7− if (event.defaultPrevented) {
7+ if (event.defaultPrevented) {
8− return;
8+ return;
9− }
9+ }
10
10
11− var key = event.key || event.keyCode;
11+ var key = event.key || event.keyCode;
12
12
13− // ESC to close search window
13+ // ESC to close search window
14− if (key === 'Escape' || key === 'Esc' || key === 27) {
14+ if (key === 'Escape' || key === 'Esc' || key === 27) {
15− document.body.classList.remove('has-active-search-window');
15+ document.body.classList.remove('has-active-search-window');
16− }
16+ }
17
17
18− // / to open toggle window
18+ // / to open toggle window
19− if (key === '/' || key === 'Period' || key === 58) {
19+ if (key === '/' || key === 'Period' || key === 58) {
20− if (bodyEl.classList.contains('has-active-search-window')) {
20+ if (bodyEl.classList.contains('has-active-search-window')) {
21− // if it's already open don't do anything!
21+ // if it's already open don't do anything!
22− } else {
22+ } else {
23− event.preventDefault();
23+ event.preventDefault();
24− document.body.classList.add('has-active-search-window');
24+ document.body.classList.add('has-active-search-window');
25− searchInput.focus();
25+ searchInput.focus();
26− }
27 }
26 }
27+ }
28
28
29− //when search is active TAB puts search input into focus
29+ //when search is active TAB puts search input into focus
30− if (bodyEl.classList.contains('has-active-search-window')) {
30+ if (bodyEl.classList.contains('has-active-search-window')) {
31− if (key === 'Tab' || key === 'Tab' || key === 9) {
31+ if (key === 'Tab' || key === 'Tab' || key === 9) {
32− searchInput.focus();
32+ searchInput.focus();
33− }
34 }
33 }
34+ }
35
35
36− if (bodyEl.classList.contains('has-active-search-window')) {
36+ if (bodyEl.classList.contains('has-active-search-window')) {
37− if (key === 'Enter' || key === 'Return' || key === 13) {
37+ if (key === 'Enter' || key === 'Return' || key === 13) {
38− event.preventDefault();
38+ event.preventDefault();
39− let firstresult = document.querySelectorAll("div#full-results a")[0];
39+ let firstresult = document.querySelectorAll("div#full-results a")[0];
40− firstresult.click();
40+ firstresult.click();
41− }
42 }
41 }
42+ }
43 });
43 });
44};
44};
45
45
@@ -173,7 +173,7 @@ function makeTeaser(body, terms) {
173}
173}
174
174
175function formatSearchResultTitle(item) {
175function formatSearchResultTitle(item) {
176− var pathArray = item.ref.split( '/' );
176+ var pathArray = item.ref.split('/');
177
177
178 var firstPartTitle = pathArray[3];
178 var firstPartTitle = pathArray[3];
179 let firstTitleCapitals = firstPartTitle.charAt(0).toUpperCase() + firstPartTitle.slice(1);
179 let firstTitleCapitals = firstPartTitle.charAt(0).toUpperCase() + firstPartTitle.slice(1);
@@ -182,7 +182,7 @@ function formatSearchResultTitle(item) {
182
182
183 var fullTitle = firstTitleCapitals + '<span class="gray1 dib pl2">' + ' / ' + lastPartTitle + '</span>';
183 var fullTitle = firstTitleCapitals + '<span class="gray1 dib pl2">' + ' / ' + lastPartTitle + '</span>';
184
184
185− return fullTitle;
185+ return fullTitle;
186}
186}
187
187
188function formatSearchResultItem(item, terms) {
188function formatSearchResultItem(item, terms) {
@@ -193,7 +193,7 @@ function formatSearchResultItem(item, terms) {
193 li.classList.add("search-results__item");
193 li.classList.add("search-results__item");
194 var hrefA = item.ref;
194 var hrefA = item.ref;
195 createA.setAttribute('href', hrefA);
195 createA.setAttribute('href', hrefA);
196− createA.setAttribute('class','no-underline db pl1 pv2');
196+ createA.setAttribute('class', 'no-underline db pl1 pv2');
197 createA.innerHTML = `<span class="capitalize ph3">${teaserTitle}</span>`;
197 createA.innerHTML = `<span class="capitalize ph3">${teaserTitle}</span>`;
198 createA.innerHTML += `<span class='dn arrow fr'>↩</span>`;
198 createA.innerHTML += `<span class='dn arrow fr'>↩</span>`;
199 createA.innerHTML += `<div class="truncate pr2 ph3">${makeTeaser(item.doc.body, terms)}</div>`;
199 createA.innerHTML += `<div class="truncate pr2 ph3">${makeTeaser(item.doc.body, terms)}</div>`;
@@ -219,8 +219,8 @@ function initSearch() {
219 bool: "AND",
219 bool: "AND",
220 expand: true, // turn on partial word search
220 expand: true, // turn on partial word search
221 fields: {
221 fields: {
222− title: {boost: 2},
222+ title: { boost: 2 },
223− body: {boost: 1},
223+ body: { boost: 1 },
224 }
224 }
225 };
225 };
226 var currentTerm = "";
226 var currentTerm = "";
@@ -233,8 +233,8 @@ function initSearch() {
233 var searchActive = bodyEl.classList.contains('has-active-search-window');
233 var searchActive = bodyEl.classList.contains('has-active-search-window');
234
234
235 if (toggleSearchWindow !== null) {
235 if (toggleSearchWindow !== null) {
236− toggleSearchWindow.onclick = function() {
236+ toggleSearchWindow.onclick = function () {
237− inputReset.style.display="none";
237+ inputReset.style.display = "none";
238
238
239 //activate search
239 //activate search
240 bodyEl.classList.toggle('has-active-search-window');
240 bodyEl.classList.toggle('has-active-search-window');
@@ -245,16 +245,16 @@ function initSearch() {
245 searchResultsHeader.value = "";
245 searchResultsHeader.value = "";
246 searchResults.style.display = searchInput.value.trim() === "" ? "none" : "block";
246 searchResults.style.display = searchInput.value.trim() === "" ? "none" : "block";
247 }
247 }
248− searchOverlay.addEventListener('click', function(e){
248+ searchOverlay.addEventListener('click', function (e) {
249− if (!searchWindow.contains(e.target)){
249+ if (!searchWindow.contains(e.target)) {
250 bodyEl.classList.toggle('has-active-search-window');
250 bodyEl.classList.toggle('has-active-search-window');
251 }
251 }
252 })
252 })
253 }
253 }
254
254
255− searchInput.addEventListener("keyup", debounce(function() {
255+ searchInput.addEventListener("keyup", debounce(function () {
256− inputReset.style.display="block";
256+ inputReset.style.display = "block";
257− glossaryResults.style.display="none";
257+ glossaryResults.style.display = "none";
258 searchResultsHeader.value = "";
258 searchResultsHeader.value = "";
259 var term = searchInput.value.trim();
259 var term = searchInput.value.trim();
260 /*
260 /*
@@ -268,24 +268,25 @@ function initSearch() {
268 searchResults.style.overflowY = term === "" ? "hidden" : "scroll";
268 searchResults.style.overflowY = term === "" ? "hidden" : "scroll";
269 searchResultsItems.innerHTML = "";
269 searchResultsItems.innerHTML = "";
270 if (term === "") {
270 if (term === "") {
271− inputReset.style.display="none";
271+ inputReset.style.display = "none";
272 return;
272 return;
273 }
273 }
274
274
275 for (let entry of glossary) {
275 for (let entry of glossary) {
276− if (entry.symbol === term) {
276+ if (entry.name === term.toLowerCase()) {
277− glossaryResults.style.display="block";
277+ glossaryResults.style.display = "block";
278 glossaryResultsItem.innerHTML = `
278 glossaryResultsItem.innerHTML = `
279− <a href="${entry.link}"><h3 class="black"><code class="pa0 red3 mr2">${entry.symbol}</code>${entry.name}</h3>
279+ <a href="${entry.link}"><h3 class="black">${entry.name}</h3>
280 <p class="black">${entry.desc}</p>
280 <p class="black">${entry.desc}</p>
281− <span class="db tr black fw5 mb3" style="font-family: 'Inter UI', sans-serif;">Read more in Documentation -></span></a>
281+ <span class="db tr black fw5 mb3" style="font-family: 'Inter UI', sans-serif;">Read more in Glossary -></span></a>
282 `
282 `
283+ break;
283− } else if (entry.name === term.toLowerCase()) {
284+ } else if (entry.symbol === term) {
284− glossaryResults.style.display="block";
285+ glossaryResults.style.display = "block";
285 glossaryResultsItem.innerHTML = `
286 glossaryResultsItem.innerHTML = `
286− <a href="${entry.link}"><h3 class="black">${entry.name}</h3>
287+ <a href="${entry.link}"><h3 class="black"><code class="pa0 red3 mr1">${entry.symbol}</code>${entry.name}</h3>
287 <p class="black">${entry.desc}</p>
288 <p class="black">${entry.desc}</p>
288− <span class="db tr black fw5 mb3" style="font-family: 'Inter UI', sans-serif;">Read more in Glossary -></span></a>
289+ <span class="db tr black fw5 mb3" style="font-family: 'Inter UI', sans-serif;">Read more in Documentation -></span></a>
289 `
290 `
290 }
291 }
291 }
292 }
@@ -310,10 +311,10 @@ function initSearch() {
310 }, 150));
311 }, 150));
311
312
312 // reset input button
313 // reset input button
313− inputReset.onclick=function(){
314+ inputReset.onclick = function () {
314 document.getElementById('search-form').reset();
315 document.getElementById('search-form').reset();
315 }
316 }
316− searchForm.addEventListener("reset", function(event){
317+ searchForm.addEventListener("reset", function (event) {
317 var e = document.createEvent('KeyboardEvent');
318 var e = document.createEvent('KeyboardEvent');
318 e.initEvent("keyup", false, true);
319 e.initEvent("keyup", false, true);
319 searchInput.dispatchEvent(e);
320 searchInput.dispatchEvent(e);
@@ -322,7 +323,7 @@ function initSearch() {
322}
323}
323
324
324if (document.readyState === "complete" ||
325if (document.readyState === "complete" ||
325− (document.readyState !== "loading" && !document.documentElement.doScroll)
326+ (document.readyState !== "loading" && !document.documentElement.doScroll)
326) {
327) {
327 initToggleSearchWindow();
328 initToggleSearchWindow();
328} else {
329} else {
@@ -333,11 +334,11 @@ if (document.readyState === "complete" ||
333}
334}
334
335
335// Scroll to current document in nav list.
336// Scroll to current document in nav list.
336−let docsNavScroll = function() {
337+let docsNavScroll = function () {
337− let docsDetails = document.querySelectorAll("nav ul details")
338+ let docsDetails = document.querySelectorAll("nav ul details")
338 for (let details in docsDetails) {
339 for (let details in docsDetails) {
339 if (docsDetails[details].open) docsDetails[details].scrollIntoView()
340 if (docsDetails[details].open) docsDetails[details].scrollIntoView()
340− }
341+ }
341}
342}
342
343
343if (window.location.href.includes("docs")) {
344if (window.location.href.includes("docs")) {
@@ -355,7 +356,7 @@ if (window.location.href.includes("docs")) {
355 // on mobile, dropdown selections go to the option
356 // on mobile, dropdown selections go to the option
356
357
357 let docsSelect = document.getElementById('docsSelect');
358 let docsSelect = document.getElementById('docsSelect');
358− let goTo = function() {
359+ let goTo = function () {
359 let url = docsSelect.options[docsSelect.selectedIndex].value;
360 let url = docsSelect.options[docsSelect.selectedIndex].value;
360 if (url.startsWith("http")) {
361 if (url.startsWith("http")) {
361 document.location.assign(url);
362 document.location.assign(url);
@@ -370,44 +371,45 @@ if (window.location.href.includes("docs")) {
370// same-page navigation on-scroll behaviour
371// same-page navigation on-scroll behaviour
371
372
372if (document.body.classList.contains("page-indiced")) {
373if (document.body.classList.contains("page-indiced")) {
373−let h2 = document.getElementsByTagName("h2");
374+ let h2 = document.getElementsByTagName("h2");
374−let h3 = document.getElementsByTagName("h3");
375+ let h3 = document.getElementsByTagName("h3");
375−let all = document.querySelectorAll("nav li a");
376+ let all = document.querySelectorAll("nav li a");
376−let headers = document.querySelectorAll("details summary");
377+ let headers = document.querySelectorAll("details summary");
377−
378+
378−// smooth scrolling on click
379+ // smooth scrolling on click
379−all.forEach(link => {
380+ all.forEach(link => {
380− link.addEventListener("click", event => {
381+ link.addEventListener("click", event => {
381− event.preventDefault();
382+ event.preventDefault();
382− let target = document.querySelector(event.target.hash);
383+ let target = document.querySelector(event.target.hash);
383− target.scrollIntoView({
384+ target.scrollIntoView({
384− behavior: "smooth",
385+ behavior: "smooth",
385− block: "start"
386+ block: "start"
387+ });
386 });
388 });
387 });
389 });
388−});
389
390
390−let lastId;
391+ let lastId;
391−let cur = [];
392+ let cur = [];
392
393
393−window.addEventListener("scroll", event => {
394+ window.addEventListener("scroll", event => {
394− let fromTop = window.scrollY;
395+ let fromTop = window.scrollY;
395
396
396− all.forEach(link => {
397+ all.forEach(link => {
397− let section = document.querySelector(link.hash);
398+ let section = document.querySelector(link.hash);
398− let sectionChildren = document.querySelector(link.hash).nextElementSibling;
399+ let sectionChildren = document.querySelector(link.hash).nextElementSibling;
399−
400+
400− if (
401+ if (
401− ((section.offsetTop <= fromTop) ||
402+ ((section.offsetTop <= fromTop) ||
402− (sectionChildren.offsetTop <= fromTop)) &&
403+ (sectionChildren.offsetTop <= fromTop)) &&
403− (section.offsetTop + section.offsetHeight + sectionChildren.offsetHeight > fromTop)
404+ (section.offsetTop + section.offsetHeight + sectionChildren.offsetHeight > fromTop)
404− ) {
405+ ) {
405− link.classList.add("current");
406+ link.classList.add("current");
406− } else {
407+ } else {
407− link.classList.remove("current");
408+ link.classList.remove("current");
408− }
409+ }
409− });
410+ });
410−})};
411+ })
412+};
411
413
412let oceanvid = document.getElementById("ocean");
414let oceanvid = document.getElementById("ocean");
413
415