"); $("#searchForm").trigger('submit'); }else{ // If not has forceSubmit, then, a button appears $(".searchSidebar__top").addClass("searchSidebar__top--submitBtn"); }}function toggleForm(){ $(".searchEngine__filters").toggleClass("-active-");}Url = { get get(){ var vars= {}; if(window.location.search.length!==0) window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value){ key=decodeURIComponent(key); if(typeof vars[key]==="undefined") {vars[key]= decodeURIComponent(value);} else {vars[key]= [].concat(vars[key], decodeURIComponent(value));} }); return vars; }};$(document).ready(function(){ /* ONLOAD */ $(window).load(function () { $('main').animate({opacity: "1"}, 500); }); /* HANDLERS */ // VIEW switcher var all_view_option = $(".fn-viewsSwitch input"), property_block_parent = $('.searchEngine'); // property_block_parent = $(".propertyBlock").closest('.propertiesList'); all_view_option.each(function(){ var view_option = $(this); view_option.on('change',function(){ o = $(this); // Set & apply view view = o.val(); document.cookie="view="+view; property_block_parent.removeClass("listado fotos"); property_block_parent.addClass(view); $('.searchEngine__filters').removeClass('-active-'); $('.fotos .searchEngine__filters').css('transition', 'none'); }); }); $(".openFiltersBtn, .searchSidebar .js-filters, .back-btn").click(function(){ $(".searchEngine__filters").toggleClass("-active-"); }); /*--- searchMain__sort - order search dropdown ---*/ // ORDER BY $('#ob_select').on('change',function(){ var o = $(this); if($('#ob_hidden').length > 0){ $('#ob_hidden').val(o.val()); $('#ob_hidden').change(); } }); // orderby - Mobile /* open/close */ $('.js-sortTitle').bind('click', function(e){ if( $('.js-sortList').is(':hidden') ){ $('.js-sortList').slideDown(); e.stopPropagation(); }else{ $('.js-sortList').slideUp(); } }); /* close on click away */ $(document).on('click', function(e){ var container = $('.js-sortList'); if (!container.is(e.target) && container.has(e.target).length === 0){ container.slideUp(); } }); /* update order on select */ $('.js-sortList > div').click(function(){ $("#ob_hidden").val($(this).data("order")); $("#searchForm").submit(); }); // PRICE - range $("[data-check-range]").each(function(){ $(this).data('pre',$(this).val()); }); // Check if range inputs correspond among themselves function checkRangeSelect(o){ var dataCheckRange = o.data('check-range'); if(typeof dataCheckRange !== typeof undefined && dataCheckRange !== false){ var parent = o.closest('.fn-check-range'), o_pre_val = parseInt(o.data('pre')), o_min_val = parseInt($("[data-check-range='min']",parent).val()), o_max_val = parseInt($("[data-check-range='max']",parent).val()); if(o_min_val == 0 || o_max_val == 0){ return true; }else if(o_min_val > o_max_val){ o.val(o_pre_val); o.change(); return false; }else if(o_min_val != 0 && o_max_val != 0 && o_min_val == o_max_val){ return false; }else{ return true; } }else{ return true; } } // PRICE FROM - select $('[name="pf"]').on('change', function(){ var price_from_value = $(this).children(":selected").val(); /* Adjust search-surface-to options based on selected */ $('[name="pt"]').children("option").show(); $('[name="pt"]').children("option").each(function(){ var option = $(this); if((parseInt(option.val()) <= parseInt(price_from_value))){ option.hide(); } }); //searchSubmit($(this)); $('[name="pt"]').trigger("chosen:updated"); }); // PRICE TO - select $('[name="pt"]').on('change', function(){ var price_to_value = $(this).children(":selected").val(); /* Adjust search-surface-to options based on selected */ $('[name="pf"]').children("option").show(); $('[name="pf"]').children("option").each(function(){ var option = $(this); if((parseInt(option.val()) >= parseInt(price_to_value))){ option.hide(); } }); //searchSubmit($(this)); $('[name="pf"]').trigger("chosen:updated"); }); // SURFACE FROM - select $('[name="sf"]').on('change', function(){ var surface_from_value = $(this).children(":selected").val(); /* Adjust search-surface-to options based on selected */ $('[name="st"]').children("option").show(); $('[name="st"]').children("option").each(function(){ var option = $(this); if((parseInt(option.val()) <= parseInt(surface_from_value))){ option.hide(); } }); //searchSubmit($(this)); $('[name="st"]').trigger("chosen:updated"); }); // SURFACE TO - select $('[name="st"]').on('change', function(){ var surface_to_value = $(this).children(":selected").val(); /* Adjust search-surface-to options based on selected */ $('[name="sf"]').children("option").show(); $('[name="sf"]').children("option").each(function(){ var option = $(this); if((parseInt(option.val()) >= parseInt(surface_to_value))){ option.hide(); } }); //searchSubmit($(this)); $('[name="sf"]').trigger("chosen:updated"); }); /* APPLYING CHOSEN */ // Apply 'chosen' style to selects $(".fn-chosen").each(function(){ var o = $(this); o.chosen({ disable_search: true, no_results_text: "No results", width: '100%' }); o.on('chosen:showing_dropdown', function() { o.next('.chosen-container').children('.chosen-drop').slideDown(200); }); o.on('chosen:hiding_dropdown', function () { o.next('.chosen-container').children('.chosen-drop').slideUp(200); }); }); // Has to be placed BEFORE fn-refreshForm handler $('.filters__typesInput').change(function(){ var o = $(this); // All types checked if(o.hasClass('filters__typesInput--alltypes') && o.is(':checked')){ $('.filters__typesInput').not(this).prop('checked',''); } // Other types checked if(!o.hasClass('filters__typesInput--alltypes') && o.is(':checked')){ $('.filters__typesInput--alltypes').prop('checked',''); } }); // To check if there are group types selector if($(".fn-searchtypegroup").length){ $('.fn-searchtypegroup + .chosen-container, .fn-searchtypegroup').on('change', function(e){ typegroup = $(this); searchTypeGroupUpdate(typegroup); }); } $('.filters__checklistOption label').click(function(){ o = $(this); el_for_attr = o.attr('for'); el = $('i', o); if(el_for_attr.indexOf("all") >= 0 ){ $('.filters__checklistOption label:not([for^="all_"]) i').removeClass('fa-check-square').addClass('fa-square-o'); } el.toggleClass('fa-check-square fa-square-o'); }); // Advanced search toggle Open/Close $('.fn-toggleAdvancedSearch').click(function(e){ e.preventDefault(); $('.filters__advancedFilters').slideToggle(); $('.filters__advancedFilters input, .filters__advancedFilters select').val(0).removeAttr('checked'); }); if($('#searchForm').length > 0){ //var reset_multiple_ar = "
", var reset_multiple_zn = "", reset_custom_zn = reset_multiple_zn, reset_select_zn = "
", reset_multiple_ar = "", reset_custom_ar = reset_multiple_ar, reset_select_ar = "
", reset_multiple_lc = "
", reset_custom_lc = reset_multiple_lc, reset_select_lc = "
", /* reset_multiple_dg = "
", reset_custom_dg = reset_multiple_dg, reset_select_dg = "
", */ reset_multiple_dg = "", reset_custom_dg = reset_multiple_dg, reset_select_dg = "", reset_select_ds = "
", reset_multiple_ds = "
", reset_custom_ds = reset_multiple_ds; $('#searchForm').each(function(){ var form = $(this), filters = form, mode_selector = $('.filters__mode .filters__selector',filters), mode_input = $('[name=o]',filters), // input or select mode = $('.filters__mode',filters), grouptypes_input = $('[name=gt]',filters), // input or select grouptypes = $('.filters__grouptypes',filters), type_input = $('[name^=type]',filters),// input or select zone_selector = $('.filters__zone .filters__selector',filters), area_selector = $('.filters__area .filters__selector',filters), location_selector = $('.filters__location .filters__selector',filters), group_selector = $('.filters__group .filters__selector',filters), district_selector = $('.filters__district .filters__selector',filters), zone_selector_sale = $('.sitGroup .filters__zone .filters__selector',filters), area_selector_sale = $('.sitGroup .filters__area .filters__selector',filters), location_selector_sale = $('.sitGroup .filters__location .filters__selector',filters), group_selector_sale = $('.sitGroup .filters__group .filters__selector',filters), district_selector_sale = $('.sitGroup .filters__district .filters__selector',filters), zone_selector_rental = $('.sitGroupRental .filters__zone .filters__selector',filters), area_selector_rental = $('.sitGroupRental .filters__area .filters__selector',filters), location_selector_rental = $('.sitGroupRental .filters__location .filters__selector',filters), group_selector_rental = $('.sitGroupRental .filters__group .filters__selector',filters), district_selector_rental = $('.sitGroupRental .filters__district .filters__selector',filters), zn_input = $('[name=z]',filters), // input or select ar_input = $('[name=a]',filters), // input or select lc_input = $('[name=l]',filters), // input or select dg_input = $('[name=g]',filters), // input or select ds_input = $('[name=d]',filters), // input or select zn_input_sale = $('.sitGroup [name=z]',filters), // input or select ar_input_sale = $('.sitGroup [name=a]',filters), // input or select lc_input_sale = $('.sitGroup [name=l]',filters), // input or select dg_input_sale = $('.sitGroup [name=g]',filters), // input or select ds_input_sale = $('.sitGroup [name=d]',filters), // input or select zn_input_rental = $('.sitGroupRental [name=z]',filters), // input or select ar_input_rental = $('.sitGroupRental [name=a]',filters), // input or select lc_input_rental = $('.sitGroupRental [name=l]',filters), // input or select dg_input_rental = $('.sitGroupRental [name=g]',filters), // input or select ds_input_rental = $('.sitGroupRental [name=d]',filters), // input or select district = $('.filters__district',filters), // district input or select group = $('.filters__group',filters), // group input or select location = $('.filters__location',filters), // location input or select area = $('.filters__area',filters), // area input or select area_options = $('.filter__option',area), // all area select options zone = $('.filters__zone',filters), // zone input or select zone_options = $('.filter__option',zone), // all zone select options district_sale = $('.sitGroup .filters__district',filters), // district input or select group_sale = $('.sitGroup .filters__group',filters), // group input or select location_sale = $('.sitGroup .filters__location',filters), // location input or select area_sale = $('.sitGroup .filters__area',filters), // area input or select area_options_sale = $('.sitGroup .filter__option',area), // all area select options zone_sale = $('.sitGroup .filters__area',filters), // area input or select zone_options_sale = $('.sitGroup .filter__option',zone), // all zone select options district_rental = $('.sitGroupRental .filters__district',filters), // district input or select group_rental = $('.sitGroupRental .filters__group',filters), // group input or select location_rental = $('.sitGroupRental .filters__location',filters), // location input or select area_rental = $('.sitGroupRental .filters__area',filters), // area input or select area_options_rental = $('.sitGroupRental .filter__option',area), // all area select options zone_rental = $('.sitGroupRental .filters__zone',filters), // zone input or select zone_options_rental = $('.sitGroupRental .filter__option',zone); // all zone select options // Delete inputs when is not the found mode form.on('submit',function(){ if($('[name="o"]:checked').val() == 'sale'){ $('.sitGroupRental [name="gt"], .sitGroupRental [name="type[]"], .sitGroupRental [name="z"], .sitGroupRental [name="a"], .sitGroupRental [name="l"], .sitGroupRental [name="g"], .sitGroupRental [name="d"], .sitGroupRental [name="q"]').remove(); }else{//rental $('.sitGroup [name="gt"], .sitGroup [name="type[]"], .sitGroup [name="z"], .sitGroup [name="a"], .sitGroup [name="l"], .sitGroup [name="g"], .sitGroup [name="d"], .sitGroup [name="q"]').remove(); } }); // PRICES HANDLERS $('[name="o"]', form).on('change', function(){ var form_mode = $(this); $('[name="pf"] option:not(:first-child), [name="pt"] option:not(:first-child)').remove(); if(form_mode.val() == 'sale'){ $('[name="pf"]').append(html_price_sale); $('[name="pt"]').append(html_price_sale); }else{ $('[name="pf"]').append(html_price_rent); $('[name="pt"]').append(html_price_rent); } }); // MODE HANDLERS var first_time_flag = false; mode_input.on('change',function(){ // Only in homepage and search if($('.sitGroup').length || $('.sitGroupRental').length){ if(isRental == 1){ zone = zone_rental; zone_selector = zone_selector_rental; zn_input = zn_input_rental; area = area_rental; area_selector = area_selector_rental; ar_input = ar_input_rental; location_selector = location_selector_rental; lc_input = lc_input_rental; group_selector = group_selector_rental; dg_input = dg_input_rental; district_selector = district_selector_rental; ds_input = ds_input_rental; }else{ zone = zone_sale; zone_selector = zone_selector_sale; zn_input = zn_input_sale; area = area_sale; area_selector = area_selector_sale; ar_input = ar_input_sale; location_selector = location_selector_sale; lc_input = lc_input_sale; group_selector = group_selector_sale; dg_input = dg_input_sale; district_selector = district_selector_sale; ds_input = ds_input_sale; } } // $('#searches').hasClass('searchHorz') allows to change selects in geo-templates if(isMobile || $('#searches').hasClass('searchHorz') || !first_time_flag){ first_time_flag = true; let _anyZoneSelected = false; let _anyAreaSelected = false; let _anyLocationSelected = false; let _anyGroupSelected = false; let _anyDistrictSelected = false; // ZONAS html = reset_select_zn; html = ""; $.each(json_zones_object,function(key, obj){ //if($('#searches').hasClass('searchHorz') && current_zone != obj.zone_id ) { return;} let _isZoneSelected = (current_zone == obj.zone_id) ? ' selected' : ''; if(_isZoneSelected != ''){ _anyZoneSelected = true; } html += "
";}); // Draw areas in the areas box zone_selector.html(html); if(_anyZoneSelected){ //$('li:not(:only-child):first-child', zone_selector).removeClass('selected'); //$('option:not(:only-child):first-child', zone_selector).prop('selected', false); }else{ $('li:first-child', zone_selector).click(); $('option:first-child', zone_selector).prop('selected', true).change(); current_zone = 1; } zone.trigger("chosen:updated"); zone_selector.trigger("chosen:updated"); // AREAS html = reset_select_ar; html = ""; $.each(json_areas_object,function(key, obj){ if($('#searches').hasClass('searchHorz') && current_zone != obj.zone_id ) { return;} let _isAreaSelected = (current_area == obj.area_id) ? ' selected' : ''; if(_isAreaSelected != ''){ _anyAreaSelected = true; } html += "
"; }); // Draw areas in the areas box area_selector.html(html); if(_anyAreaSelected){ $('li:not(:only-child):first-child', area_selector).removeClass('selected'); $('option:not(:only-child):first-child', area_selector).prop('selected', false); } area.trigger("chosen:updated"); area_selector.trigger("chosen:updated"); // LOCATIONS html = reset_select_lc; $.each(json_locations_object,function(key, obj){let _isLocationSelected = (current_location == obj.location_id) ? ' selected' : ''; if(_isLocationSelected != ''){ _anyLocationSelected = true; }html += "
";}); // Draw this area locations in the locations box location_selector.html(html); if(_anyLocationSelected){ $('li:not(:only-child):first-child', location_selector).removeClass('selected'); $('option:not(:only-child):first-child', location_selector).prop('selected', false); } location.trigger("chosen:updated"); // GROUPS html = reset_select_dg; // groups by area if(groups_by_areas){ // "todas" option groupsIds = ''; $.each(json_groups_object,function(key, obj){ if(obj.area_id == area_selector.val()){ groupsIds += obj.group_id + ','; } }); reset_select_dg = "
"; html = reset_select_dg; $.each(json_groups_object,function(key, obj){ let _isGroupSelected = (current_group == obj.group_id) ? ' selected' : ''; if(_isGroupSelected != ''){ _anyGroupSelected = true; } html += "
"; }); // groups by location }else{ $.each(json_groups_object,function(key, obj){ let _isGroupSelected = (current_group == obj.group_id) ? ' selected' : ''; if(_isGroupSelected != ''){ _anyGroupSelected = true; } html += "
"; }); } // Draw groups in the groups box group_selector.html(html); if(_anyGroupSelected){ $('li:not(:only-child):first-child', group_selector).removeClass('selected'); $('option:not(:only-child):first-child', group_selector).prop('selected', false); } group.trigger("chosen:updated"); // ok para ?¿?¿?¿ group_selector.trigger("chosen:updated"); // ok para geo-location // DISTRICTS html = reset_select_ds; // groups by area if(groups_by_areas){ /* reset_select_ds = "
"; html = reset_select_ds; */ $.each(json_districts_object,function(key, obj){ let _isDistrictSelected = (current_district == obj.district_id) ? ' selected' : ''; if(_isDistrictSelected != ''){ _anyDistrictSelected = true; } html += "
"; }); // groups by location }else{ $.each(json_districts_object,function(key, obj){ let _isDistrictSelected = (current_district == obj.district_id) ? ' selected' : ''; if(_isDistrictSelected != ''){ _anyDistrictSelected = true; } html += "
"; }); } /* $.each(json_districts_object,function(key, obj){ $.each(json_locations_object,function(keyLocation, objLocation){ if(current_location == objLocation.location_id) { let _isDistrictSelected = ''; let districtInSearch = current_district.indexOf(obj.district_id); if(districtInSearch != -1){ _isDistrictSelected = ' selected'; } if(_isDistrictSelected != ''){ _anyDistrictSelected = true; } if(obj.location_id == objLocation.location_id) { html += "
"; } } }); }); */ // Draw this area locations in the locations box district_selector.html(html); if(_anyDistrictSelected){ $('li:not(:only-child):first-child', district_selector).removeClass('selected'); $('option:not(:only-child):first-child', district_selector).prop('selected', false); } district.trigger("chosen:updated"); district_selector.trigger("chosen:updated"); } }); district_selector_container = district_selector; // Common location selector handler group_selector.on('change',function(){ district_selector_container.html(reset_select_ds); group_option_id = $(this).val(); // If not defined means that current area has not groups if(!group_option_id){ group_option_id = $(this).data('location'); $(this).after(''); } dg_input.val(group_option_id); ds_input.val(''); html = reset_select_ds; $.each(json_districts_object,function(key, obj){ if(dg_input.attr("name") == "l"){ if(obj.location_id == group_option_id){html += "
";} }else{ if(obj.group_id == group_option_id){html += "
";} } }); // Draw this area locations in the locations box district_selector_container.html(html).trigger("chosen:updated"); }); // Common location selector handler location_selector.on('change',function(){ district_selector_container.html(reset_select_ds); location_option_id = $(this).val(); //lc_input.val(location_option_id); ds_input.val(''); html = reset_select_ds; $.each(json_districts_object,function(key, obj){ if(obj.location_id == location_option_id){ html += "
"; } }); // Draw this area locations in the locations box district_selector_container.html(html); district_selector_container.trigger("chosen:updated"); }); // Common area selector handler area_selector.on('change',function(){ location_selector.html(reset_select_lc); district_selector_container.html(reset_select_ds); area_option_id = $(this).val(); lc_input.val(''); ds_input.val(''); dg_input.val(''); // Set locations selector taking in account that they could be groups or locations var areaHasGroups = false, groupsCounter = 0, groupsIds = ''; // Check if area has groups and add them in a var $.each(json_groups_object,function(key, obj){ if(obj.area_id == area_option_id){ groupsIds += obj.group_id + ','; groupsCounter++; } }); if(groupsCounter > 0){ areaHasGroups = true; } // If area has not groups, then group hidden input turns location input if(areaHasGroups){ dg_input.attr("name", "g"); }else{ dg_input.attr("name", "l"); } // Has Groups if(areaHasGroups){ // Groups depending on area_id if(groups_by_areas){ reset_multiple_dg = "
"; html = reset_multiple_dg; $.each(json_groups_object,function(key, obj){ if(obj.area_id == area_option_id){ districts_ids = obj.district_ids; /* $.each(json_districts_object,function(key2){ if(key == json_districts_object[key2].group_id) { districts_ids += key2 + ','; } }); */ html += "
"; } }); // Draw groups in selector group_selector.html(html).trigger("chosen:updated"); // TODO Groups depending on location_id }else{ } // Has not groups, so use Locations }else{ html = reset_select_lc; $.each(json_locations_object,function(key, obj){ if(obj.area_id == area_option_id){ districts_ids= ""; $.each(json_districts_object,function(key2, objDistricts){ if(key == objDistricts.location_id) { districts_ids += key2 + ','; } }); html += "
"; } }); // Draw locations in selector location_selector.html(html).trigger("chosen:updated"); group_selector.html(html).trigger("chosen:updated"); } // Update districts selector district_selector.trigger("chosen:updated"); }); // Common zone selector handler zone_selector.on('change',function(){ area_selector.html(reset_select_ar); location_selector.html(reset_select_lc); // Poner igual que ds¿?¿?¿? district_selector_container.html(reset_select_ds); zone_option_id = $(this).val(); ar_input.val(''); lc_input.val(''); dg_input.val(''); ds_input.val(''); reset_select_dg = "
"; html = reset_select_ar; $.each(json_areas_object,function(key, obj){ if(obj.zone_id == zone_option_id){ locations_ids= ""; $.each(json_locations_object,function(key2, objLocations){ if(key == objLocations.area_id) { locations_ids += key2 + ','; } }); html += "
"; } }); // Draw this area locations in the locations box area_selector.html(html).trigger("chosen:updated"); group_selector.html(reset_select_dg).trigger("chosen:updated"); location_selector.trigger("chosen:updated"); district_selector.trigger("chosen:updated"); }); }); } if($('.fn-refreshForm').length > 0){// Submit form on change - If is set as true $('.fn-refreshForm').on('change', function(){ $('.fn-reset-form-input').val(''); // For bedrooms and bathrooms, uncheck all options and allow to native check if($(this).parents('.filters__bedroomsOption').length || $(this).parents('.filters__bathroomOption').length){ $('[name="'+ $(this).attr('name') +'"]').not(this).prop('checked', false); } if(!checkRangeSelect($(this))) return false; mobile_force = ""; if($('.searchEngine').hasClass('fotos') && !$(this).is("#ob_hidden")){ $(this).closest('form').append(' '); } searchSubmit(mobile_force, $(this)); });} // Always submit form on change $('.fn-refreshFormMob').on('change', function(){ // Check if selected value is correct acording another select. if not, stop change event. if(!checkRangeSelect($(this))) return false; searchSubmit('forceSubmit', $(this)); }); // Always submit form on click $('.fn-submitSearchSidebar').on('click', function(){ searchSubmit('forceSubmit', $(this)); }); // Reset form $('.fn-resetForm').on('click', function(){ var form = $('#searchForm'), fields = 'input:not([type="checkbox"]), select'; $('.filter', form).removeClass('-hidden-'); $(fields, form).each(function(index, value){ var o = $(this); o.val(''); o.trigger("chosen:updated"); }); $('input[type="checkbox"]', form).prop("checked", false); if(!$('.fn-reset-form-input').length){ form.append(''); } }); /*--- Fotos view search sidebar ---*/ //Remove '&ref=filter' from urlfunction removeRefFilter(){var url = $(location).attr('href').replace('&ref=filter', '');window.history.replaceState({page: '1'}, document.title, url);}//close sidebar if click outside of it$(document).on('click',function(o) {if($('.searchEngine__filters').hasClass('-active-') && !$(o.target).hasClass('fn-searchFilters') && !$(o.target).closest(".searchEngine__filters.-active-").length){$('.searchEngine__filters').removeClass('-active-');removeRefFilter();}});//open/close sidebar$('.fn-searchFilters').on('click', function(){$('.fotos .searchEngine__filters').css('transition', '0.2s all');$('.searchEngine__filters').toggleClass('-active-');if(!$('.searchEngine__filters').hasClass('-active-')){removeRefFilter();}}); });