aboutsummaryrefslogtreecommitdiff
path: root/static/js/elasticlunr_bridge.js
blob: e2ff7ae399d08fe2f641205af8bcd701a4867cf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Include immediately after elasticlunr.min.js in the JS bundle.
//
// elasticlunr's UMD assigns window.elasticlunr. Keep a local binding for search.js
// in this same bundle, and expose window.lunr only long enough for optional
// on-demand language packs (lunr.stemmer.support.min.js, lunr.fr.min.js, …).
// Those scripts mutate the same object; after they run we drop the global name.
var elasticlunr = window.elasticlunr;
try { delete window.elasticlunr; } catch (e) {}
window.lunr = elasticlunr;

// head_js loads language scripts with defer, after this bundle. Deferred scripts
// run in document order before DOMContentLoaded, so stemmer/lang packs attach
// first; then we remove the temporary global. Local `elasticlunr` still has
// stemmerSupport / language plugins for search.
document.addEventListener("DOMContentLoaded", function () {
  try { delete window.lunr; } catch (e) {}
});