This basic example walks you through the steps needed to get a default Calendar up and running. It covers the set of file dependencies which need to be included as well as the basic markup and JS code required to get you started.
Note: Your file paths may vary depending on the location in which you installed the YUI libraries. The Calendar examples, when referring to file paths, use the build directory as the root for the YUI distribution.
The only markup required by Calendar is an initial empty DIV into which the Calendar will be rendered. The DIV should have a unique id specified in the markup, which will match the id passed to the Calendar's constructor.
The markup for our simple Calendar example looks like this:
Finally, the Calendar can be instantiated in a script block, like this:
Note that to avoid using the global variable space, we are placing our example Calendar's variable and the init function, into the YAHOO.example.calendar namespace (see line 2 above). For more information about namespacing, see the YAHOO Global object.
The constructor in our example (line 5) takes two arguments: the id to be used for our new Calendar's table, which is created dynamically ("cal1" in this example) and the id of the inital container where we want to render the Calendar ("cal1Container" in this case).
We are also specifying that the init() function should not be executed until the the DOM for the page is ready, using the Event Utility. This allows us to create the Calendar as soon as the browser processes the markup on the page, and not have to wait for images to load.
Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.