Yahoo User Interface Library Method Shortcuts

One of the aspects of developing with the Yahoo User Interface Library (YUI) that I do not particularly like typing the long method calls (i.e., YAHOO.util.dom.get). Fortunately, I can create shorcuts to eliminate much of the typing. I generally add these shortcuts to the top of an anonymous function:

(function() {
     var Dom = YAHOO.util.Dom,
     Event = YAHOO.util.Event,
     Selector = YAHOO.util.Selector,
     Calendar = YAHOO.widget.Calendar,
     Dialog = YAHOO.widget.Dialog;
     ...

})();

So if I need to instantiate the Calendar widget,  I can type:
var calCal = new Calendar("appointCal", {
     iframe:false
});

instead of:
var calCal = new YAHOO.widget.Calendar("appointCal", {
     iframe:false
});

Also, I recently started using $ to replace Dom.get:
var Dom = YAHOO.util.Dom,
$ = Dom.get;

So instead of typing:
var fld = Dom.get('whatever');

I now type:
var fld = $('whatever');

YUI code can be very verbose, so any shortcut is helpful.

Be Sociable, Share!

Checkout My New Site - T-shirts For Geeks