jQuery Mobile Tutorial
        2013/02/05
        Mowd Chen
 jQuery Mobile
   Introduction
   Components
   API
What is jQuery Mobile?
 Unified user interface system.
 Works seamlessly across all popular mobile device
  platforms.

 Built on the rock-solid jQuery and jQuery UI foundation.
 Focused on a feature-rich but lightweight codebase.
 Built on progressive enhancement with a flexible
  theming system and ThemeRoller tool.
What is jQuery Mobile?
 Use ajax navigation system that brings animated page
  transitions and a core set of UI widgets
   Pages
   Dialogs
   Toolbars
   Listviews
   Buttons with icons
   Form elements
   Accordions
   Collapsibles
Supported platform
   Apple iOS 3.2*-6.0 - Tested on the original     Chrome for Android 18 - Tested on
    iPad (4.3 / 5.0), iPad 2 (4.3), iPad 3 (5.1 /    Android 4.0 and 4.1 deviceset
    6.0), original iPhone (3.1), iPhone 3
    (3.2), 3GS (4.3), 4 (4.3 / 5.0), and 4S (5.1    Chrome Desktop 11-21 - Tested on OS X
    / 6.0)                                           10.7 and Windows 7
   Android 2.1-2.3 - Tested on the HTC             Safari Desktop 4-5 - Tested on OS X 10.7
    Incredible (2.2), original Droid (2.2), HTC      and Windows 7
    Aria (2.1), Google Nexus S (2.3).
    Functional on 1.5 & 1.6 but performance
    may be sluggish, tested on Google G1            Firefox Desktop 4-15 - Tested on OS X
    (1.5)                                            10.7 and Windows 7

   Android 3.2 (Honeycomb) - Tested on the         Internet Explorer 7-10 - Tested on
    Samsung Galaxy Tab 10.1 and Motorola             Windows XP, Vista and 7
    XOOM
                                                    Opera Desktop 10-12 - Tested on OS X
   Android 4.0 (ICS) - Tested on a Galaxy           10.7 and Windows 7
    Nexus. Note: transition performance can
    be poor on upgraded devices

   Android 4.1 (Jelly Bean) - Tested on a
    Galaxy Nexus and Galaxy 7
Quick start: basic page
Quick start: listview
Quick start: slider
Quick start: button
Page & dialogs
Page & dialogs
 jQuery Mobile includes a navigation system to load
  linked pages into the DOM via AJAX, enhance the new
  content, then display pages with a rich set of animated
  page transitions. The navigation system automatically
  transforms all links and forms by using progressive
  enhancement to hijack links and issue AJAX requests.
 The back button is fully supported so
  pages, dialogs, and popups all seamlessly work with
  the navigation system. There are tools to prefetch &
  cache, dynamically inject, and script pages for
  advanced use cases.
Single page
Multi-page
Multi-page
 http://jquerymobile.com/demos/1.2.0/docs/pages/multip
  age-template.html
Page title
 jQuery Mobile automatically parses the title of the page
  pulled via Ajax and changes the title attribute of the
  parent document to match.

 In multi-page template, simply use:
Linking page
Linking page
 http://jquerymobile.com/demos/1.2.0/docs/pages/page-
  links.html
Page transitions
 http://jquerymobile.com/demos/1.2.0/docs/pages/page-
  transitions.html
Page transitions
 Custom the link transition


 Change the default transitions.
   Ex: $.mobile.defaultDialogTransition = „slide‟;
Page Loading Widget



 Deprecated
     $.mobile.loadingMessage
     $.mobile.loadingMessageTextVisible
     $.mobile.loadingMessageTheme
     $.mobile.showPageLoadingMsg()
     $.mobile.hidePageLoadingMsg()
Page Loading Widget
Dialog




<a href="foo.html" data-rel="dialog">Open dialog</a>
Dialog
 Transitions
   data-transition="pop”
 Open Dialog
   $(".selector”).dialog({ overlayTheme: "e" });
 Close dialog
   $('.selector').dialog('close');
Popup
 http://jquerymobile.com/demos/1.2.0/docs/pages/popup
  /index.html
Popup
 Transitions
   data-transition="flip”
 Open popup
   $( "#myPopupDiv" ).popup( "open" );
 Close popup
   $( "#myPopupDiv" ).popup( "close" );
Popup
 Add close button
   <a href="#" data-rel="back" data-role="button" data-
     theme="a" data-icon="delete" data-iconpos="notext"
     class="ui-btn-right">Close</a>

 Add padding
   <div data-role="popup" id="popupPadded" class="ui-
     content">

 Position choice: window, origin, #id
   <a href="#positionWindow" data-rel="popup" data-
     position-to="window">
Popup
 Theme
  <div id="both" data-role="popup" data-theme="e" data-
   overlay-theme="a" class="ui-content">
Prefetching & catching pages
 Prefetching
   <a href="prefetchThisPage.html" data-prefetch>..</a>
   $.mobile.loadPage( pageUrl, { showLoadMsg: false } );
 Catching pages (default: false)
   $.mobile.page.prototype.options.domCache = true;
   <div data-role="page” data-dom-cache="true">
Scripting pages
 pageinit = DOM ready




 Changing page
Scripting pages
 Scrolling to a position within a page




 Passing parameters between pages
   page params plugin
   jQuery Mobile router plugin
   localStorage or sessionStorage
Theme
 http://jquerymobile.com/demos/1.2.0/docs/pages/pages
  -themes.html
Toolbars
Toolbars
 Toolbar page elements are used for headers and
  footers throughout many mobile sites and applications.
  These scroll with the page by default, but can have
  fixed positioning and be persistent across pages.

 jQuery Mobile also provides a navbar component that
  can be used within any toolbar or the page content.
Header bars
Header bars
 Adding Back buttons
   Add data-add-back-btn="true” in page div.
   Add data-rel="back” in anchor.
Footer bars
Footer bars
 Fixed & Persistent footers
   Add data-position="fixed” in footer bar div.
Nav bars
Nav bars
Nav bars
 Icons in navbars
   Add data-icon in nav bars.
   Set the position by data-iconpos="top” (left, right, bottom)
Buttons
Buttons
 Buttons are core widgets in jQuery Mobile, and are
  used within a wide range of other plugins. The button
  markup is flexible and can be created from links or form
  buttons.

 Each button has a range of styling options including
  icons and positioning, inline and mini sizing, grouping
  sets, and theming.
Buttons
 q
Buttons
 Buttons support data-icon and data-iconpos.
   http://jquerymobile.com/demos/1.2.0/docs/buttons/buttons
     -icons.html


 Inline buttons
Buttons
 Grouped buttons
   Vertical




   Horizontal
     Add data-type="horizontal"
Content Formatting
Content Formatting
 Layout grids
     two-column (using the ui-grid-a class)
     three-column (using the ui-grid-b class)
     four-column (using the ui-grid-c class)
     five-column (using the ui-grid-d class)
Content Formatting
 Layout grids
   Buttons




   Toolbars
Content Formatting
 Collapsible content
   Add data-role="collapsible”.
   Closed




   Opened
Content Formatting
 Collapsible support data-icon and data-iconpos


 Collapsible content
   To expanding collapsibles on load, add data-
     collapsed="false”

 Non-inset collapisibles
   Add data-inset=“false”
Content Formatting
 Collapsible content
   Programmatically close collapsible content
     $( ".selector" ).trigger( "collapse" );
   Programmatically open collapsible content
     $( ".selector" ).trigger( "expand" );

 Custom icons
   data-collapsed-icon
   data-expanded-icon
   data-iconpos
Content Formatting
 Collapsible set (accordion)
Content Formatting
 Collapsible set (accordion)
Content Formatting
 Collapsible set (accordion)
   If the collapsible has been update by script, use
    $( ".selector" ).collapsibleset( "refresh" );
Forms
Forms
 All form widgets begin with native form elements with
  rich HTML semantics that are enhanced to make them
  more attractive and easy to use. In browsers that don't
  support the custom controls, they will still have a usable
  experience.

 Most common form elements are included: text
  inputs, search, sliders, flip toggle switches, radio
  buttons, checkboxes, and select menus. Available in
  standard and mini sized versions.
Forms
 Forms
   <form action="form.php" method="post"> ... </form>
 Mini sized elements
   <input type="text" name="name" id="basic" data-
    mini="true" />

 Labels
   All elements need to pair with label, but you can hide the
    label using class="ui-hidden-accessible”.
Forms
 Disable element
   Add ui-disabled class to disable elements.
 Field containers
Forms
 Refresh elements
Forms
 Use the original form element.
   Add data-role="none"
Text inputs & Textareas
 Example 1




 Example 2
Text inputs & Textareas
 Input type support list
      Text
      Password
      Number
      Number + pattern
      Email
      Url
      Tel
      Time
      Date
      Month
      Week
      Datetime
      Datetime local
      Color
Text inputs & Textareas
 Disable a textinput
   $('.selector').textinput('disable'); (enable)
Text inputs & Textareas
 Textarea
Search input
 Add input type=“search”
Slider
 Add input type=“range”
Slider
 Available parameter
   step
   data-highlight="true”




 Programmatically control slider
   $('input').slider(); (enable, disable, refresh)
Flip toggle switch
 A binary selector




 Programmatically control flip toggle switch
   $('select').slider();
Flip toggle switch
 Loner labels
Radio buttons
Radio buttons
 Horizontal radio buttons




 Programmatically control radio buttons
   $("input[type='radio']").checkboxradio();
    (enable, disable, refresh)
Checkboxes
Checkboxes
 Contain checkboxes in <fieldset data-
  role="controlgroup">
Checkboxes
 Add data-type="horizontal” in fieldset




 Programmatically control checkboxes
   $("input[type='checkbox']").checkboxradio(); (enable,
     disable, refresh)
Select menus
Select menus
 Support optgroup
  <optgroup label="FedEx">
       <option value="firstOvernight">First Overnight</option>
       <option value="expressSaver">Express Saver</option>
       <option value="ground">Ground</option>
  </optgroup>
Selected menus
 Add <fieldset data-role="controlgroup">
   Vertical menus




   Horizontal menus: data-type="horizontal"
Select menus
 To use custom menus, add the data-native-
  menu="false”
   Support multiple="multiple”, optgroup
Select menus
 Programmatically control select menus
   $('select').selectmenu();
       enable
       disable
       open (custom menus only)
       close
       refresh
Listviews
Listviews
 Lists are used for data display, navigation, result
  lists, and data entry so jQuery Mobile includes a wide
  range of list types and formatting examples to cover
  most common design patterns. All lists start with simple
  HTML list markup and include styling for read-
  only, linked, numbered, nested, collapsible lists and
  more.
 Listviews are full width by default but can be set to be
  inset styled. To make development easy, there are
  simple ways to add a search filter and automatic
  dividers.
Basic listview
 Add data-role=“listview” in ul.




 Programmatically control listviews
   $('.selector').listview('refresh');
Nested list
 http://jquerymobile.com/demos/1.2.0/docs/lists/lists-
  nested.html
Numbered list
Split button list
List dividers
List dividers
 Auto generate list dividers
   Add data-autodividers="true” in ul.
Count bubble
Thumbnails
Icons
List formatting
Inset list
 Add data-inset="true” in ul.
Search filter bar
 Add data-filter=“true” in ul.
   http://jquerymobile.com/demos/1.2.0/docs/lists/lists-
     search.html
Search filter bar
 To search hidden data in list
   Add data-filtertext=“some text” in li.
Readonly lists
Collapsible lists
 Add data-role="collapsible” to the parent of ul.
API
Configuring default
Configuring default
 Configurable options
     activePageClass, string, default: "ui-page-active”
     defaultDialogTransition, string, default: 'pop‟
     defaultPageTransition, string, default: 'fade‟
     pushStateEnabled, boolean, default: true
Touch events
 $(“.target”).bind(“tap”,function() {});
 tap
 taphold
 swipe
 swipeleft
 swiperight
Orientation change event
 $(document).bind(“orientationchange”, function(event)
  {});
   Return event.orientation = portrait or landscape
 To use original resize javascript function
   $.mobile.orientationChangeEnabled = false
Page load events
 $(document).bind(“pagebeforeload”, function() {});
 pagebeforeload
 pageload
 pageloadfailed
Page change events
 $(document).bind(“pagebeforechange”, function() {});
 pagebeforechange
 pagechange
 pagechangefailed
Page transition events
 $(document).bind(“pagebeforeshow”, function() {});
 pagebeforeshow
 pagebeforehide
 pageshow
 pagehide
Page initialization events
 $(document).bind(“pagebeforecreate”, function() {});
 pagebeforecreate
 pagecreate
 pageinit
Page remove events
 $(document).bind(“pageremove”, function() {});
 pageremove
Methods
 $.mobile.changePage()
Methods
 $.mobile.loadPage()
Methods
 $.mobile.path.parseUrl(url)
Themes framework
 ThemeRoller
   http://jquerymobile.com/themeroller/

jQuery Mobile