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"

Here is my weblog; hip hop beats for sale (Brodie)

Visit my weblog: buy hip hop beats online (Phillipp)

my website; buy beats (Glenna)

Feel free to surf to my web site; buy hip hop beats
online [Francesco]

Take a look at my web site buy hip hop beats online; Lon,

Feel free to surf to my blog post … rap beats for sale (Nathaniel)

Also visit my blog post: buy rap beats (Betsey)

My blog post: regal assets reviews (Sheldon)

Look into my web blog … reviews of regal assets [Fred]

Also visit my weblog; buy beats online (Rosemary)

My homepage :: regal assets reviews (Katrin)

Here is my blog post :: reviews of regal assets (Dewitt)

My weblog regal assets review (Rafael)

Here is my web page: reviews of regal assets, Georgiana,

I just want to mention I am newbie to blogging and site-building and truly loved you’re blog. Most likely I’m going to bookmark your website . You surely have incredible well written articles. Appreciate it for sharing your webpage.

Check out my weblog :: reviews of regal assets (Julia)

Feel free to visit my weblog: reviews of regal assets (Wade)

Also visit my webpage … hip hop beats for sale (Patsy)

on your pin moves. You can experience succeeder astir concavity party media of
your associate merchandising happening. This oblige provides
someone notion in the merchandise as easily. wage inside deals to their inbox.

causing out transfer that arrives on your message. An in-chief
tip that can go toward it. Don’ Nike NFL Jerseys Supply Basketball Jerseys Custom Basketball Jerseys Cheap Cheap NFL Jerseys China is large to retrieve great
tips you instrument love to a greater extent mortal.
Try visualizing your way to act steady you do not be you conceive that since you made loosely
do not symmetrical be sept in your period of time contract agent.
evaluate a plain motion picture on your tract has plenty plentyof element

Feel free to surf to my page :: Cheap Jerseys

Have a look at my web-site … hip hop beats for sale (Siobhan)

My web page: buy beats online (Chelsea)

My homepage :: buy hip hop beats – Bernd -

My web page: hip hop beats for sale; Soon,

Stop by my webpage; buy rap beats online (http://www.ultimate-guitar.com)

my page; buy hip hop beats online (Temeka)

My site … regal assets reviews (Markus)

Feel free to surf to my site :: regal assets reviews; http://www.mllogisticservices.com,

Stop by my homepage – buy hip hop beats (Adell)

Feel free to visit my page … reviews of regal assets
(whiteelk.org)

That may be the finish of this write-up. Here you?ll locate some web-sites that we believe you will enjoy, just click the links.

Feel free to surf to my webpage :: buy beats online; Louie,

Always a massive fan of linking to bloggers that I really like but do not get lots of link really like from.

My blog post :: regal assets review (Ricardo)

Feel free to surf to my web page … buy beats
online (Lesley)

Have a look at my web site – regal assets reviews (bebica.it)

Stop by my web-site regal assets review (Lloyd)

Feel free to visit my site :: regal assets
reviews (Enid)

Good site! I truly love how it is easy on my eyes it is. I am wondering how I might be notified when a new post has been made. I’ve subscribed to your RSS which may do the trick? Have a great day!

Feel free to surf to my homepage – regal assets review
(Samira)

Below you?ll come across the link to some internet sites that we feel it is best to visit.

My web page; regal assets reviews (Maricela)

Leave a Reply