Skip to content

Instantly share code, notes, and snippets.

@eads
Created February 18, 2014 04:21
Show Gist options
  • Save eads/9064603 to your computer and use it in GitHub Desktop.
Save eads/9064603 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
$(document).ready(function() {
// Search 6 weeks back
var start = moment();
var end = start.clone().add('months', 1).add('weeks', 2);
// Set up collection
var collection = new EventAPICollection([], {
url: 'http://urltoapiproxy.com/events.json',
indexed: false,
params: {
date_from: start.format('YYYY-MM-DD'),
date_to: end.format('YYYY-MM-DD'),
type: "Theater",
fields: 'event_dates,neighborhood_name,venue_name,description,url,price,title,state,city_name'
},
});
// Create an input box
var filter = new FilterView({
el: $('#filter'),
collection: collection,
});
// When collection.fetch() is called, bind to the autocomplete box
collection.on("sync", function() {
$('#filter input').attr('disabled', false);
filter.$input
.bind('typeahead:selected typeahead:autocompleted',
function(e, value, dataset) {
if (value) {
var val = value.value;
if (dataset == 'day') {
val = value.day;
}
val = encodeURIComponent(val);
window.location = "http://myeventurl.com/#" + dataset + "/" + val;
}
})
;
});
// Get the data!
collection.fetch();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment