7 var SHADOW_WHEN_SCROLLING = 1;
18 standard: SHADOW_ALWAYS,
19 waterfall: SHADOW_WHEN_SCROLLING,
20 'waterfall-tall': SHADOW_WHEN_SCROLLING
24 'waterfall-tall': true
30 is: 'paper-header-panel',
33 * Fired when the content has been scrolled. `event.detail.target` returns
34 * the scrollable element which you can use to access scroll info such as
37 * <paper-header-panel on-content-scroll="{{scrollHandler}}">
39 * </paper-header-panel>
42 * scrollHandler: function(event) {
43 * var scroller = event.detail.target;
44 * console.log(scroller.scrollTop);
47 * @event content-scroll
53 * Controls header and scrolling behavior. Options are
54 * `standard`, `seamed`, `waterfall`, `waterfall-tall`, `scroll` and
55 * `cover`. Default is `standard`.
57 * `standard`: The header is a step above the panel. The header will consume the
58 * panel at the point of entry, preventing it from passing through to the
61 * `seamed`: The header is presented as seamed with the panel.
63 * `waterfall`: Similar to standard mode, but header is initially presented as
64 * seamed with panel, but then separates to form the step.
66 * `waterfall-tall`: The header is initially taller (`tall` class is added to
67 * the header). As the user scrolls, the header separates (forming an edge)
68 * while condensing (`tall` class is removed from the header).
70 * `scroll`: The header keeps its seam with the panel, and is pushed off screen.
72 * `cover`: The panel covers the whole `paper-header-panel` including the
73 * header. This allows user to style the panel in such a way that the panel is
74 * partially covering the header.
76 * <paper-header-panel mode="cover">
77 * <paper-toolbar class="tall">
78 * <core-icon-button icon="menu"></core-icon-button>
80 * <div class="content"></div>
81 * </paper-header-panel>
86 observer: '_modeChanged',
87 reflectToAttribute: true
91 * If true, the drop-shadow is always shown no matter what mode is set to.
99 * The class used in waterfall-tall mode. Change this if the header
100 * accepts a different class for toggling height, e.g. "medium-tall"
108 * If true, the scroller is at the top
118 '_computeDropShadowHidden(atTop, mode, shadow)'
122 this.scrollHandler = this._scroll.bind(this);
125 // Run `scroll` logic once to initialze class names, etc.
126 this._keepScrollingState();
129 detached: function() {
130 this._removeListener();
134 * Returns the header element
140 return Polymer.dom(this.$.headerContent).getDistributedNodes()[0];
144 * Returns the scrollable element.
150 return this._getScrollerForMode(this.mode);
154 * Returns true if the scroller has a visible shadow.
156 * @property visibleShadow
159 get visibleShadow() {
160 return this.header.classList.contains('has-shadow');
163 _computeDropShadowHidden: function(atTop, mode, shadow) {
165 var shadowMode = MODE_CONFIGS.shadowMode[mode];
168 this.toggleClass('has-shadow', true, this.header);
170 } else if (shadowMode === SHADOW_ALWAYS) {
171 this.toggleClass('has-shadow', true, this.header);
173 } else if (shadowMode === SHADOW_WHEN_SCROLLING && !atTop) {
174 this.toggleClass('has-shadow', true, this.header);
177 this.toggleClass('has-shadow', false, this.header);
182 _computeMainContainerClass: function(mode) {
183 // TODO: It will be useful to have a utility for classes
184 // e.g. Polymer.Utils.classes({ foo: true });
188 classes['flex'] = mode !== 'cover';
190 return Object.keys(classes).filter(
191 function(className) {
192 return classes[className];
196 _addListener: function() {
197 this.scroller.addEventListener('scroll', this.scrollHandler, false);
200 _removeListener: function() {
201 this.scroller.removeEventListener('scroll', this.scrollHandler);
204 _modeChanged: function(newMode, oldMode) {
205 var configs = MODE_CONFIGS;
206 var header = this.header;
207 var animateDuration = 200;
210 // in tallMode it may add tallClass to the header; so do the cleanup
211 // when mode is changed from tallMode to not tallMode
212 if (configs.tallMode[oldMode] && !configs.tallMode[newMode]) {
213 header.classList.remove(this.tallClass);
214 this.async(function() {
215 header.classList.remove('animate');
218 header.classList.toggle('animate', configs.tallMode[newMode]);
221 this._keepScrollingState();
224 _keepScrollingState: function () {
225 var main = this.scroller;
226 var header = this.header;
228 this._setAtTop(main.scrollTop === 0);
230 if (header && MODE_CONFIGS.tallMode[this.mode]) {
231 this.toggleClass(this.tallClass, this.atTop ||
232 header.classList.contains(this.tallClass) &&
233 main.scrollHeight < this.offsetHeight, header);
237 _scroll: function(e) {
238 this._keepScrollingState();
239 this.fire('content-scroll', {target: this.scroller}, {bubbles: false});
242 _getScrollerForMode: function(mode) {
243 return MODE_CONFIGS.outerScroll[mode] ?
244 this : this.$.mainContainer;