-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
45 lines (42 loc) · 1.2 KB
/
main.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
const Hash = {
get: () => {
const hash = document.location.hash.substring(1) // hash without #
if (hash) {
return hash.match(/.*\/(.*)$/)[1] // Enlever la racine du hash ex. categorie/outillage => outillage
}
return undefined
},
getType: () => {
const hash = document.location.hash.substring(1) // hash without #
if (hash) {
return hash.match(/^(.*)\//)[1] // Ne garde que la racine du hash ex. categorie/outillage => categorie
}
return undefined
},
onChange: () => filesImport
.then(json => {
Articles.display(json.body)
Categories.display(Categories.get())
})
}
const Tpl = {
getElement: tplName =>
document
.querySelector(`template[name=${tplName}]`)
.cloneNode(true)
.content
.querySelector('[data-tpl=element]')
}
const Files = {
import: () => {
const json = 'https://api.daktary.com/infolab-cd33/datalunch/tree/master/fiches'
//const json = './fiches.json'
return fetch(json)
.then(response => response.json())
},
getHome: () => {
const json = 'https://api.daktary.com/infolab-cd33/datalunch/blob/master/accueil.md'
return fetch(json)
.then(response => response.json())
}
}