451938"; // On first click initiate loading /* $('body').on('click', '.loc-picker .term', function() { if( !termClicked ) { $(this).keyup(); } termClicked = true; }); */ // Create delay var delay = (function(){ var timer = 0; return function(callback, ms){ clearTimeout (timer); timer = setTimeout(callback, ms); }; })(); $(document).ajaxSend(function(evt, request, settings) { var url = settings.url; if (url.indexOf("ajaxLoc") >= 0) { $(".loc-picker, .location-picker").addClass('searching'); } }); $(document).ajaxStop(function() { $(".loc-picker, .location-picker").removeClass('searching'); }); $('body').on('keyup', '.loc-picker .term', function(e) { delay(function(){ var min_length = 1; var elem = $(e.target); var term = encodeURIComponent(elem.val()); // If comma entered, remove characters after comma including if(term.indexOf(',') > 1) { term = term.substr(0, term.indexOf(',')); } // If comma entered, remove characters after - including (because city is shown in format City - Region) if(term.indexOf(' - ') > 1) { term = term.substr(0, term.indexOf(' - ')); } var block = elem.closest('.loc-picker'); var shower = elem.closest('.loc-picker').find('.shower'); shower.html(''); if(term != '' && term.length >= min_length) { // Combined ajax for country, region & city $.ajax({ type: "POST", url: baseAjaxUrl + "&ajaxLoc=1&term=" + term, dataType: 'json', success: function(data) { var length = data.length; var result = ''; var result_first = ''; var countCountry = 0; var countRegion = 0; var countCity = 0; if(shower.find('.service.min-char').length <= 0) { for(key in data) { // Prepare location IDs var id = ''; var country_code = ''; if( data[key].country_code ) { country_code = data[key].country_code; id = country_code; } var region_id = ''; if( data[key].region_id ) { region_id = data[key].region_id; id = region_id; } var city_id = ''; if( data[key].city_id ) { city_id = data[key].city_id; id = city_id; } // Count cities, regions & countries if (data[key].type == 'city') { countCity = countCity + 1; } else if (data[key].type == 'region') { countRegion = countRegion + 1; } else if (data[key].type == 'country') { countCountry = countCountry + 1; } // Find currently selected element var selectedClass = ''; if( data[key].type == 'country' && parseInt(currentCountry) == parseInt(data[key].country_code) || data[key].type == 'region' && parseInt(currentRegion) == parseInt(data[key].region_id) || data[key].type == 'city' && parseInt(currentCity) == parseInt(data[key].city_id) ) { selectedClass = ' selected'; } // For cities, get region name var nameTop = ''; if(data[key].name_top ) { nameTop = ' ' + data[key].name_top + ''; } if(data[key].type != 'city_more') { // When classic city, region or country in loop and same does not already exists if(shower.find('div[data-code="' + data[key].type + data[key].id + '"]').length <= 0) { result += '
' + data[key].name + '' + nameTop + '
'; } } else { // When city counter and there is more than 12 cities for search /* if(shower.find('.more-city').length <= 0) { if( parseInt(data[key].name) > 0 ) { result += '
... ' + (data[key].name) + ' more cities, specify your location
'; } } */ } } // No city, region or country found /* if( countCountry == 0 && shower.find('.empty-country').length <= 0 && shower.find('.service.min-char').length <= 0) { shower.find('.option.country').remove(); result_first += '
No country match to your criteria
'; } if( countRegion == 0 && shower.find('.empty-region').length <= 0 && shower.find('.service.min-char').length <= 0) { shower.find('.option.region').remove(); result_first += '
No region match to your criteria
'; } if( countCity == 0 && shower.find('.empty-city').length <= 0 && shower.find('.service.min-char').length <= 0) { shower.find('.option.city').remove(); result_first += '
No city match to your criteria
'; } */ if( countCity == 0 && countRegion == 0 && countCountry == 0 && shower.find('.empty-loc').length <= 0 && shower.find('.service.min-char').length <= 0) { shower.find('.option').remove(); result_first += '
No location match to your criteria
'; } } shower.html(result_first + result); } }); } else { // Term is not length enough, show default content //shower.html('
Enter at least ' + (min_length - term.length) + ' more letter(s)
'); shower.html('
مصر
أسوانمصر
أسيوطمصر
الأقصرمصر
الإسكندريةمصر
الإسماعيليةمصر
البحر الأحمرمصر
البحيرةمصر
الجيزةمصر
الدقهليةمصر
السويسمصر
الشرقيةمصر
الغربيةمصر
الفيوممصر
القاهرةمصر
القليوبيةمصر
المنوفيةمصر
المنيامصر
الوادي الجديدمصر
بني سويفمصر
بورسعيدمصر
جنوب سيناءمصر
دمياطمصر
سوهاجمصر
شمال سيناءمصر
قنامصر
كفر الشيخمصر
مطروحمصر
'); } }, 500 ); }); });