-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
59 lines (52 loc) · 1.88 KB
/
script.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
var mailLink = document.getElementById('mail-link')
var subBox = document.getElementById('sub-box')
mailLink.href = mailLink.href.replace('nospam', 'lemo')
function get(url, cb) {
var req = new XMLHttpRequest()
req.onreadystatechange = function () {
this.readyState === XMLHttpRequest.DONE && cb.call(this, this)
}
req.open('GET', url, true)
req.send(null)
return req
}
function readystatehandler(req) {
if (req.status !== 200) {
subBox.style.backgroundImage = "url('./img/s-abonner.gif')"
subBox.style.backgroundSize = '100%'
forEach.call(subBox.getElementsByTagName('input'), function (input) {
input.disabled = false
input.style.visibility = ''
})
return console.error(req.status, req.statusText)
}
console.log(req.responseText)
subBox.style.backgroundImage = "url('./img/confirmation-abonnement.gif')"
subBox.style.backgroundSize = '70%'
}
subBox.addEventListener('submit', function (event) {
event.preventDefault()
subBox.style.backgroundImage = "url('./img/sablier.gif')"
subBox.style.backgroundSize = '10%'
forEach.call(subBox.getElementsByTagName('input'), function (input) {
input.disabled = true
input.style.visibility = 'hidden'
})
var email = document.getElementById('email').value
get(api +'/sub?email='+ email, readystatehandler)
})
get('https://joptimisme.github.io/?'+ +(new Date), function (req) {
var parser = new DOMParser()
var doc = parser.parseFromString(req.responseText, 'text/html')
var container = document.getElementById('container')
var fresh = map
.call(doc.getElementsByClassName('article'), function (el) { return el })
.filter(function (el) { return !articlesById[el.id] })
.reverse()
fresh.forEach(function (el) {
container.prepend(el)
articles.unshift({ el: el, id: el.id })
})
fresh.length && articles.forEach(processArticle)
fresh.length && recalcPositions()
})