| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Fast out, slow in. | 5 // Fast out, slow in. |
| 6 var EASING_FUNCTION = 'cubic-bezier(0.4, 0, 0.2, 1)'; | 6 var EASING_FUNCTION = 'cubic-bezier(0.4, 0, 0.2, 1)'; |
| 7 var EXPAND_DURATION = 350; | 7 var EXPAND_DURATION = 350; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Provides animations to expand and collapse individual sections in a page. | 10 * Provides animations to expand and collapse individual sections in a page. |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 card.style.top = ''; | 244 card.style.top = ''; |
| 245 this.style.margin = 'auto'; | 245 this.style.margin = 'auto'; |
| 246 section.$.header.hidden = true; | 246 section.$.header.hidden = true; |
| 247 section.style.height = ''; | 247 section.style.height = ''; |
| 248 }.bind(this), function() { | 248 }.bind(this), function() { |
| 249 // The animation was canceled; catch the error and continue. | 249 // The animation was canceled; catch the error and continue. |
| 250 }).then(function() { | 250 }).then(function() { |
| 251 // Whether finished or canceled, clean up the animation. | 251 // Whether finished or canceled, clean up the animation. |
| 252 section.classList.remove('expanding'); | 252 section.classList.remove('expanding'); |
| 253 card.style.height = ''; | 253 card.style.height = ''; |
| 254 card.style.width = ''; |
| 254 }); | 255 }); |
| 255 | 256 |
| 256 return promise; | 257 return promise; |
| 257 }, | 258 }, |
| 258 | 259 |
| 259 /** | 260 /** |
| 260 * Collapses the card in |section| back to its normal position. | 261 * Collapses the card in |section| back to its normal position. |
| 261 * @param {!SettingsSectionElement} section | 262 * @param {!SettingsSectionElement} section |
| 262 * @return {!Promise} | 263 * @return {!Promise} |
| 263 * @private | 264 * @private |
| 264 */ | 265 */ |
| 265 playCollapseSection_: function(section) { | 266 playCollapseSection_: function(section) { |
| 266 var card = section.$.card; | 267 var card = section.$.card; |
| 267 | 268 |
| 268 this.style.margin = ''; | 269 this.style.margin = ''; |
| 269 section.$.header.hidden = false; | 270 section.$.header.hidden = false; |
| 270 | 271 |
| 271 var startingTop = this.parentElement.getBoundingClientRect().top; | 272 var startingTop = this.parentElement.getBoundingClientRect().top; |
| 272 | 273 |
| 273 var cardHeightStart = card.clientHeight; | 274 var cardHeightStart = card.clientHeight; |
| 275 var cardWidthStart = card.clientWidth; |
| 274 | 276 |
| 275 section.classList.add('collapsing'); | 277 section.classList.add('collapsing'); |
| 276 section.classList.remove('expanding', 'expanded'); | 278 section.classList.remove('expanding', 'expanded'); |
| 277 | 279 |
| 278 // If we navigated here directly, we don't know the original height of the | 280 // If we navigated here directly, we don't know the original height of the |
| 279 // section, so we skip the animation. | 281 // section, so we skip the animation. |
| 280 // TODO(michaelpg): remove this condition once sliding is implemented. | 282 // TODO(michaelpg): remove this condition once sliding is implemented. |
| 281 if (isNaN(card.origHeight_)) | 283 if (isNaN(card.origHeight_)) |
| 282 return Promise.resolve(); | 284 return Promise.resolve(); |
| 283 | 285 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 302 top: startingTop + 'px', | 304 top: startingTop + 'px', |
| 303 minHeight: cardHeightStart + 'px', | 305 minHeight: cardHeightStart + 'px', |
| 304 easing: EASING_FUNCTION, | 306 easing: EASING_FUNCTION, |
| 305 }, { | 307 }, { |
| 306 top: targetTop + 'px', | 308 top: targetTop + 'px', |
| 307 minHeight: card.origHeight_ + 'px', | 309 minHeight: card.origHeight_ + 'px', |
| 308 }]; | 310 }]; |
| 309 var options = /** @type {!KeyframeEffectOptions} */({ | 311 var options = /** @type {!KeyframeEffectOptions} */({ |
| 310 duration: EXPAND_DURATION | 312 duration: EXPAND_DURATION |
| 311 }); | 313 }); |
| 312 return this.animateElement('section', card, keyframes, options); | 314 |
| 315 card.style.width = cardWidthStart + 'px'; |
| 316 var promise = this.animateElement('section', card, keyframes, options); |
| 317 promise.then(function() { |
| 318 card.style.width = ''; |
| 319 }); |
| 320 return promise; |
| 313 }, | 321 }, |
| 314 }; | 322 }; |
| 315 | 323 |
| 316 | 324 |
| 317 /** @polymerBehavior */ | 325 /** @polymerBehavior */ |
| 318 var MainPageBehavior = [ | 326 var MainPageBehavior = [ |
| 319 TransitionBehavior, | 327 TransitionBehavior, |
| 320 MainPageBehaviorImpl | 328 MainPageBehaviorImpl |
| 321 ]; | 329 ]; |
| 322 | 330 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 this.$$('[section=' + section + ']')); | 404 this.$$('[section=' + section + ']')); |
| 397 }, | 405 }, |
| 398 }; | 406 }; |
| 399 | 407 |
| 400 | 408 |
| 401 /** @polymerBehavior */ | 409 /** @polymerBehavior */ |
| 402 var RoutableBehavior = [ | 410 var RoutableBehavior = [ |
| 403 MainPageBehavior, | 411 MainPageBehavior, |
| 404 RoutableBehaviorImpl | 412 RoutableBehaviorImpl |
| 405 ]; | 413 ]; |
| OLD | NEW |