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

25 lines
619 B
CoffeeScript

$(document).on 'turbolinks:load', ->
$('.digest .filter').each ->
$(this).before '
<a id="nearMe" href="#">
<em class="fa fa-2x fa-street-view"></em>
</a>'
$( '#nearMe').click (event) ->
event.preventDefault()
nearMe()
nearMe = ->
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition showPosition
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