-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
82 lines (63 loc) · 2.08 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
var firebaseConfig = {
apiKey: "AIzaSyDXYLXRVqf9QM6Bg9BwsSAifSAh01-cpXE",
authDomain: "contactform-f6785.firebaseapp.com",
projectId: "contactform-f6785",
storageBucket: "contactform-f6785.appspot.com",
messagingSenderId: "852640140610",
appId: "1:852640140610:web:7c000cb953a4459972ccdb",
measurementId: "G-M3QV6L42K2"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
// Reference messages collection
var messagesRef = firebase.database().ref('messages');
// Listen for form submit
document.getElementById('contactForm').addEventListener('submit', submitForm);
// Submit form
function submitForm(e){
e.preventDefault();
// Get values
var name = getInputVal('name');
var name = getInputVal('secondname');
var message = getInputVal('message');
// Save message
saveMessage(name,secondname,message );
// Show alert
document.querySelector('.alert').style.display = 'block';
// Hide alert after 3 seconds
setTimeout(function(){
document.querySelector('.alert').style.display = 'none';
},3000);
// Clear form
document.getElementById('contactForm').reset();
}
// Function to get get form values
function getInputVal(id){
return document.getElementById(id).value;
}
// Save message to firebase
function saveMessage(name,secondname,message){
var newMessageRef = messagesRef.push();
newMessageRef.set({
name: name,
secondname: secondname,
message:message
});
}
var checkbox = document.querySelector('input[name=theme]');
checkbox.addEventListener('change', function() {
if(this.checked) {
trans()
document.documentElement.setAttribute('data-theme', 'dark')
} else {
trans()
document.documentElement.setAttribute('data-theme', 'light')
}
})
let trans = () => {
document.documentElement.classList.add('transition');
window.setTimeout(() => {
document.documentElement.classList.remove('transition')
}, 1000)
}