Book Image

YUI 2.8: Learning the Library

Book Image

YUI 2.8: Learning the Library

Overview of this book

The YUI Library is a set of utilities and controls written in JavaScript for building Rich Internet Applications, across all major browsers and independently of any server technology. There's a lot of functionality baked into YUI, but getting to and understanding that functionality is not for the faint of heart. This book gives you a clear picture of YUI through a step-by-step approach, packed with lots of examples.YUI 2.8: Learning the Library covers all released (non-beta) components of the YUI 2.8 Library in detail with plenty of working examples, looking at the classes that make up each component and the properties and methods that can be used. It includes a series of practical examples to reinforce how each component should/can be used, showing its use to create complex, fully featured, cross-browser, Web 2.0 user interfaces. It has been updated from its first edition with the addition of several chapters covering several new controls and enriched with lots of experience of using them.You will learn to create a number of powerful JavaScript controls that can be used straightaway in your own applications. Besides giving you a deep understanding of the YUI library, this book will expand your knowledge of object-oriented JavaScript programming, as well as strengthen your understanding of the DOM and CSS. The final chapter describes many of the tools available to assist you the developer in debugging, maintaining, and ensuring the best quality in your code. In this new edition, all the examples have been updated to use the most recent coding practices and style and new ones added to cover newer components. Since the basic documentation for the library is available online, the focus is on providing insight and experience.The authors take the reader from beginner to advanced-level YUI usage and understanding.
Table of Contents (18 chapters)
YUI 2.8 Learning the Library
Credits
About the Authors
About the Reviewers
Preface

A look at the Event Utility


There are five classes defined within the Event Utility. The first, YAHOO.util.Event provides the mechanism to interact with the events built into the browser, which is supplemented by YAHOO.util.KeyListener, which deals solely with listening for keyboard events.

The other classes provide means for your own applications to declare, fire, and listen to events in a similar way to how the browser does. We'll see this later.

Listeners

The .addListener() (alias .on()) method is the one we'll use most often, as this is the method that adds the listener, which executes the callback function whenever the event in question occurs. It takes up to five arguments:

  1. 1. The HTML element or array of elements to bind the event listener to, either by their IDs or actual references to DOM elements

  2. 2. The type of event to listen for

  3. 3. A reference to the callback function to execute on detection of the event

  4. 4. (Optional) an arbitrary object to pass as an argument to the callback

  5. 5. (Optional...