Created
January 4, 2012 21:53
-
-
Save macdonst/1562377 to your computer and use it in GitHub Desktop.
Reading configuration defaults
This file contains hidden or 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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta name="viewport" content="width=320; user-scalable=no" /> | |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | |
<title>PhoneGap Config Example</title> | |
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" charset="utf-8"> | |
<script type="text/javascript" charset="utf-8" src="phonegap-1.3.0.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
// Global variables | |
// | |
var Config; | |
function onBodyLoad() { | |
document.addEventListener("deviceready",onDeviceReady,false); | |
}; | |
// PhoneGap is ready | |
// | |
function onDeviceReady(){ | |
var request = new XMLHttpRequest(); | |
request.open("GET", "config.json", true); | |
request.onreadystatechange = function(){//Call a function when the state changes. | |
console.log("state = " + request.readyState); | |
if (request.readyState == 4) { | |
if (request.status == 200 || request.status == 0) { | |
console.log("*" + request.responseText + "*"); | |
Config = JSON.parse(request.responseText); | |
var info = document.getElementById("info"); | |
info.innerHTML = "Default Path: " + Config.defaultPath + "<br/>" + | |
"Media Path: " + Config.mediaPath; | |
} | |
} | |
} | |
request.send(); | |
} | |
function playMedia() { | |
var my_media = new Media(Config.mediaPath + "test.mp3"); | |
my_media.play(); | |
} | |
</script> | |
</head> | |
<body onload="onBodyLoad();" id="stage" class="theme"> | |
<h1>Welcome to PhoneGap!</h1> | |
<h2>this file is located at assets/index.html</h2> | |
<div id="info"> | |
</div> | |
<a href="#" class="btn large" onclick="playMedia();">Play</a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment