Skip to content

Commit ed9f952

Browse files
committed
Reorganize a lil
1 parent 8c140fb commit ed9f952

1 file changed

Lines changed: 23 additions & 21 deletions

File tree

src/resources/projects/website/search/quarto-search.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
177177
title: isExpanded
178178
? language["search-hide-matches-text"]
179179
: remainingCount === 1
180-
? `${remainingCount} ${language["search-more-match-text"]}`
181-
: `${remainingCount} ${language["search-more-matches-text"]}`,
180+
? `${remainingCount} ${language["search-more-match-text"]}`
181+
: `${remainingCount} ${language["search-more-matches-text"]}`,
182182
type: kItemTypeMore,
183183
href: kItemTypeMoreHref,
184184
});
@@ -296,9 +296,8 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
296296
return createElement(
297297
"div",
298298
{
299-
class: `quarto-search-no-results${
300-
hasQuery ? "" : " no-query"
301-
}`,
299+
class: `quarto-search-no-results${hasQuery ? "" : " no-query"
300+
}`,
302301
},
303302
language["search-no-results-text"]
304303
);
@@ -1113,8 +1112,26 @@ function getLeafNodes(root) {
11131112
traverse(root);
11141113
return leaves;
11151114
}
1115+
/** create and return `<mark>${txt}</mark>` */
1116+
const markEl = txt => {
1117+
const el = document.createElement("mark");
1118+
el.appendChild(document.createTextNode(txt));
1119+
return el
1120+
}
1121+
/** get all ancestors of an element matching the given css selector */
1122+
const matchAncestors = (el, selector) => {
1123+
let ancestors = [];
1124+
while (el) {
1125+
if (el.matches?.(selector)) ancestors.push(el);
1126+
el = el.parentNode;
1127+
}
1128+
return ancestors;
1129+
};
11161130

11171131
const isWhitespace = s => s.trim().length === 0
1132+
// =================
1133+
// MATCHING CODE
1134+
// =================
11181135
const initMatch = () => ({
11191136
i: 0,
11201137
lohisByNode: new Map()
@@ -1185,12 +1202,6 @@ function searchMatches(inSearch, el) {
11851202
return matches
11861203
}
11871204

1188-
/** create and return `<mark>${txt}</mark>` */
1189-
const markEl = txt => {
1190-
const el = document.createElement("mark");
1191-
el.appendChild(document.createTextNode(txt));
1192-
return el
1193-
}
11941205
/**
11951206
* e.g. `markMatches(myTextNode, [[0,5],[12,15]])` would wrap the
11961207
* character sequences in myTextNode from 0-5 and 12-15 in marks.
@@ -1220,16 +1231,7 @@ function markMatches(node, lohis) {
12201231
return parent
12211232
}
12221233

1223-
/** get all ancestors of an element matching the given css selector */
1224-
const matchAncestors = (el, selector) => {
1225-
let ancestors = [];
1226-
while (el) {
1227-
if (el.matches?.(selector)) ancestors.push(el);
1228-
el = el.parentNode;
1229-
}
1230-
return ancestors;
1231-
};
1232-
const openAllTabsetsContainingEl = el => {
1234+
function openAllTabsetsContainingEl(el) {
12331235
for (const tab of matchAncestors(el, '.tab-pane')) {
12341236
const tabButton = document.querySelector(`[data-bs-target="#${tab.id}"]`);
12351237
if (tabButton) new bootstrap.Tab(tabButton).show();

0 commit comments

Comments
 (0)