/g, ">"); s = s.replace(/\"/g, '"'); s = s.replace(/\'/g, '''); return s; } return s; }; if (isOninputSupported($('#place-input').get(0))) { $('#place-input').get(0).oninput = function () { suggest(); }; } else { $('#place-input').keyup(function () { suggest(); }); } var suggest = function () { $('#place-list').empty(); var oriQ = $('#place-input').val(); var q = oriQ.replace(/(^\s+)|(\s+$)/g, ''); if (q === '') { return; } var key = encodeURIComponent(q); if (placeCache[key]) { renderPlaceSuggestion(placeCache[key]); return; } var params = { 'q': q, 'limit': 20, 'lang': "en_US" }; var jqxhr = $.get( 'https://macauapi.com/v0/places/suggest', params, function (res) { if (res.ok === true && res.data) { var data = res.data; } else { return; } placeCache[key] = data; if (oriQ === $('#place-input').val()) { renderPlaceSuggestion(placeCache[key]); } }, 'jsonp' ); }; var renderPlaceSuggestion = function (data) { $('#place-list').empty(); var typeMap = { 'building': "Building", 'stop': "Bus Stop", 'street': "Street", 'other': "Other" }; for (var i = 0, l = data.length; i < l; i++) { var d = data[i]; var name = escapeHTML(d.name); var lat = escapeHTML(d.lat); var lng = escapeHTML(d.lng); var type = escapeHTML(d.type) || 'other'; var locality = escapeHTML(d.locality); var description = typeMap[type]; if (type === 'business' && d.cat && d.cat.length > 0) { description = d.cat.join(', '); } if (locality !== '') { if (description.length > 0) { description += ' @ ' + locality; } else { description += locality; } } var link = $('' + '' + name + '
' + '' + description + '
' + ''); link.click(function (e) { e.preventDefault(); var attr = $(this).attr('data-attr'); var name = attr.split('|')[0]; var geo = attr.split('|')[1]; $('#place-name').html(name); $('#search-pn').val(name); $('#search-pg').val(geo); setCookie('pn', name, 7); setCookie('pg', geo, 7); if ($('#search-input').val()) { $('#search-form').submit(); } else { $('#place-clear-link').css('display', 'inline-block'); $('body').removeClass('no-scroll'); $('#place-overlay').hide(); $('.search-link').each(function () { var href = $(this).attr('href'); href = href.replace(/&pn(.*)$/, ''); href += '&pn=' + encodeURIComponent(name); href += '&pg=' + encodeURIComponent(geo); $(this).attr('href', href); }); } }); $('
').append(link) .addClass('place-item') .appendTo($('#place-list')); } }; $('#feedback').submit(function () { var txt = $('#feedback-body').val(); txt = txt.replace(/(^\s+)|(\s+$)/g, ''); if (txt) { $('#feedback-message').html(''); $.post( 'https://www.mlocal.biz/contact/send', {'body': txt}, function (data) { $('#feedback-body').val(''); $('#feedback-message').html("Thanks for your message!"); } ); } return false; }); if ($('#search-cat-filter').get(0)) { if (isOninputSupported($('#search-cat-filter').get(0))) { $('#search-cat-filter').get(0).oninput = function () { catFilter(); }; } else { $('#search-cat-filter').keyup(function () { catFilter(); }); } } if ($('#search-road-filter').get(0)) { if (isOninputSupported($('#search-road-filter').get(0))) { $('#search-road-filter').get(0).oninput = function () { roadFilter(); }; } else { $('#search-road-filter').keyup(function () { roadFilter(); }); } } if ($('#search-locality-filter').get(0)) { if (isOninputSupported($('#search-locality-filter').get(0))) { $('#search-locality-filter').get(0).oninput = function () { localityFilter(); }; } else { $('#search-locality-filter').keyup(function () { localityFilter(); }); } } function catFilter() { $('.cat-filter-item').each(function () { var c = $(this).attr('data-attr').toLowerCase(); var i = $('#search-cat-filter').val().toLowerCase(); i = i.replace(/(\s)+/g, ' '); i = i.replace(/(^\s+)|(\s+$)/g, ''); if (i && c.indexOf(i) === -1) { $(this).css('display', 'none'); } else { $(this).css('display', 'block'); } }); } function roadFilter() { $('.road-filter-item').each(function () { var c = $(this).attr('data-attr').toLowerCase(); var i = $('#search-road-filter').val().toLowerCase(); i = i.replace(/(\s)+/g, ' '); i = i.replace(/(^\s+)|(\s+$)/g, ''); if (i && c.indexOf(i) === -1) { $(this).css('display', 'none'); } else { $(this).css('display', 'block'); } }); } function localityFilter() { $('.locality-filter-item').each(function () { var c = $(this).attr('data-attr').toLowerCase(); var i = $('#search-locality-filter').val().toLowerCase(); i = i.replace(/(\s)+/g, ' '); i = i.replace(/(^\s+)|(\s+$)/g, ''); if (i && c.indexOf(i) === -1) { $(this).css('display', 'none'); } else { $(this).css('display', 'block'); } }); }});