3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7 Code distributed by Google as part of the polymer project is also
8 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11 <link rel=
"import" href=
"../polymer/polymer.html">
15 Polymer
.IronOverlayManager
= (function() {
21 // track overlays for z-index and focus managemant
22 function addOverlay(overlay
) {
23 var z0
= currentOverlayZ();
24 overlays
.push(overlay
);
25 var z1
= currentOverlayZ();
27 applyOverlayZ(overlay
, z0
);
31 function removeOverlay(overlay
) {
32 var i
= overlays
.indexOf(overlay
);
34 overlays
.splice(i
, 1);
39 function applyOverlayZ(overlay
, aboveZ
) {
40 setZ(overlay
, aboveZ
+ 2);
43 function setZ(element
, z
) {
44 element
.style
.zIndex
= z
;
47 function currentOverlay() {
48 return overlays
[overlays
.length
-1];
51 function currentOverlayZ() {
53 var current
= currentOverlay();
55 var z1
= window
.getComputedStyle(current
).zIndex
;
60 return z
|| DEFAULT_Z
;
63 function focusOverlay() {
64 var current
= currentOverlay();
65 // We have to be careful to focus the next overlay _after_ any current
66 // transitions are complete (due to the state being toggled prior to the
67 // transition). Otherwise, we risk infinite recursion when a transitioning
68 // (closed) overlay becomes the current overlay.
70 // NOTE: We make the assumption that any overlay that completes a transition
71 // will call into focusOverlay to kick the process back off. Currently:
72 // transitionend -> _applyFocus -> focusOverlay.
73 if (current
&& !current
.transitioning
) {
74 current
._applyFocus();
78 function trackBackdrop(element
) {
79 // backdrops contains the overlays with a backdrop that are currently
82 backdrops
.push(element
);
84 var index
= backdrops
.indexOf(element
);
86 backdrops
.splice(index
, 1);
91 function getBackdrops() {
96 addOverlay
: addOverlay
,
97 removeOverlay
: removeOverlay
,
98 currentOverlay
: currentOverlay
,
99 currentOverlayZ
: currentOverlayZ
,
100 focusOverlay
: focusOverlay
,
101 trackBackdrop
: trackBackdrop
,
102 getBackdrops
: getBackdrops