jQuery(document).ready(function($){
jQuery('a[href*=#]').on('click', function(e) {
e.preventDefault();
$('html, body').animate({ scrollTop: $($(this).attr('href')).offset().top}, 500, 'linear');
});
loadImage();
initializeHeader();
});
function addEmail(){
var email = jQuery('#EMAIL').val();
if(ValidateEmail(email)){
jQuery.ajax({
url : jQuery('#URL').val()+'/wp-ajax/suscribe.php',
method : 'POST',
dataType: 'json',
data : {
email : email,
},
success : function(datas){
var html = '';
if(datas.code == 0){
//Email dans la liste
html = "Votre email a éé ajouté à nos newsletter";
}
if(datas.code == -3){
//Email pas au bon format
html = "Votre email est erroné";
}
if(datas.code == -6){
//Email déjà dans la liste
html = "Votre email est déjà dans notre liste de diffusion";
}
jQuery('#formEmail').html(html);
}
});
}
}
function ValidateEmail(mail)
{
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail))
{
return (true)
}
alert("L'Email est invalide");
return (false)
}
function loadImage(){
if(typeof jQuery("#img-screen").val() != undefined){
var img = jQuery("#img-screen-large").val();
if(window.innerWidth <= 1024){
img = jQuery("#img-screen-medium").val();
}
if(window.innerWidth <= 768){
img = jQuery("#img-screen-mini").val();
}
var html = '';
jQuery("#img-screen").html(html);
}
}
function loadTitle(){
if(typeof jQuery("#text-presentation").val() != undefined){
var widthContainerVisible = jQuery("#carousel-home").width();
var heightContainerVisible = jQuery("#carousel-home").height();
var heightContainerInvisible = jQuery("#carousel-home").height() - heightContainerVisible;
var widthElement = jQuery("#text-presentation").width();
var heightElement = jQuery("#text-presentation").height();
var topPosition = (heightContainerInvisible + (heightContainerVisible / 2) - (heightElement / 2))-45;
var widthPosition = (widthContainerVisible / 2) - (widthElement / 2);
jQuery("#text-presentation").css("top", topPosition);
jQuery("#text-presentation").css("left", widthPosition);
}
}
function initializeHeader() {
loadTitle();
jQuery(window).on('resize', function(e) {
loadTitle();
});
jQuery(window).on('load', function() {
loadTitle();
});
}