//==================================================================================================
// CONFIGURATION
//==================================================================================================
// 0 = ''; 1 = lavoro, etc.
var arr_macro = ['','lavoro','immobiliari','veicoli','comprovendo','relazioni'];
//==================================================================================================
jQuery(function ($) {
'use strict';
if ($(window).width() < 992) {
$('.nascondi').slideUp();
$('.open-intro').show();
$('.close-intro').hide();
}
if($.cookie('chiudi'))
{
$('.nascondi').slideUp();
$('.open-intro').show();
$('.close-intro').hide();
}
$('.open-intro').click(function() {
$('.nascondi').slideDown();
$('.close-intro').show();
$('.open-intro').hide();
$.removeCookie("chiudi");
});
$('.close-intro').click(function() {
$('.nascondi').slideUp();
$('.open-intro').show();
$('.close-intro').hide();
$.cookie("chiudi", 1, { expires : 10 });
});
// -------------------------------------------------------------
// ScrollUp Minimum setup
// -------------------------------------------------------------
(function() {
$.scrollUp();
}());
// -------------------------------------------------------------
// Placeholder
// -------------------------------------------------------------
(function() {
var textAreas = document.getElementsByTagName('textarea');
Array.prototype.forEach.call(textAreas, function(elem) {
elem.placeholder = elem.placeholder.replace(/\\n/g, '\n');
});
}());
// -------------------------------------------------------------
// Show
// -------------------------------------------------------------
(function() {
$("document").ready(function()
{
$(".more-category.one").hide();
$(".show-more.one").click(function()
{
$(".more-category.one").show();
$(".show-more.one").hide();
});
});
$("document").ready(function()
{
$(".more-category.two").hide();
$(".show-more.two").click(function()
{
$(".more-category.two").show();
$(".show-more.two").hide();
});
});
$("document").ready(function()
{
$(".more-category.three").hide();
$(".show-more.three").click(function()
{
$(".more-category.three").show();
$(".show-more.three").hide();
});
});
}());
// -------------------------------------------------------------
// Slider
// -------------------------------------------------------------
(function() {
$('#price').slider();
}());
// -------------------------------------------------------------
// Category Select
// -------------------------------------------------------------
(function() {
$('.category-dropdown').on('click', '.category-change a', function(ev) {
if ($(this).attr('href')==="#") {
ev.preventDefault();
$(this).parents('.dropdown').removeClass('has-error').find('li').removeClass('active');
if($(this).parents('li').index()==0){
$(this).parents('.dropdown').find('.change-text').html($(this).parents('.dropdown').find('.change-text').parent().attr('rel'));
$(this).parents('.dropdown').find('input').val('');
}else{
$(this).parents('.dropdown').find('.change-text').html($(this).html());
$(this).parents('.dropdown').find('input').val($(this).attr('rel'));
$(this).parents('li').addClass('active');
}
//==================================================================================================
// CATEGORY CHANGE - SEARCH RUBRICHE
//==================================================================================================
if($(this).parents('ul').attr('id')=='search_category'){
var ajaxcall = $.ajax({
type: "POST",
//url: "home.php",
data: {
'ajax_option' : 'get_rubriche',
'macro_id' : $(this).attr('rel')
}
}).done(function(out) {
$('#search_rubriche').html(out);
});
$('#macro_id').val($(this).attr('rel'));
// Change the action of the search form
$('#search_form').attr('action','/annunci/'+($(this).attr('rel')===undefined ? '' : arr_macro[$(this).attr('rel')]+'/'));
}
//==================================================================================================
// RUBRICHE CHANGE - UPDATE THE AZIONE ID
//==================================================================================================
if($(this).parents('ul').attr('id')=='search_rubriche'){
if($('#newad').length){
var azione_id = $(this).attr('data-azione-id');
if(azione_id==1 || azione_id==2 || azione_id==3)
$('#tipologia_container').hide();
else
$('#tipologia_container').show();
}
$('#rubrica_id').val($(this).attr('rel'));
}
}else if($(this).attr('href')===""){
ev.preventDefault();
}
});
}());
// SCROLL ON MENU
$(function(){
if($('.scrollbar-inner').length){
jQuery('.scrollbar-inner').scrollbar({
"onInit" : function(){
var max_height = $(window).height() - 100;
$('.scroll-wrapper, .scroll-wrapper > .scroll-content').css('max-height', max_height+'px');
},
"onUpdate" : function(){
// WHEN CLICK THE SCROLLBAR DON'T CLOSE THE MENU (STOP PROGRAGATION OF EVENTS)
$('.scroll-y').on("click", function (e) {
e.stopPropagation();
});
}
});
$(window).resize(function(){
var max_height = $(this).height() - 100;
$('.scroll-wrapper, .scroll-wrapper > .scroll-content').css('max-height', max_height+'px');
});
}
});
// -------------------------------------------------------------
// Search form
// -------------------------------------------------------------
$('#search_form').submit(function(event){
if($('#macro_id').val()==''){
event.preventDefault();
//alert('Please fill the search.');
$('#search-modal').modal();
}
});
// -------------------------------------------------------------
// Tooltip
// -------------------------------------------------------------
(function() {
$('[data-toggle="tooltip"]').tooltip();
}());
// -------------------------------------------------------------
// Accordion
// -------------------------------------------------------------
(function () {
$('.collapse').on('show.bs.collapse', function() {
var id = $(this).attr('id');
$('a[href="#' + id + '"]').closest('.panel-heading').addClass('active-faq');
$('a[href="#' + id + '"] .panel-title span').html('');
});
$('.collapse').on('hide.bs.collapse', function() {
var id = $(this).attr('id');
$('a[href="#' + id + '"]').closest('.panel-heading').removeClass('active-faq');
$('a[href="#' + id + '"] .panel-title span').html('');
});
}());
// -------------------------------------------------------------
// select-category Change
// -------------------------------------------------------------
$('.select-category.post-option ul li a').on('click', function() {
$('.select-category.post-option ul li.link-active').removeClass('link-active');
$(this).closest('li').addClass('link-active');
});
$('.subcategory.post-option ul li a').on('click', function() {
$('.subcategory.post-option ul li.link-active').removeClass('link-active');
$(this).closest('li').addClass('link-active');
});
// -------------------------------------------------------------
// Show Mobile Number
// -------------------------------------------------------------
(function () {
$('.show-number').on('click', function() {
$('.hide-text').fadeIn(500, function() {
$(this).addClass('hide');
});
$('.hide-number').fadeIn(500, function() {
$(this).addClass('show');
});
});
}());
//==================================================================================================
// TOP MENU FIXED ON SCROLL
//==================================================================================================
if($('.home-default').length)
var initial_top = 50;
else if($('.details-page').length)
var initial_top = 132;
else
var initial_top = 162;
$(window).bind('scroll', function () {
if ($(window).scrollTop() >= initial_top) {
var header_height = parseInt($('#header').height()) + 1;
if($('#navbar-collapse.in').height()!==null)
header_height = header_height - parseInt($('#navbar-collapse.in').height()) - 1;
//console.log($('#header').height()+' + '+$('#navbar-collapse.in').height()+' + 2 = '+header_height);
$('.banner').addClass('fixed').css('top',header_height);
} else {
$('.banner').removeClass('fixed');
}
});
$(window).resize(function(){
var header_height = parseInt($('#header').height())-parseInt($('#navbar-collapse.in').height())+2;
$('.banner').addClass('fixed').css('top',header_height);
});
//==================================================================================================
// SIDEBAR FIXED
//==================================================================================================
if($("#sidebar.stick").length && $(window).width()>991){
var offset_top = $("#sidebar").offset().top;
var parent_height = $("#sidebar").parent().height();
$("#sidebar").width($("#sidebar").parent().width());
$(window).on('scroll', function() {
var scrollTop = $(this).scrollTop();
if (scrollTop > 101 && scrollTop < parent_height - $('#sidebar').height() + 101) {
$('#sidebar').removeClass('absolute-bottom').addClass('fixed');
} else if(scrollTop >= parent_height - $('#sidebar').height() + 101){
$('#sidebar').removeClass('fixed').addClass('absolute-bottom');
} else {
$('#sidebar').removeClass('fixed absolute-bottom');
}
});
}
// OLD VERSION OF FIXED SIDEBAR - TO BE DELETED
/*
function displayAllAds(){
//googletag.pubads().refresh([slot1, slot2, slot3], {changeCorrelator: false});
googletag.pubads().refresh([slot1, slot2, slot3]);
}
$(window).resize(function(){
displayAllAds();
});
if($("#sidebar.stick").length && $(window).width()>991){
$("#sidebar").stick_in_parent({
offset_top : 122,
parent: $('#sidebar_content'),
inner_scrolling: false,
//spacer: false,
//bottoming: false
//recalc_every: 1
}).on("sticky_kit:bottom", function(e) {
$('#sidebar').parent().height($('#sidebar_content').height());
displayAllAds();
console.log('BOTTOM');
}).on("sticky_kit:unbottom", function(e) {
displayAllAds();
console.log('UNBOTTOM');
}).on("sticky_kit:stick", function(e) {
displayAllAds();
console.log('STICK');
}).on("sticky_kit:unstick", function(e) {
displayAllAds();
console.log('UNSTICK');
});
$('.col-md-2 .advertisement').stick_in_parent({
offset_top : 122,
parent: $('#sidebar_content'),
inner_scrolling: false,
//spacer: false,
//bottoming: false
//recalc_every: 1
}).on("sticky_kit:bottom", function(e) {
$('.col-md-2 .advertisement').parent().height($('#sidebar_content').height());
displayAllAds();
}).on("sticky_kit:unbottom", function(e) {
displayAllAds();
}).on("sticky_kit:stick", function(e) {
displayAllAds();
}).on("sticky_kit:unstick", function(e) {
displayAllAds();
});
}
googletag.cmd.push(function() { googletag.pubads().refresh(); });
*/
//==================================================================================================
// SIMPLE LIGHT BOX
//==================================================================================================
$(function(){
if($('.details-page').length)
$('.carousel-image a').simpleLightbox();
});
//==================================================================================================
// BANNER FOOTER
//==================================================================================================
if( $.cookie('banner-footer') === undefined )
$('#banner-footer').show();
$('#banner-footer-button').on( "click", function( event ) {
event.preventDefault();
console.log('SLIDING');
$('#banner-footer').slideToggle("fast");
$.cookie("banner-footer", 1, { expires : 1 });
});
// script end
});
// -------------------------------------------------------------
// Owl Carousel
// -------------------------------------------------------------
(function() {
$("#featured-slider").owlCarousel({
items:3,
loop: true,
nav:true,
autoplay:true,
dots:true,
autoplayHoverPause:true,
nav:true,
navText: [
"",
""
],
responsive: {
0: {
items: 1,
slideBy:1
},
500: {
items: 2,
slideBy:1
},
991: {
items: 2,
slideBy:1
},
1200: {
items: 3,
slideBy:1
},
}
});
$("#featured-slider-two").owlCarousel({
items:4,
autoplay:true,
dots:true,
autoplayHoverPause:true,
nav:true,
navText: [
"",
""
],
responsive: {
0: {
items: 1,
slideBy:1
},
480: {
items: 2,
slideBy:1
},
991: {
items: 3,
slideBy:1
},
1000: {
items: 4,
slideBy:1
},
}
});
$(".carousel-indicators").owlCarousel({
autoplay:false,
dots:false,
nav:true,
margin:20,
navText: [
"",
""
],
responsive: {
0: {
items: 3,
slideBy:1
},
480: {
items: 5,
slideBy:1
},
991: {
items: 5,
slideBy:1
},
1000: {
items: 5,
slideBy:1
},
}
});
}());
(function() {
$(".testimonial-carousel").owlCarousel({
items:1,
autoplay:true,
autoplayHoverPause:true
});
}());
(function() {
$(".car-slider").owlCarousel({
items:1,
autoplay:true,
autoplayHoverPause:true
});
}());
// INTRO MODAL
if( $('#intro-modal').length ) {
if( getCookie('intro') !='true' ) {
$('#intro-modal').modal('show');
setTimeout(function () {
$('#intro-modal').modal('hide');
}, 10000);
}
}
$('#intro-modal').on('hidden.bs.modal', function (e) {
console.log('CLOSE');
setCookie('intro',true,1);
})
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}