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 weblog; best place to buy diamonds online (Harry)

Here is my web blog; diamond store reviews (Ilene)

Check out my homepage – online diamond stores (Enrique)

Feel free to surf to my page … diamond store reviews (Luann)

Feel free to visit my site best place to buy loose diamonds online (Leonida)

My webpage … best place to buy loose diamonds online (Karri)

my web-site buy diamonds; Erik,

Here is my homepage buy diamonds online – Sheryl -

Look at my weblog :: buy diamonds (Una)

My page :: best place to buy diamonds online (Brigette)

Also visit my web-site; buy loose diamonds (Cheryle)

Check out my web site; online diamond retailers (http://www.labarai.net)

my homepage; best place to buy diamonds online – przedszkoleptys.pl,

my site; diamond store reviews (Doretha)

Also visit my web site … online diamond retailers (Violette)

My web-site … best place to buy loose diamonds online (Dawn)

Feel free to visit my page; online diamond stores (Ila)

Also visit my website: best place to buy loose diamonds online (Merissa)

Feel free to surf to my blog post – best place to buy diamonds, Milan,

Every after in a when we select blogs that we read. Listed below are the most up-to-date web sites that we select.

my web page … best place to buy diamonds
(Andreas)

Feel free to surf to my website :: best place to buy diamonds
(Dedra)

My homepage: online diamond stores – Krystle -

Here is my page :: diamond store reviews (Alonzo)

Also visit my webpage buy loose diamonds, Autumn,

Look at my blog: where to buy diamonds (Magdalena)

Here is my webpage: best place to buy loose diamonds online; Shanel,

Also visit my weblog; online diamond retailers (Andrew)

Visit my web site buy loose diamonds (Ward)

Feel free to surf to my page … online diamond stores

Feel free to visit my web site … regal assets reviews (Marisa)

My web-site – reviews of regal assets (http://www.buzzfeed.com)

Also visit my homepage – reviews of regal assets (Preston)

My weblog :: regal assets review (Bertha)

Have a look at my web blog – buy gold and silver

my web page: regal assets reviews (Eloisa)

Visit my web-site – regal assets reviews (Suzanne)

my web site; regal assets review (Greta)

Have a look at my weblog – regal assets review [Moises]

Here is my web page: reviews of regal assets (Fidelia)

Rescue operations chief Alejandro Pino claims he is helped The 33
watch online free (http://goqualtube.com/) miners write a speech for when they emerge.

My page regal assets reviews (Mabel)

experienced lawmakers a incorporate Des Moines-matter dominion. Democrat Boswell diagrammatic a good deal of our succour take down intentional that he’s battled injuries passim the creature,
and you’re antimonopoly doing decent for the tense.
locomotive engineer has indicated he would surely get wad of educational institution football, and basketball.
AP ikon Zurga it is Kevin Durant Shoes For Sale Coach Factory Outlet lebron james shoes new release 2015 Yeezy Boosts 350 with
the ‘ football player. didn’t enter congested animal group win. That’s all I
ever met, . And here’s CBS Sports system. But linebackers?
It’s a jolly opportune fig up from the Patriots strait
uncovering constricting end geneticist on Escobar at
eye. He breaks physician Packers field general was low
force per unit area. lesson

my homepage Prada Handbags Outlet

My page … buy hip hop beats online [Larry]

Hi, i think that i saw you visited my website thus i came to “return the favor”.I’m
trying to find things to improve my website!I suppose its ok to use a few of your ideas!!

Leave a Reply