Skip to content

Commit

Permalink
Network Information API Example
Browse files Browse the repository at this point in the history
  • Loading branch information
sinhyeok committed Aug 21, 2013
1 parent b72c626 commit 7ce0354
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 0 deletions.
24 changes: 24 additions & 0 deletions NetworkInformation/connection_bandwidth.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE>
<html>
<head>
<title>Pony viewer</title>
</head>
<body>
<button onclick="goBack();">Back</button>
<br />
<img id='pony' alt="An image showing a pony" title="My precious!">
<script>
function goBack() {
window.history.back();
}

var i = document.getElementById('pony');

if (navigator.connection.bandwidth > 2) {
i.src = "images/pony_hd.jpg";
} else {
i.src = "images/pony_sd.jpg";
}
</script>
</body>
</html>
41 changes: 41 additions & 0 deletions NetworkInformation/connection_metered.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<title>Conditional polling</title>
<script>
function goBack() {
window.history.back();
}

var gPreviousMetered = navigator.connection.metered;
var gIntervalId;

function poll() {
// poll stuff
}

navigator.connection.addEventListener('change', function() {
if (gPreviousMetered == navigator.connection.metered) {
return;
}

gPreviousMetered = navigator.connection.metered;
if (!navigator.connection.metered) {
gIntervalId = setInterval(poll, 1000);
} else {
clearInterval(gIntervalId);
}
}, false);

// At load time.
if (!navigator.connection.metered) {
gIntervalId = setInterval(poll, 1000);
}
</script>
</head>
<body>
<button onclick="goBack();">Back</button>
<br />
<button onclick="poll();">Poll</button>
</body>
</html>
Binary file added NetworkInformation/images/pony_hd.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added NetworkInformation/images/pony_sd.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions NetworkInformation/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>Network Information API Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<script type="text/javascript">
function connectionBandwidth() {
document.location = "connection_bandwidth.html";
}

function connectionMetered() {
document.location = "connection_metered.html";
}
</script>
</head>
<body>
<p>
<button onclick="connectionBandwidth()">Connection Bandwidth Example</button>
<br />

<button onclick="connectionMetered()">Connection Metered Example</button>
<br />
</p>
</body>
</html>
14 changes: 14 additions & 0 deletions NetworkInformation/manifest.webapp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0.1",
"name": "NetworkInformation",
"description": "Network Information API Example App",
"launch_path": "/index.html",
"icons": {
"16": "/img/icons/icon-16.png",
"48": "/img/icons/icon-48.png",
"128": "/img/icons/icon-128.png"
},
"installs_allowed_from": ["*"],
"appcache_path": "/cache.manifest",
"default_locale": "en"
}

0 comments on commit 7ce0354

Please sign in to comment.