Skip to content

Commit

Permalink
Update Network test to show both new and deprecated network states.
Browse files Browse the repository at this point in the history
navigator.network.connection.type and navigator.connection.type.
  • Loading branch information
agrieve committed Oct 10, 2012
1 parent f47c2ee commit 38cd17f
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions network/index.html
Expand Up @@ -31,34 +31,38 @@

<script type="text/javascript" charset="utf-8">

var deviceReady = false;

var eventOutput = function(s) {
function eventOutput(s) {
var el = document.getElementById("results");
el.innerHTML = el.innerHTML + s + "<br>";
};
}

function printNetwork() {
eventOutput("Current network connection type is: " + navigator.network.connection.type);
eventOutput("navigator.connection.type=" + navigator.connection.type);
eventOutput("navigator.network.connection.type=" + navigator.network.connection.type);
}

/**
* Function called when page has finished loading.
*/
function init() {
var deviceReady = false;
function onEvent(e) {
eventOutput('Event of type: ' + e.type);
printNetwork();
}
document.addEventListener('online', onEvent, false);
document.addEventListener('offline', onEvent, false);
document.addEventListener("deviceready", function() {
deviceReady = true;
console.log("Device="+device.platform+" "+device.version);
eventOutput("Network Connection is: " + navigator.network.connection.type);
document.addEventListener('online', function() { eventOutput('Online event, connection is: ' + navigator.network.connection.type); }, false);
document.addEventListener('offline', function() { eventOutput('Offline event, connection is: ' + navigator.network.connection.type); }, false);

eventOutput("Device="+device.platform+" "+device.version);
printNetwork();
}, false);
window.setTimeout(function() {
if (!deviceReady) {
alert("Error: Cordova did not initialize. Demo will not run correctly.");
}
},1000);
}, 1000);
}

</script>
Expand Down

0 comments on commit 38cd17f

Please sign in to comment.