| OLD | NEW |
| (Empty) |
| 1 Polymer({ | |
| 2 is: 'app-header-layout', | |
| 3 | |
| 4 behaviors: [ | |
| 5 Polymer.IronResizableBehavior | |
| 6 ], | |
| 7 | |
| 8 properties: { | |
| 9 /** | |
| 10 * If true, the current element will have its own scrolling region. | |
| 11 * Otherwise, it will use the document scroll to control the header. | |
| 12 */ | |
| 13 hasScrollingRegion: { | |
| 14 type: Boolean, | |
| 15 value: false, | |
| 16 reflectToAttribute: true | |
| 17 } | |
| 18 }, | |
| 19 | |
| 20 listeners: { | |
| 21 'iron-resize': '_resizeHandler', | |
| 22 'app-header-reset-layout': 'resetLayout' | |
| 23 }, | |
| 24 | |
| 25 observers: [ | |
| 26 'resetLayout(isAttached, hasScrollingRegion)' | |
| 27 ], | |
| 28 | |
| 29 /** | |
| 30 * A reference to the app-header element. | |
| 31 * | |
| 32 * @property header | |
| 33 */ | |
| 34 get header() { | |
| 35 return Polymer.dom(this.$.header).getDistributedNodes()[0]; | |
| 36 }, | |
| 37 | |
| 38 /** | |
| 39 * Resets the layout. This method is automatically called when the element
is attached | |
| 40 * to the DOM. | |
| 41 * | |
| 42 * @method resetLayout | |
| 43 */ | |
| 44 resetLayout: function() { | |
| 45 this._updateScroller(); | |
| 46 this.debounce('_resetLayout', this._updateContentPosition); | |
| 47 }, | |
| 48 | |
| 49 _updateContentPosition: function() { | |
| 50 var header = this.header; | |
| 51 if (!this.isAttached || !header) { | |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 // Get header height here so that style reads are batched together befor
e style writes | |
| 56 // (i.e. getBoundingClientRect() below). | |
| 57 var headerHeight = header.offsetHeight; | |
| 58 | |
| 59 // Update the header position. | |
| 60 if (!this.hasScrollingRegion) { | |
| 61 var rect = this.getBoundingClientRect(); | |
| 62 var rightOffset = document.documentElement.clientWidth - rect.right; | |
| 63 header.style.left = rect.left + 'px'; | |
| 64 header.style.right = rightOffset + 'px'; | |
| 65 } else { | |
| 66 header.style.left = ''; | |
| 67 header.style.right = ''; | |
| 68 } | |
| 69 | |
| 70 // Update the content container position. | |
| 71 var containerStyle = this.$.contentContainer.style; | |
| 72 if (header.fixed && !header.willCondense() && this.hasScrollingRegion) { | |
| 73 // If the header size does not change and we're using a scrolling regi
on, exclude | |
| 74 // the header area from the scrolling region so that the header doesn'
t overlap | |
| 75 // the scrollbar. | |
| 76 containerStyle.marginTop = headerHeight + 'px'; | |
| 77 containerStyle.paddingTop = ''; | |
| 78 } else { | |
| 79 containerStyle.paddingTop = headerHeight + 'px'; | |
| 80 containerStyle.marginTop = ''; | |
| 81 } | |
| 82 }, | |
| 83 | |
| 84 _updateScroller: function() { | |
| 85 if (!this.isAttached) { | |
| 86 return; | |
| 87 } | |
| 88 var header = this.header; | |
| 89 if (header) { | |
| 90 header.scrollTarget = this.hasScrollingRegion ? | |
| 91 this.$.contentContainer : this.ownerDocument.documentElement; | |
| 92 } | |
| 93 }, | |
| 94 | |
| 95 _resizeHandler: function() { | |
| 96 this.resetLayout(); | |
| 97 } | |
| 98 }); | |
| OLD | NEW |