Always On, Always Connected Week 2 - HTML, CSS, JavaScript Refresher and PhoneGap Development Basics
Now that we have the PhoneGap development environment up and running, we should take a step back and refresh our knowledge of HTML, CSS, and JavaScript.
HTML for Mobile
History
WAP
WAP or Wireless Application Protocol is a protocol for accessing web like pages on mobile devices. It uses a similar language to that of HTML called WML (Wireless Markup Language) and can be delivered via HTTP (just like a webpage).
To create a WAP page, you merely create a page with the extension ".wml" and put it on a web server.
Here is a simple WML page:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<!--begin card-->
<card>
<do type="accept">
<go href="#card2"/>
</do>
<p>
This is the first card.
Press OK to go to the second card.
</p>
</card>
<!--begin card-->
<card id="card2">
<p>
This is the second card.
</p>
</card>
</wml>
WAP never really took off in the US due to several reasons: Carriers overstated it's capabilities, most devices could only see a few characters or words at a time, people were used to the normal web and this new limited web isn't very appealing and in general people weren't designing separate WML sites as would be required.
Modern mobile browsers are no longer even attempt to offer support for WAP/WML and moved towards regular HTTP with XHTML MP or regular HTML/XHTML.
XHTML MP was the start of an integration of technologies meant for desktop web browsers and those on mobile devices.
HTML5
With WebKit (as we discussed last week) and HTML5, the mobile web is now a first class citizen, on par with the normal web.
When we use HTML5, especially on a mobile device, we should be sure to let the browser know that is what we are using by specifying the correct DOCTYPE at the top of the page:
Of course, looking at a page on a hardware device is the best way to test. Second best are the various emulators and simulators available. While starting to develop and do layout, the Chrome device emulation is nice.
Meta Tags
Meta Tags generally are used to provide meta-data about a page and it's content. This is useful for search engines and other applications.
The most important one at the moment is the "viewport" tag.
A viewport tag allows the developer to specify zoom and width attributes of a page based upon the device's display capabilities.
Some Examples:
The following specifies that the content will be full screen with a virtual size of 320 pixels no matter how large the display is. If you are looking at an iPad, it will be treated as if it were 320 pixels wide and the content will be rendered on it at that size. It will appear very large and zoomed in.
<meta name="viewport" content="width=320">
Below specifies that the content will be full screen whatever the width the device is. Content here could be rendered too small on devices with large numbers of pixels per inch (retina displays and the like). If you don't use this tag, the browser will assume a page width of 960 pixels and zoom to either fill or shrink the content to fit the device.
Loading content off the network of loading new pages in the browser can be time consuming. If at all possible, having content reside on a single page is preferred.
Fragments
One thing that helps enable this is the use of internal links via URL fragments.
When designing for mobile, it is important to not use "hover" states as they don't exist on touch screens. Also make sure to use "active" state so that users see some feed back when they touch an element.
When developing with Cordova, we need to make sure we use the "deviceready" event callback in tandem with the "window load" event to ensure that we are completely ready to execute our Cordova JavaScript code:
<script type="text/javascript">
function onWindowLoad() {
document.addEventListener('deviceready', onDeviceReady);
}
function onDeviceReady() {
window.alert("We are ready to go!");
}
window.addEventListener('load', onWindowLoad);
</script>