Book Image

Yahoo User Interface Library 2.x Cookbook

By : Matt Snider
Book Image

Yahoo User Interface Library 2.x Cookbook

By: Matt Snider

Overview of this book

<p>The Yahoo! User Interface (YUI) Library is a set of utilities and controls, written in JavaScript, for building richly interactive web applications using techniques such as DOM scripting, DHTML, and AJAX. Although you can create stylish Internet applications by modifying its default components, even advanced users find it challenging to create impressive feature-rich Internet applications using YUI.</p> <p>This book will help you learn how to use YUI 2.x to build richer, more interactive web applications that impress clients and wow your friends. It has recipes explaining over twenty-five YUI components, showing how to use them, and how to configure them to meet your needs. Each covered component will have extractable code samples that showcase the common ways that the component is used.</p> <p>The book starts by explaining the core features of YUI 2.x, the utilities that the rest of the library depends on and that will make your life easier. It then explains how to build UI components and make AJAX requests using the YUI framework. Each recipe will cover the most common ways to use a component, how to configure it, and then explain any other features that may be available. We wrap things up by looking at some of the recent beta components and explain how to use them, and how they may be useful on your web application.</p> <p>For each of the recipes, there is an introductory example, then more advanced examples, followed by an explanation of how the component works and what YUI is doing. For more experienced developers, most recipes also include additional discussion of the solution, explaining to further customize and enhance the component.</p>
Table of Contents (22 chapters)
Yahoo! User Interface 2.x Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using YUI helper event functions


YUI events have four useful helpers functions: delegate, onAvailable, onContentReady, and onDOMReady. These functions augment how developers interact with the DOM. This recipe explains how they work.

Getting ready

To use the delegate function in this recipe, you will need to include the event-delegate and Selector components. Use the following DOM for the examples in this recipe:

<div id="myElementId">
<ul>
<li><a href="#" id="link1">Item Type One</a></li>
<li><a href="#" id="link2">Item Type Two</a></li>
<li><a href="#" id="link3">Item Type Three</a></li>
</ul>
</div>

How to do it...

Use event delegation to have a single handler for all three anchors:

YAHOO.util.Event.delegate("myElementId", "click", function(e, matchedElement, container) {
// The matchedElement is the default scope
alert("Default scope id: " + this.id);
alert("Clicked link id: " + matchedElement...