-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
141 lines (124 loc) · 3.87 KB
/
index.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const soundCloud = document.querySelector('.sound-cloud')
const off = document.querySelector('#off')
const on = document.querySelector('#on')
const myAudio = document.querySelector('#myAudio')
off.addEventListener('click', () => soundTrack('off'))
on.addEventListener('click', () => soundTrack('on'))
const soundTrack = (soundState) => {
if (soundState === 'off') {
on.style.display = 'block'
off.style.display = 'none'
soundCloud.style.color = '#08fdd8'
myAudio.play()
} else if (soundState === 'on') {
on.style.display = 'none'
off.style.display = 'block'
soundCloud.style.color = '#f50057'
myAudio.pause()
}
}
// Play music functionality
const btnBars = document.querySelector('.bars')
const btnTimes = document.querySelector('.times')
const SideNav = document.querySelector('.aside')
btnBars.addEventListener('click', () => myFunc('open'))
btnTimes.addEventListener('click', () => myFunc('close'))
const myFunc = (navCondition) => {
if (navCondition === 'open') {
SideNav.classList.add('show-nav')
btnTimes.style.display = 'block'
btnBars.style.display = 'none'
} else if (navCondition === 'close') {
SideNav.classList.remove('show-nav')
btnTimes.style.display = 'none'
btnBars.style.display = 'block'
}
}
// Part 1 javascript functionality ends here
$(document).ready(function () {
if (
!$('#myCanvas').tagcanvas(
{
textColour: '#08fdd8',
outlineColour: 'transparent',
reverse: true,
depth: 0.8,
maxSpeed: 0.05,
weight: true,
},
'tags',
)
) {
// something went wrong hide the canvas container,
$('#myCanvasContainer')
}
})
// Contact section functionality starts here. The FInal part
const nameInput = document.querySelector('.name')
const emailInput = document.querySelector('.email')
const subjectInput = document.querySelector('.subject')
const textareaInput = document.querySelector('.textarea')
const contactForm = document.querySelector('.contact-form')
contactForm.addEventListener('submit', (evt) => {
evt.preventDefault()
validateInput()
})
const validateInput = () => {
let email = emailInput.value
let textarea = textareaInput.value
if (!email && !textarea) {
setError(emailInput.parentElement)
setError(textareaInput.parentElement)
showMessage('Please fill in the required inputs')
} else if (!email && textarea) {
setError(emailInput.parentElement)
showMessage("Oops Email can't be empty")
} else if (!textarea && email) {
setError(textareaInput.parentElement)
showMessage('Please provide a message')
} else if (email && textarea) {
emailjs.sendForm(
'service_rvlqach',
'template_d32ix5s',
contactForm,
'lD25U1N6WN3XbKSFV',
)
setSuccess(emailInput.parentElement)
setSuccess(textareaInput.parentElement)
showMessage('Message sent successfully', 'green')
textareaInput.value = ''
emailInput.value = ''
nameInput.value = ''
subjectInput.value = ''
}
}
const setError = (input) => {
if (input.classList.contains('success')) {
input.classList.remove('success')
} else {
input.classList.add('error')
}
}
const setSuccess = (input) => {
if (input.classList.contains('error')) {
input.classList.remove('error')
} else {
input.classList.add('success')
}
}
const messageDiv = document.querySelector('.message')
const showMessage = (message, updateColor) => {
const divContent = document.createElement('div')
divContent.textContent = message
divContent.classList.add('message-content')
divContent.style.backgroundColor = updateColor
messageDiv.prepend(divContent)
messageDiv.style.transform = `translate(${(0, 0)}%)`
setTimeout(() => {
divContent.classList.add('hide')
divContent.addEventListener('transitionend', () => {
divContent.remove()
})
}, 5000)
}
// Contact section functionality ends here. The FInal part