YUI PHP Loader Utility: Using YUI Loader to Load the Calendar Control (Simple)

In this example, we bring a YUI component onto the page using the YUI PHP Loader Utility. This example implements YUI PHP Loader via a YAHOO_util_Loader instance. We include the YUI PHP Loader class file, then specify in configuration which component we want loaded on the page — and what we want to do once it is loaded.

This example loads in new window to demonstrate the simplest use case — a page with no other content, wherein the Loader is introducing YUI into a simple context.

A Simple Use Case: Using YUI PHP Loader to Load the Calendar Control

This example implements the YUI PHP Loader Utility to load the Calendar Control.

The workflow happens in three steps:

  1. Include the YUI PHP Loader class file
  2. Create a YAHOO_util_YUILoader instance: Set configuration flags as needed, call the load method with a list of components to load, and define what to do once the components are loaded (in this case, once the components are loaded we instantiate a Calendar Control on the page).
  3. Ouput Loader results

Here's what that looks like in terms of raw source — this is the full source code for this example:

This code executes the following steps in order:

  1. YUI PHP Loader loads taking the configuration settings into account. It gets instructions about what components are required and how to configure them.
  2. YUI PHP Loader checks the dependency tree. Loader knows that Calendar requires the Yahoo Global Object, the Dom Collection, the Event Utility, and the Calendar Control file as well as Calendar's CSS file. It knows that it can get Yahoo, Dom and Event in a single file, so it uses a rollup for those and loads that rolled up JavaScript file via a <script> node that it inserts on the page. It waits for that file to load, then loads the Calendar Control's JavaScript file; this must be loaded after Yahoo, Dom and Event are in place.