Skip to content

Commit a56d70b

Browse files
committed
Merge branch 'ui-docs'
2 parents dd45b1c + e1a2756 commit a56d70b

19 files changed

+994
-0
lines changed

order.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@
9292
- about-deferreds
9393
- jquery-deferreds
9494
- examples
95+
- jquery-ui:
96+
- getting-started
97+
- how-jquery-ui-works
98+
- theming:
99+
- themeroller
100+
- api
101+
- write-a-theme
102+
- widget-factory:
103+
- why-use-the-widget-factory
104+
- how-to-use-the-widget-factory
95105
- jquery-mobile:
96106
- getting-started
97107
- theme-roller

page/jquery-ui.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: jQuery UI
3+
customFields:
4+
-
5+
key: "icon"
6+
value: "magnet"
7+
---
8+
9+
[jQuery UI](http://jqueryui.com) is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library. Whether you're building highly interactive web applications or you just need to add a date picker to a form control, jQuery UI is the perfect choice.
10+
11+
jQuery UI contains many widgets that maintain state and therefore have a slightly different usage pattern than typical jQuery plugins. All of jQuery UI's widgets use the same patterns, so if you learn how to use one, then you'll know how to use all of them.

page/jquery-ui/getting-started.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
title: Getting Started with jQuery UI
3+
level: beginner
4+
---
5+
6+
### What is jQuery UI?
7+
jQuery UI is a widget and interaction library built on top of the jQuery JavaScript Library that you can use to build highly interactive web applications. This guide is designed to get you up to speed on how jQuery UI works. Follow along below to get started.
8+
9+
### Start by checking out the demos
10+
To get a feel for what jQuery UI is capable of, check out the [UI Demos](http://jqueryui.com/demos/).
11+
12+
In the demos section, the navigation lists all of the interactions and widgets that jQuery UI offers. Choose an interaction or widget and you'll be presented with several demo configurations for that particular plugin. Each demo allows you to view source code, change themes, and the URL can always be bookmarked. For example, check out the [accordion widget's fill space demo page](http://jqueryui.com/accordion/#fillspace).
13+
14+
### Build your custom jQuery UI download
15+
Once you have a basic understanding of what jQuery UI is and what it does, you're ready to try it out! It's time to head over to the [Download Builder](http://jqueryui.com/download/) on the jQuery UI website to download a copy of jQuery UI. jQuery UI's download builder allows you to choose the components you would like to download and get a custom version of the library for your project. There are 3 easy steps to building your custom jQuery UI download:
16+
17+
#### Step 1: Choose which components you need
18+
The main column of the Download Builder lists all of the javascript components in jQuery UI categorized into groups: core, interations, widgets, and effects. Some components in jQuery UI depend on other components. Just check the boxes for the widgets you'd like to download and any required dependencies will automatically be checked as well. The components you select will all be combined into a custom jQuery UI javascript file.
19+
20+
![Configuring a download](/resources/jquery-ui/configure.png)
21+
22+
#### Step 2: Select a theme (or roll your own custom theme)
23+
In the right column of the download builder, you'll find a field where you can choose from a number of pre-designed themes for your jQuery UI widgets.
24+
You can either choose from the various themes we provide, or you can design your own custom theme using ThemeRoller (more on that later).
25+
26+
**Advanced Theme Settings:** *The theme section of the download builder also offers some advanced configuration settings for your theme. If you plan to use multiple themes on a single page, these fields will come in handy. If you plan to only use one theme on a page, you can skip these settings entirely.*
27+
28+
#### Step 3: Choose a version of jQuery UI
29+
The last step in the download builder is to select a version number. This is a very important step because jQuery UI versions are designed to work with specific versions of jQuery. The current versions are:
30+
31+
* jQuery UI 1.10.0 - Requires jQuery 1.6+
32+
* jQuery UI 1.9.2 - Requires jQuery 1.6+
33+
34+
#### Click Download!
35+
You're finished with the download builder! Click the download button and you'll get a customized zip file containing everything you selected.
36+
37+
### After downloading: Intro to using jQuery UI
38+
Once you've downloaded jQuery UI, you'll get a zip containing the following files:
39+
40+
* `/css/`
41+
* `/development-bundle/`
42+
* `/js/`
43+
* `index.html`
44+
45+
### Basic overview: using jQuery UI on a web page
46+
Open up index.html in a text editor and you'll see that it links to a few dependencies: your theme, jQuery, and jQuery UI. Generally, you'll need to include these 3 files on any page to use jQuery UI widgets and interactions:
47+
48+
49+
```html
50+
<link type="text/css" href="css/themename/jquery-ui.custom.css" rel="Stylesheet" />
51+
<script type="text/javascript" src="js/jquery.min.js"></script>
52+
<script type="text/javascript" src="js/jquery-ui.custom.min.js"></script>
53+
```
54+
55+
Once you've included the necessary files, you can add some jQuery widgets to your page. For example, to make a datepicker widget, you'll add a text input element to your page and then call .datepicker(); on it. Like this:
56+
57+
**HTML:**
58+
```html
59+
<input type="text" name="date" id="date">
60+
```
61+
62+
**JS:**
63+
```javascript
64+
$('#date').datepicker();
65+
```
66+
67+
![Example Screenshot](/resources/jquery-ui/ex-datepicker.png)
68+
69+
#### That's it!
70+
For demos of all of the jQuery UI widgets and interactions. Check out the demos section of the jQuery UI website.
71+
72+
### Customizing jQuery UI to your needs
73+
jQuery UI allows you to customize it in several ways. You've already seen how the download builder allows you to customize your copy of jQuery UI to include only the portions you want, but there are additional ways to customize that code to your implementation.
74+
75+
### jQuery UI basics: using options
76+
Each plugin in jQuery UI has a default configuration which is catered to the most basic and common use case. But if you want a plugin to behave different from its default configuration, you can override each of its default settings using "options". Options are a set of properties passed into a jQuery UI widget as an argument. For example, the slider widget has an option for orientation, which allows you to specify whether the slider should be horizontal or vertical. To set this option for a slider on your page, you just pass it in as an argument, like this:
77+
78+
79+
```javascript
80+
$('#mySliderDiv').slider({
81+
orientation: 'vertical'
82+
});
83+
```
84+
85+
You can pass as many different options as you'd like by following each one with a comma (except the last one):
86+
87+
```javascript
88+
$('#mySliderDiv').slider({
89+
orientation: 'vertical',
90+
min: 0,
91+
max: 150,
92+
value: 50
93+
});
94+
```
95+
96+
Just remember to surround your options with curly brackets `{ }`, and you're well on your way. Of course, the example above barely touches on what you can do with jQuery UI. To get detailed information on the entire set of jQuery UI widgets, visit the [jQuery UI documentation](http://jqueryui.com/demos/).
97+
98+
### Visual customization: Designing a jQuery UI theme
99+
If you want to design your own theme, jQuery UI has a very slick application for just that purpose. It's called ThemeRoller, and you can always get to it by either clicking the "Themes" link in the jQuery UI navigation, or simply going to [jQuery UI Themeroller](http://jqueryui.com/themeroller/).
100+
101+
ThemeRoller provides a custom interface for designing all of the elements used by jQuery UI widgets. As you tweak the "levers" in the left column, the widgets on the right will reflect your design. The Gallery tab of ThemeRoller offers a number of pre-designed themes (the same ones offered by the download builder) that you can tweak or download as they are.
102+
103+
![Themeroller Example](/resources/jquery-ui/themeroller.png)
104+
105+
### Downloading your theme
106+
When you click the "Download theme" button in ThemeRoller, you'll be directed to the Download Builder and your custom theme will be auto-selected in the Theme dropdown menu. You can configure your download package further from there. Once you download, you'll see that the example.html page is styled using your custom theme.
107+
108+
**Quick tip:** *If you ever need to edit your theme, simply open the CSS file and find on line 43 where it says "To view and modify this theme, visit ..." That url will open the theme in ThemeRoller for editing.*
109+
110+
### Support: Where can I get help?
111+
JQuery UI user and developer resources are kept up-to-date at the [Support Center](http://jqueryui.com/support).
112+
113+
### Developers Wanted!
114+
Want to join the jQuery UI team? We'd love your help! Visit the UI [Development Center](http://jqueryui.com/development) for details on how to get involved.

page/jquery-ui/how-jquery-ui-works.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
---
2+
title: How jQuery UI Works
3+
level: Beginner
4+
---
5+
6+
jQuery UI contains many widgets that maintain [state](http://en.wikipedia.org/wiki/State_%28computer_science%29) and therefore may have a slightly different usage pattern than typical jQuery plugins you are already used to. While the initialization is the same as most jQuery plugins, jQuery UI's widgets are built on top of the [Widget Factory](/jquery-ui/widget-factory/) which provides the same general API to all of them. So if you learn how to use one, then you'll know how to use all of them! This document will walk you through the common functionality, using the [progressbar](http://jqueryui.com/progressbar/) widget for the code examples.
7+
8+
## Initialization
9+
10+
In order to track the state of the widget, we must introduce a full life cycle for the widget.
11+
The life cycle starts when the widget is initalized.
12+
To initialize a widget, we simply call the plugin on one or more elements.
13+
14+
```
15+
$( "#elem" ).progressbar();
16+
```
17+
18+
This will initialize each element in the jQuery object, in this case the element with an id of "elem".
19+
Because we called the `progressbar()` method with no parameters, the widget is initialized with its default options.
20+
We can pass a set of options during initialization in order to override the default options.
21+
22+
```
23+
$( "#elem" ).progressbar({ value: 20 });
24+
```
25+
26+
We can pass as many or as few options as we want during initialization.
27+
Any options that we don't pass will just use their default values.
28+
29+
The options are part of the widget's state,
30+
so we can set options after initialization as well.
31+
We'll see this later with the `option` method.
32+
33+
## Methods
34+
35+
Now that the widget is initialized, we can query its state or perform actions on the widget.
36+
All actions after initialization take the form of a method call.
37+
To call a method on a widget, we pass the name of the method to the jQuery plugin.
38+
For example, to call the `value` method on our progressbar widget, we would use:
39+
40+
```
41+
$( "#elem" ).progressbar( "value" );
42+
```
43+
44+
If the method accepts parameters, we can pass them after the method name.
45+
For example, to pass the parameter `40` to the `value` method, we can use:
46+
47+
```
48+
$( "#elem" ).progressbar( "value", 40 );
49+
```
50+
51+
Just like other methods in jQuery, most widget methods return the jQuery object for chaining.
52+
53+
```
54+
$( "#elem" )
55+
.progressbar( "value", 90 )
56+
.addClass( "almost-done" );
57+
```
58+
59+
### Common Methods
60+
61+
Each widget will have its own set of methods based on the functionality that the widget provides.
62+
However, there are a few methods that exist on all widgets.
63+
64+
#### option
65+
66+
As we mentioned earlier, we can change options after initialization through the `option` method.
67+
For example, we can change the progressbar's value to 30 by calling the `option` method.
68+
69+
```
70+
$( "#elem" ).progressbar( "option", "value", 30 );
71+
```
72+
73+
Note that this is different from the previous example where we were calling the `value` method.
74+
In this example, we're calling the `option` method and saying that we want to change the value option to 30.
75+
76+
We can also get the current value for an option.
77+
78+
```
79+
$( "#elem" ).progressbar( "option", "value" );
80+
```
81+
82+
In addition, we can update multiple options at once by passing an object to the `option` method.
83+
84+
```
85+
$( "#elem" ).progressbar( "option", {
86+
value: 100,
87+
disabled: true
88+
});
89+
```
90+
91+
You may have noticed that the `option` method has the same signature as getters and setters in jQuery core, such as `.css()` and `.attr()`.
92+
The only difference is that you have to pass the string "option" as the first parameter.
93+
94+
#### disable
95+
96+
As you might guess, the `disable` method disables the widget.
97+
In the case of progressbar, this changes the styling to make the progressbar look disabled.
98+
99+
```
100+
$( "#elem" ).progressbar( "disable" );
101+
```
102+
103+
Calling the `disable` method is equivalent to setting the `disabled` option to `true`.
104+
105+
#### enable
106+
107+
The `enable` method is the opposite of the `disable` method.
108+
109+
```
110+
$( "#elem" ).progressbar( "enable" );
111+
```
112+
113+
Calling the `enable` method is equivalent to setting the `disabled` option to `false`.
114+
115+
#### destroy
116+
117+
If you no longer need the widget, you can destroy it and return back to the original markup.
118+
This ends the life cycle of the widget.
119+
120+
```
121+
$( "#elem" ).progressbar( "destroy" );
122+
```
123+
124+
Once you destroy a widget, you can no longer call any methods on it unless you initialize the widget again.
125+
If you're removing the element, either directly via `.remove()` or by modifying an ancestor with `.html()` or `.empty()`,
126+
the widget will automatically destroy itself.
127+
128+
#### widget
129+
130+
Some widgets generate wrapper elements, or elements disconnected from the original element.
131+
In these cases, the `widget` method will return the generated element.
132+
In cases like the progressbar, where there is no generated wrapper, the `widget` method returns the original element.
133+
134+
```
135+
$( "#elem" ).progressbar( "widget" );
136+
```
137+
138+
## Events
139+
140+
All widgets have events associated with their various behaviors to notify you when the state is changing.
141+
For most widgets, when the events are triggered, the names are prefixed with the widget name.
142+
For example, we can bind to progressbar's change event which is triggered whenever the value changes.
143+
144+
```
145+
$( "#elem" ).bind( "progressbarchange", function() {
146+
alert( "The value has changed!" );
147+
});
148+
```
149+
150+
Each event has a corresponding callback, which is exposed as an option.
151+
We can hook into progressbar's `change` callback instead of binding to the `progressbarchange` event, if we wanted to.
152+
153+
```
154+
$( "#elem" ).progressbar({
155+
change: function() {
156+
alert( "The value has changed!" );
157+
}
158+
});
159+
```
160+
161+
### Common Events
162+
163+
While most events will be widget specific, all widgets have a `create` event.
164+
This event will be triggered immediately after the widget is created.

page/jquery-ui/theming.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Theming jQuery UI
3+
level: intermediate
4+
---
5+
6+
All jQuery UI plugins are designed to allow a developer to seamlessly integrate UI widgets into the look and feel of their site or application. Each plugin is styled with CSS and contains two layers of style information: standard [jQuery UI CSS Framework](/jquery-ui/theming/api/) styles and plugin-specific styles.
7+
8+
The jQuery UI CSS Framework provide semantic presentation classes to indicate the role of an element within a widget such as a header, content area, or clickable region. These are applied consistently across all widgets so a clickable tab, accordian or button will all have the same `ui-state-default` class applied to indicate that it is clickable. When a user mouses over one of these elements, this class is changed to `ui-state-hover`, then `ui-state-active` when selected. This level of class consistency makes it easy to ensure that all elements with a similar role or interaction state will look the same across all widgets.
9+
10+
The CSS Framework styles are encapsulated in a single file called ui.theme.css and this is the file modified by the [ThemeRoller](/jquery-ui/theming/themeroller) application. Framework styles only include attributes that affect the look and feel (primarily color, background images and icons) so these are 'safe' styles that will not affect functionality of individual plugins. This separation means that a developer can create a custom look and feel by modifying the colors and images in theme.css file and know that as future plugins or bug fixes become available, these should work with the theme without modification.
11+
12+
Since the framework styles only cover look and feel, plugin specific stylesheets are included that contain all the additional structural style rules required to make the widget functional, such as dimensions, padding, margins, positioning and floats. Stylesheets for each plugin are located in the themes/base folder of the download and are named to match the plugin such as "jquery.ui.accordion.css". These styles must be carefully edited because they work in conjunction with the scripting and provide overrides of framework styles as needed.
13+
14+
We encourage all developers creating jQuery plugins to leverage the jQuery UI CSS Framework because it will make it much easier for end users to theme and use your plugin.
15+
16+
### Getting started
17+
18+
There are three general approaches to theming jQuery UI plugins:
19+
20+
* **Download a ThemeRoller theme**: The easiest way to build a theme is to use the [Themeroller](/jquery-ui/theming/themeroller) to generate and download a theme. This app will create a new `ui.theme.css` file and and images directory containing all necessary background images and icon sprites which can simply be dropped into your project. This approach will be the easiest to create and maintain but limits customization to the options provided in ThemeRoller.
21+
* **Modify the CSS files**: To get a bit more control over the look and feel, you may choose to start with the default theme (Smoothness) or a ThemeRoller-generated theme and then adjust the `ui.theme.css` file or any of the individual plugin stylesheets. For example, you could easily tweak the corner radius for all buttons to be different than the rest of the UI components or change the path for the icon sprite to use a custom set. With a bit of style scoping, you can even use multiple themes together in a single UI. To keep maintenance simple, restricting changes to just the `ui.theme.css` file and images is recommended.
22+
* **Write completely custom CSS**: For the greatest amount of control, the CSS for each plugin can be written from scratch without using the framework classes or plugin-specific stylesheet. This may be necessary if the desired look and feel can't be achieved by modifying the CSS or if highly customized markup is used. This approach requires deep expertise in CSS and will require manual updates for future plugins.
23+
24+
### Using ThemeRoller and Themes
25+
26+
27+
* [ThemeRoller application](http://jqueryui.com/themeroller/)
28+
* [ThemeRoller documentation](/jquery-ui/theming/themeroller) - How to use the ThemeRoller application
29+
30+
### jQuery UI CSS Framework & Custom themes
31+
32+
33+
* [jQuery UI CSS Framework documentation](/jquery-ui/theming/api/) - Explore the full class API and icon set
34+
* [How to create custom themes](/jquery-ui/theming/custom-themes) - Tutorial for creating a theme from scratch

0 commit comments

Comments
 (0)