-
Book Overview & Buying
-
Table Of Contents
YUI 2.8: Learning the Library
The YUI Library has grown and improved since the first edition of this book. Several components came out of beta or experimental status and most of them will be covered in new chapters or added to related chapters, which will now have more than the two components originally presented.
The coding style has changed and that will be reflected in the examples, which have been modified accordingly.
New developer tools have appeared to make code more reliant, to reduce loading time, to debug, test, and do performance profiling and we will take a look at them.
The biggest change is the release of version 3 of the YUI Library. YUI3 has recently had its first General Availability (GA) release which includes the most basic components, the infrastructure of the whole library. The Widget component, the basis for all the components that will have a User Interface (UI) is still Beta so there are no visual components in GA. YUI3 still has some way to go to achieve the variety of UI components of YUI2 and, above all, the maturity and reliability of its code base. Thus, this book will be based on the current YUI 2.8 release of the library. YUI2 is not dead by any measure; development continues and future releases will come when and if any significant number of changes warrant it.
Loading YUI2 components in YUI3
JavaScript programming is not what it used to be. As we ventured into more complex client-side applications and learned more about the language and the environment it lives in, the programming style has changed. All the examples in the first edition of this book have been updated to the new coding style.
The components in the YUI Library show that same change in style, though some of the original ones now feel aged and the newer ones are more flexible and capable. However, for the sake of the innumerable applications out there, the old components cannot be upgraded as backward compatibility must be preserved. To get out of this tight spot, the YUI team decided to branch off with YUI3, incorporating all the techniques learned over these years. However, YUI3 is not backward compatible with YUI2. Version 2 of the library will still be maintained and upgraded and, in fact, since the two versions branched, there have been as many releases in the YUI2 branch as in the YUI3 branch.
Although YUI3 is a much better programming environment than YUI2 and it has a more consistent and capable interface, it still lacks components such as "widgets", that is, those that have a visual interface. Recently, however, the YUI3 loader (and at this point it is not necessary to go deep into what the loader does) has been enabled to load YUI2 components as well. YUI2 can and regularly does coexist with other non-YUI library components and so does YUI3; there was no reason for them to not coexist with each other. Now, this has been made much easier with the ability of the YUI3 environment to load YUI2 components.
This means two things. First, YUI2 still has a long life. By ensuring that they can run in the YUI3 environment, we can mix and match both versions. All the complex visual components in YUI2 that had no equivalent yet in YUI3 can be used in the YUI3 environment. And second, it means that the YUI team can relax and take their time migrating the YUI2 components, ensuring that when they do get released as YUI3 native, they will be high quality, as per our expectations.
WAI-ARIA
The Web Accessibility Initiative's committee of the World Wide Web Consortium has developed the ARIA (Accessible Rich Internet Application) suite of documents to make the rich applications we can build with YUI accessible to people with disabilities. The degree of support for ARIA is not even across all YUI components. Only components with a visual interface the visitor can interact with need ARIA support. Of those, most YUI components do support ARIA—some have it built-in, others need extra subcomponents, and some do not support ARIA at all. Those that do support ARIA often have a few configuration options, though the defaults rarely need any change. In other words, we as programmers usually don't need to concern ourselves with ARIA besides loading the required subcomponents, if any. We won't cover WAI-ARIA in this book just as we don't cover "beta" components, they are both a work-in-progress with its state still changing and, even when it is available, we rarely need to concern ourselves with it beyond activating it.
In Chapter 1, Getting Started with YUI, we look at the library as a whole covering subjects such as how it can be obtained, how it can be used, its structure and composition, and the license it has been released under. We also look at a coding example featuring the Calendar control.
In Chapter 2, Creating Consistency with the CSS Tools, we cover the extensive CSS tools that come with the library, specifically the Reset and Base Tools, the Fonts Tool, and the extremely capable Grids Tool. Examples on the use of each tool are covered. We also see how skinning works in the YUI Library.
In Chapter 3, DOM Manipulation and Event Handling, we look at the all-important DOM and Event utilities. These two comprehensive utilities can often form the backbone of any modern web application and are described in detail. We look at the differences between traditional and YUI methods of DOM manipulation and how the Event Utility unites the conflicting Event models of different browsers. Examples in this chapter include how the basic functions of the DOM Utility are used. We also look at the Element Utility, which is the basis of most of the new UI components and any a developer might build.
In Chapter 4, Calling Back Home, client-server communication is the subject, where we look at how the Connection Manager handles all of our XHR requirements. Then we look at the JSON data interchange format, which is becoming a popular alternative to XML, and at the Get Utility, which allows us to break out of the same-origin policy that limits XHR. Examples include obtaining remote data from external domains and the sending and receiving of data asynchronously to and from our own servers.
In Chapter 5, Animation, the Browser History Manager, and Cookies, we first look at how the Animation Utility can be used to add professional effects to your web pages. The chapter then moves on to cover how the Browser History Manager re-enables the back and forward buttons and book marking functionality of the browser when used with dynamic web applications. Finally, we take a brief look at the Cookies Utility, which allows us to persist information at the browser, helping us save user preferences across our site and in between visits.
In Chapter 6, Content Containers and Tabs, we look at the Container family of controls as well as the TabView control. Each member of the Container family is investigated and implemented in the coding examples. We also look at and implement the visually engaging and highly interactive TabView control.
In Chapter 7, Menus, we look at one of the most common parts of any website—the navigation structure. The example looks with the ease at which the Menu control can be implemented.
In Chapter 8, Buttons and Trees, the focus is on the Button family of controls and the TreeView control. We first cover each of the different buttons and look at examples of their use. We then implement a TreeView control and investigate the methods and properties made available by its classes.
In Chapter 9, DataSource and AutoComplete, we deal with the DataSource Utility, which allows us to fetch and parse tabular data from various sources, both local and remote and in various formats and deliver it to other components in a consistent manner. We will then look at one of those components, AutoComplete.
In Chapter 10, DataTable, we will see another user of DataSource, the DataTable control that allows us to display tabular information and efficiently operate on it on the client side with minimal server intervention.
In Chapter 11, Rich Text Editor, we see the Rich Text Editor, which allows our users to create enhanced text as one of the most popular forms of user interaction over the Internet is user-created content.
In Chapter 12, Drag-and-Drop with the YUI, the first part is Drag-and-Drop, one of DHTML's crowning achievements wrapped up in an easy-to-use utility. In the second part of this chapter we look at the related Slider control and how this basic but useful control can be added to pages with ease. We also briefly mention the Resizer and Layout components that allow us to move and resize dynamic panels within the browser.
In Chapter 13, Everyday Tools, we cover several developer tools. We see how the Logger Control is used to view the event execution of other controls and how it can be used to debug existing controls and custom classes. We also look at other resources such as JSLint and the YUI Compressor. We briefly mention other more advanced tools such as YUI Test, Performance Analyzer, and YSlow.
This book expects and requires you to have a prior knowledge and understanding of at least JavaScript, HTML, and CSS. While the use of the utilities, controls, and CSS tools will be explained in detail throughout the book, any HTML, CSS, or PHP code that is featured in any of the examples may not be explained in detail. Other skills, such as the ability to install and configure a web server, are required. A PC or Mac, a browser, text editor, the YUI, and a web server are also required.
This book is for web developers comfortable with JavaScript and CSS, who want to use the YUI Library to easily put together rich, responsive web interfaces. No knowledge of the YUI Library is presumed.
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: "In a capable, supported browser the library can transform the <textarea> element into the full Rich Text Editor control."
A block of code is set as follows:
<script type="text/javascript" src="http://yui.yahooapis.com/ 2.8.0/build/yahoo-dom-event/yahoo-dom-event.js"> </script> <script type="text/javascript" src="http://yui.yahooapis.com/ 2.8.0/build/animation/animation-min.js"> </script>
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
<div id="hd">This is your Header</div>
<div id="bd">This is the body
<div class="yui-b">This is the secondary block</div>
<div class="yui-main">
<div class="yui-b">This is the main block</div>
</div>
</div>
<div id="ft">This is your footer</div>
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "The Collapse button will reduce it to the title bar itself".
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail <[email protected]>.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book on, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code for the book
You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.
Change the font size
Change margin width
Change background colour