-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
97 lines (78 loc) · 2.74 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
$(document).ready(function(){
$("header .main-nav .menu i,.toggle-menu ul li a,header .main-nav.scrolled .menu i").click(function(){
$("header .main-nav .menu i").toggleClass("fa-times-circle");
$(".toggle-menu").toggleClass("active");
});
});
$(".toggle-menu ul li a").click(function(){
$('html,body').toggleClass("add-Opacity");
});
$(function () {
$(document).scroll(function () {
let nav = $("header .main-nav");
nav.toggleClass('scrolled', $(this).scrollTop()>91);
});
});
const height = $("header .main-nav").outerHeight();
$(function(){
$('a[href*="#"]').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
&& location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
if ($target.length) {
var targetOffset = $target.offset().top;
$('html,body').animate({scrollTop: targetOffset - 91,}, 1000);
return false;
}
}
});
});
// Initialize Firebase
var config = {
apiKey: "AIzaSyA4o0s6YMv78_m-MivqAAmBwdU8EW6_p00",
authDomain: "portfolio-contact-edcad.firebaseapp.com",
databaseURL: "https://portfolio-contact-edcad.firebaseio.com",
projectId: "portfolio-contact-edcad",
storageBucket: "portfolio-contact-edcad.appspot.com",
messagingSenderId: "800087795947"
};
firebase.initializeApp(config);
//initializing firebase in app
var messageRef = firebase.database().ref('messages');
//form values
document.getElementById('contact-me').addEventListener('submit',submitForm);
function submitForm(e){
e.preventDefault();
const name = getInput('yourname');
const email = getInput('email');
const Telephone = getInput('telephone');
const companyname = getInput('companyname');
const website = getInput('website');
const position= getInput('position');
const message= getInput('message');
//function referenced to DOM
function getInput(id){
return document.getElementById(id).value;
}
//save values to data base
saveMessage(name,email,message, Telephone,companyname,website,position);
document.querySelector("#showalert").style.display ="inline-block";
setTimeout(function(){
document.querySelector("#showalert").style.display ="none";
document.getElementById('contact-me').reset();
},3000);
};
//save message to fire base
function saveMessage(name,email,message,Telephone,companyname,position,website) {
const newMessageRef = messageRef.push();
newMessageRef.set({
name:name,
email:email,
Telephone:Telephone,
companyname:companyname,
website:website,
position: position,
message:message
});
};