-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (53 loc) · 2.28 KB
/
index.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* ------------------------------------------------------------------------
* Footnotes
* ------------------------------------------------------------------------
*/
const Footnotes = {
init: function() {
const footnoteItems = document.querySelectorAll('a[data-toggle="footnote"]');
if ( footnoteItems.length === 0 ) {
return;
}
console.log(footnoteItems);
this.setupFootnoteContainer();
footnoteItems.forEach(element => {
element.addEventListener('click', this.eventHandler);
});
},
eventHandler: function(e) {
e.preventDefault();
console.log(e.target.getAttribute('href'));
const selectedFootnoteContent = document.querySelector( e.target.getAttribute('href') ).innerHTML;
const footnoteArea = document.querySelector('#footnote-area');
const footnoteContent = document.querySelector('#footnote-content');
console.log(selectedFootnoteContent);
footnoteContent.innerHTML = selectedFootnoteContent;
console.log(footnoteContent);
footnoteArea.classList.add('show');
},
setupFootnoteContainer: function() {
const footnoteArea = document.createElement('div');
const footnoteContainer = document.createElement('div');
const footnoteContent = document.createElement('div');
const footnoteCloseBtn = document.createElement('button');
footnoteCloseBtn.id = 'footnote-close';
footnoteCloseBtn.classList.add('footnote-close', 'btn-close');
footnoteCloseBtn.setAttribute('aria-label', 'close');
footnoteArea.classList.add('footnote-area');
footnoteArea.id = 'footnote-area';
footnoteContainer.classList.add('footnote-container');
footnoteContainer.classList.add('container');
footnoteContent.id = 'footnote-content';
footnoteContent.classList.add('footnote-content');
footnoteCloseBtn.addEventListener('click', function() {
this.parentElement.parentElement.classList.remove('show')
});
footnoteContainer.append(footnoteCloseBtn);
footnoteContainer.append(footnoteContent);
footnoteArea.append(footnoteContainer);
document.body.append(footnoteArea);
}
};
// init module
Footnotes.init();