Now possible to quickly filter 20km around one self

This commit is contained in:
echarp 2019-05-14 15:14:15 +02:00
parent 142b125dfb
commit fab2a3f8e6
3 changed files with 31 additions and 8 deletions

View File

@ -0,0 +1,24 @@
$(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

View File

@ -10,9 +10,7 @@
= favicon_link_tag '/favicon.ico'
= auto_discovery_link_tag :rss, controller: '/events', format: :rss
= stylesheet_link_tag 'application', media: 'all',
'data-turbolinks-track' => true
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tags

View File

@ -3,10 +3,11 @@
- if params[:tag].present?
= render partial: '/tags/context', locals: { tags: params[:tag] }
- if params[:near].present? && params[:near][:location].present? && params[:near][:distance].present?
- if params[:near].present? && params[:near][:location].present?
%span.near
%em.fa.fa-map-pin
= params[:near][:location]
- if params[:near][:distance].present?
%em.fa.fa-arrows-alt-h
= params[:near][:distance]
km
@ -14,7 +15,7 @@
%em.fa.fa-times
- if params[:tag].blank? && (params[:near].blank? || params[:near][:location].blank?)
= link_to page_path('filter') do
= link_to page_path('filter'), class: 'filter' do
= t 'title', scope: 'pages.filter'
= link_to page_path('filter'), title: t('title', scope: 'pages.filter') do