2019-05-14 15:14:15 +02:00
|
|
|
$(document).on 'turbolinks:load', ->
|
2019-05-14 22:57:32 +02:00
|
|
|
return unless navigator.geolocation
|
|
|
|
|
2019-06-27 22:17:40 +02:00
|
|
|
$('a.near-me').click (event) ->
|
|
|
|
event.preventDefault()
|
|
|
|
|
|
|
|
# We store the url we're going to
|
|
|
|
window.goto = event.target.href
|
|
|
|
|
|
|
|
navigator.geolocation.getCurrentPosition showPosition, (error) ->
|
|
|
|
switch error.code
|
|
|
|
when error.PERMISSION_DENIED
|
|
|
|
$('ul.regions li#near-me').remove()
|
2019-05-14 15:14:15 +02:00
|
|
|
|
|
|
|
showPosition = (position) ->
|
2019-06-27 22:17:40 +02:00
|
|
|
location.replace window.goto.replace '[me]',
|
|
|
|
"[#{position.coords.latitude}, #{position.coords.longitude}]"
|