1 Polymer
.IronOverlayManager
= (function() {
7 // track overlays for z-index and focus managemant
8 function addOverlay(overlay
) {
9 var z0
= currentOverlayZ();
10 overlays
.push(overlay
);
11 var z1
= currentOverlayZ();
13 applyOverlayZ(overlay
, z0
);
17 function removeOverlay(overlay
) {
18 var i
= overlays
.indexOf(overlay
);
20 overlays
.splice(i
, 1);
25 function applyOverlayZ(overlay
, aboveZ
) {
26 setZ(overlay
, aboveZ
+ 2);
29 function setZ(element
, z
) {
30 element
.style
.zIndex
= z
;
33 function currentOverlay() {
34 var i
= overlays
.length
- 1;
35 while (overlays
[i
] && !overlays
[i
].opened
) {
41 function currentOverlayZ() {
43 var current
= currentOverlay();
45 var z1
= window
.getComputedStyle(current
).zIndex
;
50 return z
|| DEFAULT_Z
;
53 function focusOverlay() {
54 var current
= currentOverlay();
55 // We have to be careful to focus the next overlay _after_ any current
56 // transitions are complete (due to the state being toggled prior to the
57 // transition). Otherwise, we risk infinite recursion when a transitioning
58 // (closed) overlay becomes the current overlay.
60 // NOTE: We make the assumption that any overlay that completes a transition
61 // will call into focusOverlay to kick the process back off. Currently:
62 // transitionend -> _applyFocus -> focusOverlay.
63 if (current
&& !current
.transitioning
) {
64 current
._applyFocus();
68 function trackBackdrop(element
) {
69 // backdrops contains the overlays with a backdrop that are currently
72 backdrops
.push(element
);
74 var index
= backdrops
.indexOf(element
);
76 backdrops
.splice(index
, 1);
81 function getBackdrops() {
86 addOverlay
: addOverlay
,
87 removeOverlay
: removeOverlay
,
88 currentOverlay
: currentOverlay
,
89 currentOverlayZ
: currentOverlayZ
,
90 focusOverlay
: focusOverlay
,
91 trackBackdrop
: trackBackdrop
,
92 getBackdrops
: getBackdrops