This is the first entry to the blog series dedicated to developing mobile applications for Firefox OS.
Firefox OS apps are created using the standard web technologies: HTML, CSS, and Javascript. Let’s create three files that test the basic functionality of each of these technologies.
HTML:
<!-- hello.html -->
<html>
<head>
<title> Hello, Firefox OS </title>
<script type="text/javascript" src="hello.js"> </script>
<link rel="stylesheet" type="text/css" href="hello.css">
</head>
<body>
<p>Hello, Firefox OS</p>
<button type="button" id="coolButton">Do Something Cool</button>
</body>
</html>
CSS:
/* hello.css */
.body {
background-color:#00ff00;
}
Javascript:
// hello.js
var readyStateCheckInterval = setInterval(function() {
if (document.readyState === "complete") {
init();
clearInterval(readyStateCheckInterval);
}
}, 100);
function init() {
console.log("ready!");
var button = document.getElementById('coolButton');
var state = 0; // 0 = normal | 1 = converted
button.addEventListener('click', function(event) {
if(state === 0) {
document.body.style.backgroundColor = 'black';
this.innerHTML = "Turn It Back!";
state = 1;
} else if( state === 1) {
document.body.style.backgroundColor = '#fdf3e6';
this.innerHTML = "Do That Again!";
state = 0;
}
});
}
Save all these files in the same directory/folder. Now open a web browser and point it to hello.html. Check that everything is working. All the files work as a website. Let’s make them work as an application.
The easiest way to test a Firefox OS application is to use the simulator for the Firefox web browser. Here’s a quick tutorial on how to install it.
Start Simulator on the bottom of the pageInstall SimulatorInstall Simulator button on the pageAllow in the menu that pops up under the URL barInstall NowAnd it’s installed! Here’s how to start the simulator.
Start SimulatorFirefox OS 1.2Now, we’re ready to test the application. Let’s convert our website into the application.
The App Manifest is a JSON file that contains metadata about a Firefox OS application. It can contains data on the developer and the permissions that the application uses. To turn our Hello World website into an application we only need to provide the required metadata fields
The manifest only requires the fields
Our manifest will look like this
{
"name": "Hello, Firefox OS",
"description": "Simple Demo App",
"launch_path": "/hello.html",
"icons": {
"128": "/hello.png"
}
}
The field launch_path is needed because our HTML file is not name index.html. Also, it is required that your application has an icon (To save some time, feel free to use this one I made myself).
Finally, it’s time to test the application on the simulator.
Apps tabAdd Packaged AppUpdateAnd that’s it! It’s a simple process