jQuery Mobile: For Fun and Profit

33
for fun and profit jQuery Mobile © 2010 The jQuery Project http://jquerymobile.com /

description

Talk given at Where 2.0 2011 in Santa Clara, CA. Code samples here: https://github.com/dcousineau/jQuery-Mobile-For-Fun-And-Profit

Transcript of jQuery Mobile: For Fun and Profit

Page 1: jQuery Mobile: For Fun and Profit

for fun and profit

jQuery Mobile © 2010 The jQuery Project http://jquerymobile.com/

Page 2: jQuery Mobile: For Fun and Profit

Daniel CousineauInteractive Software Engineer @ RAPPhttp://dcousineau.com/@[email protected]

Page 3: jQuery Mobile: For Fun and Profit

What Is jQuery Mobile?

Page 4: jQuery Mobile: For Fun and Profit

Multi Platform

Images from jquerymobile.com

Page 5: jQuery Mobile: For Fun and Profit

Touch-optimized & ThemableImages from jquerymobile.com

Page 6: jQuery Mobile: For Fun and Profit

Mobile Web Framework

Unified User Interface

My Term: Half Stack

Widget Library

Touch Events

Page 7: jQuery Mobile: For Fun and Profit

Project Status

As of October 19th, 2011: RC2

This talk centers around RC1

Page 8: jQuery Mobile: For Fun and Profit

More Details

Built on jQuery

Lightweight (12k compressed)

Progressive Enhancement

HTML5

Accessibility baked-in (WAI-ARIA)

Modular & Theme-able

Page 9: jQuery Mobile: For Fun and Profit

jQuery Mobile Primer

Page 10: jQuery Mobile: For Fun and Profit

ProvidedInterface elements

Simple device orientation detection

Tap & mobile events

DOES NOT PROVIDE Geo Location, Canvas, Local Storage, etc.

Remember: A ‘HALF’ STACK

Page 11: jQuery Mobile: For Fun and Profit

Sencha Touch © 2011 Sencha, Example from Sencha Touch Hello World

<!DOCTYPE html>

<html> <head>

<title>Hello World</title> <script src="path/to/sencha-touch.js" type="text/javascript"></script>

<link href="path/to/sencha-touch.css" rel="stylesheet" type="text/css" /> <script type="text/javascript">

new Ext.Application({ launch: function() { new Ext.Panel({ fullscreen: true, html: 'Hello World!' }); } }); </script> </head>

<body></body></html>

<!DOCTYPE html> <html> <head> <title>Page Title</title> <link rel="stylesheet" href="/path/to/jquery.mobile.css" /> <script type="text/javascript" src="/path/to/jquery.js"></script> <script type="text/javascript" src="/path/to/jquery.mobile.js"></script> </head> <body> <div data-role="page"> <div data-role="content"> <p>Hello World.</p> </div> </div> </body></html>

Page 12: jQuery Mobile: For Fun and Profit

Sencha Touch © 2011 Sencha, Example from Sencha Touch Hello World

<!DOCTYPE html>

<html> <head>

<title>Hello World</title> <script src="path/to/sencha-touch.js" type="text/javascript"></script>

<link href="path/to/sencha-touch.css" rel="stylesheet" type="text/css" /> <script type="text/javascript">

new Ext.Application({ launch: function() { new Ext.Panel({ fullscreen: true, html: 'Hello World!' }); } }); </script> </head>

<body></body></html>

<!DOCTYPE html> <html> <head> <title>Page Title</title> <link rel="stylesheet" href="/path/to/jquery.mobile.css" /> <script type="text/javascript" src="/path/to/jquery.js"></script> <script type="text/javascript" src="/path/to/jquery.mobile.js"></script> </head> <body> <div data-role="page"> <div data-role="content"> <p>Hello World.</p> </div> </div> </body></html>

Semantic &Progressive Refinement

Page 13: jQuery Mobile: For Fun and Profit

In The Beginning

<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Page Title</title> <link rel="stylesheet" href="/path/to/jquery.mobile.css" /> <script type="text/javascript" src="/path/to/jquery.js"></script> <script type="text/javascript" src="/path/to/jquery.mobile.js"></script></head><body>

</body></html>

Page 14: jQuery Mobile: For Fun and Profit

Configuration

Configuration ONLY in mobileinit listener

All mobileinit listeners defined BEFORE loading jQuery Mobile

Page 15: jQuery Mobile: For Fun and Profit

In The Beginning<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Page Title</title> <link rel="stylesheet" href="/path/to/jquery.mobile.css" /> <script type="text/javascript" src="/path/to/jquery.js"></script> <script> $( document ).bind("mobileinit", function() { $.extend( $.mobile, { configurationKey: configurationValue }); }); </script> <script type="text/javascript" src="/path/to/jquery.mobile.js"></script></head><body>

</body></html>

Page 16: jQuery Mobile: For Fun and Profit

Think In Pages

<div data-role=”page” />

Only 1 visible at any time

Multiple allowed per document

You can write a single-file application

Contains header, footer, and content area

Page 17: jQuery Mobile: For Fun and Profit

<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Page Title</title> <link rel="stylesheet" href="/path/to/jquery.mobile.css" /> <script type="text/javascript" src="/path/to/jquery.js"></script> <script> $( document ).bind("mobileinit", function() { $.extend( $.mobile, {} ); }); </script> <script type="text/javascript" src="/path/to/jquery.mobile.js"></script></head><body> <div data-role="page"> <div data-role="header"> <h1>Page Title</h1> </div>

<div data-role="content"> <p>Page content goes here.</p> </div>

<div data-role="footer"> <h4>Page Footer</h4> </div></div></body></html>

Page 18: jQuery Mobile: For Fun and Profit

Progressive Enhancement

Uses the HTML5 data-* attributes to auto-enhance and configure widgets

data-role is now the center of your world.

E.g. To create a button, add a <a href=”#” data-role=”button”>LABEL</a> and jQuery Mobile will automagically set it up during page creation.

Page 19: jQuery Mobile: For Fun and Profit

<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Page Title</title> <link rel="stylesheet" href="/path/to/jquery.mobile.css" /> <script type="text/javascript" src="/path/to/jquery.js"></script> <script> $( document ).bind("mobileinit", function() { $.extend( $.mobile, {} ); }); </script> <script type="text/javascript" src="/path/to/jquery.mobile.js"></script></head><body> <div data-role="page"> <div data-role="header"> <h1>Page Title</h1> </div>

<div data-role="content"> <a href="#">Normal Link</a> <a href="#" data-role="button">Button</a> </div>

<div data-role="footer"> <h4>Page Footer</h4> </div></div></body></html>

Page 20: jQuery Mobile: For Fun and Profit

jQuery Mobile.com Docs

http://jquerymobile.com/demos/1.0rc1

Page 21: jQuery Mobile: For Fun and Profit

Load jQueryMobile JS mobileinit

pagebeforecreate pagecreate

pagebeforeshow

domready

pageshowNavigate

Enhance Page

pagehide

pagebeforehide

pagebeforechange

pagechange

Page 22: jQuery Mobile: For Fun and Profit

Touch Eventstap

taphold

swipe

swipeleft

swiperight

orientationchange

scrollstart

scrollstop

Page 23: jQuery Mobile: For Fun and Profit

Normalized “Virtual” Events

vmouseover

vmousedown

vmousemove

vmouseup

vclick

vmousecancel

Page 24: jQuery Mobile: For Fun and Profit

Auto-‘AJAX’By default, all local links get a click listener

Can be disabled

Overrides default action:

Fires XMLHTTP request for target

Pulls <div data-role=”page”></div> from results, inserts into DOM

Transitions to displaying the new target page

Page 25: jQuery Mobile: For Fun and Profit

Auto-‘AJAX’

By default, all local forms get a submission handler

Same process as links, only overriding for form submit

Page 26: jQuery Mobile: For Fun and Profit

Auto-‘AJAX’

CAUTION: There is no baked-in way to pass parameters to AJAX’ed pages

Sever side via GET requests to back-end

Use #page?key=value, manually parse window.location

Disable / override hash listener

Page 27: jQuery Mobile: For Fun and Profit

Learn By Doing

Page 29: jQuery Mobile: For Fun and Profit

Wrap Up

Page 30: jQuery Mobile: For Fun and Profit

http://jqmgallery.com/

Page 31: jQuery Mobile: For Fun and Profit

Resources

@jquerymobile

http://jquerymobile.com/blog/http://jquerymobile.com/demos/1.0rc1

Page 32: jQuery Mobile: For Fun and Profit

Advanced Learning

Panel / iPad Ready Layouts

http://asyraf9.github.com/jquery-mobile/

Page 33: jQuery Mobile: For Fun and Profit

http://joind.in/3762