2019-05-14 15:14:15 +02:00
|
|
|
$(document).on 'turbolinks:load', ->
|
2019-05-14 22:57:32 +02:00
|
|
|
return unless navigator.geolocation
|
|
|
|
|
|
|
|
$('.digest .filter:first-child').each ->
|
2019-05-14 15:14:15 +02:00
|
|
|
$(this).before '
|
2019-05-14 22:57:32 +02:00
|
|
|
<a id="nearMe" href="#" title="⯐">
|
2019-05-14 15:14:15 +02:00
|
|
|
<em class="fa fa-2x fa-street-view"></em>
|
|
|
|
</a>'
|
2019-05-14 22:57:32 +02:00
|
|
|
$('#nearMe').click (event) ->
|
2019-05-14 15:14:15 +02:00
|
|
|
event.preventDefault()
|
2019-05-14 22:57:32 +02:00
|
|
|
navigator.geolocation.getCurrentPosition showPosition, (error) ->
|
|
|
|
switch error.code
|
|
|
|
when error.PERMISSION_DENIED
|
|
|
|
$('#nearMe').remove()
|
2019-05-14 15:14:15 +02:00
|
|
|
|
|
|
|
showPosition = (position) ->
|
|
|
|
coords = "[#{position.coords.latitude}, #{position.coords.longitude}]"
|
|
|
|
url = location.href
|
|
|
|
if location.search
|
|
|
|
url = url.replace 'near=', ''
|
|
|
|
url += '&'
|
|
|
|
else
|
|
|
|
url += '?'
|
|
|
|
url += "near[location]=#{coords}&near[distance]=20"
|
|
|
|
location.replace url
|