73bcce88
luigser
COMPONENTS
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
<script>
|
c5169e0e
Renato De Donato
a new hope
|
15
|
Polymer.IronOverlayManager = (function() {
|
73bcce88
luigser
COMPONENTS
|
16
|
|
c5169e0e
Renato De Donato
a new hope
|
17
18
19
|
var overlays = [];
var DEFAULT_Z = 10;
var backdrops = [];
|
73bcce88
luigser
COMPONENTS
|
20
21
|
// track overlays for z-index and focus managemant
|
c5169e0e
Renato De Donato
a new hope
|
22
23
24
25
26
27
|
function addOverlay(overlay) {
var z0 = currentOverlayZ();
overlays.push(overlay);
var z1 = currentOverlayZ();
if (z1 <= z0) {
applyOverlayZ(overlay, z0);
|
73bcce88
luigser
COMPONENTS
|
28
|
}
|
c5169e0e
Renato De Donato
a new hope
|
29
|
}
|
73bcce88
luigser
COMPONENTS
|
30
|
|
c5169e0e
Renato De Donato
a new hope
|
31
32
|
function removeOverlay(overlay) {
var i = overlays.indexOf(overlay);
|
73bcce88
luigser
COMPONENTS
|
33
|
if (i >= 0) {
|
c5169e0e
Renato De Donato
a new hope
|
34
35
|
overlays.splice(i, 1);
setZ(overlay, '');
|
73bcce88
luigser
COMPONENTS
|
36
|
}
|
c5169e0e
Renato De Donato
a new hope
|
37
38
39
40
41
|
}
function applyOverlayZ(overlay, aboveZ) {
setZ(overlay, aboveZ + 2);
}
|
73bcce88
luigser
COMPONENTS
|
42
|
|
c5169e0e
Renato De Donato
a new hope
|
43
44
45
46
47
48
49
|
function setZ(element, z) {
element.style.zIndex = z;
}
function currentOverlay() {
var i = overlays.length - 1;
while (overlays[i] && !overlays[i].opened) {
|
73bcce88
luigser
COMPONENTS
|
50
51
|
--i;
}
|
c5169e0e
Renato De Donato
a new hope
|
52
53
|
return overlays[i];
}
|
73bcce88
luigser
COMPONENTS
|
54
|
|
c5169e0e
Renato De Donato
a new hope
|
55
56
57
|
function currentOverlayZ() {
var z;
var current = currentOverlay();
|
73bcce88
luigser
COMPONENTS
|
58
59
60
61
62
63
|
if (current) {
var z1 = window.getComputedStyle(current).zIndex;
if (!isNaN(z1)) {
z = Number(z1);
}
}
|
c5169e0e
Renato De Donato
a new hope
|
64
65
66
67
68
|
return z || DEFAULT_Z;
}
function focusOverlay() {
var current = currentOverlay();
|
73bcce88
luigser
COMPONENTS
|
69
70
71
72
73
74
75
76
77
78
79
|
// We have to be careful to focus the next overlay _after_ any current
// transitions are complete (due to the state being toggled prior to the
// transition). Otherwise, we risk infinite recursion when a transitioning
// (closed) overlay becomes the current overlay.
//
// NOTE: We make the assumption that any overlay that completes a transition
// will call into focusOverlay to kick the process back off. Currently:
// transitionend -> _applyFocus -> focusOverlay.
if (current && !current.transitioning) {
current._applyFocus();
}
|
c5169e0e
Renato De Donato
a new hope
|
80
|
}
|
73bcce88
luigser
COMPONENTS
|
81
|
|
c5169e0e
Renato De Donato
a new hope
|
82
|
function trackBackdrop(element) {
|
73bcce88
luigser
COMPONENTS
|
83
84
85
|
// backdrops contains the overlays with a backdrop that are currently
// visible
if (element.opened) {
|
c5169e0e
Renato De Donato
a new hope
|
86
|
backdrops.push(element);
|
73bcce88
luigser
COMPONENTS
|
87
|
} else {
|
c5169e0e
Renato De Donato
a new hope
|
88
|
var index = backdrops.indexOf(element);
|
73bcce88
luigser
COMPONENTS
|
89
|
if (index >= 0) {
|
c5169e0e
Renato De Donato
a new hope
|
90
|
backdrops.splice(index, 1);
|
73bcce88
luigser
COMPONENTS
|
91
92
|
}
}
|
c5169e0e
Renato De Donato
a new hope
|
93
|
}
|
73bcce88
luigser
COMPONENTS
|
94
|
|
c5169e0e
Renato De Donato
a new hope
|
95
96
|
function getBackdrops() {
return backdrops;
|
73bcce88
luigser
COMPONENTS
|
97
98
|
}
|
c5169e0e
Renato De Donato
a new hope
|
99
100
101
102
103
104
105
106
107
108
109
|
return {
addOverlay: addOverlay,
removeOverlay: removeOverlay,
currentOverlay: currentOverlay,
currentOverlayZ: currentOverlayZ,
focusOverlay: focusOverlay,
trackBackdrop: trackBackdrop,
getBackdrops: getBackdrops
};
})();
|
73bcce88
luigser
COMPONENTS
|
110
111
|
</script>
|