Skip to content

Commit

Permalink
Separate event script from event data
Browse files Browse the repository at this point in the history
  • Loading branch information
saivann committed May 1, 2015
1 parent 4a89cc4 commit 262b550
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
3 changes: 3 additions & 0 deletions _less/screen.less
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,9 @@ h2 .rssicon{
background-image:none;
color:#fff;
}
.eventdata{
display:none;
}

.detectmobile{
width:0;
Expand Down
4 changes: 2 additions & 2 deletions _plugins/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def meetups
time.utc
date = time.year.to_s + '-' + time.month.to_s.rjust(2,'0') + '-' + time.day.to_s.rjust(2,'0')
country = country.upcase
geoloc = lat + ', ' + lon
geoloc = {'lat' => lat, 'lon' => lon}
# Use address_2 and state when available
if m['venue'].has_key?('address_2') and ( m['venue']['address_2'].is_a?(String) or m['venue']['address_2'].is_a?(Integer) or m['venue']['address_2'].is_a?(Float) ) and /^.{1,150}$/.match(m['venue']['address_2'].to_s)
address = address + ' ' + m['venue']['address_2'].to_s
Expand All @@ -105,7 +105,7 @@ def conferences
begin
geoloc = JSON.parse(open("https://maps.googleapis.com/maps/api/geocode/json?address=" + CGI::escape(data['address'] + ', ' + data['city'] + ', ' + data['country']) + "&sensor=false","User-Agent"=>"Ruby/#{RUBY_VERSION}").read)
if geoloc['status'] == 'OK'
data['geoloc'] = geoloc['results'][0]['geometry']['location']['lat'].to_s + ", " + geoloc['results'][0]['geometry']['location']['lng'].to_s
data['geoloc'] = {'lat' => geoloc['results'][0]['geometry']['location']['lat'].to_s, 'lon' => geoloc['results'][0]['geometry']['location']['lng'].to_s}
end
rescue
print 'Google Maps API Call Failed!'
Expand Down
12 changes: 12 additions & 0 deletions _templates/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
layout: base
id: events
---
<!-- Note: this file is built non-deterministically -->
<link rel="alternate" type="application/rss+xml" href="/en/rss/events.rss" title="Bitcoin conferences and events">
<h1>{% translate pagetitle %}<a type="application/rss+xml" href="/en/rss/events.rss"><img src="/img/icons/icon_rss.svg" alt="rss" class="rssicon"></a></h1>
<p class="summary">{% translate pagedesc %}</p>
Expand All @@ -15,6 +16,17 @@ <h1>{% translate pagetitle %}<a type="application/rss+xml" href="/en/rss/events.
<script src="/js/leaflet/leaflet.js"></script>
<script src="/js/leaflet-markercluster/leaflet.markercluster.js"></script>
<div id="eventmap" class="eventmap"></div>
<div id="eventdata" class="eventdata">

{% filter_for p in site.conferences sort_by:date %}{% if p.geoloc %}
<div data-lat="{{ p.geoloc.lat }}" data-lon="{{ p.geoloc.lon }}"><b><a href="{{ p.link | htmlescape }}">{{ p.title | htmlescape }}</a></b><br>{{ p.date }}<br>{{ p.venue | htmlescape }}<br>{{ p.address | htmlescape }}<br>{{ p.city | htmlescape }}, {{ p.country | htmlescape }}')</div>
{% endif %}{% endfilter_for %}

{% filter_for p in site.meetups sort_by:date %}{% if p.geoloc %}
<div data-lat="{{ p.geoloc.lat }}" data-lon="{{ p.geoloc.lon }}"><b><a href="{{ p.link | htmlescape }}">{{ p.title | htmlescape }}</a></b><br>{{ p.date }}<br>{{ p.venue | htmlescape }}<br>{{ p.address | htmlescape }}<br>{{ p.city | htmlescape }}, {{ p.country | htmlescape }}</div>
{% endif %}{% endfilter_for %}

</div>
<script src="/js/events.js"></script>
<h2 id="upcoming">{% translate upcoming %}</h2>
<div class="listtable eventtable">
Expand Down
12 changes: 4 additions & 8 deletions js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ layout: null
---
var zoom=2;
var minzoom=1;
if(/Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))var zoom=minzoom=0;
if(isMobile())var zoom=minzoom=0;
var map = L.map('eventmap',{ 'zoom': zoom, 'minZoom': minzoom, 'center': [20.00, 10.00]});
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Data &copy; by <a href="http://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>.',
maxZoom: 18
}).addTo(map);

var markers = new L.MarkerClusterGroup({showCoverageOnHover: false, maxClusterRadius: 40});
{% filter_for p in site.conferences sort_by:date %}{% if p.geoloc %}
L.marker([{{ p.geoloc }}]).bindPopup('<b><a href="{{ p.link | htmlescape }}">{{ p.title | htmlescape }}</a></b><br>{{ p.date }}<br>{{ p.venue | htmlescape }}<br>{{ p.address | htmlescape }}<br>{{ p.city | htmlescape }}, {{ p.country | htmlescape }}').addTo(markers);
{% endif %}{% endfilter_for %}

{% filter_for p in site.meetups sort_by:date %}{% if p.geoloc %}
L.marker([{{ p.geoloc }}]).bindPopup('<b><a href="{{ p.link | htmlescape }}">{{ p.title | htmlescape }}</a></b><br>{{ p.date }}<br>{{ p.venue | htmlescape }}<br>{{ p.address | htmlescape }}<br>{{ p.city | htmlescape }}, {{ p.country | htmlescape }}').addTo(markers);
{% endif %}{% endfilter_for %}
for (var i=0, nds=document.getElementById('eventdata').getElementsByTagName('DIV'), n=nds.length; i < n; i++) {
L.marker([parseFloat(nds[i].getAttribute('data-lat')), parseFloat(nds[i].getAttribute('data-lon'))]).bindPopup(nds[i].innerHTML).addTo(markers);
}

map.addLayer(markers);

0 comments on commit 262b550

Please sign in to comment.