




























































































Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Esta página não é visível na pré-visualização
Não perca as partes importantes!





























































































by Eric Sarrion
Copyright © 2012 Eric Sarrion. All rights reserved. Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles ( http://my.safaribooksonline.com ). For more information, contact our corporate/institutional sales department: (800) 998-9938 or [email protected].
2012-03-09 First release See http://oreilly.com/catalog/errata.csp?isbn=9781449316990 for release details.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. jQuery UI , the image of a turnstone, and related trade dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information con- tained herein.
ISBN: 978-1-449-31699-
[LSI]
1331233105
The switchClass () Method 223 Example of Using the toggleClass () Method 224
viii | Table of Contents
Preface
jQuery is a popular JavaScript library that is extensible using plug-ins. Some plug-ins, specifically those for managing the user interface, have been collected together in the jQuery UI library. These plug-ins help facilitate interaction with the user, and these interactions are simpler to manage if you use jQuery only.
This book covers the following extensions in jQuery UI version 1.8:
Who Should Read This Book
All users of jQuery should read this book! More specifically, this book will interest people who want to improve the user interface of their websites and enrich them with new features.
Structure of the Book
Each of the features offered by jQuery UI (tabs, accordion menus, etc.) are treated in a separate chapter. Each chapter is independent of the others, allowing you to imple- ment the functionality directly.
ix
Safari® Books Online
Safari Books Online ( www.safaribooksonline.com ) is an on-demand digital library that delivers expert content in both book and video form from the world’s leading authors in technology and business. Technology profes- sionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for re- search, problem solving, learning, and certification training.
Safari Books Online offers a range of product mixes and pricing programs for organi- zations, government agencies, and individuals. Subscribers have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable da- tabase from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Tech- nology, and dozens more. For more information about Safari Books Online, please visit us online.
How to Contact Us
Please address comments and questions concerning this book to the publisher:
O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax)
We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:
http://shop.oreilly.com/product/0636920023159.do
To comment or ask technical questions about this book, send email to:
For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia
Preface | xi
Acknowledgments
Thank you to the O’Reilly team that allowed me to write this book (notably, Simon, Mike, and Amy), and to Daisaku Ikeda, who gave me the courage and perseverance to achieve this goal.
xii | Preface
Figure 1-1. jQuery UI home page
In this file, you can see the different features that jQuery UI adds (Figure 1-2), including the following:
2 | Chapter 1: Introduction to jQuery UI
Figure 1-2. jQuery UI home page: list of components
These are all possibilities that we will discuss later in the book. We will also consider other mechanisms such as drag-and-drop, new visual effects, CSS theme files, and more.
What Is a CSS Theme?
What are the CSS themes we talked about earlier? To find out, just download a new customized version of jQuery UI, depending on the chosen theme. For that, go to http: //jqueryui.com/download , which displays the page shown in Figure 1-3.
Choose the UI lightness theme from the list on the right, then retrieve the ZIP file for jQuery UI associated with this theme by clicking the Download button. This ZIP file contains the same directory, but the CSS files included in css directory are adapted to the new theme. To see the look of this theme, view the new index.html file included in
What Is a CSS Theme? | 3
Figure 1-4. The ui-lightness theme
The ui directory (located under development-bundle ) contains the JavaScript files. The jquery.ui.core.js file includes the basic features (mandatory), while other files will be included only if required. The file ending in custom.js (e.g., jquery-ui-1.8.16.cus- tom.js ) brings together all the JavaScript files and eliminates the need to include each separately. The minified directory (located under ui ) contains the same files in com- pressed format.
Which Files Should We Include in Our HTML Pages? | 5
The themes directory (located under development-bundle ) contains the CSS files. It consists of various directories, each containing themes (e.g., the base , smoothness , and ui-lightness directories). Each theme includes an images directory and other CSS files.
The jquery.ui.core.css file contains basic functionality (required), while other files will be included only if they are required. The jquery.ui.theme.css file contains the definition of the theme itself (required).
The jquery.ui.base.css file includes all of the files in the development-bundle directory except jquery.ui.theme.css. The jquery.ui.all.css file includes all files (that is to say, jquery.ui.base.css and jquery.ui.theme.css ).
Finally, the file ending with custom.css (e.g., jquery-ui-1.8.16.custom.css ) includes all CSS files and eliminates the need to include each separately (it is identical to jquery.ui.all.css , except that it includes other files via CSS directives, while custom.css physically includes every line of all files).
Here we want to display a simple page with two tabs. The main JavaScript file will be jquery.ui.tabs.js and the main CSS file will be jquery.ui.tabs.css. The main page will include the following base files:
The jquery.js file is here at the same level as the jqueryui directory_._ This file is the standard jQuery JavaScript file.
The core.js file is mandatory, while the tabs.js file requires the inclusion of widget.js (as indicated in the tabs.js file).
The core.css file is mandatory, as is the theme.css file. The tabs.css file contains specific tabs definitions.
Now that we have the basic building blocks for the page, let’s create and label two tabs and place some text in each. The following code goes directly below the previous code that calls the base files.
Tab 1
6 | Chapter 1: Introduction to jQuery UI