Skip to content

Commit cd2ec06

Browse files
committed
js cleanup
1 parent 549851c commit cd2ec06

File tree

17 files changed

+706
-745
lines changed

17 files changed

+706
-745
lines changed

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "none",
4+
"semi": false
5+
}

source/_static/js/common.js

Lines changed: 89 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,128 @@
11
// Close search on click
2-
window.onclick = function(e) {
3-
if (!e.target.matches('#searchResults') && !e.target.matches('#searchInput')) {
4-
const searchResults = document.getElementById('searchResults')
5-
searchResults.style.display = 'none'
6-
}
2+
window.onclick = function (e) {
3+
if (
4+
!e.target.matches('#searchResults') &&
5+
!e.target.matches('#searchInput')
6+
) {
7+
const searchResults = document.getElementById('searchResults')
8+
searchResults.style.display = 'none'
9+
}
710
}
811

912
// Copy/paste button in code
1013
function copy(event) {
11-
const table = event.parentNode.parentNode
12-
const codeContainer = table.querySelector('td.code pre')
13-
const code = codeContainer.textContent
14-
15-
const textarea = document.createElement('textarea')
16-
textarea.value = code
17-
textarea.setAttribute('readonly', '')
18-
textarea.style.position = 'absolute'
19-
textarea.style.left = '-9999px'
20-
document.body.appendChild(textarea)
21-
textarea.select()
22-
document.execCommand('copy')
23-
document.body.removeChild(textarea)
14+
const table = event.parentNode.parentNode
15+
const codeContainer = table.querySelector('td.code pre')
16+
const code = codeContainer.textContent
17+
18+
const textarea = document.createElement('textarea')
19+
textarea.value = code
20+
textarea.setAttribute('readonly', '')
21+
textarea.style.position = 'absolute'
22+
textarea.style.left = '-9999px'
23+
document.body.appendChild(textarea)
24+
textarea.select()
25+
document.execCommand('copy')
26+
document.body.removeChild(textarea)
2427
}
2528

2629
function addCopyPaste() {
27-
const codeTables = document.getElementsByClassName('highlighttable')
28-
29-
for (let i = 0; i < codeTables.length; i++) {
30-
const button = document.createElement('button')
31-
button.className = 'copy-button'
32-
button.innerHTML = '<span class="clipboard-message">Copied to clipboard</span><i class="far fa-clone"></i>'
33-
button.onclick = function(e){
34-
copy(this)
35-
this.children[0].classList.toggle('clipboard-message--active')
36-
setTimeout(() => {this.children[0].classList.remove("clipboard-message--active")}, 2000)
37-
}
38-
39-
codeTables[i].appendChild(button)
40-
}
30+
const codeTables = document.getElementsByClassName('highlighttable')
31+
32+
for (let i = 0; i < codeTables.length; i++) {
33+
const button = document.createElement('button')
34+
button.className = 'copy-button'
35+
button.innerHTML =
36+
'<span class="clipboard-message">Copied to clipboard</span><i class="far fa-clone"></i>'
37+
button.onclick = function (e) {
38+
copy(this)
39+
this.children[0].classList.toggle('clipboard-message--active')
40+
setTimeout(() => {
41+
this.children[0].classList.remove('clipboard-message--active')
42+
}, 2000)
43+
}
44+
45+
codeTables[i].appendChild(button)
46+
}
4147
}
4248

43-
setTimeout(function() {
44-
addCopyPaste()
45-
}, 500);
49+
setTimeout(function () {
50+
addCopyPaste()
51+
}, 500)
4652

4753
// Up button
48-
window.onscroll = function() { scrollFunc() }
54+
window.onscroll = function () {
55+
scrollFunc()
56+
}
4957

5058
function scrollFunc() {
51-
if (document.body.scrollTop > 40 || document.documentElement.scrollTop > 40)
52-
document.getElementById('upButton').style.display = 'block'
53-
else
54-
document.getElementById('upButton').style.display = 'none'
59+
if (document.body.scrollTop > 40 || document.documentElement.scrollTop > 40)
60+
document.getElementById('upButton').style.display = 'block'
61+
else document.getElementById('upButton').style.display = 'none'
5562
}
5663

5764
function scrollTop() {
58-
document.body.scrollTop = 0;
59-
document.documentElement.scrollTop = 0;
65+
document.body.scrollTop = 0
66+
document.documentElement.scrollTop = 0
6067
}
6168

6269
function addUpButton() {
63-
const div = document.createElement('div')
64-
div.id = 'upButton'
65-
div.className = 'up-button'
66-
div.innerHTML = '<i class="fas fa-angle-double-up"></i>'
67-
div.onclick = function() { scrollTop() }
68-
69-
const header = document.getElementsByTagName('header')[0]
70-
header.appendChild(div)
70+
const div = document.createElement('div')
71+
div.id = 'upButton'
72+
div.className = 'up-button'
73+
div.innerHTML = '<i class="fas fa-angle-double-up"></i>'
74+
div.onclick = function () {
75+
scrollTop()
76+
}
77+
78+
const header = document.getElementsByTagName('header')[0]
79+
header.appendChild(div)
7180
}
7281

73-
let scrollPos = 0;
82+
let scrollPos = 0
7483
function updateUpButton() {
75-
76-
77-
if ((document.body.getBoundingClientRect()).top > scrollPos) {
78-
document.getElementById('upButton').classList.add('up');
79-
document.getElementById('upButton').classList.remove('down');
84+
if (document.body.getBoundingClientRect().top > scrollPos) {
85+
document.getElementById('upButton').classList.add('up')
86+
document.getElementById('upButton').classList.remove('down')
8087
} else {
81-
document.getElementById('upButton').classList.add('down');
82-
document.getElementById('upButton').classList.remove('up');
88+
document.getElementById('upButton').classList.add('down')
89+
document.getElementById('upButton').classList.remove('up')
8390
}
84-
scrollPos = (document.body.getBoundingClientRect()).top;
91+
scrollPos = document.body.getBoundingClientRect().top
8592
}
8693

8794
addUpButton()
8895

8996
// Highlight nav links
9097
function updateBlur() {
91-
const toc = document.getElementById('toc')
92-
const els_ = document.querySelectorAll('#toc li')
93-
const anchors_ = document.querySelectorAll('.section')
94-
95-
const offset = window.pageYOffset
96-
97-
if (anchors_.length === 0)
98-
return
99-
100-
let last = 0
101-
for (let i = 0; i < Math.min(els_.length, anchors_.length); i++) {
102-
if ((anchors_[i].offsetTop-70) <= offset) {
103-
els_[i].classList.add('blur')
104-
last = i
105-
} else {
106-
els_[i].classList.remove('blur')
107-
}
108-
}
109-
110-
{ // scroll toc to current element
111-
const div = toc.children[0]
98+
const toc = document.getElementById('toc')
99+
const els_ = document.querySelectorAll('#toc li')
100+
const anchors_ = document.querySelectorAll('.section')
101+
102+
const offset = window.pageYOffset
103+
104+
if (anchors_.length === 0) return
105+
106+
let last = 0
107+
for (let i = 0; i < Math.min(els_.length, anchors_.length); i++) {
108+
if (anchors_[i].offsetTop - 70 <= offset) {
109+
els_[i].classList.add('blur')
110+
last = i
111+
} else {
112+
els_[i].classList.remove('blur')
113+
}
114+
}
115+
116+
{
117+
// scroll toc to current element
118+
const div = toc.children[0]
112119
// div.scrollTo(0, els_[last].offsetTop-div.offsetHeight/2)
113-
}
120+
}
114121
}
115122

116123
updateBlur()
117124

118-
document.addEventListener('scroll', function() {
125+
document.addEventListener('scroll', function () {
119126
updateBlur()
120127
updateUpButton()
121128
})

source/_static/js/github.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,41 @@ const githubOrganization = 'FreeFem'
22
const githubRepository = 'FreeFem-sources'
33

44
function HTTPGet(url, callback) {
5-
const xhr = new XMLHttpRequest()
6-
xhr.open('GET', url, true)
7-
xhr.onload = function(e) {
8-
if (xhr.readyState === 4) {
9-
if (xhr.status === 200) {
10-
callback(xhr.responseText)
11-
} else {
12-
console.error(xhr.statusText)
13-
}
5+
const xhr = new XMLHttpRequest()
6+
xhr.open('GET', url, true)
7+
xhr.onload = function (e) {
8+
if (xhr.readyState === 4) {
9+
if (xhr.status === 200) {
10+
callback(xhr.responseText)
11+
} else {
12+
console.error(xhr.statusText)
1413
}
15-
}
16-
xhr.onerror = function(e) {
17-
console.error(xhr.statusText)
18-
}
19-
xhr.send(null)
14+
}
15+
}
16+
xhr.onerror = function (e) {
17+
console.error(xhr.statusText)
18+
}
19+
xhr.send(null)
2020
}
2121

22-
const githubURL = 'https://api.github.com/repos/' + githubOrganization + '/' + githubRepository
22+
const githubURL =
23+
'https://api.github.com/repos/' + githubOrganization + '/' + githubRepository
2324

2425
function starsAndForks(data) {
25-
const jdata = JSON.parse(data)
26+
const jdata = JSON.parse(data)
2627

27-
const headerGithubStarsForks = document.getElementById('headerGithubStarsForks')
28-
headerGithubStarsForks.style.display = 'block'
28+
const headerGithubStarsForks = document.getElementById(
29+
'headerGithubStarsForks'
30+
)
31+
headerGithubStarsForks.style.display = 'block'
2932

30-
const stars = jdata.stargazers_count
31-
const headerGithubStars = document.getElementById('headerGithubStars')
32-
headerGithubStars.innerHTML = stars
33+
const stars = jdata.stargazers_count
34+
const headerGithubStars = document.getElementById('headerGithubStars')
35+
headerGithubStars.innerHTML = stars
3336

34-
const forks = jdata.forks_count
35-
const headerGithubForks = document.getElementById('headerGithubForks')
36-
headerGithubForks.innerHTML = forks
37+
const forks = jdata.forks_count
38+
const headerGithubForks = document.getElementById('headerGithubForks')
39+
headerGithubForks.innerHTML = forks
3740
}
3841

3942
HTTPGet(githubURL, starsAndForks)

source/_static/js/katex-config.js

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)