-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
114 lines (89 loc) · 4.14 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { convertStringToHTML } from './shared/js/utils';
import './main.css';
import './shared/css/fonts.css';
import './shared/css/shared.css';
import './shared/css/modal.css';
import brandIconImgUrl from './shared/images/uhost-icon.png';
import htmlStrNav from './shared/views/header.html?raw';
import htmlStrFooter from './shared/views/footer.html?raw';
import htmlStrHome from './main.html?raw';
import htmlStrModal from './shared/views/modal.html?raw';
// // importing `SVG` as html string
import trustingCustomerSvgStr from './shared/img-data/svg-html/trusting-customer.html?raw';
import uptimeGuaranteeSvgStr from './shared/img-data/svg-html/uptime-guarantee.html?raw';
import fastCdnSvgStr from './shared/img-data/svg-html/fast-cdn.html?raw';
const BASE_URL = import.meta.env.BASE_URL;
const navHtml = convertStringToHTML(htmlStrNav);
const homeHtml = convertStringToHTML(htmlStrHome);
const modalHtml = convertStringToHTML(htmlStrModal);
const brandHtml = navHtml.querySelector('.main-header__brand');
brandHtml.href = BASE_URL;
// adding `html element` as sibling: `backdropHtml` is existing Node, `modalHtml` is new node
const backdropHtml = document.querySelector('.backdrop');
modalHtml.querySelector('.modal__action').href = `${BASE_URL}pages/start-hosting/`;
backdropHtml.parentNode.insertBefore(modalHtml.childNodes[0], backdropHtml.nextSibling);
// ^ Replacing `navigation urls`
navHtml.querySelector('#pkg-link').href = `${BASE_URL}pages/packages/`;
navHtml.querySelector('#cus-link').href = `${BASE_URL}pages/customers/`;
navHtml.querySelector('#host-link').href = `${BASE_URL}pages/start-hosting/`;
// navHtml.querySelector('.brand-img').src = brandIconImgUrl;
navHtml.querySelector('#pkg-link-mobile').href = `${BASE_URL}pages/packages/`;
navHtml.querySelector('#cus-link-mobile').href = `${BASE_URL}pages/customers/`;
navHtml.querySelector('#host-link-mobile').href = `${BASE_URL}pages/start-hosting/`;
// ! inserting `svg` string inside `html`
homeHtml.querySelector('#trust-customer').innerHTML = trustingCustomerSvgStr;
homeHtml.querySelector('#uptime-guarantee').innerHTML = uptimeGuaranteeSvgStr;
homeHtml.querySelector('#fast-cdn').innerHTML = fastCdnSvgStr;
// * Creating `img` tag
const imgHtml = document.createElement('img');
imgHtml.src = brandIconImgUrl;
imgHtml.alt = 'Your favorite uHost';
imgHtml.className = 'brand-img';
// ? appending `img` tag to `brandHtml` as child
// brandHtml.innerHTML = imgHtml.outerHTML;
brandHtml.appendChild(imgHtml);
// ~ inserting modified `html` snip into placeholder
document.querySelector('#nav').innerHTML = navHtml.innerHTML;
document.querySelector('#app').innerHTML = homeHtml.innerHTML;
document.querySelector('#footer').innerHTML = htmlStrFooter;
// // Mobile nav elements
const toggleBtn = document.querySelector('.toggle-button');
const mobileNav = document.querySelector('.mobile-nav');
// // enabling backdrop & pop-up when clicking on the plans on homepage
const selectPlanBtns = document.querySelectorAll('.plan button');
const backdrop = document.querySelector('.backdrop');
const modal = document.querySelector('.modal');
const onOpenModal = () => {
// modal.style.display = 'block';
modal.classList.add('open');
backdrop.classList.add('open');
}
const onCloseModal = () => {
// modal.style.display = 'none';
modal.classList.remove('open');
backdrop.classList.remove('open');
}
for (let i = 0; i < selectPlanBtns.length; i++) {
selectPlanBtns[i].addEventListener('click', onOpenModal);
}
// // closing modal
const modalNoBtn = document.querySelector('.modal__action--negative');
backdrop.addEventListener('click', () => {
mobileNav.classList.remove('open');
onCloseModal();
});
modalNoBtn.addEventListener('click', onCloseModal);
// & triggering mobile nav
toggleBtn.addEventListener('click', () => {
backdrop.classList.add('open');
mobileNav.classList.add('open');
});
// & logging to browser's console
console.log('Domain : ', document.location.origin);
console.log('Base : ', BASE_URL);
console.groupCollapsed('1️⃣Navbar before modification 👇');
console.log(htmlStrNav);
console.groupEnd();
console.group('2️⃣Navbar after modification 👇');
console.log(navHtml.innerHTML);
console.groupEnd();