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' = favicon_link_tag '/favicon.ico'
= auto_discovery_link_tag :rss, controller: '/events', format: :rss = 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 = javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tags = csrf_meta_tags

View File

@ -3,18 +3,19 @@
- if params[:tag].present? - if params[:tag].present?
= render partial: '/tags/context', locals: { tags: params[:tag] } = 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 %span.near
%em.fa.fa-map-pin %em.fa.fa-map-pin
= params[:near][:location] = params[:near][:location]
%em.fa.fa-arrows-alt-h - if params[:near][:distance].present?
= params[:near][:distance] %em.fa.fa-arrows-alt-h
km = params[:near][:distance]
km
%a(href="?near=") %a(href="?near=")
%em.fa.fa-times %em.fa.fa-times
- if params[:tag].blank? && (params[:near].blank? || params[:near][:location].blank?) - 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' = t 'title', scope: 'pages.filter'
= link_to page_path('filter'), title: t('title', scope: 'pages.filter') do = link_to page_path('filter'), title: t('title', scope: 'pages.filter') do