This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
120 lines (93 loc) · 2.74 KB
/
popup.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
/* TOAST */
function Toast(text){
this.text = text;
this.body = $(document.body);
this.toast = $('.toast');
this.p = $('.toast > p');
this.me = this;
console.log('Toast elem = ');
console.log(this.toast);
console.log(this.p);
this.show = function(){
this.p.html(this.text);
this.toast.css('opacity', '1');
}
this.hide = function(){
this.toast.css('opacity', '0');
}
}
/* AFFICHAGE POPUP*/
var loading = false;
function hide (addr) {
document.getElementById(addr).style.display = "none" ;
}
function show (addr) {
document.getElementById(addr).style.display = "block" ;
loading = true;
setTimeout(function(){
loading = false;
}, 1000);
}
var input_name = document.getElementById("input_name");
var input_mail = document.getElementById("input_mail");
var input_message = document.getElementById("input_message");
var text = document.getElementById("text");
function toggle () {
if(!loading){
if(document.getElementById('popup').style.display == "none") {
show('popup');
}else {
hide('popup');
}
input_name.value="";
input_mail.value="";
input_message.value="";
text.style.display = "none";
}
}
window.onload = function() { hide ('popup'); };
/*--------------------------------------------------*/
/* FERMER POPUP */
var lienpopup = document.getElementById('linkpopup');
var body = document.body;
var popup = document.getElementById('popup');
var close = document.getElementById('close');
var button_send = document.getElementById('button_send');
lienpopup.addEventListener("click", toggle, false);
close.addEventListener("click", toggle, false);
button_send.addEventListener("click", sendform, false);
/*--------------------------------------------------*/
/* RECUPÉRATION DES DONNÉES */
function button (){
console.log(input_name.value);
console.log(input_mail.value);
console.log(input_message.value);
}
/*--------------------------------------------------*/
/*ENVOI DU FORMULAIRE*/
function sendform (){
if( input_name.value=="" || input_mail.value == "" || input_message.value==""){
text.style.display = "block";
} else {
var sendtab = [];
sendtab.push(input_name.value);
sendtab.push(input_mail.value);
sendtab.push(input_message.value);
console.log('SendData');
sendData();
toggle();
var toast = new Toast("Votre message a bien été envoyé");
toast.show();
setTimeout(function(){
toast.hide();
},2500);
}
function sendData(){
$.post('form.php', {
data: sendtab
}, function(response) {
console.log(response);
});
}
}
// JavaScript Document