dcsimg

JQuery Mobile Preview, Part 2

We whip up a small sample app to see just how much heavy-lifting jQuery takes off a mobile developer's hands.

Getting Started

Last week we introduced JQuery Mobile as a new option for mobile software development. JQuery Mobile is from the same team that has produced the popular JQuery Project.

In this article we take a look at a basic JQuery Mobile-based application.

The example code for this article is hosted at http://jquery.lm.msiservices.com and should be viewed with a WebKit based browser including but not limited to the following browser platforms:

  • Chrome
  • Safari or webkit nightly build
  • Android
  • iPhone/iPad
  • Palm WebOS

The ingredients, HTML5 from the start

The doctype declaration of a JQuery Mobile application follows the HTML5 requirement:

<!DOCTYPE HTML>

Next comes the html head section:

<!DOCTYPE html>
<html>
<head>
<title>Linux Mag JQuery Mobile Sample</title>
<link rel="stylesheet"
href="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.css" />
<script
src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script
src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script>
</head>

The items to note here:

  • Style sheet reference. JQuery Mobile relies heavily on CSS.
  • Javascript include of the core JQuery library. Note that JQuery Mobile relies upon JQuery 1.4.4 or later.
  • Javascript include of the JQuery Mobile library.

These includes are for the Alpha 2 release of JQuery Mobile.

When using libraries such as JQuery Mobile, these include files are used on virtually every page of your site or application. The terminolgy is getting blurred of late between what is a site or an application. I’ll leave that debate to others who are more interested in semantics.

The important aspect of the includes is that they need to be download from someone’s server. Broadly speaking there are two common practices:

  • Option one is to download a copy of the needed include files and distribute them from your own server. The benefit of this approach is that your application won’t have unexpected changes occuring in the core library components. The downside is that you don’t get the latest features and bug fixes automatically. Additionally if you serve these files over and over from your own web server it may have a negative impact on your application’s performance and the bandwidth consumed may lead to increased hosting costs.
  • The second option is to use a hosted version available from others such as Google or the JQuery project themselves. You can download the required files from JQuery’s Content Delivery Network (CDN). To learn more about this option visit the JQuery Mobile download page.

Now that we’ve got the required files into our application, let’s look at application structure.

HTML5 attributes

JQuery Mobile relies heavily on the HTML5 data attribute. This attribute is somewhat of a magic bullet to HTML5. Any attribute which starts with “data-” is ignored by the rendering engine and is available for pushing data, instructions, etc. to an application. In the case of JQuery Mobile, the data attribute is used to help with application structure. Let’s look at an example.

The “data-role” attribute is used by JQuery Mobile to segment html elements into pages and parts of pages.

The image below shows the first page of the sample application.

First page of JQuery Mobile sample application
First page of JQuery Mobile sample application

Here is the code which corresponds to the prior screen shot:

<div data-role="page" id="page1">
	<div data-role="header">
	<h1>Header goes here</h1>
	</div>
	<div data-role="content">
	Content goes here
	<a href="#page2" data-transition="slide">Slide to page two</a><br/>
	</div>
	<div data-role="footer">
	Footer, Copyright, etc.
	</div>
</div>

The page includes a header portion, a content portion, and a footer portion. Each of these is implemented as a div element and designated via the data-role attribute. Additionally the data-role tag is used to delineate a “page”. So, for starters we are interested in four values of the data-role attribute used by the div tag:

  • page
  • header
  • content
  • footer

Comments on "JQuery Mobile Preview, Part 2"

My web-site regal assets review (Luz)

We came across a cool web-site that you could possibly enjoy. Take a search for those who want.

my blog – regal assets review (Randy)

Here is my blog … buy beats online (Bobby)

Here is my homepage reviews of regal assets (Birgit)

my webpage: regal assets reviews (Tiffani)

We came across a cool website that you just may possibly appreciate. Take a look for those who want.

Check out my weblog: regal assets reviews (Casie)

My webpage regal assets review (521sh.net)

Visit my website … regal assets review (http://www.qimila5.com)

Feel free to surf to my web blog rap beats [Enid]

my web page :: regal assets review (Marcela)

My weblog; regal assets review (Rodney)

Feel free to surf to my web-site :: regal assets reviews – Darren,

Feel free to surf to my weblog – regal assets reviews; Florencia,

Here is my page :: regal assets review [Allie]

Here is a superb Blog You may Uncover Interesting that we encourage you to visit.

my site: buy beats (Tiffiny)

My web site buy rap beats online (Loreen)

Although sites we backlink to beneath are considerably not associated to ours, we really feel they are really really worth a go by means of, so possess a look.

My blog post reviews of regal assets (Young)

Also visit my website: reviews of regal assets (Donnie)

Leave a Reply