Skip to content

Commit 5f1cff7

Browse files
authored
Merge branch 'eclipse-esmf:main' into main
2 parents cf0fafb + 655a191 commit 5f1cff7

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
}],
1111
"max-len": [1, 120, 2],
1212
"spaced-comment": "off"
13+
},
14+
"globals": {
15+
"globalThis": "writable"
1316
}
1417
}

src/js/vendor/search.js renamed to src/js/vendor/search-ui.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
/* eslint-env browser */
2-
window.antoraLunr = (function (lunr) {
3-
const scriptAttrs = document.getElementById('search-script').dataset
4-
const basePath = scriptAttrs.basePath
5-
const pagePath = scriptAttrs.pagePath
1+
;(globalThis || window).lunrSiteSearch = (function () {
2+
/* eslint-disable no-var */
3+
const config = document.getElementById('search-script').dataset
4+
const siteRootPath = config.siteRootPath || ''
65
var searchInput = document.getElementById('search-input')
76
var searchResult = document.createElement('div')
87
searchResult.classList.add('search-result-dropdown-menu')
@@ -20,7 +19,7 @@ window.antoraLunr = (function (lunr) {
2019

2120
var end = start + length
2221
var textEnd = text.length - 1
23-
var contextOffset = 15
22+
var contextOffset = 100
2423
var contextAfter = end + contextOffset > textEnd ? textEnd : end + contextOffset
2524
var contextBefore = start - contextOffset < 0 ? 0 : start - contextOffset
2625
if (start === 0 && end === textEnd) {
@@ -93,7 +92,7 @@ window.antoraLunr = (function (lunr) {
9392
return hits
9493
}
9594

96-
function createSearchResult(result, store, searchResultDataset) {
95+
function createSearchResult (result, store, searchResultDataset) {
9796
result.forEach(function (item) {
9897
var url = item.ref
9998
var hash
@@ -115,8 +114,7 @@ window.antoraLunr = (function (lunr) {
115114
var documentHit = document.createElement('div')
116115
documentHit.classList.add('search-result-document-hit')
117116
var documentHitLink = document.createElement('a')
118-
var rootPath = basePath
119-
documentHitLink.href = rootPath + item.ref
117+
documentHitLink.href = siteRootPath + item.ref
120118
documentHit.appendChild(documentHitLink)
121119
hits.forEach(function (hit) {
122120
documentHitLink.appendChild(hit)
@@ -194,13 +192,22 @@ window.antoraLunr = (function (lunr) {
194192
}
195193
}
196194

197-
function init (data) {
198-
var index = Object.assign({index: lunr.Index.load(data.index), store: data.store})
195+
function init (lunr, data) {
196+
var index = Object.assign({ index: lunr.Index.load(data.index), store: data.store })
197+
var debug = 'URLSearchParams' in window && new URLSearchParams(window.location.search).has('lunr-debug')
199198
var search = debounce(function () {
200-
searchIndex(index.index, index.store, searchInput.value)
199+
try {
200+
searchIndex(index.index, index.store, searchInput.value)
201+
} catch (err) {
202+
if (debug) console.debug('Invalid search query: ' + searchInput.value + ' (' + err.message + ')')
203+
}
201204
}, 100)
202205
searchInput.addEventListener('keydown', search)
203206

207+
searchInput.addEventListener('keydown', function (event) {
208+
if (event.key === 'Escape') searchInput.value = ''
209+
})
210+
204211
// this is prevented in case of mousedown attached to SearchResultItem
205212
searchInput.addEventListener('blur', function (e) {
206213
while (searchResult.firstChild) {
@@ -209,7 +216,5 @@ window.antoraLunr = (function (lunr) {
209216
})
210217
}
211218

212-
return {
213-
init: init,
214-
}
215-
})(window.lunr)
219+
return { init: init }
220+
})()

src/partials/footer-scripts.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script src="{{uiRootPath}}/js/site.js"></script>
22
<script src="{{uiRootPath}}/js/vendor/lunr.min.js"></script>
3-
<script src="{{uiRootPath}}/js/vendor/search.js" id="search-script" data-base-path="{{or siteRootPath (or site.url siteRootUrl)}}" data-page-path="{{@root.page.url}}"></script>
4-
<script async src="{{uiRootPath}}/../search-index.js"></script>
3+
<script src="{{uiRootPath}}/js/vendor/search-ui.js" id="search-script" data-site-root-path="{{siteRootPath}}" data-stylesheet="{{uiRootPath}}/css/search.css"></script>
4+
<script async src="{{siteRootPath}}/search-index.js"></script>
55
<script async src="{{uiRootPath}}/js/vendor/highlight.js"></script>

0 commit comments

Comments
 (0)