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.
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:
1 | // Build panel1 based on markup |
2 | YAHOO.example.container.panel1 = new YAHOO.widget.Panel("panel1", { xy:[250,100], |
3 | visible:false, |
4 | width:"300px" |
5 | } ); |
6 | YAHOO.example.container.panel1.render(); |
7 | |
8 | // Build panel2 based on markup |
9 | YAHOO.example.container.panel2 = new YAHOO.widget.Panel("panel2", { xy:[350,150], |
10 | visible:false, |
11 | width:"300px" |
12 | } ); |
13 | YAHOO.example.container.panel2.render(); |
14 | |
15 | // Build panel3 based on markup |
16 | YAHOO.example.container.panel3 = new YAHOO.widget.Panel("panel3", { xy:[450,200], |
17 | visible:false, |
18 | width:"300px" |
19 | } ); |
20 | YAHOO.example.container.panel3.render(); |
view plain | print | ? |
Next, we will instantiate a new OverlayManager and register the Panels as an array:
1 | YAHOO.example.container.manager = new YAHOO.widget.OverlayManager(); |
2 | YAHOO.example.container.manager.register([YAHOO.example.container.panel1, |
3 | YAHOO.example.container.panel2, |
4 | YAHOO.example.container.panel3]); |
view plain | print | ? |
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:
1 | <div> |
2 | panel1: |
3 | <button id="show1">Show</button> |
4 | <button id="hide1">Hide</button> |
5 | <button id="focus1">Focus</button> |
6 | </div> |
7 | <div> |
8 | panel2: |
9 | <button id="show2">Show</button> |
10 | <button id="hide2">Hide</button> |
11 | <button id="focus2">Focus</button> |
12 | </div> |
13 | <div> |
14 | panel3: |
15 | <button id="show3">Show</button> |
16 | <button id="hide3">Hide</button> |
17 | <button id="focus3">Focus</button> |
18 | </div> |
19 | <div> |
20 | All Panels: |
21 | <button id="showAll">Show All</button> |
22 | <button id="hideAll">Hide All</button> |
23 | <button id="blurAll">Blur All</button> |
24 | </div> |
view plain | print | ? |
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.
1 | <div id="panel1" style="visibility:hidden"> |
2 | <div class="hd">Panel #1 from Markup</div> |
3 | <div class="bd">This is a Panel that was marked up in the document.</div> |
4 | <div class="ft">End of Panel #1</div> |
5 | </div> |
6 | |
7 | <div id="panel2" style="visibility:hidden"> |
8 | <div class="hd">Panel #2 from Markup</div> |
9 | <div class="bd">This is a Panel that was marked up in the document.</div> |
10 | <div class="ft">End of Panel #2</div> |
11 | </div> |
12 | |
13 | <div id="panel3" style="visibility:hidden"> |
14 | <div class="hd">Panel #3 from Markup</div> |
15 | <div class="bd">This is a Panel that was marked up in the document.</div> |
16 | <div class="ft">End of Panel #3</div> |
17 | </div> |
view plain | print | ? |
You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.
INFO 1156ms (+0) 1:36:44 AM:
Config
Firing Config event: iframe=false
INFO 1156ms (+0) 1:36:44 AM:
Config
setProperty: xy=450,200
INFO 1156ms (+0) 1:36:44 AM:
Config
setProperty: y=200
INFO 1156ms (+0) 1:36:44 AM:
Config
setProperty: x=450
INFO 1156ms (+0) 1:36:44 AM:
Config
Firing Config event: iframe=false
INFO 1156ms (+0) 1:36:44 AM:
Config
setProperty: xy=350,150
INFO 1156ms (+0) 1:36:44 AM:
Config
setProperty: y=150
INFO 1156ms (+0) 1:36:44 AM:
Config
setProperty: x=350
INFO 1156ms (+0) 1:36:44 AM:
Config
Firing Config event: iframe=false
INFO 1156ms (+0) 1:36:44 AM:
Config
setProperty: xy=250,100
INFO 1156ms (+0) 1:36:44 AM:
Config
setProperty: y=100
INFO 1156ms (+7) 1:36:44 AM:
Config
setProperty: x=250
INFO 1149ms (+0) 1:36:44 AM:
Config
setProperty: zindex=4
INFO 1149ms (+0) 1:36:44 AM:
Config
Firing Config event: zindex=4
INFO 1149ms (+0) 1:36:44 AM:
Config
setProperty: zindex=4
INFO 1149ms (+0) 1:36:44 AM:
Config
setProperty: zindex=0
INFO 1149ms (+0) 1:36:44 AM:
Config
Firing Config event: zindex=0
INFO 1149ms (+0) 1:36:44 AM:
Config
setProperty: zindex=0
INFO 1149ms (+0) 1:36:44 AM:
Config
Config event queue: manager=OverlayManager,
INFO 1149ms (+0) 1:36:44 AM:
Config
queueProperty: manager=OverlayManager
INFO 1149ms (+0) 1:36:44 AM:
Config
setProperty: manager=OverlayManager
INFO 1149ms (+0) 1:36:44 AM:
Config
Added property: manager
INFO 1149ms (+0) 1:36:44 AM:
Config
setProperty: zindex=2
INFO 1149ms (+0) 1:36:44 AM:
Config
Firing Config event: zindex=2
INFO 1149ms (+0) 1:36:44 AM:
Config
setProperty: zindex=2
INFO 1149ms (+0) 1:36:44 AM:
Config
setProperty: zindex=0
INFO 1149ms (+0) 1:36:44 AM:
Config
Firing Config event: zindex=0
INFO 1149ms (+0) 1:36:44 AM:
Config
setProperty: zindex=0
INFO 1149ms (+0) 1:36:44 AM:
Config
Config event queue: manager=OverlayManager,
INFO 1149ms (+0) 1:36:44 AM:
Config
queueProperty: manager=OverlayManager
INFO 1149ms (+0) 1:36:44 AM:
Config
setProperty: manager=OverlayManager
INFO 1149ms (+0) 1:36:44 AM:
Config
Added property: manager
INFO 1149ms (+0) 1:36:44 AM:
Config
setProperty: zindex=0
INFO 1149ms (+0) 1:36:44 AM:
Config
Firing Config event: zindex=0
INFO 1149ms (+1) 1:36:44 AM:
Config
setProperty: zindex=0
INFO 1148ms (+0) 1:36:44 AM:
Config
Config event queue: manager=OverlayManager,
INFO 1148ms (+0) 1:36:44 AM:
Config
queueProperty: manager=OverlayManager
INFO 1148ms (+0) 1:36:44 AM:
Config
setProperty: manager=OverlayManager
INFO 1148ms (+0) 1:36:44 AM:
Config
Added property: manager
INFO 1148ms (+0) 1:36:44 AM:
Config
Firing Config event: focusevent=mousedown
INFO 1148ms (+0) 1:36:44 AM:
Config
Config event queue: focusevent=mousedown,
INFO 1148ms (+0) 1:36:44 AM:
Config
queueProperty: focusevent=mousedown
INFO 1148ms (+0) 1:36:44 AM:
Config
setProperty: focusevent=mousedown
INFO 1148ms (+0) 1:36:44 AM:
Config
Added property: focusevent
INFO 1148ms (+0) 1:36:44 AM:
Config
setProperty: overlays=undefined
INFO 1148ms (+0) 1:36:44 AM:
Config
Added property: overlays
INFO 1148ms (+0) 1:36:44 AM:
Config
Firing Config event: iframe=false
INFO 1148ms (+0) 1:36:44 AM:
Config
Config event queue: iframe=false,
INFO 1148ms (+0) 1:36:44 AM:
Config
queueProperty: iframe=undefined
INFO 1148ms (+0) 1:36:44 AM:
Config
setProperty: xy=450,200
INFO 1148ms (+0) 1:36:44 AM:
Config
setProperty: y=200
INFO 1148ms (+0) 1:36:44 AM:
Config
setProperty: x=450
INFO 1148ms (+0) 1:36:44 AM:
Config
Firing Config event: y=200
INFO 1148ms (+0) 1:36:44 AM:
Config
Config event queue: y=200, iframe=false,
INFO 1148ms (+0) 1:36:44 AM:
Config
queueProperty: iframe=undefined
INFO 1148ms (+1) 1:36:44 AM:
Config
setProperty: xy=450,200
INFO 1147ms (+0) 1:36:44 AM:
Config
setProperty: y=200
INFO 1147ms (+0) 1:36:44 AM:
Config
setProperty: x=450
INFO 1147ms (+0) 1:36:44 AM:
Config
Firing Config event: x=450
INFO 1147ms (+0) 1:36:44 AM:
Config
Firing Config event: fixedcenter=false
INFO 1147ms (+0) 1:36:44 AM:
Config
Config event queue: fixedcenter=false, x=450, y=200, iframe=false,
INFO 1147ms (+0) 1:36:44 AM:
Config
queueProperty: iframe=undefined
INFO 1147ms (+0) 1:36:44 AM:
Config
Firing Config event: width=300px
INFO 1147ms (+0) 1:36:44 AM:
Config
Firing Config event: visible=false
INFO 1147ms (+0) 1:36:44 AM:
Config
Config event queue: visible=false, width=300px, fixedcenter=false, x=450, y=200, iframe=false,
INFO 1147ms (+0) 1:36:44 AM:
Config
queueProperty: iframe=undefined
IFRA 1147ms (+0) 1:36:44 AM:
global
xy: 450,200
INFO 1147ms (+0) 1:36:44 AM:
Config
Config event queue: visible=false, width=300px, fixedcenter=false, x=450, y=200, iframe=false,
INFO 1147ms (+0) 1:36:44 AM:
Config
queueProperty: y=200
INFO 1147ms (+0) 1:36:44 AM:
Config
setProperty: y=200
INFO 1147ms (+0) 1:36:44 AM:
Config
Config event queue: visible=false, width=300px, fixedcenter=false, x=450, iframe=false,
INFO 1147ms (+0) 1:36:44 AM:
Config
queueProperty: x=450
INFO 1147ms (+0) 1:36:44 AM:
Config
setProperty: x=450
INFO 1147ms (+0) 1:36:44 AM:
Config
Firing Config event: xy=450,200
INFO 1147ms (+0) 1:36:44 AM:
Config
Firing Config event: close=true
INFO 1147ms (+0) 1:36:44 AM:
Config
setProperty: strings=[object Object]
INFO 1147ms (+0) 1:36:44 AM:
Config
Firing Config event: strings=[object Object]
INFO 1147ms (+1) 1:36:44 AM:
Config
setProperty: zindex=0
INFO 1146ms (+0) 1:36:44 AM:
Config
Firing Config event: zindex=null
INFO 1146ms (+0) 1:36:44 AM:
Config
Firing Config event: modal=false
INFO 1146ms (+0) 1:36:44 AM:
Config
Firing Config event: underlay=shadow
INFO 1146ms (+0) 1:36:44 AM:
Config
Firing Config event: draggable=true
INFO 1146ms (+0) 1:36:44 AM:
Config
Firing Config event: dragonly=false
INFO 1146ms (+0) 1:36:44 AM:
Config
Firing Config event: constraintoviewport=false
INFO 1146ms (+0) 1:36:44 AM:
Config
Firing Config event: preventcontextoverlap=false
INFO 1146ms (+0) 1:36:44 AM:
Config
setProperty: autofillheight=body
INFO 1146ms (+0) 1:36:44 AM:
Config
Firing Config event: autofillheight=body
INFO 1146ms (+0) 1:36:44 AM:
Config
Firing Config event: appendtodocumentbody=false
INFO 1146ms (+0) 1:36:44 AM:
Config
Firing Config event: monitorresize=true
INFO 1146ms (+0) 1:36:44 AM:
Config
Config event queue: monitorresize=true, appendtodocumentbody=false, autofillheight=body, preventcontextoverlap=false, constraintoviewport=false, dragonly=false, draggable=true, underlay=shadow, modal=false, zindex=null, strings=[object Object], close=true, xy=450,200, visible=false, width=300px, fixedcenter=false, iframe=false,
INFO 1146ms (+0) 1:36:44 AM:
Config
queueProperty: width=300px
INFO 1146ms (+0) 1:36:44 AM:
Config
Config event queue: monitorresize=true, appendtodocumentbody=false, fixedcenter=false, autofillheight=body, preventcontextoverlap=false, constraintoviewport=false, dragonly=false, draggable=true, underlay=shadow, modal=false, zindex=null, strings=[object Object], close=true, xy=450,200, iframe=false, visible=false,
INFO 1146ms (+0) 1:36:44 AM:
Config
queueProperty: visible=false
INFO 1146ms (+0) 1:36:44 AM:
Config
Config event queue: monitorresize=true, appendtodocumentbody=false, fixedcenter=false, autofillheight=body, preventcontextoverlap=false, constraintoviewport=false, dragonly=false, draggable=true, underlay=shadow, modal=false, visible=true, zindex=null, strings=[object Object], close=true, xy=450,200, iframe=false,
INFO 1146ms (+0) 1:36:44 AM:
Config
queueProperty: xy=450,200
INFO 1146ms (+0) 1:36:44 AM:
Config
Config event queue: monitorresize=true, appendtodocumentbody=false, fixedcenter=false, autofillheight=body, iframe=false, preventcontextoverlap=false, constraintoviewport=false, dragonly=false, draggable=true, underlay=shadow, modal=false, visible=true, zindex=null, strings=[object Object], close=true,
INFO 1146ms (+0) 1:36:44 AM:
Config
queueProperty: strings=[object Object]
INFO 1146ms (+0) 1:36:44 AM:
Config
setProperty: strings=[object Object]
INFO 1146ms (+0) 1:36:44 AM:
Config
Added property: strings
INFO 1146ms (+1146) 1:36:44 AM:
Config
setProperty: keylisteners=undefined
INFO 0ms (+0) 1:36:43 AM:
global
Logger initialized
Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.
Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings