You're most likely to use the Module Control when building a custom widget; its importance in the YUI Library is as a foundation rather than as a UI control in its own right.
Module is fundamentally a building block for other UI controls. The concepts presented in this example will form the basis for the way that you interact with all of its subclasses.
container_core.js), which only contains Module, Overlay, and its supporting classes. Otherwise, the full library should be included (
container.js). You can see what the full list of included files looks like below. Please note that your file paths may vary depending on the location in which you installed the YUI libraries.
module1 will be associated with our existing markup;
module2 will be created dynamically from script. In this tutorial, we pass to the Module constructor the one required argument: the id associated with that Module's container element.
Note that to avoid using the global variable space, we are placing our example Modules into the
YAHOO.example.container namespace. For more information about namespacing, see the YAHOO Global object.
module1 is already in the document, the call to the render method requires no arguments. If that element wasn't present in the document, we would pass into the
render method the element into which we wanted the module rendered.
To see our newly created Modules more easily, we can add a style block that defines custom CSS for the
module CSS class. By default, Module doesn't come with any predefined styles, so it is up to you as a developer to provide any applicable styles. Our style block will define the
module CSS class such that Modules and each of their child elements will have distinct border colors:
Finally, we will add some HTML buttons to the page and wire them (using the YUI Event Utility) to the Modules'
yui-pe is added to an ancestor of the Module markup programmatically as early as possible in the page. In this example the class is added to the documentElement, however it could also be added to the body element. It is essentially is used to mark the fact
yui-pe-content class, as shown in the Module markup example above.
Finally, just before we create a Module, we remove the temporary
yui-pe-content so that the display:none does not impact the way the Module is rendered (NOTE: This is not really an issue
for Module, but is required if using this technique for the other members of the container family, since they use
visiblity instead of
display to hide themselves:
the markup will be hidden, until the Module is instantiated, at which point the modules visibility handling will take over.
Note: Logging and debugging is currently turned off for this example.