agenda-libre-ruby/app/assets/javascripts/pages.js.coffee

26 lines
724 B
CoffeeScript
Raw Normal View History

$(document).on 'turbolinks:load', ->
2019-05-14 22:57:32 +02:00
return unless navigator.geolocation
$('.digest .filter:first-child').each ->
$(this).before '
2019-05-14 22:57:32 +02:00
<a id="nearMe" href="#" title="">
<em class="fa fa-2x fa-street-view"></em>
</a>'
2019-05-14 22:57:32 +02:00
$('#nearMe').click (event) ->
event.preventDefault()
2019-05-14 22:57:32 +02:00
navigator.geolocation.getCurrentPosition showPosition, (error) ->
switch error.code
when error.PERMISSION_DENIED
$('#nearMe').remove()
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