/*-----------------------------------------------------------------------*/ /*----------------------- JAVASCRIPT STANDARD2 -----------------------*/ /*---------------------------- By IMMOMIG SA ----------------------------*/ /*--------------- JS Sliders ---------------*/ var displayFull = function (value, handler) { var full = handler.siblings('.slider_base').children('.slider_full'); var minInput = handler.siblings('input.min'); var maxInput = handler.siblings('input.max'); var minPos = Number(minInput.val()); var maxPos = Number(maxInput.val()); if (!minPos) { minPos=0; } if (handler.hasClass('min')) { if (value > maxPos && value > minPos) { handler.siblings('.slider_handler').css({left:value}); maxPos = value; full.width(0); transformValues(handler.parent('.slider_box').attr('id'), maxInput, value); } else { full.width(maxPos-value).css({left:value}); } minInput.val(value); transformValues(handler.parent('.slider_box').attr('id'), minInput, value); } else { if (value < minPos && value < maxPos) { handler.siblings('.slider_handler').css({left:value}); minPos = value; full.width(0); transformValues(handler.parent('.slider_box').attr('id'), minInput, value); } else { full.width(value-minPos).css({left:minPos}); } transformValues(handler.parent('.slider_box').attr('id'), maxInput, value); } } var transformValues = function (type, input, val) { input.val(val); var valueMax = input.parent().width()-input.siblings('.slider_handler').outerWidth(); var type = input.parent().attr('id'); var value = (Math.round((val*(slider_options[type]['max']-slider_options[type]['min'])/valueMax)/slider_options[type]['step'])*slider_options[type]['step'])+slider_options[type]['min']; if (slider_options[type]['step_change'] && slider_options[type]['step2'] && value >= slider_options[type]['step_change'] && slider_options[type]['step2']) { value = Math.round(value/slider_options[type]['step2'])*slider_options[type]['step2']; } if (value >= 1000000) { valueDisplay = String(value/1000000)+" Mio"; } else if (type != 'building_year' && type != 'restoration_year' && value >= 1000) { var str = String(value); var nbr = str.length; valueDisplay = ((nbr % 3) ? str.substr(0, nbr % 3) + "'" : '') + str.substr(nbr % 3).match(new RegExp('[0-9]{3}', 'g')).join("'"); } else { var valueDisplay = value + (type == 'yield' ? "%" : ""); } if (value == slider_options[type]['max'] && slider_options[type]['more'] && input.hasClass('max')) { $('input#'+input.attr('id')+'_transformed').val(999999999); if ($('#filter_slider_display_bigger').length) { var bigger = $('#filter_slider_display_bigger').val(); } else { var bigger = ' +'; } input.parent().siblings('.value_display').children('#'+input.attr('id')+'_value').html(valueDisplay+bigger); } else if (value == slider_options[type]['min'] && slider_options[type]['min'] && input.hasClass('min')) { $('input#'+input.attr('id')+'_transformed').val(0); if ($('#filter_slider_display_smaller').length) { var smaller = $('#filter_slider_display_smaller').val(); } else { var smaller = '< '; } input.parent().siblings('.value_display').children('#'+input.attr('id')+'_value').html(smaller+valueDisplay); } else { $('input#'+input.attr('id')+'_transformed').val(value); input.parent().siblings('.value_display').children('#'+input.attr('id')+'_value').html(valueDisplay); } } var displayValues = function (type, input) { var valueMax = input.parent().width()-input.siblings('.slider_handler').outerWidth(); var inputTrans = input.siblings('input#'+input.attr('id')+'_transformed'); var value = ((inputTrans.val()-slider_options[type]['min'])*valueMax)/(slider_options[type]['max']-slider_options[type]['min']); input.val(value); } var displayBaseSliders = function () { $('.slider_box').each(function () { $(this).children('.slider_base').width($(this).width()-($(this).outerWidth()-$(this).width())); }); $('.slider_handler').each(function () { var handler = $(this); if ($(handler.parent().parent()).is(':visible')) { var maxValue = handler.parent().width()-handler.outerWidth(); if (handler.hasClass('min')) { displayValues(handler.parent('.slider_box').attr('id'), handler.siblings('input.min')); var value = Number(handler.siblings('input.min').val()); } else { displayValues(handler.parent('.slider_box').attr('id'), handler.siblings('input.max')); var value = Number(handler.siblings('input.max').val()); } if (value > maxValue) { value = maxValue; } else if (value < 0) { value = 0; } handler.css({left:value}); displayFull(value, handler); } }); $('.search_module .disabled_check').change(function () { disabledCheck = $(this); if(!disabledCheck.attr('checked')) { disabledCheck.parents('.search_module').addClass('inactive'); } else { disabledCheck.parents('.search_module').removeClass('inactive'); } }); $('.search_filter').each(function() { var id = $(this).attr('id'); if ($(this).is(':visible')) { $('#' + id + ' .objects_filter_data').removeAttr('disabled'); } else { $('#' + id + ' .objects_filter_data').attr('disabled', 'disabled'); } }); } var detectMouseOn = function () { $(document).bind('mouseup touchend', function (event) { if (searchObjects.isMouseDown) { searchObjects.submit(); searchObjects.isMouseDown = false; } }); } var sliderHandlersInit = function () { if ($('.slider_box').length) { $(".slider_handler").draggable({ axis: 'x', containment: "parent", drag: function(event, ui) { displayFull(ui.position.left, $(this)); } }); if ($('.slider_base:visible').length) { displayBaseSliders(); } $(window).resize(function () { if ($('.slider_base:visible').length) { $('.slider_base').css({width:"100%"}); displayBaseSliders(); } }); } $( ".module_menu_top > .search_module" ).last().addClass("search_module_last"); detectMouseOn(); $('.slider_handler').not('.no_auto_submit').bind('mousedown touchstart', function (event) { searchObjects.isMouseDown = true; }); // even filters are invisible still can be sent through post, so need to be disabled $('.search_filter').each(function() { var id = $(this).attr('id'); if (!$(this).is(':visible')) { $('#' + id + ' .objects_filter_data').attr('disabled', 'disabled'); } }); } /*----- Page loaded -----*/ $(window).load(function () { if ($('.slider_box').length) { sliderHandlersInit(); } }); /*--------------- Search Objects ---------------*/ var searchObjects = { isMouseDown: false, looadingLocality: false, submit: function (additional_data) { $('#object_filter_page').val('1'); $('#object_filter_ref_id_from_map').val(''); if ('object' === typeof additional_data && additional_data.object_filter_from_map == 1) { $('[name="object_filter_from_map"]').val(1); } else { $('[name="object_filter_from_map"]').val(0); } searchObjects.update(additional_data); }, page: function (page) { $('#object_filter_page').val(page); searchObjects.update(); }, sort: function() { searchObjects.update(); }, map: function(object_ids) { $('#object_filter_ref_id_from_map').val(object_ids); $('#object_filter_page').val('1'); searchObjects.update(); }, update: function (additional_data) { if ($("#object_filter_locality_id").val() != '' && $("#object_filter_categories").val() != '') { $(".save_search_criteria").show(); } if ($('#object_container, #detail_container').hasClass('onloading')) { return; } if ('objects/detail' == $('#untranslated_current_route').val()) { $('#object_filter_from').submit(); return; } $('#object_container, #detail_container').addClass('onloading'); var serialize = $('.objects_filter_data').serialize(); if ('reset' == additional_data) { serialize = $('.default_filter').val(); } else if ('object' === typeof additional_data) { additional_data = '&' + $.param(additional_data); } else { additional_data = ''; } $.post( $('#objects_search_form_action').val(), serialize + additional_data, function (data) { if ('map' == $('#object_filter_view_type').val() && '1' == $('#objects_filter_get_only_coordinates').val()) { googleMap.update(data); } else { if ('map' == $('#object_filter_view_mode').val()) { $('#search_results_map').html(data); $('#object_filter_view_mode').val('mixed'); } else { if ('load_more_button_container' == $('#load_more_button_container').attr('id') && '1' == $('#load_more_button_activated').val()) { $('#load_more_button_container').replaceWith(data); } else { $('#search_results').html(data); } if ('mixed' == $('#object_filter_view_mode').val() && '0' == $('[name="object_filter_from_map"]').val()) { googleMap.update($('#map_coordinates_json').text()); } else if ('list' == $('#object_filter_view_mode').val() && '' != $('#banner_map_canvas').text() && 'mixed' != $('#object_filter_view_mode_saved').val() ) { $('#search_results_map').html(''); } } // update number of objects per country if ('countries_json' == $('#countries_json').attr('id')) { var data = $.parseJSON($('#countries_json').text()); $("label[for^='country_'], #countries_multiselect option").each(function () { $(this).text($(this).text().replace(/\([0-9]+\)/, '(0)')); }); for (id in data) { $('#objects_per_country_' + id).text( $('#objects_per_country_' + id).text().replace('0', data[id].count) ); } $('#update_objects_by_country').removeClass('objects_filter_data'); $("#countries_multiselect").multiselect("refresh"); createJsCheckboxes($("input[name^='multiselect_countries_multiselect']:not(.awesome-checkbox)")); } } if ($('#object_filter_view_mode_saved').length) { if ('' != $('#object_filter_view_mode_saved').val()) { $('#object_filter_view_mode').val($('#object_filter_view_mode_saved').val()); $('#object_filter_view_mode_saved').val(''); } if ('list' != $('#object_filter_view_mode').val() && $("#mixed_display").length) { $('#mixed_display').html("Liste"); } else if ('list' == $('#object_filter_view_mode').val() && !$("#mixed_display").length) { $('.map_display').removeClass('selected'); $('.list_display').addClass('selected'); } else if (('map' == $('#object_filter_view_mode').val() || 'mixed' == $('#object_filter_view_mode').val()) && !$("#mixed_display").length) { $('.list_display').removeClass('selected'); $('.map_display').addClass('selected'); } } $('#object_container, #detail_container').removeClass('onloading'); if ($('#template_name').val() && $('#template_name').val() == 'exquiso') { updateObjects(); } if( $(".animateAtStart").length ){ $(".animateAtStart").removeClass("animateAtStart"); } } ); } } function saveSearchCriteria() { $("#search_criteria_results").hide(); $("#search_criteria_loading").show(); var serialize = $('.objects_filter_data').serialize(); var urlAjax = ajaxURL + "saveSearchCriteria"; $.ajax({ type: "POST", url: urlAjax, data: serialize, success: function(msg) { if (msg != null) { searchCriteriaSaved(msg); } else { return false; } }, error: function() {} }); } function searchCriteriaSaved(msg) { $("#search_criteria_loading").hide(); $("#search_criteria_results").html(msg); $("#search_criteria_results").show(); } /*--------------- JS Checkbox ---------------*/ function createJsCheckboxes (selector, type) { if (!$('body').hasClass('browser_oldIE')) { selector.each(function () { var selectInput = $(this); if (!selectInput.parent('.checkBoxParent').length) { selectInput.wrap('').after(''); if (selectInput.is(':checked')) { selectInput.siblings('.checkBoxDyn').addClass('checked'); } selectInput.css({display:"none"}); } }); $('input:checkbox, input:radio').change(function () { var selectInput = $(this); if (selectInput.attr('type') == 'radio') { var selectInputs = $('input[name='+selectInput.attr('name')+']'); } else { var selectInputs = selectInput; } selectInputs.each(function () { selectInput = $(this); if (selectInput.is(':checked')) { selectInput.siblings('.checkBoxDyn').addClass('checked'); } else { selectInput.siblings('.checkBoxDyn').removeClass('checked'); } }); }); } } function checkBoxDynClick (checkbox) { var selectInput = checkbox.siblings('input'); if (!(selectInput.is(':radio') && $(this).hasClass('checked'))) { if (selectInput.is(':checked')) { checkbox.addClass('checked'); } else { checkbox.removeClass('checked'); } if (!$('body').hasClass('browser_ie9')) { selectInput.click(); } else { selectInput.trigger('click'); } } } /*----- Page loaded -----*/ $(window).load(function () { if ($('input:checkbox:not(.awesome-checkbox):not(.noJsCheckbox), input:radio:not(.awesome-checkbox):not(.noJsCheckbox)').length) { $('input:checkbox:not(.awesome-checkbox):not(.noJsCheckbox)').each(function () { createJsCheckboxes($(this), 'type_checkbox'); }); $('input:radio:not(.awesome-checkbox):not(.noJsCheckbox)').each(function () { createJsCheckboxes($(this), 'type_radio'); }); } }); /*--------------- Responsive popup ---------------*/ function magnificPopupDisableSwipe () { var zoom = document.documentElement.clientWidth / window.innerWidth; if (zoom > 1) { $('.touchscreen .mfp-container.mfp-image-holder').swipe("disable"); } else { $('.touchscreen .mfp-container.mfp-image-holder').swipe("enable"); } } function magnificPopupSwipe (magnificPopup) { $('meta[name="viewport"]').attr('content', 'width=device-width, initial-scale=1'); $('.touchscreen .mfp-container.mfp-image-holder').swipe({ swipeRight:function(event, direction, distance, duration, fingerCount) { if(distance > 50) { magnificPopup.prev(); } }, swipeLeft:function(event, direction, distance, duration, fingerCount) { if(distance > 50) { magnificPopup.next(); } }, threshold:0 }); } function magnificPopupNoSwipe () { $('.touchscreen .mfp-container.mfp-image-holder').swipe("destroy"); $('meta[name="viewport"]').attr('content', 'width=device-width, initial-scale=1, user-scalable=no, maximum-scale=1'); } function magnificPopupScript () { $('.pictures_thumbs').each(function () { $(this).magnificPopup({ delegate: 'a, .pics', type: 'image', gallery: { enabled: true, navigateByImgClick: true, preload: [0,1] }, image: { cursor: null }, callbacks: { open: function() { if (!$('body').hasClass('template_integration2b')) { magnificPopupSwipe(this); } }, beforeClose: function() { if (!$('body').hasClass('template_integration2b')) { magnificPopupNoSwipe(this); } } } }); }); } $(window).load(function () { $('.imagebox').magnificPopup({ type: 'image', gallery: { enabled: true, navigateByImgClick: true, preload: [0,1] }, image: { cursor: null }, callbacks: { open: function() { if (!$('body').hasClass('template_integration2b')) { magnificPopupSwipe(this); } }, beforeClose: function() { if (!$('body').hasClass('template_integration2b')) { magnificPopupNoSwipe(this); } } } }); if ($('body').hasClass('touchscreen')) { window.addEventListener("resize", function () { if (!$('body').hasClass('template_integration2b')) { magnificPopupDisableSwipe(); } }); window.addEventListener("scroll", function () { if (!$('body').hasClass('template_integration2b')) { magnificPopupDisableSwipe(); } }); } }); /*--------------- Login popup ---------------*/ function magnificPopupLoginScript(button_id, redirect_route) { $('#' + button_id).magnificPopup({ type: 'ajax', preloader: false, focus: '#login_name', callbacks: { ajaxContentAdded : function () { magnificPopupLoginScriptCallback(redirect_route); }, open : function () { $(document).off('touchend'); }, close : function () { detectMouseOn(); } }, image: { cursor: null } }); } function magnificPopupLoginScriptCallback(redirect_route) { $('.mfp-content input:checkbox, .mfp-content input:radio').each(function () { createJsCheckboxes($(this)); }); $('#loginform').submit(function (event) { event.preventDefault(); $.post( $('#loginform').attr('action'), $('#loginform').serialize() ).done(function (data, textStatus, jqXHR) { var ct = jqXHR.getResponseHeader("content-type") || ""; if (ct.indexOf('text/plain') > -1 && 'ok' == data) { var redirect = '#current_route'; if (redirect_route) { redirect = '#' + redirect_route; } else { if ('postlogin_redirect' == $('#postlogin_redirect').attr('id')) { redirect = '#postlogin_redirect'; } } window.location.replace($(redirect).val()); } else { $.magnificPopup.open({ items: { src: data, type: 'inline' }, focus: '#login_name' }); magnificPopupLoginScriptCallback(redirect_route); } }); }); } /*--------------- Multi select checklist ---------------*/ function checklist_content (checklist, first) { var list = checklist.siblings('.scroll_checklist_hide').children('.scroll_checklist_content'); var selected = ""; if (first) { checklist.after(''); } var limit = checklist.siblings('.checklist_nbr_limit').val(); var separator = checklist.siblings('.checklist_selected_separator').val(); var prefix = checklist.siblings('.checklist_selected_prefix').val(); var suffix = checklist.siblings('.checklist_selected_suffix').val(); var max_displayed = checklist.siblings('.checklist_selected_max_display').val(); var nbr = 0; var nbr_total = 0; list.children('div:not(.noCountCheck)').find('input[type=checkbox]').each(function () { var checkbox = $(this); if (checkbox.is(':checked')) { if (nbr!=0) { selected += separator; } if (checkbox.parent('.checkBoxParent').length) { checkbox = checkbox.parent('.checkBoxParent'); } selected += prefix+checkbox.siblings('label').html()+suffix; nbr++; } nbr_total++; }); if (nbr == 0) { checklist.html(checklist.siblings('.checklist_button_base').val()); } else if (nbr > limit) { if (max_displayed) { checklist.html(nbr+'/'+nbr_total+checklist.siblings('.checklist_elements_label').val()); } else { checklist.html(nbr+checklist.siblings('.checklist_elements_label').val()); } } else { checklist.html('
'+selected+'
'); } } function checklist_js_scroll(){ var multiIndex=0; if ($('div').hasClass('scroll_checklist_hide')) { $('.scroll_checklist_button, .scroll_checklist_arrow').click(function () { var checklist = $(this).parent(); if (!checklist.hasClass('scroll_checklist_open')) { checklist.addClass('scroll_checklist_open'); $(".scroll_checklist_hide", checklist).stop(true, true).slideDown(); multiIndex++; checklist.css({zIndex:60+multiIndex}); } else { $(".scroll_checklist_hide", checklist).stop(true, true).slideUp(function () { checklist.removeClass('scroll_checklist_open'); checklist.css({zIndex:"1"}); }); } }); } $('.scroll_checklist_dynamic_values .scroll_checklist_hide input[type=checkbox]').change(function () { var checklist = $(this).parents('.scroll_checklist_hide').siblings('.scroll_checklist_button'); if (!checklist.hasClass('no_list_selected')) { checklist_content(checklist, false); } }); } /*----- Page loaded -----*/ $(window).load(function () { if ($('.scroll_checklist').length) { checklist_js_scroll(); $('.scroll_checklist_dynamic_values .scroll_checklist_button').each(function () { if (!$(this).hasClass('no_list_selected')) { checklist_content($(this), true); } }); } }); function responssiveMulstiselect(){ if( !$(".filter_top").length && !$(".forceClose").length ){ } if( $(window).width() < 800 && $(window).width() > 580 ){ $("#categories .scroll_checklist_dynamic_values").addClass("categories_close"); $("#categories .scroll_checklist_dynamic_values").removeClass("categories_open"); }else{ $("#categories .scroll_checklist_dynamic_values").addClass("categories_open"); $("#categories .scroll_checklist_dynamic_values").removeClass("categories_close"); } } /*----- document ready -----*/ $(document).ready(function () { responssiveMulstiselect(); $(window).resize(function () { responssiveMulstiselect(); }); }); /*--------------- Search criterias ---------------*/ var digits = "0123456789"; var manage_objects_delete = 'Supprimer'; function stripCharsNotInBag_ (s, bag) { var i; var returnString = ""; for (i = 0; i < s.length; i++) { /* Check that current character isn't whitespace. */ var c = s.charAt(i); if (bag.indexOf(c) != -1) { returnString += c; } } return returnString; } function checkPriceFormat() { var valoare = arguments[0].value; var limit = arguments[1]; if (limit < 1) { limit = 100; } var sir = stripCharsNotInBag_(new String(valoare), new String(digits)).valueOf(); sir = sir.substr(0, limit); sirrev = sir.split("").reverse(); var arfin = new Array(); for (i = 0; i < sirrev.length; i++) { if (i > 0 && i % 3 == 0) { arfin[i] = sirrev[i] + "'"; } else { arfin[i] = sirrev[i]; } } sirfin = arfin.reverse().join(""); arguments[0].value = sirfin; } var displayLocation = function (action, tab_id) { var prefix = 'locality'; if (action == 'include'){ prefix = 'locality_include'; } var radius = 0; radius = ($('#' + prefix + '_radius_id_'+tab_id).val()); var id = $('#' + prefix + '_id_'+tab_id).val(); var label = $('#' + prefix + '_label_'+tab_id).val(); if (id != ''){ data = action + '_' + tab_id + '[\'' + id + '\']'; var duplicate = $('#' + action + '_' + id + '_' + tab_id + '_p').val(); if (typeof(duplicate) == "undefined"){ var text = '

'; text += ''; text += ''; text += label; if (radius != 0) { text += ' + ' + radius + ' km'; } text += ' '+manage_objects_delete+'' text += '

'; $('#' + action + 'dLocationsContainer_'+tab_id).append(text); } } $('#' + 'object_filter_' + prefix +'_'+tab_id).val(''); $.each( ['_id','_label'], function(i, l){ $('#' + prefix + l + '_' + tab_id).val(''); }); $('#' + prefix + '_radius_id_' + tab_id).val(0); } var hiddeLocation = function (id) { $('#' + id + '_p').remove(); } var localityToInclude = function(action, tab_id) { localityToExclude(action, 'include', tab_id); } var localityToExclude = function(action, what, tab_id) { if (what == 'include') { var infix = 'include_'; var prefix = 'include'; } else { var infix = ''; var prefix = 'exclude'; var what = ''; } var usersObjectsId = tab_id; var doThis = ''; var posteId = ''; var radius = 0; if(0 == action) {//Add new locality doThis = 'add'; posteId = $('#locality_' + infix + 'id_'+tab_id).val(); radius = $('#locality_' + infix + 'radius_id_'+tab_id).attr('value'); } else if(0 < action) { doThis = 'delete'; posteId = action; } var regions = 2; $.getJSON($("#locality_to_excluded_url").val() ,{usersObjectsId: usersObjectsId, localityAction: doThis, posteId: posteId, radius: radius, what: what, regions: regions, noadmin: 1}, function(rsp){ var msg = rsp.split("|"); var canBeDeleted = msg[0]; var j = jQuery.parseJSON(msg[1].replace('\\"','\"')); data = prefix + '[\'' + posteId + '\']'; var table = ''; for (var i = 0; i < j.length; i++) { data = prefix + '_' + tab_id + '[\'' + j[i].npa + '\']'; if (j[i].radius > 0) { var text_radius = ' + ' + j[i].radius + ' km'; } else { var text_radius = ''; } table += '' + '' + '' + '' + '' table += ''; } table += '
' + manage_objects_delete + '
'; $("#" + prefix + "dLocationsContainer_"+tab_id).html(table); }); } $(window).load(function () { if ($('.manage_objects_delete').length) { manage_objects_delete = $('.manage_objects_delete').val(); } $('input[id^="object_filter_locality_include_"]').each(function() { var id = $(this).attr("id").replace('object_filter_locality_include_', ""); if ('newcriteria' != id) { localityToInclude(-1, id); localityToExclude(-1, '', id); } }); if ($('#searchcriteria_container').length) { $('.searchcriteria_title h3, .searchcriteria_title .arrow').click(function () { var searchcriteria = $(this).parent('.searchcriteria_title'); if (searchcriteria.hasClass('searchcriteriaOn')) { searchcriteria.removeClass('searchcriteriaOn'); searchcriteria.siblings('.searchcriteria_box_content').hide(); } else { searchcriteria.addClass('searchcriteriaOn'); searchcriteria.siblings('.searchcriteria_box_content').show(); } }); $('#new_criteria').click(function () { $('#new_criteria_submit').val(1); var counter = 1; $('.selectedproposition_box').each(function () { if (counter > 1) { $(this).children('.selectedpropositionOn').click(); } counter++; }); $('.searchcriteria_title ').removeClass('searchcriteriaOn'); $('.searchcriteria_box_content').hide(); $('#inscription_table_newcriteria').show(); $('#inscription_table_newcriteria').find('.searchcriteria_title ').addClass('searchcriteriaOn'); $('#inscription_table_newcriteria').find('.searchcriteria_box_content').show(); $('#new_criteria').hide(); }); $('.searchcriteria_title .delete_filter').click(function () { var id = $(this).attr('id'); if (id != '') { var delete_button = $(this); delete_button.parents('.searchcriteria_box').hide(); var url = "/fr/ajax/deleteSearchCriteria/"+ id; $.ajax({ type: 'GET', url: url, success: function(msg) { }, error: function () { $('#messages').empty(); $('#messages').addClass('error'); $('#messages').append('Erreur lors du transfert de données'); } }); } }); } }); var locality_cache = {}; var localityAutocompleteSource = function(request, response) { var term = request.term; if (typeof $("#not_cache_location_filter").val() === 'undefined' || !$("#not_cache_location_filter").val()) { if ( term in locality_cache ) { response( locality_cache[ term ] ); return; } } var country_ids = new Array(); if ($("input[name^='object_filter_country']:checked").length) { $("input[name^='object_filter_country']:checked").each(function() { country_ids.push($(this).val()); }); } else if ($('#custom_countries').val() == '1') { country_ids.push(''); } else { $("input[name^='object_filter_country']").each(function() { country_ids.push($(this).val()); }); } $.getJSON( $('#locality_source_url').val(), { q: request.term, "country": country_ids.join() }, function( data, status, xhr ) { locality_cache[ term ] = data; searchObjects.looadingLocality = true; response( data ); searchObjects.looadingLocality = false; }); } var localityAutocompleteInit = function() { // source url must be there: if ('locality_source_url' != $('#locality_source_url').attr('id')) { return; } /* Search filter */ $("#object_filter_locality").autocomplete({ minLength: 2, source: localityAutocompleteSource, autoFocus: true, select: function( event, ui ) { if (ui.item) { $('#object_filter_locality_id').val(ui.item.id); $('#object_filter_locality').val(ui.item.label); } else { $('#object_filter_locality_id').val(''); } $('#slider_radius_containder').removeClass('hide'); $('#location_search').removeClass('radius_hidden'); var default_radius = $('#default_radius').val(); $('#radius_max_transformed').val(default_radius); displayBaseSliders(); searchObjects.submit(); return false; } }); $('#object_filter_locality').keyup(function() { locality_cache = {}; if ("" == $(this).val() && "" != $('#object_filter_locality_id').val()) { $('#object_filter_locality_id').val(''); $('#slider_radius_containder').addClass('hide'); $('#location_search').addClass('radius_hidden'); searchObjects.submit(); } }); $('#object_filter_locality').keypress(function(e) { if (e.keyCode == 13 && searchObjects.looadingLocality) { searchObjects.submit(); } }); /* Search criteria */ $('input[id^="object_filter_locality_"]').autocomplete({ minLength: 2, source: localityAutocompleteSource, select: function( event, ui ) { var name_fix = ''; if (0 == $(this).attr('id').indexOf('object_filter_locality_include_')) { name_fix = '_include'; } $('#locality' + name_fix + '_id_' + $(this).attr("id").replace('object_filter_locality' + name_fix + '_', "")).val(ui.item.id); $('#locality' + name_fix + '_label_' + $(this).attr("id").replace('object_filter_locality' + name_fix + '_', "")).val(ui.item.label); /*if (ui.item) { $('#object_filter_locality_id').val(ui.item.id); } else { $('#object_filter_locality_id').val(''); }*/ } }); /* Home page searchbox */ $('.searchbox_filter_locality').keyup(function(input) { var object_filter_locality_id = $(this).siblings("[name='object_filter_locality_id']").eq(0); if ("" == $(this).val() && "" != object_filter_locality_id.val('')) { object_filter_locality_id.val(''); } }); $('.searchbox_filter_locality').not(".ui-autocomplete-input").autocomplete({ minLength: 2, source: localityAutocompleteSource, select: function( event, ui ) { var object_filter_locality_id = $(this).siblings("[name='object_filter_locality_id']").eq(0); if (ui.item) { object_filter_locality_id.val(ui.item.id); $('input[name=object_filter_locality]').val(ui.item.label); } else { object_filter_locality_id.val(''); } return false; } }); } $(function() { localityAutocompleteInit(); }); /*--------------- Agency propositions ---------------*/ $(window).load(function () { if ($('.agencypropositions_title').length) { $('.agencypropositions_title').click(function () { var agencypropositions = $(this); if (agencypropositions.hasClass('agencypropositionsOn')) { agencypropositions.removeClass('agencypropositionsOn'); agencypropositions.siblings('.agencypropositions_box_content').hide(); } else { agencypropositions.addClass('agencypropositionsOn'); agencypropositions.siblings('.agencypropositions_box_content').show(); } }); } }); /*--------------- Checkbox all categories ---------------*/ $(window).load(function () { if ($('input[class^=cat_]').length) { $('input[class^=cat_]').click(function () { var allCat = $(this); if (allCat.is(':checked')) { $('input.sub'+allCat.attr('class')).prop('checked', true).change(); } else { $('input.sub'+allCat.attr('class')).prop('checked', false).change(); } }); $('input[class^=subcat_]').click(function () { var subCat = $(this).attr('class'); var allSubCat = $('.'+subCat); var allCat = $('.'+subCat.substring(3)); var allChecked = true; allSubCat.each(function () { if (!$(this).is(':checked')) { allChecked = false; return false; } }); if (allChecked) { allCat.prop('checked', true).change(); } else { allCat.prop('checked', false).change(); } }); } }); /*--------------- Banner slide ---------------*/ $(window).load(function () { if($('.banner_picture').length > 1){ slide_home = countBanner = 0; $('#banner_img, .banner_img').each(function(){ if( $(this).hasClass("banner_img") ){ countBanner++; $(this).attr("id", "banner_img_"+countBanner); } var banner = $(this); var header_actu = 0; var target = 0; var header_total= banner.find('.banner_picture').length; var speed = banner.find('input[name="banner_speed"]').val(); var time_banner = null; var slide_home = function(target, auto, transition_speed) { clearTimeout(time_banner); if (auto && header_actu+1 < header_total) { target=header_actu+1; } else if (auto) { target=0; } if (target!=header_actu) { banner.find('.banner_picture').stop(true, true); banner.find('#banner_picture_'+header_actu).stop(true, true).css({zIndex:header_total+1}); banner.find('#banner_picture_'+target).stop(true, true).css({zIndex:header_total}); banner.find('#banner_picture_'+header_actu).fadeOut(transition_speed, function () { banner.find('.banner_picture:not(#banner_picture_'+target+')').css({zIndex:1}); banner.find('#banner_picture_'+target).css({zIndex:header_total+2}); $(this).css({zIndex:1}).show(); time_banner = setTimeout(function () {slide_home(false, true, 2000);}, speed); }); header_actu=target; } else { time_banner = setTimeout(function () {slide_home(false, true, 2000);}, speed); } $('.banner_bullet').removeClass('selected'); $('#bullet_'+target).addClass('selected'); } time_banner = setTimeout(function () {slide_home(false, true, 2000);}, speed); /*----- Bullets -----*/ if (banner.find('.banner_bullets').length) { banner.find('.banner_bullet').click(function(){ slide_home(Number($(this).attr('id').substr(7)), false, 1000); }); } /*----- Touchswipe for touchscreen -----*/ if ((banner.find('#banner_touchswipe').val() == 'true' || banner.find('#banner_touchswipe').val() == true) && $('body').hasClass('touchscreen')) { banner.swipe({ swipeRight:function(event, direction, distance, duration, fingerCount) { if(distance > 100) { if (header_actu - 1 >= 0) { var target = header_actu - 1; } else { var target = header_total - 1; } slide_home(target, false, 500); } }, swipeLeft:function(event, direction, distance, duration, fingerCount) { if(distance > 100) { slide_home(false, true, 500); } }, threshold:0 }); } }); } }); /*--------------- Form source other ---------------*/ $(window).load(function () { if ($('#sources_other').length) { var source_other = function () { if ($('#sources').val() == "51" || $('#source_51').is(':checked')) { $('#sources_other').show(); } else { $('#sources_other').hide(); } } source_other(); $('#sources').change(function () { source_other(); }); } }); function showknownelementR(box){ if (box.value == '51'){ $('#sources_othertxt:not(.placeholder_other)').val('Veuillez préciser svp !'); $('#sources_othertxt').show(); } else { $('#sources_othertxt').val(''); $('#sources_othertxt').hide(); } } /*--------------- Tooltip ---------------*/ $(window).load(function () { if ($('.tooltip').length) { $('.touchscreen .tooltip:not(input), .notouchscreen .tooltip').tooltip({ track: true, content: function () { return $(this).prop('title'); } }); } }); /*--------------- Navigation sub menu ---------------*/ $(window).load(function () { if ($('.submenu_parent').length && !$('body').hasClass('browser_oldIE')) { $('.submenu_title').mouseover(function () { if (submenu_active) { $(this).parents('.submenu_parent').addClass('submenu_open'); $(this).parents('.submenu_parent').find('.submenu_content2').stop(true, true).slideDown(); } }); $('.submenu_parent').hover(function () { }, function () { if (submenu_active) { $(this).removeClass('submenu_open'); $(this).find('.submenu_content2').stop(true, true).slideUp(); } }); $('.submenu_parent').click(function () { if (submenu_active) { if (!$(this).find('.submenu_content').is(':visible')) { $(this).addClass('submenu_open'); $(this).find('.submenu_content2').stop(true, true).slideDown(); } else { $(this).removeClass('submenu_open'); $(this).find('.submenu_content2').stop(true, true).slideUp(); } } }); var submenu_active = true; var submenu_disabled_mobile = function () { if ($('.navigation_mobile').is(':visible')) { submenu_active = false; } else { submenu_active = true; } } submenu_disabled_mobile(); $(window).resize(function () { submenu_disabled_mobile(); }); } }); /*--------------- Picture détail size ---------------*/ var resizePicture = function () { $('.pictures_zoom:visible').each(function () { var imagebox = $(this); var mainImage = $(this).find('#mainimage'); var baseWidth = Number($(this).find('.picture_size_zoom_width').val()); var baseHeight = Number($(this).find('.picture_size_zoom_height').val()); if (mainImage.width() <= baseWidth) { mainImage.css({ height:(imagebox.width()*baseHeight/baseWidth), minHeight:(imagebox.width()*baseHeight/baseWidth), marginBottom:10 }); } else { $('#mainimage').css({ height:baseHeight, minHeight:baseHeight, marginBottom:0 }); } }); } $(window).load(function () { if ($('#detail_container').length) { resizePicture(); $(window).resize(function () { resizePicture(); }); } if ($('.nbr_pictures_mobile').length) { $('.nbr_pictures_mobile').each(function(){ var nbr_pictures_mobile = $(this); nbr_pictures_mobile.insertAfter(nbr_pictures_mobile.parents('.pictures_zoom').find('img')); }); } }); /*--------------- Detail pictures thumbs slide ---------------*/ var defineSlideSize = function () { $('.pictures_thumbs:not(.home_slider_objects):not(.owl-carousel)').each(function () { var picMask = $(this); if (picMask.children('.image_preview').length) { var picSlide = picMask.children('.image_preview'); var mask_size = picMask.width(); var slide_size = picSlide.width(); if (slide_size > mask_size) { picMask.siblings('.pictures_slide_arrow_right').show(); picMask.removeClass('pics_thumbs_no_slide'); } else { picMask.siblings('.pictures_slide_arrow').hide(); picSlide.css({marginLeft:0}); picMask.addClass('pics_thumbs_no_slide'); } if (picSlide.css('marginLeft').replace('px', '') < mask_size-slide_size && picSlide.width() > mask_size) { picSlide.css({marginLeft:mask_size-slide_size}) } picMask.height(picSlide.height()); } }); } $(window).load(function () { if ($('.pictures_thumbs #gallery_points').length) { var interval = setInterval; defineSlideSize(); $(window).resize(function () { defineSlideSize(); }); var stopSlide = function () { clearInterval(interval); $('.image_preview').stop(true, true); } $('.pictures_slide_arrow_right').hover(function () { var arrow = $(this); var otherArrow = arrow.siblings('.pictures_slide_arrow_left'); var picSlide = arrow.siblings('.pictures_thumbs').find('.image_preview'); var mask_size = arrow.siblings('.pictures_thumbs').width(); var slide_size = picSlide.width(); interval = setInterval(function () { if (picSlide.css('marginLeft').replace('px', '') > mask_size-slide_size) { picSlide.animate({marginLeft:"-=2px"}, 0, 'linear'); if (otherArrow.not(':visible')) { otherArrow.fadeIn(); } } else { stopSlide(); arrow.fadeOut(); } }, 5); }, function () { stopSlide(); }); $('.pictures_slide_arrow_left').hover(function () { var arrow = $(this); var otherArrow = arrow.siblings('.pictures_slide_arrow_right'); var picSlide = arrow.siblings('.pictures_thumbs').find('.image_preview'); interval = setInterval(function () { if (picSlide.css('marginLeft').replace('px', '') < 0) { picSlide.animate({marginLeft:"+=2px"}, 0, 'linear'); if (otherArrow.not(':visible')) { otherArrow.fadeIn(); } } else { stopSlide(); arrow.fadeOut(); } }, 5); }, function () { stopSlide(); }); } }); /*--------------- Project detail table ---------------*/ $(window).load(function () { if ($('.project_row').length) { var url = window.location.href; var row_id = ''; if (url.indexOf("#") >= 0) { var res = url.split("#"); row_id = res[1]; } if (row_id != '') { var row_content_id = $("#detail_"+row_id); if ($("#"+row_id).hasClass('project_row_closed')) { $("#"+row_id).removeClass('project_row_closed').addClass('project_row_open'); row_content_id.removeClass('project_detail_closed').addClass('project_detail_open'); $('html, body').animate({ scrollTop: $("#"+row_id).offset().top - $("#"+row_id)[0].offsetHeight }, 2000); defineSlideSize(); resizePicture(); } } $(".project_row").click(function () { var projectRow = $(this); if (projectRow.hasClass('project_row_closed')) { projectRow.removeClass('project_row_closed').addClass('project_row_open'); $('#detail_'+projectRow.attr('id')).removeClass('project_detail_closed').addClass('project_detail_open'); defineSlideSize(); resizePicture(); } else { projectRow.removeClass('project_row_open').addClass('project_row_closed'); $('#detail_'+projectRow.attr('id')).removeClass('project_detail_open').addClass('project_detail_closed'); } }); } }); /*--------------- Menu Mobile ---------------*/ $(window).load(function () { $('.navigation_mobile').click(function () { var navig = $(this); var navigation = $(this).parents('#navigation'); if (!navig.hasClass('navigation_mobile_open')) { navig.addClass('navigation_mobile_open'); navigation.addClass('navigation_is_open'); navig.siblings('.navigation_content').stop(true, true).slideDown(); $('#menu_top').slideDown(); if( $(".anim_menu_mobile").length ){ $(".crossOff").addClass("cross"); } if( $(".nav_fixed_on_top").length && $("#navigation .center_content").css("position") != "fixed" ){ $('html, body').animate({ scrollTop:$("#navigation").offset().top+1 }, 'fast'); } } else { navig.siblings('.navigation_content').stop(true, true).slideUp(function(){ navig.removeClass('navigation_mobile_open'); navigation.removeClass('navigation_is_open'); }); $('#menu_top').slideUp(); if( $(".anim_menu_mobile").length ){ $(".crossOff").removeClass("cross"); } } }); var menu_mobile_disabled = function () { if ($('.navigation_mobile').length) { if ($('.navigation_mobile').is(':visible')) { $('.navigation_mobile').removeClass('navigation_mobile_open'); $('#navigation').removeClass('navigation_is_open'); $('.navigation_content, #menu_top').hide(); if( $(".anim_menu_mobile").length ){ $(".crossOff").removeClass("cross"); } } else { $('.navigation_content, #menu_top').attr('style', ''); } } } var refreshMultiSelects = function () { if ($(".multiselect").length) { $(".multiselect").multiselect('refresh'); $(".multiselect").multiselect('close'); } } $('#filter_title_mobile').click(function () { var navig = $(this); if (!navig.hasClass('filter_mobile_open')) { navig.addClass('filter_mobile_open'); navig.siblings('#filter_content_mobile').stop(true, true).slideDown(function(){ displayBaseSliders(); refreshMultiSelects(); }); } else { navig.removeClass('filter_mobile_open'); navig.siblings('#filter_content_mobile').stop(true, true).slideUp(); } }); var filter_mobile_disabled = function () { if ($('#filter_title_mobile').is(':visible')) { $('#filter_title_mobile').removeClass('filter_mobile_open'); $('#filter_content_mobile').hide(); } else { $('#filter_content_mobile').attr('style', ''); refreshMultiSelects(); } } menu_mobile_disabled(); filter_mobile_disabled(); var windowWidth = $('body').width(); $(window).resize(function () { if ($('body').width() != windowWidth) { windowWidth = $('body').width(); menu_mobile_disabled(); filter_mobile_disabled(); refreshMultiSelects(); } }); }); function reloadCaptchaImage() { var captcha = $('#captcha_image'); var img_src = captcha.attr('src'); img_src = img_src.replace(/\?.*$/, '') + '?' + Math.random(); captcha.attr('src', img_src); if (captcha.hasClass('tooltip')) { captcha.attr('title', ""); $('#captcha_zoom').attr('title', ""); } } /*----- Page loaded -----*/ $(window).load(function () { $('#captcha_zoom').click(function(){ var row = $(this).parents('.row'); if (row.hasClass('big_captcha')) { row.removeClass('big_captcha'); } else { row.addClass('big_captcha'); } }); }); var searchPromotions = { submit: function () { searchPromotions.update(); }, page: function (page) { $('#object_filter_page').val(page); searchPromotions.update(); }, update: function () { $.post( $('#promotions_form_action').val(), $('.objects_filter_data').serialize(), function (data) { $('#promotion_special_container').html(data); $('.status_box input:checkbox').each(function() { createJsCheckboxes($(this)); }); } ); } } /*--------------- Favorite ---------------*/ function favorite_onmouseover(id) { $('#' + id).addClass("favoriOver"); } function favorite_onmouseout(id) { $('#' + id).removeClass("favoriOver"); } function toggle_favorite(object_id, lang, label_add, label_delete, url) { var action = ''; var update_count_favorites = false; if ($(".favoriOn.favoriOver").length) { action = 'remove'; } else { action = 'add'; } $.ajax({ type : 'POST', url : '/' + lang + '/objects/favorites/' + action + '/' + object_id, success: function(msg) { var data = $.parseJSON(msg); if ('added_successfully' == data['message']) { $("#favorite_" + object_id).addClass("favoriOn"); if (data['button_label'] && (typeof url !== 'undefined')) { $("a#favorite_" + object_id).text(data['button_label']); } if (typeof label_delete !== 'undefined') { $("#overlib_" + object_id).html(label_delete); } update_count_favorites = true; } else if ('removed_successfully' == data['message']) { if ($("#web_favorites_objects_list").val() == 1) { searchObjects.submit(); } else { $("#favorite_" + object_id).removeClass("favoriOn"); if (data['button_label'] && (typeof url !== 'undefined')) { $("a#favorite_" + object_id).text(data['button_label']); } } if (typeof label_add !== 'undefined') { $("#overlib_" + object_id).html(label_add); } update_count_favorites = true; } else if ('' != data['message']) { alert(data['message']); } if ($('#favorites_count').length && update_count_favorites) { var html_text = (data['count_favorites'] ? ' (' + data['count_favorites'] + ')' : ''); $('#favorites_count').text(html_text); } } }); } /*--------------- Recommend popup ---------------*/ function magnificObjectRecommendScript() { $('.recommend_popup_button').magnificPopup({ type: 'ajax', preloader: false, callbacks: { ajaxContentAdded : function () { magnificObjectRecommendCallback(); }, open : function () { $(document).off('touchend'); }, close : function () { detectMouseOn(); } } }); } function magnificObjectRecommendCallback() { $('#form_recommend').submit(function (event) { event.preventDefault(); $.post( $('#form_recommend').attr('action'), $('#form_recommend').serialize() ).done(function (data) { $.magnificPopup.open({ items: { src: data, type:'inline' } }); magnificObjectRecommendCallback(); }); }); } /*----- Page loaded -----*/ $(window).load(function () { /*------------------- Social Share button detail--------------------------*/ if ($('.share_container').length) { if(!$('.shared_link_container').hasClass('no_button')){ $('.share_container').hover(function() { $( ".shared_link_container" ).stop().fadeIn( "slow"); }, function(){ if(!$('.shared_link_container').hasClass('open')){ $('.shared_link_container').stop().fadeOut( "fast"); } }); $('.share_container').click(function() { if($('.shared_link_container').hasClass('open')){ $('.shared_link_container').fadeOut('fast'); $('.shared_link_container').removeClass('open'); }else{ $('.shared_link_container').addClass('open'); $('.shared_link_container').fadeIn('fast'); } }) } } }); /*--------------- Youtube popup ---------------*/ $(window).load(function () { if ($('#youtube_button.youtube_popup').length) { $('#youtube_button.youtube_popup').magnificPopup({ type: 'iframe' }); } }); /*--------------- Navigation sub menu ---------------*/ $(window).load(function () { if ($("#detail_container .contact_form_include").length) { $('.button.show_contact_form').click(function () { if (!$('.contact_form_include').is(':visible')) { $(this).addClass('contact_form_open'); $('.contact_form_include').stop(true, true).slideDown(); } else { $(this).removeClass('contact_form_open'); $('.contact_form_include').stop(true, true).slideUp(); } }); } }); /*--------------- Tooltip ---------------*/ $(window).ready(function () { if ($('.open_contact_visit').length) { $('.open_contact_visit').click(function(){ $(this).hide(); $(this).parents(".buttons_box").hide(); $(this).parents(".visit_box").find(".hideContentVisite").fadeIn(500); }); } });