Introduction to jQuery Mobile

59
Intro to jQuery Mobile South Bay Mobile User Group - 26 February 2013 Monday, February 25, 13

description

jQuery Mobile is the easiest way to go from web to mobile. It can be used for internet application or serve as the UI for PhoneGap applications. Here is a fast pace introduction to jQuery Mobile.

Transcript of Introduction to jQuery Mobile

Page 1: Introduction to jQuery Mobile

Intro to jQuery MobileSouth Bay Mobile User Group - 26 February 2013

Monday, February 25, 13

Page 2: Introduction to jQuery Mobile

Introduction

Monday, February 25, 13

Page 3: Introduction to jQuery Mobile

Who Am I?

• Troy Miles

• Senior Software Engineer w/ 30+ years of experience

• Mobile/Mobile Web

• iOS, Android, & Windows Phone 7

Monday, February 25, 13

Page 4: Introduction to jQuery Mobile

Monday, February 25, 13

Page 5: Introduction to jQuery Mobile

Intermediate PhoneGap

• Learn by doing

• JS best practices, iScroll, Maps, Ajax + more

• Saturday, May 18th - 9 AM to 6 PM

• $99 - lunch & materials included

• http://bit.ly/XlxzYp

• CraveLab - Los Angeles

Monday, February 25, 13

Page 6: Introduction to jQuery Mobile

You May Get Mad At Me

• Sorry, in advance if I insult your favorite: company, device, or personality

• I have nothing against any of these companies

• I will gladly do a project for any of them, for the right price

Monday, February 25, 13

Page 7: Introduction to jQuery Mobile

Our Agenda

• The Mobile Space Today

• Getting Started with jQuery Mobile

• Understanding Page Architecture

• Creating jQuery Mobile Forms

• Working with Lists

• jQuery Mobile Events

Monday, February 25, 13

Page 8: Introduction to jQuery Mobile

Our Agenda

• Version 1.3.0

• Packaging for Distribution

Monday, February 25, 13

Page 9: Introduction to jQuery Mobile

The Mobile Space Today

Monday, February 25, 13

Page 10: Introduction to jQuery Mobile

85% of all US adults now own a mobile

phone

Monday, February 25, 13

Page 11: Introduction to jQuery Mobile

56% of all mobile phone owners in the

US access the internet.

Monday, February 25, 13

Page 12: Introduction to jQuery Mobile

Did you know 80% of customers abandon a mobile site if they have a bad user experience?

Monday, February 25, 13

Page 13: Introduction to jQuery Mobile

Web Apps Native Apps

Can migrate web skills Longer learning curve

One source base Many source bases

Deploy when you want Deployment needs approval

You choose when to update User chooses when to update

No device memory used Uses device memory

Difficult to monetize Monetization is built-in

Restricted device access Full access to device hardware

Slower Faster

Monday, February 25, 13

Page 14: Introduction to jQuery Mobile

What is a Web App?

• A web app is more than just a website

• It incorporates app-like behavior

• Think GMail or Google Maps

Monday, February 25, 13

Page 15: Introduction to jQuery Mobile

A unified, HTML5-based user interface system for 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 theme-able design. 

Requires jQuery.

Monday, February 25, 13

Page 16: Introduction to jQuery Mobile

From Web to Mobile

• Your HTML/CSS skills are still valuable

• Good design is more important than ever

Monday, February 25, 13

Page 17: Introduction to jQuery Mobile

JQM & HTML5

• JQM doesn’t require you know HTML5

• JQM uses HTML5 when available

• Prefers semantic markup: header, footer, section

Monday, February 25, 13

Page 18: Introduction to jQuery Mobile

Getting Started with jQuery Mobile

Monday, February 25, 13

Page 19: Introduction to jQuery Mobile

Downloading JQM

• jquerymobile.com/download

• Use the uncompressed version while developing

• Use the minimized version for deployment

• Get the correct version of jQuery

Monday, February 25, 13

Page 20: Introduction to jQuery Mobile

Loading JQM<!DOCTYPE html><html><head> <title>Page Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/ jquery.mobile-1.3.0.min.css"/> <script src="http://code.jquery.com/jquery-1.9.1.min.js"> </script> <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"> </script></head>

Monday, February 25, 13

Page 21: Introduction to jQuery Mobile

Self-hosting vs. CDN

• CDN = Content Delivery Network

• Can speed up app load two ways:

• CDN’s use edge servers

• May be cached by other apps

Monday, February 25, 13

Page 22: Introduction to jQuery Mobile

CDN Fallback Code<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.0.min.js"><\/script>');</script>

Monday, February 25, 13

Page 23: Introduction to jQuery Mobile

Understanding Page Architecture

Monday, February 25, 13

Page 24: Introduction to jQuery Mobile

Best Practices

• Downloading is slow so,

• Download as few files as possible

• Download as little data as possible

• Use a JS minifier

Monday, February 25, 13

Page 25: Introduction to jQuery Mobile

JQM Pages

• A single HTML page can contain many JQM Pages

• This allows page transitions without server contact

Monday, February 25, 13

Page 26: Introduction to jQuery Mobile

JQM Pages

• Pages are denoted with data-role=”page”

• Multiple JQM pages can be on an HTML page

• Only one page is active at a time

• $.mobile.activePage is the currently active page

Monday, February 25, 13

Page 27: Introduction to jQuery Mobile

Page Transitions

• Animate from one page to next

• Only work on platforms that support CSS 3D transforms

• Others will see only “fade”

• Android below version 4

Monday, February 25, 13

Page 28: Introduction to jQuery Mobile

Page Transitions

• fade

• pop

• flip

• turn

• flow

• and more

Monday, February 25, 13

Page 29: Introduction to jQuery Mobile

Toolbars

• Supports HTML5 header/footer tags

• Or via div tag with data-role

• data-role=”header”

• data-role=”footer”

Monday, February 25, 13

Page 30: Introduction to jQuery Mobile

Positioning Toolbars

• Toolbars will normally flow with the page

• data-position=”fixed”

• data-fullscreen=”true”

Monday, February 25, 13

Page 31: Introduction to jQuery Mobile

Navbars

• Denoted by data-role=”navbar”

• When a link is clicked, it gets the active state (ui-btn-active)

• JQM automatically sizes button

• 5 or less buttons, single line

• More than 5, two across

Monday, February 25, 13

Page 32: Introduction to jQuery Mobile

Navbars

• Can appear in headers

• Or footers

• Can be persisted

• Can have icons

Monday, February 25, 13

Page 33: Introduction to jQuery Mobile

Creating jQuery Mobile Forms

Monday, February 25, 13

Page 34: Introduction to jQuery Mobile

Form Basics

• Buttons

• Sliders

• Range Slider

• Flip Switch

• Checkboxes

Monday, February 25, 13

Page 35: Introduction to jQuery Mobile

Selects

• Select

• Mini select

• Custom select

• Multi-slect with optgroups+

Monday, February 25, 13

Page 36: Introduction to jQuery Mobile

Text

• Text input

• Textarea

• Number, date, tel, search

• File

• Password

Monday, February 25, 13

Page 37: Introduction to jQuery Mobile

Getting Data to the Server

Monday, February 25, 13

Page 38: Introduction to jQuery Mobile

Working with Lists

Monday, February 25, 13

Page 39: Introduction to jQuery Mobile

Listviews

• Unordered (ul)

• Ordered (ol)

• Linked

• Inset

• Filter

• List dividers

Monday, February 25, 13

Page 40: Introduction to jQuery Mobile

Listviews

• Autodividers

• Count bubbles

• Icons

• Thumbnails

• Formatted content

Monday, February 25, 13

Page 41: Introduction to jQuery Mobile

Nested listviews have been deprecated in version 1.3 - they will be removed in version 1.4.

Monday, February 25, 13

Page 42: Introduction to jQuery Mobile

jQuery Mobile Events

Monday, February 25, 13

Page 43: Introduction to jQuery Mobile

Events

• Touch events

• Orientation events

• Scroll events

• Page events

Monday, February 25, 13

Page 44: Introduction to jQuery Mobile

Touch Events

• swipe

• swipeleft

• swiperight

• tap

• taphold

Monday, February 25, 13

Page 45: Introduction to jQuery Mobile

Orientation Change

• orientationchange

• Not supported natively universally

Monday, February 25, 13

Page 46: Introduction to jQuery Mobile

Scroll Events

• scrollstart

• scrollstop

Monday, February 25, 13

Page 47: Introduction to jQuery Mobile

Page Events

• pageinit - use this instead of DOM ready()

• pagehide

• pageshow

Monday, February 25, 13

Page 48: Introduction to jQuery Mobile

Version 1.3.0

Monday, February 25, 13

Page 49: Introduction to jQuery Mobile

New Features

• Panels

• Responsive tables

• Range sliders

• Responsive grids

• Deprecated: nested lists

Monday, February 25, 13

Page 50: Introduction to jQuery Mobile

Packaging for Distribution

Monday, February 25, 13

Page 51: Introduction to jQuery Mobile

Hybrid Apps

• HTML5 web app

• Wrapped in a native app

• Usually adds a way to access native features

• Distributable in most app stores

Monday, February 25, 13

Page 52: Introduction to jQuery Mobile

Hybrid Apps

Can migrate web skills

One source base

Deployment needs approval

User chooses when to update

Uses device memory

Monetization is possible

Access to some device hardware

Faster than web, slower than device

Monday, February 25, 13

Page 53: Introduction to jQuery Mobile

Ways to Hybridize

• PhoneGap

• Icenium

• Others

Monday, February 25, 13

Page 54: Introduction to jQuery Mobile

PhoneGap

• Created by Nitobi, acquired by Adobe

• Open sourced as Apache Cordova

• PhoneGap is a trademark of Adobe

Monday, February 25, 13

Page 55: Introduction to jQuery Mobile

Icenium

• Also based on Apache Cordova

• Built by Telerik

• PhoneGap code runs unmodified

• Deploy directly to device

• Includes Kendo UI Mobile

• Free until May 1st

Monday, February 25, 13

Page 56: Introduction to jQuery Mobile

Others

• Appcelerator Titanium

• Trigger.io

• CodeName One

• (and still more)

Monday, February 25, 13

Page 58: Introduction to jQuery Mobile

My Links

• @therockncoder

[email protected]

• http://therockncoder.blogspot.com/

• http://www.youtube.com/user/rockncoder

• https://github.com/Rockncoder

Monday, February 25, 13

Page 59: Introduction to jQuery Mobile

Questions?

Monday, February 25, 13