YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: Container Family: Using the Overlay Manager to Manage Multiple Panels

# Container Family: Using the Overlay Manager to Manage Multiple Panels

OverlayManager allows you to manage multiple Overlays (and Overlay subclasses like Panel, Dialog, SimpleDialog and Tooltip) on the same page, giving focus and z-index supremacy to the focused overlay and providing you with event hooks to respond to focus and blur of your overlays with your own scripts.

Use the buttons below to show and hide the overlays in this example's OverlayManager group. Click within differnt overlays and drag them around to get a sense for how OverlayManager provides a light, operating-system-like feel to the interaction.

View example in new window.

panel1:
panel2:
panel3:
All Panels:
Panel #1 from Markup
This is a Panel that was marked up in the document.
End of Panel #1
Panel #2 from Markup
This is a Panel that was marked up in the document.
End of Panel #2
Panel #3 from Markup
This is a Panel that was marked up in the document.
End of Panel #3

## Managing Overlay Focus & Blur

OverlayManager provides an easy way to manage multiple Overlays and keep track of which Overlay is currently in focus. When you register an Overlay with the OverlayManager, it is augmented with focus and blur, as well as two additional events, focusEvent and blurEvent. By default, clicking on an Overlay that is registered with the OverlayManager will bring it to the top by setting its z-index higher than all the other registered Overlays and will add the CSS class "focused" to its element.

In this tutorial, we will build three separate Panels and register them with an OverlayManager. To begin, we will instantiate three Panels that are hidden by default and render them:

// Build panel1 based on markup YAHOO.example.container.panel1 = new YAHOO.widget.Panel("panel1", { xy:[150,100], visible:false, width:"300px" } ); YAHOO.example.container.panel1.render(); // Build panel2 based on markup YAHOO.example.container.panel2 = new YAHOO.widget.Panel("panel2", { xy:[250,200], visible:false, width:"300px" } ); YAHOO.example.container.panel2.render(); // Build panel3 based on markup YAHOO.example.container.panel3 = new YAHOO.widget.Panel("panel3", { xy:[350,300], visible:false, width:"300px" } ); YAHOO.example.container.panel3.render();

Next, we will instantiate a new OverlayManager and register the Panels as an array:

YAHOO.example.container.manager = new YAHOO.widget.OverlayManager(); YAHOO.example.container.manager.register([YAHOO.example.container.panel1, YAHOO.example.container.panel2, YAHOO.example.container.panel3]);

Each of the Panels is then automatically augmented with focus and blur methods and events. Each Panel will be automatically focused when clicked, but we can also wire up buttons to focus and blur our Panels. The OverlayManager also has showAll, hideAll, and blurAll methods:

<div> panel1: <button id="show1">Show</button> <button id="hide1">Hide</button> <button id="focus1">Focus</button> </div> <div> panel2: <button id="show2">Show</button> <button id="hide2">Hide</button> <button id="focus2">Focus</button> </div> <div> panel3: <button id="show3">Show</button> <button id="hide3">Hide</button> <button id="focus3">Focus</button> </div> <div> All Panels: <button id="showAll">Show All</button> <button id="hideAll">Hide All</button> <button id="blurAll">Blur All</button> </div>

Finally, we will place the basic markup for our Panels, which looks identical to much of the standard module markup we've seen in previous tutorials. Note that we set the "visibility:hidden" style inline on these Panels because we don't want them to flash before they are hidden by default. Setting the style inline ensures that the Panels will not be seen in the browser until they are made visible.

<div id="panel1" style="visibility:hidden"> <div class="hd">Panel #1 from Markup</div> <div class="bd">This is a Panel that was marked up in the document.</div> <div class="ft">End of Panel #1</div> </div> <div id="panel2" style="visibility:hidden"> <div class="hd">Panel #2 from Markup</div> <div class="bd">This is a Panel that was marked up in the document.</div> <div class="ft">End of Panel #2</div> </div> <div id="panel3" style="visibility:hidden"> <div class="hd">Panel #3 from Markup</div> <div class="bd">This is a Panel that was marked up in the document.</div> <div class="ft">End of Panel #3</div> </div>

### YUI Logger Output:

Note: Logging and debugging is currently turned off for this example.

Reload with logging
and debugging enabled.

### Container Family Examples:

- The Module Control
- Creating and Positioning an Overlay
- Simple Tooltip Example
- One Tooltip, Many Context Elements
- Simple Panel Example
- Skinning a Panel with Custom CSS: Introduction
- Skinning a Panel with Custom CSS: Advanced
- Creating a Modal "Loading" Panel
- Creating a Resizable Panel
- Dialog Quickstart Example
- SimpleDialog Quickstart Example
- Using ContainerEffect Transitions
- Using the Overlay Manager to Manage Multiple Panels
- Implementing Container Keyboard Shortcuts with KeyListener
- Using the Button ARIA Plugin (included with examples for Button Control)
- Using the Container ARIA Plugin
- Example of Color Picker Built in a Dialog via JavaScript (included with examples for Color Picker Control)
- Layout inside a resizable Panel (included with examples for Layout Manager)
- Calendar inside a Container (included with examples for Calendar Control)
- Menu Buttons (included with examples for Button Control)
- Showing, Hiding, and Reordering Columns. (included with examples for DataTable Control)
- Split Buttons (included with examples for Button Control)
- Simple Calendar Menu Button (included with examples for Button Control)
- Calendar Menu Button with Date on Button Face (included with examples for Button Control)
- Color Picker Button (included with examples for Button Control)
- Fixed Width Menu Button (included with examples for Button Control)
- OS-Style Programs Menu (included with examples for Menu Family)
- Application Menubar (included with examples for Menu Family)
- Slider Button (included with examples for Button Control)
- Complex Application (included with examples for Layout Manager)

### More Container Family Resources:

- User's Guide (external)
- API Documentation
- Cheat Sheet PDF (external)

Copyright © 2008 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings