-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
178 lines (142 loc) · 4.53 KB
/
script.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
var stopPlayAt = 1657; // Stop play at time in seconds
var stopPlayTimer; // Reference to settimeout call
var startAt =257;
// This code loads the IFrame Player API code asynchronously.
var tag = document.createElement("script");
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player("player", {
"height": "315",
"width": "560",
"videoId": "ln-CeHYkQvg",
"playerVars": {
start: startAt,
rel:0
},
"events": {
"onStateChange": onPlayerStateChange
}
});
}
// The API will call this function when the video player is ready.
// This automatically starts the video playback when the player is loaded.
// The API calls this function when the player's state changes.
function onPlayerStateChange(event) {
var time, rate, remainingTime;
clearTimeout(stopPlayTimer);
if (event.data == YT.PlayerState.PLAYING) {
time = player.getCurrentTime();
// Add .4 of a second to the time in case it's close to the current time
// (The API kept returning ~9.7 when hitting play after stopping at 10s)
if (time + .4 < stopPlayAt) {
rate = player.getPlaybackRate();
remainingTime = (stopPlayAt - time) / rate;
stopPlayTimer = setTimeout(pauseVideo, remainingTime * 1000);
}
}
}
function pauseVideo() {
player.pauseVideo();
}
$(document).ready(function(){
$("#buttonPrint").click(function(){
var Nome = $("#Nome").val();
var Citta = $("#Citta").val();
var Mail = $("#Mail").val();
var CheckPrivacy = $("#checkPrivacy").is(":checked");
var Telefono= $("#Telefono").val();
//dummy validation
if(Nome === "" || Citta === "" || CheckPrivacy === false)
{
}
else
{
//validazioneMail
var mailValida = validaMail(Mail);
if(mailValida)
{
$("#Mail").removeClass("is-invalid");
event.preventDefault();
ajaxCalls(Nome,Citta,Mail,Telefono);
goToNextPage();
}
else
{
$("#Mail").addClass("is-invalid");
return false;
}
}
});
$("#buttonPrintBlu").click(function(){
var Nome = $("#NomeBlu").val();
var Citta = $("#CittaBlu").val();
var Mail = $("#MailBlu").val();
var CheckPrivacy = $("#checkPrivacyBlu").is(":checked");
var Telefono= $("#TelefonoBlu").val();
//dummy validation
if(Nome === "" || Citta === "" || Mail === "" || CheckPrivacy === false){
//doNothing: input are not ok
}
else
{
//validazioneMail
var mailValida = validaMail(Mail);
if(mailValida)
{
$("#MailBlu").removeClass("is-invalid");
event.preventDefault();
ajaxCalls(Nome,Citta,Mail,Telefono);
goToNextPage();
}
else
{
$("#MailBlu").addClass("is-invalid");
return false;
}
}
});
$('a.nav-link').on('shown.bs.tab', function(e) {
var href = $(this).attr('href');
$('html, body').animate({
scrollTop: $(href).offset().top
}, 'slow');
});
function validaMail(mail){
debugger;
var regexp= /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if(regexp.test(mail)){
return true;
} else{
return false;
}
}
function goToNextPage(){
setTimeout(function(){
window.location.replace("contacts.html");
}, 1000);
}
function ajaxCalls(nome,citta,mail,telefono){
$.ajax({
url: 'https://fathomless-headland-00945.herokuapp.com/sendMail',
type: 'GET',
dataType:'json',
data: {
Nome: nome,
Mail: mail,
Telefono: telefono,
Citta : citta
},
success: function(data) {
console.log('form submitted.' + data);
},
error: function(data){
console.log(data);
},
});
}
});