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
|
/* Mobile check */
export const isiPhone = !!((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
export const isiPad = !!(navigator.userAgent.match(/iPad/i))
export const isAndroid = !!(navigator.userAgent.match(/Android/i))
export const isMobile = isiPhone || isiPad || isAndroid
export const isDesktop = !isMobile
export const isFirefox = typeof InstallTrigger !== 'undefined'
const htmlClassList = document.body.parentNode.classList
htmlClassList.add(isDesktop ? 'desktop' : 'mobile')
if (isFirefox) {
htmlClassList.add('firefox')
}
/* AJAX */
export const get = (uri, data) => {
let headers = {
Accept: 'application/json, application/xml, text/play, text/html, *.*',
}
let opt = {
method: 'GET',
body: data,
headers,
// credentials: 'include',
}
// console.log(headers)
// headers['X-CSRFToken'] = csrftoken
return fetch(uri, opt).then(res => res.json())
}
export const post = (uri, data) => {
let headers
if (data instanceof FormData) {
headers = {
Accept: 'application/json, application/xml, text/play, text/html, *.*',
}
} else {
headers = {
Accept: 'application/json, application/xml, text/play, text/html, *.*',
'Content-Type': 'application/json; charset=utf-8',
}
data = JSON.stringify(data)
}
let opt = {
method: 'POST',
body: data,
headers,
// credentials: 'include',
}
// console.log(headers)
// headers['X-CSRFToken'] = csrftoken
return fetch(uri, opt).then(res => res.json())
}
|