3 Polymer.IronOverlayManager = (function() {
9 // track overlays for z-index and focus managemant
10 function addOverlay(overlay) {
11 var z0 = currentOverlayZ();
12 overlays.push(overlay);
13 var z1 = currentOverlayZ();
15 applyOverlayZ(overlay, z0);
19 function removeOverlay(overlay) {
20 var i = overlays.indexOf(overlay);
22 overlays.splice(i, 1);
27 function applyOverlayZ(overlay, aboveZ) {
28 setZ(overlay, aboveZ + 2);
31 function setZ(element, z) {
32 element.style.zIndex = z;
35 function currentOverlay() {
36 var i = overlays.length - 1;
37 while (overlays[i] && !overlays[i].opened) {
43 function currentOverlayZ() {
45 var current = currentOverlay();
47 var z1 = window.getComputedStyle(current).zIndex;
52 return z || DEFAULT_Z;
55 function focusOverlay() {
56 var current = currentOverlay();
57 // We have to be careful to focus the next overlay _after_ any current
58 // transitions are complete (due to the state being toggled prior to the
59 // transition). Otherwise, we risk infinite recursion when a transitioning
60 // (closed) overlay becomes the current overlay.
62 // NOTE: We make the assumption that any overlay that completes a transition
63 // will call into focusOverlay to kick the process back off. Currently:
64 // transitionend -> _applyFocus -> focusOverlay.
65 if (current && !current.transitioning) {
66 current._applyFocus();
70 function trackBackdrop(element) {
71 // backdrops contains the overlays with a backdrop that are currently
74 backdrops.push(element);
76 var index = backdrops.indexOf(element);
78 backdrops.splice(index, 1);
83 function getBackdrops() {
88 addOverlay: addOverlay,
89 removeOverlay: removeOverlay,
90 currentOverlay: currentOverlay,
91 currentOverlayZ: currentOverlayZ,
92 focusOverlay: focusOverlay,
93 trackBackdrop: trackBackdrop,
94 getBackdrops: getBackdrops