YUI Container - Using OverlayManager (YUI Library)

# YUI Container: Using OverlayManager

# 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>
Continue to Functional Example >