Skip to content

Commit

Permalink
Merge pull request #9 from sinhyeok/master
Browse files Browse the repository at this point in the history
Add NetworkInformation API Example
  • Loading branch information
hyeonseok committed Aug 29, 2013
2 parents 9e7440c + b3908f1 commit f802627
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 1 deletion.
1 change: 0 additions & 1 deletion IndexedDB/manifest.webapp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
"128": "/img/icons/icon-128.png"
},
"installs_allowed_from": ["*"],
"appcache_path": "/cache.manifest",
"default_locale": "en"
}
Binary file added NetworkInformation.zip
Binary file not shown.
28 changes: 28 additions & 0 deletions NetworkInformation/connection_bandwidth.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE>
<html>
<head>
<title>Pony viewer</title>
</head>
<body>
<button onclick="goBack();">Back</button>
<br />
<br />
<br />
<br />
<img id='pony' alt="An image showing a pony" title="My precious!">
<script>
function goBack() {
window.history.back();
}

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

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

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

function poll() {
alert("Polling!");
}

var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
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.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/turtle.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>
10 changes: 10 additions & 0 deletions NetworkInformation/manifest.webapp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "NetworkInformation",
"description": "Network Information API Example App",
"launch_path": "/index.html",
"icons": {
"16": "img/icon-16.png",
"48": "img/icon-48.png",
"128": "img/icon-128.png"
}
}

0 comments on commit f802627

Please sign in to comment.