4 Polymer('core-scroll-header-panel',Polymer.mixin({
7 * Fired when the content has been scrolled.
13 * Fired when the header is transformed.
15 * @event core-header-transform
20 * If true, the header's height will condense to `_condensedHeaderHeight`
21 * as the user scrolls down from the top of the content area.
23 * @attribute condenses
30 * If true, no cross-fade transition from one background to another.
32 * @attribute noDissolve
39 * If true, the header doesn't slide back in when scrolling back up.
48 * If true, the header is fixed to the top and never moves away.
57 * If true, the condensed header is always shown and does not move away.
59 * @attribute keepCondensedHeader
63 keepCondensedHeader: false,
66 * The height of the header when it is at its full size.
68 * By default, the height will be measured when it is ready. If the height
69 * changes later the user needs to either set this value to reflect the
70 * new height or invoke `measureHeaderHeight()`.
72 * @attribute headerHeight
79 * The height of the header when it is condensed.
81 * By default, `_condensedHeaderHeight` is 1/3 of `headerHeight` unless
84 * @attribute condensedHeaderHeight
88 condensedHeaderHeight: 0,
91 * By default, the top part of the header stays when the header is being
92 * condensed. Set this to true if you want the top part of the header
93 * to be scrolled away.
95 * @attribute scrollAwayTopbar
99 scrollAwayTopbar: false
109 'headerMargin fixed': 'setup'
113 'core-resize': 'measureHeaderHeight'
116 attached: function() {
117 this.resizableAttachedHandler();
121 this._scrollHandler = this.scroll.bind(this);
122 this.scroller.addEventListener('scroll', this._scrollHandler);
125 detached: function() {
126 this.scroller.removeEventListener('scroll', this._scrollHandler);
127 this.resizableDetachedHandler();
130 domReady: function() {
131 this.async('measureHeaderHeight');
135 return this.$.headerContent.getDistributedNodes()[0];
139 * Returns the scrollable element.
145 return this.$.mainContainer;
149 * Invoke this to tell `core-scroll-header-panel` to re-measure the header's
152 * @method measureHeaderHeight
154 measureHeaderHeight: function() {
155 var header = this.header;
156 if (header && header.offsetHeight) {
157 this.headerHeight = header.offsetHeight;
161 headerHeightChanged: function() {
162 if (!this.condensedHeaderHeight) {
163 // assume _condensedHeaderHeight is 1/3 of the headerHeight
164 this._condensedHeaderHeight = this.headerHeight * 1 / 3;
166 this.condensedHeaderHeightChanged();
169 condensedHeaderHeightChanged: function() {
170 if (this.condensedHeaderHeight) {
171 this._condensedHeaderHeight = this.condensedHeaderHeight;
173 if (this.headerHeight) {
174 this.headerMargin = this.headerHeight - this._condensedHeaderHeight;
178 condensesChanged: function() {
179 if (this.condenses) {
182 // reset transform/opacity set on the header
183 this.condenseHeader(null);
188 var s = this.scroller.style;
189 s.paddingTop = this.fixed ? '' : this.headerHeight + 'px';
190 s.top = this.fixed ? this.headerHeight + 'px' : '';
192 this.transformHeader(null);
198 transformHeader: function(y) {
199 var s = this.$.headerContainer.style;
200 this.translateY(s, -y);
202 if (this.condenses) {
203 this.condenseHeader(y);
206 this.fire('core-header-transform', {y: y, height: this.headerHeight,
207 condensedHeight: this._condensedHeaderHeight});
210 condenseHeader: function(y) {
211 var reset = y == null;
212 // adjust top bar in core-header so the top bar stays at the top
213 if (!this.scrollAwayTopbar && this.header.$ && this.header.$.topBar) {
214 this.translateY(this.header.$.topBar.style,
215 reset ? null : Math.min(y, this.headerMargin));
217 // transition header bg
218 var hbg = this.$.headerBg.style;
219 if (!this.noDissolve) {
220 hbg.opacity = reset ? '' : (this.headerMargin - y) / this.headerMargin;
222 // adjust header bg so it stays at the center
223 this.translateY(hbg, reset ? null : y / 2);
224 // transition condensed header bg
225 var chbg = this.$.condensedHeaderBg.style;
226 if (!this.noDissolve) {
227 chbg = this.$.condensedHeaderBg.style;
228 chbg.opacity = reset ? '' : y / this.headerMargin;
229 // adjust condensed header bg so it stays at the center
230 this.translateY(chbg, reset ? null : y / 2);
234 translateY: function(s, y) {
235 var t = y == null ? '' : 'translate3d(0, ' + y + 'px, 0)';
239 scroll: function(event) {
244 var sTop = this.scroller.scrollTop;
246 var y = Math.min(this.keepCondensedHeader ?
247 this.headerMargin : this.headerHeight, Math.max(0,
248 (this.noReveal ? sTop : this.y + sTop - this.prevScrollTop)));
250 if (this.condenses && this.prevScrollTop >= sTop && sTop > this.headerMargin) {
251 y = Math.max(y, this.headerMargin);
254 if (!event || !this.fixed && y !== this.y) {
255 this.transformHeader(y);
258 this.prevScrollTop = Math.max(sTop, 0);
262 this.fire('scroll', {target: this.scroller}, this, false);
266 }, Polymer.CoreResizable));
268 //determine proper transform mechanizm
269 if (document.documentElement.style.transform !== undefined) {
270 var setTransform = function(style, string) {
271 style.transform = string;
274 var setTransform = function(style, string) {
275 style.webkitTransform = string;