Skip to content

Commit f70c065

Browse files
committed
run prettier-format
1 parent 4efbdb7 commit f70c065

1 file changed

Lines changed: 21 additions & 26 deletions

File tree

htdocs/js/SampleProblemViewer/search.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
about every page to be searched (macro POD and sample problems).
44
*/
55
(() => {
6-
76
// ChatGPT generated throttle function similar to Lodash.
87
function throttle(func, wait) {
98
let lastCallTime = 0;
@@ -18,23 +17,23 @@
1817
lastContext = this;
1918

2019
if (remaining <= 0 || remaining > wait) {
21-
if (timeout) {
22-
clearTimeout(timeout);
23-
timeout = null;
24-
}
25-
lastCallTime = now;
26-
func.apply(lastContext, lastArgs);
27-
} else if (!timeout) {
28-
timeout = setTimeout(() => {
29-
lastCallTime = Date.now();
30-
timeout = null;
20+
if (timeout) {
21+
clearTimeout(timeout);
22+
timeout = null;
23+
}
24+
lastCallTime = now;
3125
func.apply(lastContext, lastArgs);
32-
}, remaining);
26+
} else if (!timeout) {
27+
timeout = setTimeout(() => {
28+
lastCallTime = Date.now();
29+
timeout = null;
30+
func.apply(lastContext, lastArgs);
31+
}, remaining);
3332
}
3433
};
3534
}
3635

37-
const miniSearch = new MiniSearch({fields: ['terms', 'filename', 'name', 'description']});
36+
const miniSearch = new MiniSearch({ fields: ['terms', 'filename', 'name', 'description'] });
3837
let pages;
3938
// This is the data from sample-problems/macros POD.
4039
fetch('../../DATA/search.json')
@@ -45,24 +44,23 @@
4544
})
4645
.catch((e) => console.error(e));
4746

48-
const resultList = document.getElementById("searchResults");
49-
const searchBox = document.getElementById("searchDocs");
50-
document.getElementById("clearSearchButton").addEventListener('click', () => {
47+
const resultList = document.getElementById('searchResults');
48+
const searchBox = document.getElementById('searchDocs');
49+
document.getElementById('clearSearchButton').addEventListener('click', () => {
5150
searchBox.value = '';
5251
resultList.innerHTML = '';
5352
});
5453

55-
5654
const search = throttle(() => {
5755
const results = miniSearch.search(searchBox.value);
5856
const ids = results.map((p) => p.id);
5957

6058
resultList.innerHTML = '';
61-
ids.forEach(id => {
62-
const item = document.createElement("div");
63-
item.classList.add("card");
64-
const p = pages[id-1];
65-
const file = p.filename.replace('.pg','');
59+
ids.forEach((id) => {
60+
const item = document.createElement('div');
61+
item.classList.add('card');
62+
const p = pages[id - 1];
63+
const file = p.filename.replace('.pg', '');
6664
const path = p.type == 'sample problem' ? 'sampleproblems' : p.type == 'macro' ? 'pod' : '';
6765

6866
// This is the search results for each page.
@@ -75,12 +73,9 @@
7573
</div>
7674
`;
7775

78-
resultList.appendChild(item)
76+
resultList.appendChild(item);
7977
});
80-
8178
}, 250);
8279

8380
searchBox.addEventListener('keypress', search);
84-
85-
8681
})();

0 commit comments

Comments
 (0)