Blame view

bower_components/iron-overlay-behavior/iron-overlay-manager.html 3.3 KB
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>
  
a1a3bc73   Luigi Serra   graphs updates
15
    Polymer.IronOverlayManager = {
73bcce88   luigser   COMPONENTS
16
  
a1a3bc73   Luigi Serra   graphs updates
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
      _overlays: [],
  
      // iframes have a default z-index of 100, so this default should be at least
      // that.
      _minimumZ: 101,
  
      _backdrops: [],
  
      _applyOverlayZ: function(overlay, aboveZ) {
        this._setZ(overlay, aboveZ + 2);
      },
  
      _setZ: function(element, z) {
        element.style.zIndex = z;
      },
73bcce88   luigser   COMPONENTS
32
33
  
      // track overlays for z-index and focus managemant
a1a3bc73   Luigi Serra   graphs updates
34
35
36
37
38
39
      addOverlay: function(overlay) {
        var minimumZ = Math.max(this.currentOverlayZ(), this._minimumZ);
        this._overlays.push(overlay);
        var newZ = this.currentOverlayZ();
        if (newZ <= minimumZ) {
          this._applyOverlayZ(overlay, minimumZ);
73bcce88   luigser   COMPONENTS
40
        }
a1a3bc73   Luigi Serra   graphs updates
41
      },
73bcce88   luigser   COMPONENTS
42
  
a1a3bc73   Luigi Serra   graphs updates
43
44
      removeOverlay: function(overlay) {
        var i = this._overlays.indexOf(overlay);
73bcce88   luigser   COMPONENTS
45
        if (i >= 0) {
a1a3bc73   Luigi Serra   graphs updates
46
47
          this._overlays.splice(i, 1);
          this._setZ(overlay, '');
73bcce88   luigser   COMPONENTS
48
        }
a1a3bc73   Luigi Serra   graphs updates
49
      },
73bcce88   luigser   COMPONENTS
50
  
a1a3bc73   Luigi Serra   graphs updates
51
52
53
      currentOverlay: function() {
        var i = this._overlays.length - 1;
        while (this._overlays[i] && !this._overlays[i].opened) {
73bcce88   luigser   COMPONENTS
54
55
          --i;
        }
a1a3bc73   Luigi Serra   graphs updates
56
57
        return this._overlays[i];
      },
73bcce88   luigser   COMPONENTS
58
  
a1a3bc73   Luigi Serra   graphs updates
59
60
61
      currentOverlayZ: function() {
        var z = this._minimumZ;
        var current = this.currentOverlay();
73bcce88   luigser   COMPONENTS
62
63
64
65
66
67
        if (current) {
          var z1 = window.getComputedStyle(current).zIndex;
          if (!isNaN(z1)) {
            z = Number(z1);
          }
        }
a1a3bc73   Luigi Serra   graphs updates
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
        return z;
      },
  
      /**
       * Ensures that the minimum z-index of new overlays is at least `minimumZ`.
       * This does not effect the z-index of any existing overlays.
       *
       * @param {number} minimumZ
       */
      ensureMinimumZ: function(minimumZ) {
        this._minimumZ = Math.max(this._minimumZ, minimumZ);
      },
  
      focusOverlay: function() {
        var current = this.currentOverlay();
73bcce88   luigser   COMPONENTS
83
84
85
86
87
88
89
90
91
92
93
        // 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();
        }
a1a3bc73   Luigi Serra   graphs updates
94
      },
73bcce88   luigser   COMPONENTS
95
  
a1a3bc73   Luigi Serra   graphs updates
96
      trackBackdrop: function(element) {
73bcce88   luigser   COMPONENTS
97
98
99
        // backdrops contains the overlays with a backdrop that are currently
        // visible
        if (element.opened) {
a1a3bc73   Luigi Serra   graphs updates
100
          this._backdrops.push(element);
73bcce88   luigser   COMPONENTS
101
        } else {
a1a3bc73   Luigi Serra   graphs updates
102
          var index = this._backdrops.indexOf(element);
73bcce88   luigser   COMPONENTS
103
          if (index >= 0) {
a1a3bc73   Luigi Serra   graphs updates
104
            this._backdrops.splice(index, 1);
73bcce88   luigser   COMPONENTS
105
106
          }
        }
a1a3bc73   Luigi Serra   graphs updates
107
      },
73bcce88   luigser   COMPONENTS
108
  
a1a3bc73   Luigi Serra   graphs updates
109
110
      getBackdrops: function() {
        return this._backdrops;
73bcce88   luigser   COMPONENTS
111
112
      }
  
a1a3bc73   Luigi Serra   graphs updates
113
    };
73bcce88   luigser   COMPONENTS
114
115
  
  </script>