Skip to content

Commit

Permalink
Move ios stuff to a js include and use on stop page too. Add ios home…
Browse files Browse the repository at this point in the history
… screen web app link fix
  • Loading branch information
jwheare committed May 20, 2012
1 parent d5092d2 commit 78b60b6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
30 changes: 30 additions & 0 deletions static/mobile.js
Original file line number Diff line number Diff line change
@@ -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);
}
11 changes: 2 additions & 9 deletions templates/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<title><% if @search_results %>Search Buses Live!<% else %>Buses Live!<% end %></title>
<meta name="viewport" content="width=device-width">
<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="stylesheet" href="/style.css" type="text/css">
<link rel="stylesheet" href="/style.css" type="text/css">
<script src="/mobile.js"></script>
</head>

<p class="instruction">Search for a bus stop name here, or try <a href="/nearby">autolocation</a>.</p>
Expand Down Expand Up @@ -48,13 +49,5 @@
</table>
<% end %>

<script>
// Hide address bar on iOS
window.addEventListener("load",function() {
setTimeout(function () {
window.scrollTo(0, 1);
}, 0);
});
</script>
</body>
</html>
1 change: 1 addition & 0 deletions templates/stop.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
poll()
});
</script>
<script src="/mobile.js"></script>
<link rel="apple-touch-icon" href="http://colour.abscond.org/<%= Digest::MD5.hexdigest(@stop["smsCode"])[0..5] %>.png" />
</head>

Expand Down

0 comments on commit 78b60b6

Please sign in to comment.