/
home
/
obinna
/
html
/
cravings
/
public
/
js
/
Upload File
HOME
function searchInput(address, food){ var vexInstance; const openVex = (content) => { vexInstance = vex.open({ unsafeContent: content, showCloseButton: false, className: 'customVex', overlayClassName: 'customVexOverlay' }); } var locationTemplate = () => ` <form action="/search" class="location-form search-input search-page-form"> <div class="address-input"> <input type="text" class="form-control" id="address" placeholder="Where should we ${food ? 'find ' + food : 'look?'}" /> <a href="#" class="get-location"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M256 176c-44.004 0-80.001 36-80.001 80 0 44.004 35.997 80 80.001 80 44.005 0 79.999-35.996 79.999-80 0-44-35.994-80-79.999-80zm190.938 58.667c-9.605-88.531-81.074-160-169.605-169.599V32h-42.666v33.067c-88.531 9.599-160 81.068-169.604 169.599H32v42.667h33.062c9.604 88.531 81.072 160 169.604 169.604V480h42.666v-33.062c88.531-9.604 160-81.073 169.605-169.604H480v-42.667h-33.062zM256 405.333c-82.137 0-149.334-67.198-149.334-149.333 0-82.136 67.197-149.333 149.334-149.333 82.135 0 149.332 67.198 149.332 149.333S338.135 405.333 256 405.333z"></path></svg> </a> </div> <button class="button button-primary inline-button">Find</button> </form> ` openVex(locationTemplate()); var loc = {}; var search = document.getElementById('address'); search.value = address || ""; search.focus(); search.select(); return new Promise(function(resolve, reject){ autocomplete(search).then(autolocation => { resolve(autolocation); }).catch(error => console.log(error)) document.querySelector('.get-location').addEventListener('click', function(e){ e.preventDefault(); const target = e.target; startMap().then(locate => { target.closest('div').querySelector('input').value = locate.address loc = locate resolve(locate) }).catch(error => alert(error)) }) // On location form submit document.querySelector('.location-form').addEventListener('submit', async function(e){ e.preventDefault(); if(search.value && !loc.longitude) { loc.address = search.value; var response = await doGet(`${getCoords(loc.address)}`); const { lat, lng } = response.results && response.results[0].geometry.location resolve({...loc, longitude: lng, latitude: lat}) }else if(loc.longitude) resolve(loc) else reject("Enter address") }); }) }