| OLD | NEW |
| 1 Polymer({ | 1 Polymer({ |
| 2 is: 'app-header', | 2 is: 'app-header', |
| 3 | 3 |
| 4 behaviors: [ | 4 behaviors: [ |
| 5 Polymer.AppScrollEffectsBehavior, | 5 Polymer.AppScrollEffectsBehavior, |
| 6 Polymer.IronResizableBehavior | 6 Polymer.IronResizableBehavior |
| 7 ], | 7 ], |
| 8 | 8 |
| 9 properties: { | 9 properties: { |
| 10 /** | 10 /** |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 var dScrollTop = scrollTop - this._lastScrollTop; | 224 var dScrollTop = scrollTop - this._lastScrollTop; |
| 225 var absDScrollTop = Math.abs(dScrollTop); | 225 var absDScrollTop = Math.abs(dScrollTop); |
| 226 var isScrollingDown = scrollTop > this._lastScrollTop; | 226 var isScrollingDown = scrollTop > this._lastScrollTop; |
| 227 var now = Date.now(); | 227 var now = Date.now(); |
| 228 | 228 |
| 229 if (this._mayMove()) { | 229 if (this._mayMove()) { |
| 230 top = this._clamp(this.reveals ? lastTop + dScrollTop : scrollTop, 0,
maxHeaderTop); | 230 top = this._clamp(this.reveals ? lastTop + dScrollTop : scrollTop, 0,
maxHeaderTop); |
| 231 } | 231 } |
| 232 | 232 |
| 233 if (scrollTop >= this._dHeight) { | 233 if (scrollTop >= this._dHeight) { |
| 234 top = this.condenses ? Math.max(this._dHeight, top) : top; | 234 top = this.condenses && !this.fixed ? Math.max(this._dHeight, top) : t
op; |
| 235 this.style.transitionDuration = '0ms'; | 235 this.style.transitionDuration = '0ms'; |
| 236 } | 236 } |
| 237 | 237 |
| 238 if (this.reveals && !this.disabled && absDScrollTop < 100) { | 238 if (this.reveals && !this.disabled && absDScrollTop < 100) { |
| 239 // set the initial scroll position | 239 // set the initial scroll position |
| 240 if (now - this._initTimestamp > 300 || this._wasScrollingDown !== isSc
rollingDown) { | 240 if (now - this._initTimestamp > 300 || this._wasScrollingDown !== isSc
rollingDown) { |
| 241 this._initScrollTop = scrollTop; | 241 this._initScrollTop = scrollTop; |
| 242 this._initTimestamp = now; | 242 this._initTimestamp = now; |
| 243 } | 243 } |
| 244 | 244 |
| 245 if (scrollTop >= maxHeaderTop) { | 245 if (scrollTop >= maxHeaderTop) { |
| 246 // check if the header is allowed to snap | 246 // check if the header is allowed to snap |
| 247 if (Math.abs(this._initScrollTop - scrollTop) > 30 || absDScrollTop
> 10) { | 247 if (Math.abs(this._initScrollTop - scrollTop) > 30 || absDScrollTop
> 10) { |
| 248 if (isScrollingDown && scrollTop >= maxHeaderTop) { | 248 if (isScrollingDown && scrollTop >= maxHeaderTop) { |
| 249 top = maxHeaderTop; | 249 top = maxHeaderTop; |
| 250 } else if (!isScrollingDown && scrollTop >= this._dHeight) { | 250 } else if (!isScrollingDown && scrollTop >= this._dHeight) { |
| 251 top = this.condenses ? this._dHeight : 0; | 251 top = this.condenses && !this.fixed ? this._dHeight : 0; |
| 252 } | 252 } |
| 253 | |
| 254 var scrollVelocity = dScrollTop / (now - this._lastTimestamp); | 253 var scrollVelocity = dScrollTop / (now - this._lastTimestamp); |
| 255 this.style.transitionDuration = this._clamp((top - lastTop) / scro
llVelocity, 0, 300) + 'ms'; | 254 this.style.transitionDuration = this._clamp((top - lastTop) / scro
llVelocity, 0, 300) + 'ms'; |
| 256 } else { | 255 } else { |
| 257 top = this._top; | 256 top = this._top; |
| 258 } | 257 } |
| 259 } | 258 } |
| 260 } | 259 } |
| 261 | 260 |
| 262 if (this._dHeight === 0) { | 261 if (this._dHeight === 0) { |
| 263 progress = scrollTop > 0 ? 1 : 0; | 262 progress = scrollTop > 0 ? 1 : 0; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 /** | 311 /** |
| 313 * Returns true if there's content below the current element. | 312 * Returns true if there's content below the current element. |
| 314 * | 313 * |
| 315 * @method isContentBelow | 314 * @method isContentBelow |
| 316 * @return {boolean} | 315 * @return {boolean} |
| 317 */ | 316 */ |
| 318 isContentBelow: function() { | 317 isContentBelow: function() { |
| 319 if (this._top === 0) { | 318 if (this._top === 0) { |
| 320 return this._clampedScrollTop > 0; | 319 return this._clampedScrollTop > 0; |
| 321 } | 320 } |
| 322 | |
| 323 return this._clampedScrollTop - this._maxHeaderTop >= 0; | 321 return this._clampedScrollTop - this._maxHeaderTop >= 0; |
| 324 }, | 322 }, |
| 325 | 323 |
| 326 /** | 324 /** |
| 327 * Transforms the header. | 325 * Transforms the header. |
| 328 * | 326 * |
| 329 * @param {number} y | 327 * @param {number} y |
| 330 */ | 328 */ |
| 331 _transformHeader: function(y) { | 329 _transformHeader: function(y) { |
| 332 this.translate3d(0, (-y) + 'px', 0); | 330 this.translate3d(0, (-y) + 'px', 0); |
| 333 | |
| 334 if (this._primaryEl && this.condenses && y >= this._primaryElTop) { | 331 if (this._primaryEl && this.condenses && y >= this._primaryElTop) { |
| 335 this.translate3d(0, (Math.min(y, this._dHeight) - this._primaryElTop)
+ 'px', 0, | 332 this.translate3d(0, (Math.min(y, this._dHeight) - this._primaryElTop)
+ 'px', 0, |
| 336 this._primaryEl); | 333 this._primaryEl); |
| 337 } | 334 } |
| 338 }, | 335 }, |
| 339 | 336 |
| 340 _resizeHandler: function() { | 337 _resizeHandler: function() { |
| 341 this.resetLayout(); | 338 this.resetLayout(); |
| 342 }, | 339 }, |
| 343 | 340 |
| 344 _clamp: function(v, min, max) { | 341 _clamp: function(v, min, max) { |
| 345 return Math.min(max, Math.max(min, v)); | 342 return Math.min(max, Math.max(min, v)); |
| 346 }, | 343 }, |
| 347 | 344 |
| 345 _ensureBgContainers: function() { |
| 346 if (!this._bgContainer) { |
| 347 this._bgContainer = document.createElement('div'); |
| 348 this._bgContainer.id = 'background'; |
| 349 |
| 350 this._bgRear = document.createElement('div'); |
| 351 this._bgRear.id = 'backgroundRearLayer'; |
| 352 this._bgContainer.appendChild(this._bgRear); |
| 353 |
| 354 this._bgFront = document.createElement('div'); |
| 355 this._bgFront.id = 'backgroundFrontLayer'; |
| 356 this._bgContainer.appendChild(this._bgFront); |
| 357 |
| 358 Polymer.dom(this.root).insertBefore(this._bgContainer, this.$.contentC
ontainer); |
| 359 } |
| 360 }, |
| 361 |
| 362 _getDOMRef: function(id) { |
| 363 switch (id) { |
| 364 case 'backgroundFrontLayer': |
| 365 this._ensureBgContainers(); |
| 366 return this._bgFront; |
| 367 case 'backgroundRearLayer': |
| 368 this._ensureBgContainers(); |
| 369 return this._bgRear; |
| 370 case 'background': |
| 371 this._ensureBgContainers(); |
| 372 return this._bgContainer; |
| 373 case 'title': |
| 374 return Polymer.dom(this).querySelector('[title]'); |
| 375 case 'condensedTitle': |
| 376 return Polymer.dom(this).querySelector('[condensed-title]'); |
| 377 } |
| 378 return null; |
| 379 }, |
| 380 |
| 348 /** | 381 /** |
| 349 * Returns an object containing the progress value of the scroll effects | 382 * Returns an object containing the progress value of the scroll effects |
| 350 * and the top position of the header. | 383 * and the top position of the header. |
| 351 * | 384 * |
| 352 * @method getScrollState | 385 * @method getScrollState |
| 353 * @return {Object} | 386 * @return {Object} |
| 354 */ | 387 */ |
| 355 getScrollState: function() { | 388 getScrollState: function() { |
| 356 return { progress: this._progress, top: this._top }; | 389 return { progress: this._progress, top: this._top }; |
| 357 } | 390 } |
| 358 | 391 |
| 359 /** | 392 /** |
| 360 * Fires when the layout of `app-header` changed. | 393 * Fires when the layout of `app-header` changed. |
| 361 * | 394 * |
| 362 * @event app-header-reset-layout | 395 * @event app-header-reset-layout |
| 363 */ | 396 */ |
| 364 }); | 397 }); |
| OLD | NEW |