var studi_maps = [];
var template = $('body').attr('class').split(' ')[0];
var navbar_height = $('#main-navbar-nav').outerHeight();
$(window).scroll(function () {
change_navbar_background();
});
$(document).ready(function () {
new WOW().init();
// check if scrolled to add navbar backgrounnd
change_navbar_background();
// Select all links with hashes
jQuery('a[href*="#"]').not('[href="#"]').not('[href="#0"]').click(function (event) {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
// Figure out element to scroll to
var target = jQuery(this.hash);
target = target.length ? target : jQuery('[name=' + this.hash.slice(1) + ']');
// Does a scroll target exist?
if (target.length) {
// Only prevent default if animation is actually gonna happen
event.preventDefault();
// close mobile menù if open
var delay = 0;
if ($('#main-navbar').hasClass('show')) {
$('#main-navbar').collapse('hide');
delay = 350;
}
var offset_add = 0;
if ($('#main-navbar-nav .navbar-collapse .navbar-nav .nav-item .nav-link').css('text-transform') == 'none') {
offset_add = navbar_height;
}
setTimeout(function () {
jQuery('html, body').animate({
scrollTop: target.offset().top - offset_add + 10
}, 1000);
}, delay);
// Update URL
window.history.replaceState("", document.title, window.location.href.replace(location.hash, "") + this.hash);
}
}
});
// initialize link articoli
$('a[data-type="pubblicazione"]').on('click', function () {
var id_pub_enc = $(this).data('id');
$.ajax({
type: "POST",
url: api_url + "siti/articoli",
data: {
id_pub_enc: id_pub_enc
},
error: function (data) {
alert("Errore, riprovare");
},
success: function (data) {
$('#contentArticolo .titolo').html(data.data.titolo);
$('#contentArticolo .corpo').html(data.data.corpo);
$('.main-container, section, #main-navbar-nav').addClass('d-none');
$('#contentArticolo').removeClass('d-none');
$("html, body").animate({ scrollTop: 0 }, "fast");
}
});
});
// initialize link articoli keyword
$('a[data-type="keyword"]').on('click', function () {
var id_pub_enc = $(this).data('id');
$.ajax({
type: "POST",
url: api_url + "siti/articoli-patologie",
data: {
id_pub_enc: id_pub_enc
},
error: function (data) {
alert("Errore, riprovare");
},
success: function (data) {
$('#contentArticolo .titolo').html(data.data.titolo);
$('#contentArticolo .corpo').html(data.data.corpo);
$('section, #main-navbar-nav').addClass('d-none');
$('#contentArticolo').removeClass('d-none');
$("html, body").animate({ scrollTop: 0 }, "fast");
}
});
});
$('.close-article').on('click', function () {
$('.main-container, section, #main-navbar-nav').removeClass('d-none');
$('#contentArticolo').addClass('d-none');
$("html, body").animate({ scrollTop: $('#pubblicazioni').offset().top - 50 }, "fast");
});
// form contatti submit
$('#contatti-form').on('submit', function (e) {
e.preventDefault();
var htmlBtn = $('#contatti-form .btn').html();
var htmlLoadingBtn = ' Attendi...';
var myhoney = $(this).find('input[name="myhoney"]').val();
if (myhoney != '') {
$('#contatti-form .btn').remove();
$('#contatti-modal').modal('show');
return false;
}
$.ajax({
type: "POST",
url: api_url + "siti/contatti",
data: $('#contatti-form').serialize(),
beforeSend: function (formData, jqForm, options) {
$('#contatti-form .btn').html(htmlLoadingBtn);
$('#contatti-form .btn').prop('disabled', true);
},
error: function (data) {
console.log(data);
if (data.status == 422) {
$(data.responseJSON.errors).each(function (k, v) {
for (var key in v) {
if (v.hasOwnProperty(key)) {
$('#contatti-form input[name="' + key + '"]').parent().append('' + v[key] + '');
$('#contatti-form input[name="' + key + '"]').parent().addClass('has-error');
}
}
});
$('#contatti-form .btn').html(htmlBtn);
$('#contatti-form .btn').prop('disabled', false);
return false;
}
alert(data.statusText);
$('#contatti-form .btn').html(htmlBtn);
$('#contatti-form .btn').prop('disabled', false);
},
success: function (data) {
if (data.result) {
$('#contatti-form .btn').remove();
$('#contatti-modal').modal('show');
}
}
});
return false;
});
$('#contatti-form input').on('keyup', function () {
if ($(this).closest('div').hasClass('has-error')) {
if ($(this).val() != '') {
$(this).closest('div').removeClass('has-error');
$(this).closest('div').find('.form-text').remove();
}
}
});
if ($('.idc-lista-prestazioni').length > 0 || $('.idc-lista-prestazioni-modal').length > 0) {
$.ajax({
type: "POST",
url: api_url + "siti/prestazioni",
data: {
id_medico_enc: $('#id-medico-enc').val()
},
success: function (data) {
if (data.data.prestazioni_prenotate.length > 0) {
var html_prest_pren = '
';
html_prest_pren += '
Prestazioni più prenotate
';
html_prest_pren += '
';
$(data.data.prestazioni_prenotate).each(function (k, v) {
html_prest_pren += '- ';
html_prest_pren += '' + v.nome + '';
html_prest_pren += '';
html_prest_pren += '';
if (v.prezzo2 > v.prezzo1) {
html_prest_pren += 'da ' + v.prezzo1 + ' €';
} else {
html_prest_pren += v.prezzo1 + ' €';
}
html_prest_pren += '';
html_prest_pren += '';
html_prest_pren += '
';
});
html_prest_pren += '
';
html_prest_pren += '
';
$('.idc-lista-prestazioni').append(html_prest_pren);
$('.idc-lista-prestazioni-modal').append(html_prest_pren);
}
if (data.data.prestazioni.length > 0) {
var html_prest = '';
html_prest += '
Lista prestazioni
';
html_prest += '
';
$(data.data.prestazioni).each(function (k, v) {
html_prest += '- ';
html_prest += '' + v.nome + '';
html_prest += '';
html_prest += '';
if (v.prezzo2 > v.prezzo1) {
html_prest += 'da ' + v.prezzo1 + ' €';
} else if (v.prezzo2 == 0) {
html_prest += 'Gratis';
} else {
html_prest += v.prezzo1 + ' €';
}
html_prest += '';
html_prest += '';
html_prest += '
';
});
html_prest += '
';
html_prest += '
';
$('.idc-lista-prestazioni').append(html_prest);
$('.idc-lista-prestazioni-modal').append(html_prest);
}
if (data.data.keywords.length > 0) {
var html_keywords = '';
html_keywords += '
' + data.data.keywords_types + '
';
html_keywords += '
';
$(data.data.keywords).each(function (k, v) {
html_keywords += '- ' + v + '
';
});
html_keywords += '
';
html_keywords += '
';
$('.idc-lista-prestazioni').append(html_keywords);
}
if ($('.idc-studio-orari').length > 0) {
$('.idc-studio-orari').each(function (k, v) {
get_studio_orari(v);
});
}
}
});
} else if ($('.idc-studio-orari').length > 0) {
/***
* Questa azione è duplicata sia qui che sopra al success del prendi prestazioni
* perchè se viene eseguita in parallelo, essendo async, in alcuni casi va a togliere il tasto altre prestazioni, come se non ce ne fossero
*/
$('.idc-studio-orari').each(function (k, v) {
get_studio_orari(v);
});
}
if ($('.idc-lista-commenti').length > 0) {
$.ajax({
type: "POST",
url: api_url + "siti/commenti",
data: {
id_medico_enc: $('#id-medico-enc').val()
},
success: function (data) {
if (data.data.length > 0) {
var html = '';
var num_visible = 6;
var col = 'col-md-8 offset-md-2';
if (template = 'template1_2col') {
col = 'col-md-6'
} else if (template = 'template1_pren') {
col = 'col-12'
}
$(data.data).each(function (k, v) {
html += '
';
html += '
';
html += '
';
html += '
' + v.commento + '
';
html += '
';
html += '
' + v.paziente + ', ' + v.citta + '
';
html += '
' + v.data + '
';
html += '
';
html += '
';
html += '
';
});
html += '
';
if (data.data.length > num_visible) {
html += ''
}
$('.idc-lista-commenti').append(html);
$('.load-more-comments').on('click', function () {
$('.idc-lista-commenti .d-none').each(function (k, v) {
if (k < num_visible) {
$(v).removeClass('d-none');
}
});
if ($('.idc-lista-commenti .d-none').length == 0) {
$('.load-more-comments').remove();
}
});
}
}
});
}
if ($('.studio-map').length > 0) {
$('.studio-map').each(function (k, v) {
var map = L.map('studio-' + $(v).data('id'), { scrollWheelZoom: false }).setView([$(v).data('latitudine'), $(v).data('longitudine')], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
L.marker([$(v).data('latitudine'), $(v).data('longitudine')]).addTo(map).on('click', function (e) {
window.open('https://www.google.com/maps/place/' + e.latlng.lat + ',' + e.latlng.lng, '_blank');
});
studi_maps.push(map);
});
}
if ($('.idc-editable').length > 0) {
$('.idc-editable').tooltip({
title: 'Clicca per modificare'
})
}
$('#main-navbar').on('show.bs.collapse', function () {
$('#main-navbar-nav').addClass('scrolled');
});
if ($('#mobile_alert').length > 0) {
$('#mobile_alert').modal('show');
}
});
function set_prestazione(id_prest, listStudi) {
if ($('.idc-studio-orari').length > 0) {
$('.idc-studio-orari').each(function (k, v) {
if (listStudi.indexOf($(v).data('studio')) != -1) {
$(v).data('id-prest', id_prest);
get_studio_orari(v);
}
});
$('#prestazioni-modal').modal('hide');
jQuery('html, body').animate({
scrollTop: $('.idc-studio-orari[data-studio="' + listStudi[0] + '"]').closest('.card').offset().top - 50
}, 1000);
}
}
function get_studio_orari(studio) {
var id_studio_enc = $(studio).data('id');
var id_prest = $(studio).data('id-prest');
var id_keyword = $(studio).data('id-keyword');
$.ajax({
type: "POST",
url: api_url + "siti/orari-studio",
data: {
id_medico_enc: $('#id-medico-enc').val(),
id_studio_enc: id_studio_enc,
id_prestazione: id_prest,
id_keyword: id_keyword
},
success: function (data) {
if (data.data && data.data.listDisp && Object.keys(data.data.listDisp).length > 0) {
$(studio).html(data.data.html);
if (studi_maps.length > 0) {
$(studi_maps).each(function (k, v) {
if (v.getContainer().id == "studio-" + id_studio_enc) {
v.invalidateSize();
}
});
}
} else {
$(studio).html('' +
'Al momento non è possibile prenotare online' +
'
');
}
}
});
}
function scroll_box_disp(elem, direction) {
var div = $(elem).parent().find('.disp-days');
var scroll = 200;
if (direction == 'left') {
scroll *= -1;
}
div.animate({ scrollLeft: div.scrollLeft() + scroll });
}
function change_disp_hours(box, time) {
var div = $(box).parent().parent();
div.find('.disp-days .day-box').removeClass('active');
$(box).addClass('active');
div.find('.day-hours').addClass('d-none');
div.find('.' + time).removeClass('d-none');
var box_offset_left = $(box).offset().left;
var box_parent_offset_left = $(box).parent().offset().left;
var box_parent_scroll_left = $(box).parent().scrollLeft();
var scrollTo = box_offset_left - box_parent_offset_left + box_parent_scroll_left - 15;
div.find('.disp-days').animate({ scrollLeft: scrollTo });
}
function change_navbar_background() {
if ($(this).scrollTop() > 50) {
$('#main-navbar-nav').addClass('scrolled');
} else {
$('#main-navbar-nav').removeClass('scrolled');
}
}