2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9 <link rel=
"import" href=
"../polymer/polymer.html">
11 <polymer-element name=
"core-overlay-layer">
31 Polymer('core-overlay-layer', {
35 openedChanged: function() {
36 this.classList
.toggle('core-opened', this.opened
);
39 * Adds an element to the overlay layer
41 addElement: function(element
) {
42 if (!this.parentNode
) {
43 document
.querySelector('body').appendChild(this);
45 if (element
.parentNode
!== this) {
46 element
.__contents
= [];
47 var ip
$ = element
.querySelectorAll('content');
48 for (var i
=0, l
=ip
$.length
, n
; (i
<l
) && (n
= ip
$[i
]); i
++) {
49 this.moveInsertedElements(n
);
50 this.cacheDomLocation(n
);
51 n
.parentNode
.removeChild(n
);
52 element
.__contents
.push(n
);
54 this.cacheDomLocation(element
);
55 this.updateEventController(element
);
56 var h
= this.makeHost();
57 h
.shadowRoot
.appendChild(element
);
61 makeHost: function() {
62 var h
= document
.createElement('overlay-host');
67 moveInsertedElements: function(insertionPoint
) {
68 var n
$ = insertionPoint
.getDistributedNodes();
69 var parent
= insertionPoint
.parentNode
;
70 insertionPoint
.__contents
= [];
71 for (var i
=0, l
=n
$.length
, n
; (i
<l
) && (n
=n
$[i
]); i
++) {
72 this.cacheDomLocation(n
);
73 this.updateEventController(n
);
74 insertionPoint
.__contents
.push(n
);
75 parent
.appendChild(n
);
78 updateEventController: function(element
) {
79 element
.eventController
= this.element
.findController(element
);
82 * Removes an element from the overlay layer
84 removeElement: function(element
) {
85 element
.eventController
= null;
86 this.replaceElement(element
);
87 var h
= element
.__host
;
89 h
.parentNode
.removeChild(h
);
92 replaceElement: function(element
) {
93 if (element
.__contents
) {
94 for (var i
=0, c
$=element
.__contents
, c
; (c
=c
$[i
]); i
++) {
95 this.replaceElement(c
);
97 element
.__contents
= null;
99 if (element
.__parentNode
) {
100 var n
= element
.__nextElementSibling
&& element
.__nextElementSibling
101 === element
.__parentNode
? element
.__nextElementSibling
: null;
102 element
.__parentNode
.insertBefore(element
, n
);
105 cacheDomLocation: function(element
) {
106 element
.__nextElementSibling
= element
.nextElementSibling
;
107 element
.__parentNode
= element
.parentNode
;