SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 142 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"


YUI is also heavily namespaced. There??™s the main YAHOO object; then everything branches
off from there. For example, to retrieve an element via the identifier, use the following:
YAHOO.util.Dom.get('elementID');
Of the three categories of problems that libraries try to solve, YUI mostly tackles DOM
tools such as those offered up in the Dom namespace and the Anim namespace (for animation).
It also includes a number of widgets, such as those shown in Figure 4-3.
CHAPTER 4 n LIBRARIES 90
Figure 4-3. The TreeView, TabView, and Calendar controls available within the YUI library
Using the widgets can be a handy way to add complex functionality into an application.
The calendar widget is a very common one that can be used easily as a date picker:
function selEvent(type, args)
{
// type = event type ='select'
// the date selected is the first element in the array
var dates = args[0];
// the date clicked on is the first element of that array
var date = dates[0];
// the date is stored in an array as [YYYYY, MM, DD]
var year = date[0], month = date[1], day = date[2];
}
widget = new YAHOO.widget.Calendar("cal1","calwidget",{close:true,iframe:true});
widget.selectEvent.subscribe(selEvent, this, true);
widget.render();
The calendar widget takes three parameters: the first parameter is a unique identifier for
the calendar itself, the second is the ID of the HTML element being used as the placeholder
for the widget, and the third is an object literal to store options.


Pages:
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154