-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.js
117 lines (104 loc) · 3.35 KB
/
function.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
$(".card-toggle").on("click", function(){
// Card toggle state
$(".card-toggle").removeClass("active");
$(this).addClass("active");
var isAnimating = false;
if( !isAnimating ){
isAnimating = true;
$(".card").find(".card-content").css("z-index",0);
$(".card").removeClass("active");
var that = $(this);
$(this).siblings().css("z-index",1);
setTimeout(function(){
that.parent().toggleClass("active").find(".card-content").on("transitionend", function(){
isAnimating = false;
}); ;
},10);
} else {
return;
}
});
$("input,textarea").blur(function(){
if( $(this).val() ){
$(this).parent().addClass("filled");
} else {
$(this).parent().removeClass("filled");
}
});
$(".contact").on("click",function(){
$(".contact-form").toggleClass("active");
});
$(".contact-form .close").on("click",function(e){
e.preventDefault();
$(".contact-form").toggleClass("active");
});
$(".contact-form input[type=submit]").on("click",function(e){
e.preventDefault();
//now send this data and clear values of contact form
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (this.responseText == "200") {
alertbox.show("Message sent!");
//clear values based on above response
$("#email").val("");
$("#name").val("");
$("#message").val("");
$(".contact-form").toggleClass("active");
}
else {
alertbox.show(this.responseText);
}
return;
}
};
xhttp.open("POST", "https://nso.vikesh.me/email.php?email="+encodeURIComponent($("#email").val())+"&name="+encodeURIComponent($("#name").val()), true);
xhttp.send($("#message").val());
});
// The main class
var AlertBox = function(id, option) {
this.show = function(msg) {
if (msg === '' || typeof msg === 'undefined' || msg === null) {
throw '"msg parameter is empty"';
}
else {
var alertArea = document.querySelector(id);
var alertBox = document.createElement('DIV');
var alertContent = document.createElement('DIV');
var alertClose = document.createElement('A');
var alertClass = this;
alertContent.classList.add('alert-content');
alertContent.innerText = msg;
alertClose.classList.add('alert-close');
alertClose.setAttribute('href', '#');
alertBox.classList.add('alert-box');
alertBox.appendChild(alertContent);
if (!option.hideCloseButton || typeof option.hideCloseButton === 'undefined') {
alertBox.appendChild(alertClose);
}
alertArea.appendChild(alertBox);
alertClose.addEventListener('click', function(event) {
event.preventDefault();
alertClass.hide(alertBox);
});
if (!option.persistent) {
var alertTimeout = setTimeout(function() {
alertClass.hide(alertBox);
clearTimeout(alertTimeout);
}, option.closeTime);
}
}
};
this.hide = function(alertBox) {
alertBox.classList.add('hide');
var disperseTimeout = setTimeout(function() {
alertBox.parentNode.removeChild(alertBox);
clearTimeout(disperseTimeout);
}, 500);
};
};
var alertbox = new AlertBox('#alert-area', {
closeTime: 5000,
persistent: false,
hideCloseButton: false
});