diff --git a/bus.rb b/bus.rb index d49d8df..e54151b 100644 --- a/bus.rb +++ b/bus.rb @@ -3,7 +3,7 @@ require 'json' require 'erb' set :views, File.dirname(__FILE__) + '/templates' -set :public, File.dirname(__FILE__) + '/static' +set :public_folder, File.dirname(__FILE__) + '/static' STOPS = JSON.parse(File.read("./bus_stops.json"))["markers"] @@ -12,7 +12,7 @@ @search_results = STOPS.select {|x| x["name"] =~ /#{params[:search]}/i} elsif params[:lat] && params[:lon] && params[:lat] != "" && params[:lon] != "" @search_results = STOPS.select { |x| approximate_distance_between(x, params) < 0.005 } - @search_results.sort_by! { |x| approximate_distance_between(x, params) } + @search_results.sort!{ |a, b| approximate_distance_between(a, params) <=> approximate_distance_between(b, params) } end erb :index end diff --git a/static/mobile.js b/static/mobile.js new file mode 100644 index 0000000..4843914 --- /dev/null +++ b/static/mobile.js @@ -0,0 +1,30 @@ +// Hide address bar on iOS +window.addEventListener("load",function() { +setTimeout(function () { + window.scrollTo(0, 1); +}, 0); +}); + +// Mobile Safari in standalone mode +if(("standalone" in window.navigator) && window.navigator.standalone){ + + // If you want to prevent remote links in standalone web apps opening Mobile Safari, change 'remotes' to true + var noddy, remotes = false; + + document.addEventListener('click', function(event) { + + noddy = event.target; + + // Bubble up until we hit link or top HTML element. Warning: BODY element is not compulsory so better to stop on HTML + while(noddy.nodeName !== "A" && noddy.nodeName !== "HTML") { + noddy = noddy.parentNode; + } + + if('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes)) + { + event.preventDefault(); + document.location.href = noddy.href; + } + + },false); +} diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..c415e0d --- /dev/null +++ b/static/style.css @@ -0,0 +1,38 @@ +body { + font: normal 14px "Helvetica Neue", "Helvetica", "Arial" sans-serif; + margin: 0; + padding: 0; +} +p.instruction { + margin: 5px; + font-size: 13px; +} +form.search { + margin: 5px; +} +td.stop, +td.map { + vertical-align: top; + border-bottom: 1px solid #ddd; +} +td.map a { + padding: 5px 3px 5px 0; + display: block; +} +a.stop { + padding: 5px 6px 6px 6px; + color: #000; + display: block; + text-decoration: none; +} +a.stop span.name { + font-weight: bold; + font-size: 17px; +} +a span.details { + color: #000; + font-size: 14px; +} +a.stop span.direction { + color: #36C; +} diff --git a/templates/index.erb b/templates/index.erb index d096c52..5b0e994 100644 --- a/templates/index.erb +++ b/templates/index.erb @@ -1,28 +1,53 @@ -
Search for a bus stop name here, or try autolocation.
- <% if @search_results %> -
+ ">
+
+ <%= result["name"] %>
+ <% if result["stopIndicator"] %>
+ (<%= result["stopIndicator"] %>)
+ <% end %>
+
+
+ <% if result["towards"] %>
+ + Towards <%= result["towards"].downcase.gsub(/\b\w/){$&.upcase} %> + <% end %> + + <%= result["routes"].collect {|x| x["name"]}.join(", ") %> + + + |
+ + +<%= result["lng"]%>">map + | +