Skip to content

Commit 5c05bb5

Browse files
committed
adding 1st version of getting started with jQuery Mobile guide
1 parent 99a8f3e commit 5c05bb5

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

order.yml

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
- feature-browser-detection
7979
- misc:
8080
- understanding-index
81+
- jquery-mobile:
82+
- getting-started
8183
- faq:
8284
- add_keyboard_navigation
8385
- enable_the_back_button

page/jquery-mobile.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Getting started with jQuery Mobile
3+
level: beginner
4+
---
5+
6+
jQuery Mobile provides a set of touch-friendly UI widgets and an AJAX-powered navigation system to support animated page transitions. Building your first jQuery Mobile page is easy.
7+

page/jquery-mobile/getting-started.md

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
##Create a basic page template
2+
3+
Pop open your favorite text editor, paste in the page template below, save and open in a browser. You are now a mobile developer!
4+
5+
Here's what's in the template. In the `head`, a meta `viewport` tag sets the screen width to the pixel width of the device and references to jQuery, jQuery Mobile and the mobile theme stylesheet from the CDN add all the styles and scripts. jQuery Mobile 1.2 (1.2.0) works with versions of jQuery core from 1.7.0 to 1.8.2.
6+
7+
In the `body`, a div with a `data-role` of `page` is the wrapper used to delineate a page, and the header bar (`data-role="header"`) and content region (`data-role="content"`) are added inside to create a basic page (these are both optional). These `data-` attributes are HTML5 attributes used throughout jQuery Mobile to transform basic markup into an enhanced and styled widget.
8+
9+
<!DOCTYPE html>
10+
<html>
11+
<head>
12+
<title>My Page</title>
13+
<meta name="viewport" content="width=device-width, initial-scale=1">
14+
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
15+
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
16+
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
17+
</head>
18+
<body>
19+
20+
<div data-role="page">
21+
22+
<div data-role="header">
23+
<h1>My Title</h1>
24+
</div><!-- /header -->
25+
26+
<div data-role="content">
27+
<p>Hello world</p>
28+
</div><!-- /content -->
29+
30+
</div><!-- /page -->
31+
32+
</body>
33+
</html>
34+
35+
36+
##Add your content
37+
38+
Inside your content container, you can add any standard HTML elements - headings, lists, paragraphs, etc. You can write your own custom styles to create custom layouts by adding an additional stylesheet to the `head` after the jQuery Mobile stylesheet.
39+
40+
##Make a listview
41+
42+
jQuery Mobile includes a diverse set of common listviews that are coded as lists with a `data-role="listview"` added. Here is a simple linked list that has a role of `listview`. We're going to make this look like an inset module by adding a `data-inset="true"` and add a dynamic search filter with the `data-filter="true"` attributes.
43+
44+
<ul data-role="listview" data-inset="true" data-filter="true">
45+
<li><a href="#">Acura</a></li>
46+
<li><a href="#">Audi</a></li>
47+
<li><a href="#">BMW</a></li>
48+
<li><a href="#">Cadillac</a></li>
49+
<li><a href="#">Ferrari</a></li>
50+
</ul>
51+
52+
53+
##Add a slider
54+
55+
The framework contains a full set of form elements that automatically are enhanced into touch-friendly styled widgets. Here's a slider made with the new HTML5 input type of range, no `data-role` needed. Be sure to wrap these in a `form` element and always properly associate a `label` to every form element.
56+
57+
<form>
58+
<label for="slider-0">Input slider:</label>
59+
<input type="range" name="slider" id="slider-0" value="25" min="0" max="100" />
60+
</form>
61+
62+
Input slider:
63+
##Make a button
64+
65+
There are a few ways to make buttons, but lets turn a link into a button so it's easy to click. Just start with a link and add a `data-role="button"` attribute to it. You can add an icon with the `data-icon` attribute and optionally set its position with the `data-iconpos` attribute.
66+
67+
<a href="#" data-role="button" data-icon="star">Star button</a>
68+
69+
##Play with theme swatches
70+
71+
jQuery Mobile has a robust theme framework that supports up to 26 sets of toolbar, content and button colors, called a "swatch". Just add a `data-theme="e"` attribute to any of the widgets on this page: page, header, list, input for the slider, or button to turn it yellow. Try different swatch letters in default theme from a-e to mix and match swatches.
72+
73+
Cool party trick: add the theme swatch to the page and see how all the widgets inside the content will automatically inherit the theme (headers and footers don't inherit, they default to swatch "a").
74+
75+
<a href="#" data-role="button" data-icon="star" data-theme="a">Button</a>
76+
77+
When you're ready to build a custom theme, use ThemeRoller to drag and drop, then download a custom theme.
78+
79+
##Go forth and build stuff
80+
81+
This is just scratching the surface of all the cool things you can build with jQuery Mobile with little effort. Be sure to explore linking pages, adding animated page transitions, and creating dialogs. Use the data-attribute reference to try out some of the other `data-` attributes you can play with.
82+
83+
More of a developer? Great, forget everything we just covered (kidding). If you don't want to use the `data-` attribute configuration system, you can take full control of everything and call plugins directly because these are all just standard jQuery plugins built with the UI widget factory. Be sure to dig into global configuration, events, and methods. Then read up on scripting pages, generating dynamic pages, and building PhoneGap apps.
84+

0 commit comments

Comments
 (0)