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

Including YUI CSS


YUI contains several general CSS files that are useful for normalizing browser default style variations, font-sizes, and grid-based layouts. Additionally, many components also include a component-specific CSS files. While each component can be used without including the base CSS, for best results you should include them or incorporate them into your own CSS. This recipe will explore the global CSS files and explain how component-based CSS will work in the future.

How to do it...

To normalize variations in the default element styles across browsers, include:

<link href="pathToBuild/reset/reset-min.css" rel="stylesheet" type="text/css"/>

To set the base font-size of the Body element to 10 pixels, include:

<link href="pathToBuild/font/font-min.css" rel="stylesheet" type="text/css"/>

To set some intelligent default styles to various elements, include:

<link href="pathToBuild/base/base-min.css" rel="stylesheet" type="text/css"/>

To use YUI to manage your layout, include:

<link href="pathToBuild/grids/grids-min.css" rel="stylesheet" type="text/css"/>

To use grids create a Div element inside the Body element and add one of the "doc" IDs to it ("doc", "doc2", "doc3", "doc4"), use code similar to the following:

<div id="doc2">
<div class="hd">Put header here</div>
<div class="bd">Put body here</div>
<div class="ft">Put footer here</div>
</div>

Later in this book, we will include components which have their own custom CSS, such as the Logger component:

<link href="pathToBuild/logger/assets/skins/sam/logger.css" rel="stylesheet" type="text/css"/>

Components like Logger, will namespace all their styles below the"yui-skin-sam" class, and therefore require the"yui-skin-sam" to be added to an ancestor element of the component markup. Most developers choose to simply apply it to the Body element:

<body class="yui-skin-sam">
...
</body>

How it works...

The reset CSS file applies rules that remove styles, such as font-sizes, padding, margins, and borders that may be applied to various elements by the browser. This ensures that CSS rules will be the same across browsers, as all elements start being styled the same way. The rules in this file have been built by the web community and are found on many sites and in many CSS frameworks.

The fonts CSS file adjusts the font-size of the Body element so that 1em is exactly 10 pixels (or as approximately close to 10 as possible). This makes building sites that scale according to font-size much easier. There are also a few additional rules that correct rounding errors and style discrepancies on several elements.

The base CSS file applies some intelligent default styles, since all the defaults have been reset, such as header (H1, H2, etc.) tag font-sizes, bolding of the Strong element, and italicizing of the Em element.

The grids CSS file sets up rules that can be used to layout the page. The example in this recipe will be centered on the page with a 950 pixel width, and have simple textual content for the header, body, and footer. You can use grids to manage simple or nested columns, and even more complex document sections. To find out more about what you can do with grids, see: http://developer.yahoo.com/yui/grids/.

The CSS for components will be mentioned in their respective chapters, but it is important to remember that the files are generally located at "someComponent/assets/skins/sam/someComponent.css" and that the"yui-skin-sam" class needs to be applied to an ancestor of the component markup for the styles to be applied.

There's more...

Additionally, there are two convenient files that combine the minified versions of reset, font, and grid for use in your production environment:

<link href="pathToBuild/reset-fonts/reset-fonts.css" rel="stylesheet" type="text/css"/>
<link href="pathToBuild/reset-fonts-grids/reset-fonts-grids.css" rel="stylesheet" type="text/css"/>