forked from letsencrypt/website
-
Notifications
You must be signed in to change notification settings - Fork 3
/
glossary.js
26 lines (25 loc) · 891 Bytes
/
glossary.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// search all links (into definitions) linking to elements in the current page (href starts with #)
// To set the title of the link to the definition it points to
document.querySelectorAll('[id^="def-"]').forEach(function(def){
const id = def.id;
let title = def.parentNode.textContent;
if ( title.match(/\.\s/) ) {
// We take everything until the last period. (Everything after are links such as "Wikipedia"
title = title.match(/^.*\.\s/)[0];
}
document.querySelectorAll('.definition>a[href^="#'+id+'"]').forEach(function(a){
a.title = title;
});
});
// search for invalid links
document.querySelectorAll('.definition>a[href^="#"]').forEach(function(a){
if ( a.title ) return;
let href = a.href;
let id = href.substring(href.indexOf('#')+1);
if ( ! id ) return;
let el = document.getElementById(id);
if ( ! el ) {
console.error("Invalid link to:"+id);
return;
}
});