functiongetLocation(){navigator.geolocation.getCurrentPosition(function(e){addPlacesMap(e.coords.latitude,e.coords.longitude,e.coords.accuracy)})}functionaddPlacesMap(e,t,a){fetch("/places/near/"+e+"/"+t+"?u="+a,{credentials:"same-origin",method:"get"}).then(function(e){returne.json()}).then(function(a){if(1==a.error&&(alertify.reset(),alertify.error(a.error_description)),a.length>0){varn,r=[];for(n=0;n<a.length;++n){varo=parseLocation(a[n].location),l=a[n].name,c=a[n].slug;r.push([l,c,o[0],o[1]])}addMap(e,t,r)}elseaddMap(e,t)}).catch(function(e){console.error(e)})}functionaddMap(e,t,a){2==arguments.length&&(a=null);varn=button.parentNode,r=document.createElement("div");r.setAttribute("id","map"),n.appendChild(r),L.mapbox.accessToken="pk.eyJ1Ijoiam9ubnliYXJuZXMiLCJhIjoiVlpndW1EYyJ9.aP9fxAqLKh7lj0LpFh5k1w";varo=L.mapbox.map("map","jonnybarnes.gnoihnim").setView([e,t],15).addLayer(L.mapbox.tileLayer("jonnybarnes.gnoihnim",{detectRetina:!0})),l=L.marker([e,t],{draggable:!0}).addTo(o);l.on("dragend",function(){vare=document.querySelector("#place-latitude");null!==e&&(e.value=getLatitudeFromMapboxMarker(l.getLatLng()));vart=document.querySelector("#place-longitude");null!==t&&(t.value=getLongitudeFromMapboxMarker(l.getLatLng()))});varc=document.createElement("select");c.setAttribute("name","location");vari=document.createElement("option");i.setAttribute("selected","selected"),i.setAttribute("value","no-location");vard=document.createTextNode("Select no location");i.appendChild(d),c.appendChild(i),n.insertBefore(c,r),null!==a&&(a.forEach(function(e){vart=document.createElement("option");t.setAttribute("value",e[1]);vara=document.createTextNode(e[0]);t.appendChild(a),t.dataset.latitude=e[2],t.dataset.longitude=e[3],c.appendChild(t);varn=L.marker([e[2],e[3]],{icon:L.mapbox.marker.icon({"marker-size":"large","marker-symbol":"building","marker-color":"#fa0"})}).addTo(o),r="Name: "+e[0];n.bindPopup(r,{closeButton:!0}),n.on("click",function(){o.panTo([e[2],e[3]]),selectPlace(e[1])})}),c.addEventListener("change",function(){if("no-location"!==c.value){vare=c[c.selectedIndex].dataset.latitude,t=c[c.selectedIndex].dataset.longitude;o.panTo([e,t])}}));varu=document.createElement("button");u.setAttribute("type","button"),u.setAttribute("id","create-new-place"),u.appendChild(document.createTextNode("Create New Place?")),u.addEventListener("click",function(){vare=document.createElement("label");e.setAttribute("for","place-name"),e.classList.add("place-label"),e.appendChild(document.createTextNode("Place Name:"));vart=document.createElement("input");t.setAttribute("placeholder","Name"),t.setAttribute("name","place-name"),t.setAttribute("id","place-name"),t.setAttribute("type","text");vara=document.createElement("label");a.setAttribute("for","place-description"),a.classList.add("place-label"),a.appendChild(document.createTextNode("Place Description:"));varr=document.createElement("input");r.setAttribute("placeholder","Description"),r.setAttribute("name","place-description"),r.setAttribute("id","place-description"),r.setAttribute("type","text");vari=document.createElement("label");i.setAttribute("for","place-latitude"),i.classList.add("place-label"),i.appendChild(document.createTextNode("Place Latitude:"));vard=document.createElement("input");d.setAttribute("name","place-latitude"),d.setAttribute("id","place-latitude"),d.setAttribute("type","text"),d.value=getLatitudeFromMapboxMarker(l.getLatLng());varu=document.createElement("label");u.setAttribute("for","place-longitude"),u.classList.add("place-label"),u.appendChild(document.createTextNode("Place Longitude:"));varp=document.createElement("input");p.setAttribute("name","place-longitude"),p.setAttribute("id","place-longitude"),p.setAttribute("type","text"),p.value=getLongitudeFromMapboxMarker(l.getLatLng());varm=document.createElement("button");m.setAttribute("id","place-submit"),m.setAttribute("value","Submit New Place"),m.setAttribute("name","place-submit"),m.setAttribute("type","button"),m.appendChild(document.createTextNode("Submit New Place")),n.appendChild(e