ITeye博客

UI Development using jQueryMobile

eonbell · 2011-03-20 14:49 · 网文收藏 · Web前端 · Markdown

Introduction to jQueryMobile

Following is an extract from jQueryMobile site -

jQuery Mobile: Touch-Optimized Web Framework for Smartphones & Tablets

A unified user interface system across all popular mobile device platforms, built on the rock-solid jQuery and jQuery UI foundation. Its lightweight code is built with progressive enhancement, and has a flexible, easily themeable design. Alpha Release Notes

Seriously cross-platform & cross-device

jQuery mobile framework takes the "write less, do more" mantra to the next level: Instead of writing unique apps for each mobile device or OS, the jQuery mobile framework will allow you to design a single highly branded and customized web application that will work on all popular smartphone and tablet platforms. Device support grid

iOS Android BlackBerry™ Bada Windows® Phone Palm webOS™ Symbian MeeGo™

Touch-optimized layouts & UI widgets

Our aim is to provide tools to build dynamic touch interfaces that will adapt gracefully to a range of device form factors. The system will include both layouts (lists, detail panes, overlays) and a rich set of form controls and UI widgets (toggles, sliders, tabs). Demos

Themable designs: Bigger and better

To make building mobile themes easy, we’re dramatically expanding the CSS framework to have the power to design full applications. For more polished visuals without the bloat, we added support for more CSS3 properties liketext-shadow, box-shadow, and gradients.

Demo Video

Getting started with JQueryMobile

There are two parts to jQueryMobile

jQuery - (Event Handling, DOM Manipulation and Ajax) jQuery Mobile UI

jQuery - ( Event Handling, DOM Manipulation and Ajax)

This is out of scope for this Article. Please refer to w3c Tutorial on jQuery - http://www.w3schools.com/jquery/default.asp

jQuery Mobile UI

jQuery Mobile Declarative UI

This is the best part about jQuery Mobile. The UI is not declared by using HTML 5 style "data-role". This makes the UI development a breeze. Building a prototype of jQuery Mobile UI (wireframe) would not require any coding, but just html tags.

Lets try to build the following Page in Phone Gap



Step 1 - Include needed Javascript and CSS

Step 2 - Declare different Pages

home is the first screenshot and search is the second screen shot.

 <div data-role="page" id="home"> 

      .....

 </div>



 <div data-role="page" id="search"> 

      .....

 </div>



 <div data-role="page" id="recent"> 

      .....

 </div>

Step 3 - Declare Header and Page Navigation

 <div data-role="page" id="home"> 
<h1>AlternativeTo Home</h1> 
<p>Find Alternatives To Your favourite Softwares </p>

<p><a href="#search" data-role="button">Search Alternatives</a></p>    <!-- navigation button's href points to other page -->

<p><a href="#recent" data-role="button">Recent Alternatives</a></p>
 </div> 





 <div data-role="page" id="search">  

      <div data-role="content"> 

           <ul data-role="listview" id="list">                     <!-- Special Widget which is List View to show data in a list -->

          </ul> 

     </div>

 </div>

jQuery Mobile API

      The jQuery Mobile API talks about Page Loading, Transition, Dialog box handling, List View manipulation, item click etc.



      Complete API reference - http://jquerymobile.com/demos/1.0a3/

JQueryMobile + PhoneGap

 Boot Events

 The main thing when using any Javascript library is to be handle the library boot strap event. A Boot strap event is when js library hells that it is ok to start using its api





     A Boot strap event handling in case of jquery is the as follows

$(document).ready(function() { //Its ok to use all jquery functions here });

A Boot strap event handling in case of jQuery mobile is as follows (read more here)

$(document).bind("deviceready", function(){

});

or

document.addEventListener("deviceready", onDeviceReady, false);

These bootstraps need to be chained (i,e one calling another one), in order to properly bootstrap both jquery/jquerymobile and phonegap.

Ideally following should be enough ( PS- I need to verify the following code)

$(document).ready(function() {

$(document).bind("deviceready", function(){

}); });

 Rest of Integration

 The Rest of the Integration is using jQuery selector, event handling  to call jQueryMobile and  phonegap api.

Demo Apps

Following is the Demo App, with complete index.html file of the UI

Source Code

<div data-role="page" id="home"> 
<h1>AlternativeTo Home</h1> 
<p>Find Alternatives To Your favourite Softwares </p>

<p><a href="#search" data-role="button">Search Alternatives</a></p>    

<p><a href="#recent" data-role="button">Recent Alternatives</a></p>
<h1>Search Alternatives</h1> 

<div class="class= ui-body ui-body-b"> 



     <input type="text" name="search" id="searchBox" value="" data-theme="a" /> 

     <button type="submit" data-theme="a" id="searchButton">Search</button>     



</div>  
 <ul data-role="listview" id="list"> 



</ul> 
<h1> Recent Alternatives</h1> 
<p>This app rocks!</p> 

Download Demo Source

Download Demo Source here - PhoneGap.zip

This is a working Demo of PhoneGap Client of site - http://alternativeto.net

Issues to watch out

The issue you will notice first and not like is that of ListView with header and footer.

Here is an example

Notice the scrollbar starting from top of page and going it the bottom Notice the header missing in the second image, (it is missing because it has moved up)

Ideally we would want

Scroll to start below header and end above footer Header and Footer to be fixed

Fortunately, the fix for this could be provided very soon. Here is an experimental source of jQuery mobile handling the issue - http://jquerymobile.com/test/experiments/scrollview

I would wait for this fix and still bet on jQuery Mobile.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。