Cover image for YUI 3 Cookbook

Book description

Solve a wide range of problems in your web application quickly and efficiently with the Yahoo! User Interface Library (YUI). With this definitive, getting-started guide to version 3 of the popular open source JavaScript library, you’ll learn how to address many of the most common and challenging problems that web development presents.

Table of Contents

  1. YUI 3 Cookbook
  2. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  3. Preface
    1. YUI 2 Versus YUI 3
      1. Why Use YUI?
      2. Library or Framework?
    2. Who This Book Is For
    3. Resources and Community
    4. Conventions Used in This Book
      1. About the Examples
      2. Typesetting Conventions
    5. Using Code Examples
    6. Safari® Books Online
    7. How to Contact Us
    8. Acknowledgments
  4. 1. Loading Modules
    1. Loading Rollups and Modules
      1. Problem
      2. Solution
      3. Discussion
    2. Loading SimpleYUI
      1. Problem
      2. Solution
      3. Discussion
    3. Identifying and Loading Individual Modules
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Loading a Different Default Skin
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. Loading Gallery Modules
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. Loading a YUI 2 Widget
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. Loading Locally Hosted Builds
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. Creating Your Own Modules
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. Creating a Module with Dependencies
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. Creating Truly Reusable Modules
      1. Problem
      2. Solution
      3. Discussion
    11. Defining Groups of Custom Modules
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. Reusing a YUI Configuration
      1. Problem
      2. Solution
      3. Discussion
    13. Defining Your Own Rollups
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. Loading jQuery as a YUI Module
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. Loading Modules Based on Browser Capabilities
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. Monkeypatching YUI
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    17. Loading Modules on Demand
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    18. Enabling Predictive Module Loading on User Interaction
      1. Problem
      2. Solution
      3. Discussion
    19. Binding a YUI Instance to an iframe
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    20. Implementing Static Loading
      1. Problem
      2. Solution
      3. Discussion
  5. 2. DOM Manipulation
    1. Getting Element References
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    2. Manipulating CSS Classes
      1. Problem
      2. Solution
      3. Discussion
    3. Getting and Setting DOM Properties
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Changing an Element’s Inner Content
      1. Problem
      2. Solution
      3. Discussion
    5. Working with Element Collections
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. Creating New Elements
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. Adding Custom Methods to Nodes
      1. Problem
      2. Solution
      3. Discussion
    8. Adding Custom Properties to Nodes
      1. Problem
      2. Solution
      3. Discussion
  6. 3. UI Effects and Interactions
    1. Hiding an Element
      1. Problem
      2. Solution
      3. Discussion
    2. Fading an Element
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. Moving an Element
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Creating a Series of Transitions
      1. Problem
      2. Solution
      3. Discussion
    5. Defining Your Own Canned Transitions
      1. Problem
      2. Solution
      3. Discussion
    6. Creating an Infinite Scroll Effect
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. Dragging an Element
      1. Problem
      2. Solution
      3. Discussion
    8. Creating a Resizable Node
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. Implementing a Reorderable Drag-and-Drop Table
      1. Problem
      2. Solution
      3. Discussion
  7. 4. Events
    1. Responding to Mouseovers, Clicks, and Other User Actions
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    2. Responding to Element and Page Lifecycle Events
      1. Problem
      2. Solution
      3. Discussion
    3. Controlling Event Propagation and Bubbling
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Preventing Default Behavior
      1. Problem
      2. Solution
      3. Discussion
    5. Delegating Events
      1. Problem
      2. Solution
      3. Discussion
    6. Firing and Capturing Custom Events
      1. Problem
      2. Solution
      3. Discussion
    7. Driving Applications with Custom Events
      1. Problem
      2. Solution
      3. Discussion
    8. Using Object Methods as Event Handlers
      1. Problem
      2. Solution
      3. Discussion
    9. Detaching Event Subscriptions
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. Controlling the Order of Event Handler Execution
      1. Problem
      2. Solution
      3. Discussion
    11. Creating Synthetic DOM Events
      1. Problem
      2. Solution
      3. Discussion
    12. Responding to a Method Call with Another Method
      1. Problem
      2. Solution
      3. Discussion
  8. 5. Ajax
    1. Fetching and Displaying XHR Data
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    2. Handling Errors During Data Transport
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. Loading Content Directly into a Node
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Submitting Form Data with XHR
      1. Problem
      2. Solution
      3. Discussion
    5. Uploading a File with XHR
      1. Problem
      2. Solution
      3. Discussion
    6. Getting JSON Data Using Script Nodes (JSONP)
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. Fetching and Displaying Data with YQL
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. Scraping HTML with YQL
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. Querying Data Using DataSource
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. Normalizing DataSource Responses with a DataSchema
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  9. 6. CSS
    1. Normalizing Browser Style Inconsistencies
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    2. Rebuilding Uniform Base Styles
      1. Problem
      2. Solution
      3. Discussion
    3. Applying Consistent Fonts
      1. Problem
      2. Solution
      3. Discussion
    4. Laying Out Content with Grids
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. Using Grids for Responsive Design
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. Creating Consistent Buttons
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  10. 7. Infrastructure
    1. Managing State with Attributes
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    2. Creating Base Components with Y.extend()
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. Creating Base Components with Y.Base.create()
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Creating a Basic Widget
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. Creating a Widget That Uses Progressive Enhancement
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. Rendering Remote Data with a Widget
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. Creating a Simple Plugin
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. Creating a Plugin That Alters Host Behavior
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. Bundling CSS with a Widget as a CSS Module
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. Bundling CSS with a Widget as a Skin
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. Representing Data with a Model
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. Persisting Model Data with a Sync Layer
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. Managing Models with a Syncing ModelList
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. Rendering HTML with a View
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. Rendering a Model with a View
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. Rendering a ModelList with a View
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    17. Saving State Changes in the URL
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    18. Defining and Executing Routes
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  11. 8. Using Widgets
    1. Instantiating, Rendering, and Configuring Widgets
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    2. Creating an Overlay
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. Aligning and Centering an Overlay
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Making an Overlay Draggable
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. Creating a Simple, Styled Information Panel
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. Creating a Modal Dialog or Form
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. Creating a Tooltip from an Overlay
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. Creating a Lightbox from an Overlay
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. Creating a Slider
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. Creating a Tabview
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. Creating a Basic DataTable
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. Formatting a DataTable’s Appearance
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. Displaying a Remote JSON DataSource in a DataTable
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. Plotting Data in a Chart
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. Choosing Dates with a Calendar
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. Defining Calendar Rules
      1. Problem
      2. Solution
      3. Discussion
    17. Creating a Basic AutoComplete
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    18. Highlighting and Filtering AutoComplete Results
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    19. Using AutoComplete with Remote Data
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    20. Customizing the AutoComplete Result List
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  12. 9. Utilities
    1. Determining a Variable’s Type
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    2. Iterating Over Arrays and Objects
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. Filtering an Array
      1. Problem
      2. Solution
      3. Discussion
    4. Merging Objects
      1. Problem
      2. Solution
      3. Discussion
    5. Composing and Inheriting from Other Objects
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. Automatically Caching Function Call Results
      1. Problem
      2. Solution
      3. Discussion
    7. Templating with Simple String Substitution
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. Formatting Numbers
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. Formatting Dates
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. Parsing Arbitrary XML
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. Converting Color Values
      1. Problem
      2. Solution
      3. Discussion
    12. Managing History and the Back Button
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. Escaping User Input
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. Assigning Special Behavior to a Checkbox Group
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. Implementing Easy Keyboard Actions and Navigation
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. Reliably Detecting Input Field Changes
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    17. Managing and Validating Forms
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  13. 10. Server-Side YUI
    1. Installing and Running YUI on the Server
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    2. Loading Modules Synchronously on the Server
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. Using YUI on the Command Line
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Calling YQL on the Server
      1. Problem
      2. Solution
      3. Discussion
    5. Using the YUI REPL
      1. Problem
      2. Solution
      3. Discussion
    6. Constructing and Serving a Page with YUI, YQL, and Handlebars
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  14. 11. Universal Access
    1. Preventing the Flash of Unstyled Content
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    2. Adding ARIA to Form Error Messages
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. Building a Widget with ARIA
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Retrofitting a Widget with an ARIA Plugin
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. Defining Translated Strings
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. Internationalizing a Widget
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  15. 12. Professional Tools
    1. Enabling Debug Logging
      1. Problem
      2. Solution
      3. Discussion
    2. Rendering Debug Log Output in the Page
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. Writing Unit Tests
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Organizing Unit Tests into Suites
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. Testing Event Handlers by Simulating Events
      1. Problem
      2. Solution
      3. Discussion
    6. Mocking Objects
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. Testing Asynchronously Using wait()
      1. Problem
      2. Solution
      3. Discussion
    8. Collecting and Posting Test Results
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. Precommit Testing in Multiple Browsers
      1. Problem
      2. Solution
      3. Discussion
    10. Testing on Mobile Devices
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. Testing Server-Side JavaScript
      1. Problem
      2. Solution
      3. Discussion
    12. Minifying Your Code
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. Documenting Your Code
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  16. Index
  17. About the Author
  18. Colophon
  19. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  20. Copyright