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 events with button and ButtonGroup objects


The Button and ButtonGroup widget components both extend from Element, and therefore can be used to subscribe to any DOM event. Additionally, they come equipped with many useful CustomEvents. This recipe will explain the CustomEvents that are available on both these objects.

Getting ready

For this recipe, we will use the following Button and ButtonGroup objects:

var oButton = new YAHOO.widget.Button({ label: "Click Me!" });
var oButtonGroup = new YAHOO.widget.ButtonGroup({
id: "myButtonGroupId",
name: "nameOfButtons"
});
oButtonGroup.addButton(oButton);
var callback = function(o) {
YAHOO.log('event name=' + o.type);
YAHOO.log('new value=' + o.newValue);
YAHOO.log('previous value=' + o.prevValue);
};

How to do it...

Subscribe to the attribute changed events:

oButton.on('checkedChange', callback);
oButton.on('containerChange', callback);
oButton.on('disabledChange', callback);
oButton.on('nameChange', callback);
oButton.on('valueChange',...