| <!-- |
| Copyright (c) 2014 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"> |
| |
| <!-- |
| @element core-overlay-layer |
| --> |
| <polymer-element name="core-overlay-layer"> |
| <template> |
| <style> |
| :host { |
| position: fixed; |
| top: 0; |
| left: 0; |
| z-index: 1000; |
| display: none; |
| } |
| |
| :host(.core-opened) { |
| display: block; |
| } |
| </style> |
| <content></content> |
| </template> |
| <script> |
| (function() { |
| |
| Polymer('core-overlay-layer', { |
| publish: { |
| opened: false |
| }, |
| openedChanged: function() { |
| this.classList.toggle('core-opened', this.opened); |
| }, |
| /** |
| * Adds an element to the overlay layer |
| */ |
| addElement: function(element) { |
| if (!this.parentNode) { |
| document.querySelector('body').appendChild(this); |
| } |
| if (element.parentNode !== this) { |
| element.__contents = []; |
| var ip$ = element.querySelectorAll('content'); |
| for (var i=0, l=ip$.length, n; (i<l) && (n = ip$[i]); i++) { |
| this.moveInsertedElements(n); |
| this.cacheDomLocation(n); |
| n.parentNode.removeChild(n); |
| element.__contents.push(n); |
| } |
| this.cacheDomLocation(element); |
| this.updateEventController(element); |
| var h = this.makeHost(); |
| h.shadowRoot.appendChild(element); |
| element.__host = h; |
| } |
| }, |
| makeHost: function() { |
| var h = document.createElement('overlay-host'); |
| h.createShadowRoot(); |
| this.appendChild(h); |
| return h; |
| }, |
| moveInsertedElements: function(insertionPoint) { |
| var n$ = insertionPoint.getDistributedNodes(); |
| var parent = insertionPoint.parentNode; |
| insertionPoint.__contents = []; |
| for (var i=0, l=n$.length, n; (i<l) && (n=n$[i]); i++) { |
| this.cacheDomLocation(n); |
| this.updateEventController(n); |
| insertionPoint.__contents.push(n); |
| parent.appendChild(n); |
| } |
| }, |
| updateEventController: function(element) { |
| element.eventController = this.element.findController(element); |
| }, |
| /** |
| * Removes an element from the overlay layer |
| */ |
| removeElement: function(element) { |
| element.eventController = null; |
| this.replaceElement(element); |
| var h = element.__host; |
| if (h) { |
| h.parentNode.removeChild(h); |
| } |
| }, |
| replaceElement: function(element) { |
| if (element.__contents) { |
| for (var i=0, c$=element.__contents, c; (c=c$[i]); i++) { |
| this.replaceElement(c); |
| } |
| element.__contents = null; |
| } |
| if (element.__parentNode) { |
| var n = element.__nextElementSibling && element.__nextElementSibling |
| === element.__parentNode ? element.__nextElementSibling : null; |
| element.__parentNode.insertBefore(element, n); |
| } |
| }, |
| cacheDomLocation: function(element) { |
| element.__nextElementSibling = element.nextElementSibling; |
| element.__parentNode = element.parentNode; |
| } |
| }); |
| |
| })(); |
| </script> |
| </polymer-element> |