forked from basir/node-javascript-ecommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
58 lines (54 loc) · 1.62 KB
/
Copy pathutils.js
File metadata and controls
58 lines (54 loc) · 1.62 KB
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
import { getCartItems } from './localStorage';
export const parseRequestUrl = () => {
const address = document.location.hash.slice(1).split('?')[0];
const queryString =
document.location.hash.slice(1).split('?').length === 2
? document.location.hash.slice(1).split('?')[1]
: '';
const url = address.toLowerCase() || '/';
const r = url.split('/');
const q = queryString.split('=');
return {
resource: r[1],
id: r[2],
verb: r[3],
name: q[0],
value: q[1],
};
};
export const rerender = async (component) => {
document.getElementById('main-container').innerHTML =
await component.render();
await component.after_render();
};
export const showLoading = () => {
document.getElementById('loading-overlay').classList.add('active');
};
export const hideLoading = () => {
document.getElementById('loading-overlay').classList.remove('active');
};
export const showMessage = (message, callback) => {
document.getElementById('message-overlay').innerHTML = `
<div>
<div id="message-overlay-content">${message}</div>
<button id="message-overlay-close-button">OK</button>
</div>
`;
document.getElementById('message-overlay').classList.add('active');
document
.getElementById('message-overlay-close-button')
.addEventListener('click', () => {
document.getElementById('message-overlay').classList.remove('active');
if (callback) {
callback();
}
});
};
export const redirectUser = () => {
console.log(getCartItems().length);
if (getCartItems().length !== 0) {
document.location.hash = '/shipping';
} else {
document.location.hash = '/';
}
};