Skip to content

Commit

Permalink
fixed typeahead for events
Browse files Browse the repository at this point in the history
  • Loading branch information
vigliag committed Aug 3, 2016
1 parent 3171c4a commit d30c713
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
16 changes: 11 additions & 5 deletions webapp/app/assets/javascripts/typeahead.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
function initTypeahead(remoteUrl, itemUrl) {


function initTypeahead(remoteUrl, itemUrl, suggestionClickHandler) {
"use strict";

function defaultSuggestionClickHandler(event, datum, name){
var identifier = datum.slug || datum.uid || datum.id;
window.location.href = itemUrl + identifier;
}

suggestionClickHandler = suggestionClickHandler || defaultSuggestionClickHandler;

var searchSelector = 'input.typeahead';

var bloodhound = new Bloodhound({
Expand All @@ -27,8 +36,5 @@ function initTypeahead(remoteUrl, itemUrl) {
});

// this is the event that is fired when a user clicks on a suggestion
$(searchSelector).bind('typeahead:selected', function(event, datum, name) {
//console.debug('Suggestion clicked:', event, datum, name);
window.location.href = itemUrl + datum.slug;
});
$(searchSelector).bind('typeahead:selected', suggestionClickHandler);
}
9 changes: 7 additions & 2 deletions webapp/app/views/events/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
</div>

<script type="text/javascript">
var mymap = null;

function iconForEvent(ev) {
if (ev.isToday) {
Expand Down Expand Up @@ -94,7 +95,10 @@
function drawMap(locations) {
var sicily_coords = [37.5579, 14.1368];
var zoom = 8;
var mymap = L.map('mapid').setView(sicily_coords, zoom);
if (mymap){
mymap.remove();
}
mymap = L.map('mapid').setView(sicily_coords, zoom);

var OpenStreetMap_DE = L.tileLayer('http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png', {
maxZoom: 19,
Expand Down Expand Up @@ -207,7 +211,8 @@
}

$(document).ready(function () {
initTypeahead('/events/typeahead', '/events/');
initTypeahead('/events/typeahead', 'https://www.facebook.com/events/');

//wait for gcharts to be loaded before loading the rest of the page
google.charts.setOnLoadCallback(onGoogleChartsLoaded);
});
Expand Down

0 comments on commit d30c713

Please sign in to comment.