From 19e37a2da5f6608bfb6299fc5ee207fd6a86adb9 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Wed, 18 Nov 2015 20:34:22 -0500 Subject: initial commit --- frontend.js | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 frontend.js (limited to 'frontend.js') diff --git a/frontend.js b/frontend.js new file mode 100644 index 0000000..fcf8504 --- /dev/null +++ b/frontend.js @@ -0,0 +1,88 @@ +var streets = []; +var img_dir = '/streets/images/'; +var street_file = '/streets/streets.min.json'; + +function doSearch() { + + // take out previous results + $('#results').text(''); + + // figure out which districts to search + var enabled_districts = []; + + if ($('#dist_51').prop('checked')) { + enabled_districts.push('51'); + } + + if ($('#dist_52').prop('checked')) { + enabled_districts.push('52'); + } + + if ($('#dist_53').prop('checked')) { + enabled_districts.push('53'); + } + + // perform the search + var f = new Fuse(streets, {keys: ['name', 'alternates'], threshold: 0.3}); + var result = f.search($('#search').val()); + + // display results + result.forEach(function(street) { + + // ensure it is in an enabled district + if (enabled_districts.indexOf(street.district) > -1) { + + var html = '
' + + '

' + street.name + '

'; + + if (street.hasOwnProperty("route")) { + html += '

' + street.route + '

'; + } else if (street.hasOwnProperty("routes")) { + + street.routes.forEach(function(route) { + html += '
' + + '

' + route.title + '

' + + '

' + route.route + '

' + + '
'; + }); + } + + if (street.hasOwnProperty('note')) { + html += '

' + street.note + '

'; + } + + if (street.hasOwnProperty('image')) { + html += 'map'; + } + + // add street to the results + $('#results').append(html); + } + + }); + +} + + +$(document).ready(function() { + + // give focus to search box + $('#search').focus(); + + // load the streets + $.getJSON(street_file, function (data) { + streets = data; + }); + + // search when value changed + $('#search').keyup(doSearch); + + // search and refocus when checkboxes change + $(':checkbox').change(function () { + doSearch(); + $('#search').focus(); + }); + + $('#dist_51').prop('checked', true); + +}); \ No newline at end of file -- cgit v1.2.3