1
1
{% extends "!search.html" %}
2
2
{% block extrahead %}
3
3
{{ super() }}
4
+ < meta name ="robots " content ="noindex ">
4
5
< script type ="text/javascript ">
5
- var GLOSSARY_PAGE = 'glossary.html' ;
6
+ const GLOSSARY_PAGE = 'glossary.html' ;
6
7
7
- jQuery ( function ( ) {
8
- $ . getJSON ( "_static/glossary.json" , function ( glossary ) {
9
- var RESULT_TEMPLATE = '<div style="display: none" class="admonition seealso" id="glossary-result">' +
8
+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
9
+ fetch ( '_static/glossary.json' )
10
+ . then ( function ( response ) {
11
+ if ( response . ok ) {
12
+ return response . json ( ) ;
13
+ } else {
14
+ throw new Error ( 'Failed to fetch glossary.json' ) ;
15
+ }
16
+ } )
17
+ . then ( function ( glossary ) {
18
+ const RESULT_TEMPLATE = '<div style="display: none" class="admonition seealso" id="glossary-result">' +
10
19
' <p class="topic-title">' +
11
20
' <a class="glossary-title" href="#"></a>' +
12
21
' </p>' +
13
22
' <div class="glossary-body"></div>' +
14
23
'</div>' ;
15
- $ ( "#search-results" ) . prepend ( RESULT_TEMPLATE ) ;
24
+ let searchResults = document . getElementById ( 'search-results' ) ;
25
+ searchResults . insertAdjacentHTML ( 'afterbegin' , RESULT_TEMPLATE ) ;
16
26
17
- var params = $ . getQueryParameters ( ) ;
18
- if ( params . q ) {
19
- var search_param = params . q [ 0 ] . toLowerCase ( ) ;
20
- var glossary_item = glossary [ search_param ] ;
21
- if ( glossary_item ) {
22
- var resultDiv = $ ( "# glossary-result" ) ;
27
+ const params = new URLSearchParams ( document . location . search ) . get ( "q" ) ;
28
+ if ( params ) {
29
+ const searchParam = params . toLowerCase ( ) ;
30
+ const glossaryItem = glossary [ searchParam ] ;
31
+ if ( glossaryItem ) {
32
+ let resultDiv = document . getElementById ( ' glossary-result' ) ;
23
33
24
- // set up the title text with a link to the glossary page
25
- resultDiv . find ( ".glossary-title" ) . text ( 'Glossary: ' + glossary_item . title ) ;
26
- var link_target = search_param . replace ( / / g, '-' ) ;
27
- resultDiv . find ( ".glossary-title" ) . attr (
28
- 'href' , GLOSSARY_PAGE + '#term-' + link_target
29
- ) ;
34
+ // set up the title text with a link to the glossary page
35
+ let glossaryTitle = resultDiv . querySelector ( '.glossary-title' ) ;
36
+ glossaryTitle . textContent = 'Glossary: ' + glossaryItem . title ;
37
+ const linkTarget = searchParam . replace ( / / g, '-' ) ;
38
+ glossaryTitle . href = GLOSSARY_PAGE + '#term-' + linkTarget ;
30
39
31
- // rewrite any anchor links (to other glossary terms)
32
- // to have a full reference to the glossary page
33
- var body = $ ( glossary_item . body ) . children ( ) ;
34
- body . find ( "a[href^='#']" ) . each ( function ( ) {
35
- var current_url = $ ( this ) . attr ( 'href' ) ;
36
- $ ( this ) . attr ( 'href' , GLOSSARY_PAGE + current_url ) ;
37
- } ) ;
38
- resultDiv . find ( ".glossary-body" ) . html ( body ) ;
40
+ // rewrite any anchor links (to other glossary terms)
41
+ // to have a full reference to the glossary page
42
+ let body = document . createElement ( 'div' ) ;
43
+ body . innerHTML = glossaryItem . body ;
44
+ const anchorLinks = body . querySelectorAll ( 'a[href^="#"]' ) ;
45
+ anchorLinks . forEach ( function ( link ) {
46
+ const currentUrl = link . getAttribute ( 'href' ) ;
47
+ link . href = GLOSSARY_PAGE + currentUrl ;
48
+ } ) ;
49
+ resultDiv . querySelector ( '.glossary-body' ) . appendChild ( body ) ;
39
50
40
- resultDiv . show ( ) ;
41
- } else {
42
- $ ( "#glossary-result" ) . hide ( '' ) ;
43
- }
51
+ resultDiv . style . display = '' ;
52
+ } else {
53
+ document . getElementById ( 'glossary-result' ) . style . display = 'none' ;
44
54
}
55
+ }
56
+ } )
57
+ . catch ( function ( error ) {
58
+ console . error ( error ) ;
45
59
} ) ;
46
60
} ) ;
47
61
</ script >
48
- {% endblock %}
62
+ {% endblock %}
0 commit comments