-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from sinhyeok/master
Add NetworkInformation API Example
- Loading branch information
Showing
8 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |