| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 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.g
ithub.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/CONTRI
BUTORS.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/PATEN
TS.txt | |
| 8 --> | |
| 9 <link rel="import" href="../polymer/polymer.html"> | |
| 10 | |
| 11 <polymer-element name="core-overlay-layer"> | |
| 12 <template> | |
| 13 <style> | |
| 14 :host { | |
| 15 position: fixed; | |
| 16 top: 0; | |
| 17 left: 0; | |
| 18 z-index: 1000; | |
| 19 display: none; | |
| 20 } | |
| 21 | |
| 22 :host(.core-opened) { | |
| 23 display: block; | |
| 24 } | |
| 25 </style> | |
| 26 <content></content> | |
| 27 </template> | |
| 28 <script> | |
| 29 (function() { | |
| 30 | |
| 31 Polymer('core-overlay-layer', { | |
| 32 publish: { | |
| 33 opened: false | |
| 34 }, | |
| 35 openedChanged: function() { | |
| 36 this.classList.toggle('core-opened', this.opened); | |
| 37 }, | |
| 38 /** | |
| 39 * Adds an element to the overlay layer | |
| 40 */ | |
| 41 addElement: function(element) { | |
| 42 if (!this.parentNode) { | |
| 43 document.querySelector('body').appendChild(this); | |
| 44 } | |
| 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); | |
| 53 } | |
| 54 this.cacheDomLocation(element); | |
| 55 this.updateEventController(element); | |
| 56 var h = this.makeHost(); | |
| 57 h.shadowRoot.appendChild(element); | |
| 58 element.__host = h; | |
| 59 } | |
| 60 }, | |
| 61 makeHost: function() { | |
| 62 var h = document.createElement('overlay-host'); | |
| 63 h.createShadowRoot(); | |
| 64 this.appendChild(h); | |
| 65 return h; | |
| 66 }, | |
| 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); | |
| 76 } | |
| 77 }, | |
| 78 updateEventController: function(element) { | |
| 79 element.eventController = this.element.findController(element); | |
| 80 }, | |
| 81 /** | |
| 82 * Removes an element from the overlay layer | |
| 83 */ | |
| 84 removeElement: function(element) { | |
| 85 element.eventController = null; | |
| 86 this.replaceElement(element); | |
| 87 var h = element.__host; | |
| 88 if (h) { | |
| 89 h.parentNode.removeChild(h); | |
| 90 } | |
| 91 }, | |
| 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); | |
| 96 } | |
| 97 element.__contents = null; | |
| 98 } | |
| 99 if (element.__parentNode) { | |
| 100 var n = element.__nextElementSibling && element.__nextElementSibling | |
| 101 === element.__parentNode ? element.__nextElementSibling : null; | |
| 102 element.__parentNode.insertBefore(element, n); | |
| 103 } | |
| 104 }, | |
| 105 cacheDomLocation: function(element) { | |
| 106 element.__nextElementSibling = element.nextElementSibling; | |
| 107 element.__parentNode = element.parentNode; | |
| 108 } | |
| 109 }); | |
| 110 | |
| 111 })(); | |
| 112 </script> | |
| 113 </polymer-element> | |
| OLD | NEW |