Sign In Advertise
Flats Houses Sharehouses New development Plots Premises More…
Garages New price Ready, auctions Modular houses
'); } if (e.keyCode === 38 || e.keyCode === 40) { if (!$autoSuggest.hasClass('hide')) { var totalElems = 0; var activeElem = 0; $autoSuggest.find('span').each(function () { totalElems++; if ($(this).hasClass('focus')) activeElem = totalElems; }); $autoSuggest.find('span.focus').removeClass('focus'); if (e.keyCode === 38) activeElem--; if (e.keyCode === 40) activeElem++; if (activeElem <= 0) activeElem = totalElems; if (activeElem > totalElems) activeElem = 1; $autoSuggest.find('span:nth-child(' + activeElem + ')').addClass('focus'); $('#keyword, .fake-keyword').val($autoSuggest.find('span.focus').data('keyword')); } } else if (e.keyCode === 27) { $(this).val(''); $autoSuggest.addClass('hide'); } else if (e.keyCode === 13) { var locationIds = $autoSuggest.find('span.focus').data('location'); if (locationIds && typeof (locationIds) !== 'undefined') { e.preventDefault(); Search.addressKeyword = $autoSuggest.find('span.focus').data('location-keyword'); Search.autosuggestLocations(locationIds); } $autoSuggest.addClass('hide'); } else { $autoSuggest.addClass('hide'); if (Search.autoCompleteTimeout) clearTimeout(Search.autoCompleteTimeout); Search.autoCompleteTimeout = setTimeout(Search.createAutoComplete, 200); } }); } if (DEVICE === 'mobile') { $('.fake-keyword').unbind('focus keyup').on('focus keyup', function (e) { $('#keyword, .fake-keyword').val($(this).val()).trigger('fake-keyword', [e.originalEvent]); }).on('blur', function () { $('#auto-suggest').addClass('hide'); }); let roomsPrefix = agentForm ? '#agent_rooms' : '#rooms'; $(roomsPrefix + '_select a').unbind('click').on('click', function () { let $min = $(roomsPrefix + '_min'); let $max = $(roomsPrefix + '_max'); let minVal = parseInt($(roomsPrefix + '_min').val()); let maxVal = parseInt($(roomsPrefix + '_max').val()); let currVal = parseInt($(this).data('value')); if ($min.val() === parseInt($max.val()) && currVal === parseInt($min.val())) currVal = 0; if (!currVal || (minVal === maxVal || minVal === 5) && minVal === currVal) { $min.val(''); $max.val(''); } else if (!minVal && !maxVal) { $min.val(currVal); $max.val(currVal === 5 ? '' : currVal); } else if (currVal === 5 && minVal !== 5 && maxVal) { $max.val(''); } else if (minVal === currVal) { $min.val(currVal >= maxVal ? '' : currVal + 1); } else if (!maxVal && currVal === 5 || maxVal === currVal && minVal < currVal) { $max.val(currVal - 1); } else { minVal < currVal ? $max.val(currVal) : $min.val(currVal); } $min.trigger('change'); }); $(roomsPrefix + '_min, ' + roomsPrefix + '_max').unbind('change').on('change', function () { let min = parseInt($(roomsPrefix + '_min').val()); let max = parseInt($(roomsPrefix + '_max').val()); if (!max) max = 5; let $roomsSelect = $(roomsPrefix + '_select a'); $roomsSelect.removeClass('active'); if (!min) { $roomsSelect.first().addClass('active'); } else { for (let i = min; i <= max; i++) { $roomsSelect.eq(i).addClass('active'); } } }).trigger('change'); setTimeout(() => $(roomsPrefix + '_min').trigger('change'), 500); $('.main-search .collapse a').on('click', function () { setTimeout(function () { if ($('#search-outer,#search-outer-modulars,#search-outer-developments').hasClass('show')) { $('.main-menu').removeClass('hide'); } else if (PAGE !== 'home') { $('.main-menu').addClass('hide'); } }); }); $('#short-search').on('stateChanged', function () { let copyElem; if (Search.resetPages.includes(PAGE) && ($(this).hasClass('show') || (!$(this).hasClass('show') && !$(this).hasClass('hide')))) { $('.main-search div[data-copy-short-search]').each(function () { copyElem = $($(this).data('copy-short-search')); copyElem.after('
'); $(this).replaceWith(copyElem); let cityElem = $('[data-group="city"]'); if (cityElem.html() === '') { $('.short-search-city').addClass('hide'); } }); } else { Search.hideMobileSearch(); } }); } Search.$form.on('submit', function (e) { e.preventDefault(); KV.newSearch = true; }); if (agentForm) { setTimeout(function () { Search.loading(false); }, 300); } Search.initiated = true; } }, createAutoComplete: function () { let urlParams = KV.trimUrl('/search/keyword' + '&' + Search.$form.serialize(), Search.$form.data('post-trim')); KV.api('/search/keyword' + urlParams, null, function (res) { if (res['items']) { let keyword = $('#keyword' + (MOBILE ? ', .fake-keyword' : '')).val().trim(); let html = ''; for (var row of res['items']) { var pattern = '(' + keyword.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&') + ')'; row['label'] = row['label'].toString() .replace(new RegExp(pattern, 'gi'), '$1') .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/<(\/?strong)>/g, '<$1>'); html += ''; if (row['location_str']) html += ' ' + row['location_str'] + ''; html += row['label']; if (row['category']) html += ' ' + lang('lbl_autocomplete_' + row['category']) + ''; html += ''; } if (html) { if (!keyword) { html = '
' + lang('popular_searches') + '
' + html + '
'; } $('#auto-suggest').html(html).removeClass('hide'); setTimeout(function () { $('#auto-suggest span').on('mousedown tap', function () { let locationIds = $(this).data('location'); let $this = $(this); if (locationIds && typeof (locationIds) !== 'undefined') { Search.addressKeyword = $(this).data('location-keyword'); Search.autosuggestLocations(locationIds, false); } else { let keyword = ''; if ($this.data('company-id')) { Search.$form.find('input[name="company_id"]').val($this.data('company-id')); } else if ($this.data('broker-id')) { Search.$form.find('input[name="broker_id"]').val($this.data('broker-id')); } else if ($this.data('keyword')) { keyword = $this.data('keyword'); } $('#keyword, .fake-keyword').val(keyword); $('#auto-suggest').addClass('hide'); Search.$form.submit(); } }); }, 100); } else { $('#auto-suggest').addClass('hide'); } } }); }, createParishSelect: function (opts) { if (!opts) { Search.$form.find('[name="parish"]').prop('disabled', true).find('option').not(':first,:disabled').remove(); return false; } opts.sort((a, b) => (a['new_parish_name'] > b['new_parish_name']) ? 1 : -1); var html = ''; var usedOpts = []; for (var i in opts) { if (!usedOpts.includes(opts[i]['new_parish_name'])) { usedOpts.push(opts[i]['new_parish_name']); html += '
'; if (opts[i]['old_parish_count'] > 1) { for (var i2 in opts) { if (opts[i2]['new_parish_id'] !== opts[i]['new_parish_id']) continue; html += '
'; } } } } let parishVal = (typeof Search.tmp_parish_id != 'undefined' ? Search.tmp_parish_id : Search.initiated ? '' : Search.urlParams['parish']); Search.$form.find('[name="parish"]').prop('disabled', false).append(html).val(parishVal).trigger('change'); delete Search.tmp_parish_id; if (Search.$form.attr('id') === 'agent_searchform') { Search.$form.find('select[name="parish"]').prop('disabled', true); } if (Search.submitAfter === 'parish') { $('#keyword, .fake-keyword').val(Search.addressKeyword); Search.$form.submit(); delete Search.submitAfter; } }, createCitySelect: function (opts) { if (!opts) { Search.$form.find('[data-group="city"]').html(''); return false; } opts.sort((a, b) => (a['city_name'] > b['city_name']) ? 1 : -1); var html = '
'; var htmlAfter = ''; for (var i in opts) { if (opts[i]['parent_city_id']) continue; var sub = ''; for (var i2 in opts) { if (opts[i2]['parent_city_id'] !== opts[i]['city_id']) continue; sub += ''; sub += ''; } var currHtml = ''; currHtml += ''; if (sub) { html += currHtml + sub; html += '
'; } else { htmlAfter += currHtml; } } Search.$form.find('[data-group="city"]').html(html + '
' + lang('lbl_cities') + '
' + htmlAfter + '
'); if (Search.tmp_city_id) { Search.$form.find('#city_' + Search.tmp_city_id).attr('checked', true); delete Search.tmp_city_id; } else if (Search.urlParams.city) { for (let cityId of Object.values(Search.urlParams.city)) { Search.$form.find('#city_' + cityId).prop('checked', true); } } Search.$form.find('[data-group="city"] input').on('change', function () { if ($(this).data('parent-id')) { Search.$form.find('[data-group="city"] input[value="' + $(this).data('parent-id') + '"]') .prop('checked', Search.$form.find('[data-group="city"] input[data-parent-id="' + $(this).data('parent-id') + '"]').length === Search.$form.find('[data-group="city"] input[data-parent-id="' + $(this).data('parent-id') + '"]:checked').length); } else { Search.$form.find('[data-group="city"] input[data-parent-id="' + $(this).val() + '"]').prop('checked', $(this).prop('checked')); } }); Search.$form.find('[data-group="city"]').parent().removeClass('hide'); if (Search.submitAfter === 'city') { $('#keyword, .fake-keyword').val(Search.addressKeyword); Search.$form.submit(); delete Search.submitAfter; } }, showGroups: function (noAnimation, dealType) { if (!dealType) dealType = Search.$form.find('[name="deal_type"]').val(); let mainDealType = Search.getMainDealType(dealType); let showGroups = Object.assign([], Search.dtGroups[mainDealType]); showGroups.push('deal_type', 'city', 'parish'); if (Search.shownOnce && !noAnimation && Search.$form.data('last-search') !== dealType) { if (!Search.$form.hasClass('main-search') && !Search.$form.hasClass('map-filters')) { Search.$form.addClass('main-search'); } Search.$form.removeClass('animate'); setTimeout(function () { Search.$form.addClass('animate'); setTimeout(function () { Search.$form.removeClass('animate'); }, 500); }); } if (dealType < 30) { showGroups.push('change_interest'); } else if (dealType >= 30) { showGroups.push('nr_of_people'); let del; let removeGroups = ['area', 'area_total', 'area_ground', 'structures', 'conditions']; for (var group of removeGroups) { if ((del = showGroups.indexOf(group)) > -1) showGroups.splice(del, 1); } } if (parseInt(dealType) === 2) { showGroups.push('kv_rent'); } if (parseInt(mainDealType) === 5) { Search.$form.find('[data-group="area_ground"]').children().appendTo('[data-group="area_ground-up"]').find('input').addClass('center'); $('#search-outer .extended .opt-group:first-child').addClass('hide'); $('#search-outer .extended .opt-group:nth-child(2)').addClass('no-border'); } else { Search.$form.find('[data-group="area_ground-up"]').children().appendTo('[data-group="area_ground"]').find('input').removeClass('center'); $('#search-outer .extended .opt-group:first-child').removeClass('hide'); $('#search-outer .extended .opt-group:nth-child(2)').removeClass('no-border'); } if (parseInt(mainDealType) === 8 || parseInt(mainDealType) === 7) { Search.$form.find('[data-group="area_total"]').children().appendTo('[data-group="area_total-up"]').find('input').addClass('center'); if (parseInt(mainDealType) === 7) { Search.$form.find('[data-group="rooms"]').children().appendTo('[data-group="rooms-down"]').find('input').removeClass('center'); } } else { Search.$form.find('[data-group="area_total-up"]').children().appendTo('[data-group="area_total"]').find('input').removeClass('center'); Search.$form.find('[data-group="rooms-down"]').children().appendTo('[data-group="rooms"]').find('input').addClass('center'); } setTimeout(function () { let $groups = Search.$form.find('[data-group]').not('[data-group="persist"]'); $groups.each(function () { $(this).addClass('hide'); $(this).find('input, select').prop('disabled', true); }); for (var group of showGroups) { let $group = Search.$form.find('[data-group="' + group + '"]'); $group.removeClass('hide'); $group.find('input, select').prop('disabled', false); } }, 250); $('#searchform-extend, #searchform .extended').css('display', (mainDealType === 8 ? 'none' : '')); Search.$form.data('last-search', dealType); }, loading: function (loading) { if (loading) { Search.$form.addClass('hide'); if (!Search.$form.parent().find('.loader')) { Search.$form.parent().addClass('loader'); } return; } if (Search.$form.parent().find('.loader')) { Search.$form.parent().find('.loader').remove(); } else { Search.$form.parent().removeClass('loader'); } Search.$form.removeClass('hide'); }, getMainDealType: function (dealType) { if (!searchForm['deal_type']) { return null; } dealType = parseInt(dealType); let mainDealType = dealType; for (var dt of searchForm['deal_type']) { if (dt.includes(dealType)) mainDealType = dt[0]; } return mainDealType; }, removeTag: function (type, name, val, allowSubmit) { if (type === 'select') { if ($('#' + name).length) $('#' + name + '').val('').trigger('change'); else $('select[name="' + name + '"]').val('').trigger('change'); } else if (type === 'selectmulti') { if (val === 'all') { $('#' + name + ' option').prop('selected', false); } else { $('#' + name + ' option[value="' + val + '"]').prop('selected', false); } } else if (type === 'text') { $('#' + name).val(''); } else if (type === 'multitext') { $('#' + name + '_min').val(''); $('#' + name + '_max').val(''); if (name === 'rooms') { $('#rooms_select a').removeClass('active'); } } else if (type === 'check') { if (name === 'company_id1') { $('#' + name).prop('checked', false); $('#company_id').val(''); } else { $('#' + name).prop('checked', false); } } else if (type === 'multicheck') { if (val === 'all') { $('input[name="' + name + '"]').prop('checked', false); } else { $('#' + name).prop('checked', false); } } if (allowSubmit === true) { Search.$form.submit(); } else if (typeof allowSubmit === 'string') { $(allowSubmit).submit(); } }, autosuggestLocations: function (locationIds, onlyChange) { var parts = locationIds.split(','); var prevChanged = false; if (parts[0] && Search.$form.find('[name="county"]').val() !== parts[0]) { Search.$form.find('[name="county"]').val(parts[0]).trigger('change'); prevChanged = true; } if (parts[1]) { if (prevChanged) { Search.tmp_parish_id = parts[1]; } else if (Search.$form.find('[name="parish"]').val() !== parts[1]) { Search.$form.find('[name="parish"]').val(parts[1]).trigger('change'); prevChanged = true; } Search.submitAfter = 'parish'; } if (parts[2] || parts[3]) { var useCityId = parts[3] ? parts[3] : parts[2]; if (prevChanged) { Search.tmp_city_id = useCityId; } else { Search.$form.find('[data-group="city"] input').prop('checked', false); Search.$form.find('#city_' + useCityId).prop('checked', true); } Search.submitAfter = 'city'; } else { Search.$form.find('[data-group="city"] input').prop('checked', false); } if (!onlyChange && Search.submitAfter && !prevChanged) { $('#keyword, .fake-keyword').val(Search.addressKeyword); Search.$form.submit(); delete Search.submitAfter; } else if (onlyChange) { Search.submitAfter = null; } }, checkState: function () { if (MOBILE) { if (PAGE === 'home') { $('header .main-menu').removeClass('hide'); $('#search-outer').addClass('hide'); } else { let $searchOuter = $('#search-outer'); $('header .main-menu').addClass('hide'); if ($searchOuter.hasClass('show')) { $('#searchform .collapse a[data-toggle]').first().click(); } else { $searchOuter.addClass('hide').removeClass('show'); } } $('#short-search').trigger('stateChanged'); } if (!Search.$form.find('.active').data('deal-type') && $.inArray(PAGE, ['search', 'developments']) === -1) { let lastActiveType = Search.getMainDealType(Search.$form.find('[name="deal_type"]').val()); $('header .main-menu a').removeClass('active'); $('header .main-menu a[data-deal-type="' + lastActiveType + '"]').addClass('active'); if (!MOBILE) $('#search-outer').removeClass('hide').removeClass('show'); } if (Search.resetPages.includes(PAGE)) { if (!MOBILE) { Search.$form.find('#search-options a').removeClass('hide'); Search.$form.find('.extended').removeClass('show').addClass('hide'); Search.$form.find('#search-options .fa-angle-up').addClass('fa-angle-down').removeClass('fa-angle-up'); } Search.$form[0].reset(); Search.$form.find('#bid_objects').val(''); Search.$form.find('#company_id').val(''); Search.$form.find('#broker_id').val(''); Search.$form.find('input[name="orderby"]').val(''); Search.$form.find('.btn-select a').removeClass('active'); Search.$form.find('select').trigger('change'); Search.$form.attr('action', '/search'); $('.main-menu').scrollLeft(0); $('header .main-menu a').first().trigger('click', [false]); Search.$form.find('#short-search').removeClass('hide').trigger('stateChanged'); } if (!MOBILE && Search.openedSearchPages.includes(PAGE)) { $('#search-outer').removeClass('hide').removeClass('show'); Search.$form.find('.collapse').addClass('hide'); } else if (Search.closedSearchPages.includes(PAGE)) { Search.hideSearch(); } Search.urlParams = getUrlParams(realUrl); if (Search.urlParams['deal_type']) { $('.main-menu a').removeClass('active'); $('.main-menu a[data-deal-type="' + Search.getMainDealType(Search.urlParams['deal_type']) + '"]').addClass('active'); } if (Search.urlParams['county']) { Search.autosuggestLocations(Search.locationStr(), true); Search.init(null, Search.$form); } }, goToMobileSearch: function () { if (!$('#search-outer').hasClass('show')) { $('.main-search a[data-toggle]').first().click(); } $('html').css('scroll-behavior', 'initial'); $(document).scrollTop(0); }, locationStr: function () { return Search.urlParams['county'] + ',' + (typeof Search.urlParams['parish'] != 'undefined' ? Search.urlParams['parish'] : '') + ',' + (typeof(Search.urlParams['city']) == 'object' ? Object.values(Search.urlParams['city']).join(',') : '0'); }, hideSearch: function (hideMenu) { $('#search-outer').addClass('hide').removeClass('show'); if (Search.$form.find('.collapse .fa-angle-up').length && Search.$form.find('.collapse a[data-toggle-text]').length) { let $extender = Search.$form.find('.collapse a[data-toggle-text]'); let newText = $extender.data('toggle-text'); newText += ' '; $extender.data('toggle-text', $extender.text()); $extender.html(newText); } Search.$form.find('.collapse').removeClass('hide').find('.fal').addClass('fa-angle-down').removeClass('fa-angle-up'); if (hideMenu && MOBILE) { $('.main-menu,#short-search,#search-outer').addClass('hide'); Search.hideMobileSearch(); } }, hideMobileSearch: function () { $('.main-search div[data-copy-long-search]').each(function () { let copyElem = $($(this).data('copy-long-search')); copyElem.after('
'); $(this).replaceWith(copyElem); }); $('.short-search-city').removeClass('hide'); }, changeDealType: function ($this, submitForm) { let dealType = parseInt($this[0].tagName === 'SELECT' ? $this.val() : $this.data('deal-type')); $('.main-menu a').removeClass('active'); $('.main-menu a[data-deal-type="' + dealType + '"]').addClass('active'); if (dealType) { if (Search.urlParams['deal_type'] !== dealType || Search.exitPages.includes(PAGE)) { Search.prev['deal_type'] = Search.$form.find('[name="deal_type"] option:selected').text(); Search.init(dealType); Search.$form.find('[name="deal_type"] option').each(function () { let $option = $(this); if ($option.text() === Search.prev['deal_type']) { Search.prev['deal_type'] = $option.val(); $option.prop('selected', true); setTimeout(function () { $option.prop('selected', true); }, 200); } }); Search.showGroups(null, dealType); if (submitForm) { setTimeout(function () { Search.$form.submit(); }, 300); } } } else if ($this.data('extra')) { Search.$form.find('[name="' + $(this).data('extra') + '"]').val(1); } }, mapSearch: function () { let urlParams = getUrlParams(Search.$form.serialize(), 1); if ([3, 5].includes(Search.getMainDealType(urlParams['deal_type']))) { KVmap.initCataster(); } KVmap.dataUrlExtra = KVmap.dataUrl.includes('?') ? '&' : '?' + $.param(urlParams); let finalUrl = KVmap.dataUrl + KVmap.dataUrlExtra; document.location.href = (PAGE === 'my' ? document.location.pathname : '') + '#' + finalUrl; KVmap.googlePlace(() => { KVmap.updateMarkers(); }); } };