5 var SHADOW_WHEN_SCROLLING = 1;
16 'standard': SHADOW_ALWAYS,
17 'waterfall': SHADOW_WHEN_SCROLLING,
18 'waterfall-tall': SHADOW_WHEN_SCROLLING
22 'waterfall-tall': true
28 is: 'paper-header-panel',
31 * Fired when the content has been scrolled. `event.detail.target` returns
32 * the scrollable element which you can use to access scroll info such as
35 * <paper-header-panel on-content-scroll="scrollHandler">
37 * </paper-header-panel>
40 * scrollHandler: function(event) {
41 * var scroller = event.detail.target;
42 * console.log(scroller.scrollTop);
45 * @event content-scroll
51 * Controls header and scrolling behavior. Options are
52 * `standard`, `seamed`, `waterfall`, `waterfall-tall`, `scroll` and
53 * `cover`. Default is `standard`.
55 * `standard`: The header is a step above the panel. The header will consume the
56 * panel at the point of entry, preventing it from passing through to the
59 * `seamed`: The header is presented as seamed with the panel.
61 * `waterfall`: Similar to standard mode, but header is initially presented as
62 * seamed with panel, but then separates to form the step.
64 * `waterfall-tall`: The header is initially taller (`tall` class is added to
65 * the header). As the user scrolls, the header separates (forming an edge)
66 * while condensing (`tall` class is removed from the header).
68 * `scroll`: The header keeps its seam with the panel, and is pushed off screen.
70 * `cover`: The panel covers the whole `paper-header-panel` including the
71 * header. This allows user to style the panel in such a way that the panel is
72 * partially covering the header.
74 * <paper-header-panel mode="cover">
75 * <paper-toolbar class="tall">
76 * <core-icon-button icon="menu"></core-icon-button>
78 * <div class="content"></div>
79 * </paper-header-panel>
84 observer: '_modeChanged',
85 reflectToAttribute: true
89 * If true, the drop-shadow is always shown no matter what mode is set to.
97 * The class used in waterfall-tall mode. Change this if the header
98 * accepts a different class for toggling height, e.g. "medium-tall"
106 * If true, the scroller is at the top
116 '_computeDropShadowHidden(atTop, mode, shadow)'
120 this.scrollHandler = this._scroll.bind(this);
123 // Run `scroll` logic once to initialze class names, etc.
124 this._keepScrollingState();
127 detached: function() {
128 this._removeListener();
132 * Returns the header element
138 return Polymer.dom(this.$.headerContent).getDistributedNodes()[0];
142 * Returns the scrollable element.
148 return this._getScrollerForMode(this.mode);
152 * Returns true if the scroller has a visible shadow.
154 * @property visibleShadow
157 get visibleShadow() {
158 return this.$.dropShadow.classList.contains('has-shadow');
161 _computeDropShadowHidden: function(atTop, mode, shadow) {
163 var shadowMode = MODE_CONFIGS.shadowMode[mode];
166 this.toggleClass('has-shadow', true, this.$.dropShadow);
168 } else if (shadowMode === SHADOW_ALWAYS) {
169 this.toggleClass('has-shadow', true, this.$.dropShadow);
171 } else if (shadowMode === SHADOW_WHEN_SCROLLING && !atTop) {
172 this.toggleClass('has-shadow', true, this.$.dropShadow);
175 this.toggleClass('has-shadow', false, this.$.dropShadow);
180 _computeMainContainerClass: function(mode) {
181 // TODO: It will be useful to have a utility for classes
182 // e.g. Polymer.Utils.classes({ foo: true });
186 classes['flex'] = mode !== 'cover';
188 return Object.keys(classes).filter(
189 function(className) {
190 return classes[className];
194 _addListener: function() {
195 this.scroller.addEventListener('scroll', this.scrollHandler, false);
198 _removeListener: function() {
199 this.scroller.removeEventListener('scroll', this.scrollHandler);
202 _modeChanged: function(newMode, oldMode) {
203 var configs = MODE_CONFIGS;
204 var header = this.header;
205 var animateDuration = 200;
208 // in tallMode it may add tallClass to the header; so do the cleanup
209 // when mode is changed from tallMode to not tallMode
210 if (configs.tallMode[oldMode] && !configs.tallMode[newMode]) {
211 header.classList.remove(this.tallClass);
212 this.async(function() {
213 header.classList.remove('animate');
216 header.classList.toggle('animate', configs.tallMode[newMode]);
219 this._keepScrollingState();
222 _keepScrollingState: function() {
223 var main = this.scroller;
224 var header = this.header;
226 this._setAtTop(main.scrollTop === 0);
228 if (header && this.tallClass && MODE_CONFIGS.tallMode[this.mode]) {
229 this.toggleClass(this.tallClass, this.atTop ||
230 header.classList.contains(this.tallClass) &&
231 main.scrollHeight < this.offsetHeight, header);
235 _scroll: function() {
236 this._keepScrollingState();
237 this.fire('content-scroll', {target: this.scroller}, {bubbles: false});
240 _getScrollerForMode: function(mode) {
241 return MODE_CONFIGS.outerScroll[mode] ?
242 this : this.$.mainContainer;