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 return overlays[overlays.length-1];
39 function currentOverlayZ() {
41 var current = currentOverlay();
43 var z1 = window.getComputedStyle(current).zIndex;
48 return z || DEFAULT_Z;
51 function focusOverlay() {
52 var current = currentOverlay();
53 // We have to be careful to focus the next overlay _after_ any current
54 // transitions are complete (due to the state being toggled prior to the
55 // transition). Otherwise, we risk infinite recursion when a transitioning
56 // (closed) overlay becomes the current overlay.
58 // NOTE: We make the assumption that any overlay that completes a transition
59 // will call into focusOverlay to kick the process back off. Currently:
60 // transitionend -> _applyFocus -> focusOverlay.
61 if (current && !current.transitioning) {
62 current._applyFocus();
66 function trackBackdrop(element) {
67 // backdrops contains the overlays with a backdrop that are currently
70 backdrops.push(element);
72 var index = backdrops.indexOf(element);
74 backdrops.splice(index, 1);
79 function getBackdrops() {
84 addOverlay: addOverlay,
85 removeOverlay: removeOverlay,
86 currentOverlay: currentOverlay,
87 currentOverlayZ: currentOverlayZ,
88 focusOverlay: focusOverlay,
89 trackBackdrop: trackBackdrop,
90 getBackdrops: getBackdrops