Chromium Code Reviews| 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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 minHeight: card.origHeight_ + 'px', | 302 minHeight: card.origHeight_ + 'px', |
| 303 }]; | 303 }]; |
| 304 var options = /** @type {!KeyframeEffectOptions} */({ | 304 var options = /** @type {!KeyframeEffectOptions} */({ |
| 305 duration: EXPAND_DURATION | 305 duration: EXPAND_DURATION |
| 306 }); | 306 }); |
| 307 var promise = this.animateElement('section', card, keyframes, options); | 307 var promise = this.animateElement('section', card, keyframes, options); |
| 308 return promise; | 308 return promise; |
| 309 }, | 309 }, |
| 310 }; | 310 }; |
| 311 | 311 |
| 312 | |
| 312 /** @polymerBehavior */ | 313 /** @polymerBehavior */ |
| 313 var MainPageBehavior = [ | 314 var MainPageBehavior = [ |
| 314 TransitionBehavior, | 315 TransitionBehavior, |
| 315 MainPageBehaviorImpl | 316 MainPageBehaviorImpl |
| 316 ]; | 317 ]; |
| 317 | 318 |
| 319 | |
| 318 /** | 320 /** |
| 319 * TODO(michaelpg): integrate slide animations. | 321 * TODO(michaelpg): integrate slide animations. |
| 320 * @polymerBehavior RoutableBehavior | 322 * @polymerBehavior RoutableBehavior |
| 321 */ | 323 */ |
| 322 var RoutableBehaviorImpl = { | 324 var RoutableBehaviorImpl = { |
| 323 properties: { | 325 properties: { |
| 324 /** Contains the current route. */ | 326 /** Contains the current route. */ |
| 325 currentRoute: { | 327 currentRoute: { |
| 326 type: Object, | 328 type: Object, |
| 327 notify: true, | 329 notify: true, |
| 328 observer: 'currentRouteChanged_', | 330 observer: 'currentRouteChanged_', |
| 329 }, | 331 }, |
| 330 }, | 332 }, |
| 331 | 333 |
| 334 /** | |
| 335 * @param {string} section Name of the item to scroll into view. | |
| 336 */ | |
| 337 scrollToSection: function(section) { | |
| 338 if (section) { | |
| 339 // TODO(dschuyler): Determine whether this setTimeout can be removed. | |
|
michaelpg
2016/04/29 20:19:04
I filed Polymer/polymer#3629 so you can link to th
dschuyler
2016/04/29 21:27:45
Done.
| |
| 340 setTimeout(function() { | |
| 341 var element = this.getSection_(section); | |
| 342 if (element) | |
|
michaelpg
2016/04/29 20:19:04
Looks like this should be an assert.
dschuyler
2016/04/29 21:27:45
Done. I removed the 'if' and made this one line.
| |
| 343 element.scrollIntoView(); | |
| 344 }.bind(this)); | |
| 345 } | |
| 346 }, | |
| 347 | |
| 332 /** @private */ | 348 /** @private */ |
| 333 currentRouteChanged_: function(newRoute, oldRoute) { | 349 currentRouteChanged_: function(newRoute, oldRoute) { |
| 334 // route.section is only non-empty when the user is within a subpage. | 350 var newRouteIsSubpage = newRoute && newRoute.subpage.length; |
| 335 // When the user is not in a subpage, but on the Basic page, route.section | 351 var oldRouteIsSubpage = oldRoute && oldRoute.subpage.length; |
| 336 // is an empty string. | |
| 337 var newRouteIsSubpage = newRoute && newRoute.section; | |
| 338 var oldRouteIsSubpage = oldRoute && oldRoute.section; | |
| 339 | 352 |
| 340 if (!oldRoute && newRouteIsSubpage) { | 353 if (!oldRoute && newRouteIsSubpage) { |
| 341 // Allow the page to load before expanding the section. TODO(michaelpg): | 354 // Allow the page to load before expanding the section. TODO(michaelpg): |
| 342 // Time this better when refactoring settings-animated-pages. | 355 // Time this better when refactoring settings-animated-pages. |
| 343 setTimeout(function() { | 356 setTimeout(function() { |
| 344 var section = this.getSection_(newRoute.section); | 357 var section = this.getSection_(newRoute.section); |
| 345 if (section) | 358 if (section) |
| 346 this.expandSection(section); | 359 this.expandSection(section); |
| 347 }.bind(this)); | 360 }.bind(this)); |
| 348 return; | 361 return; |
| 349 } | 362 } |
| 350 | 363 |
| 351 if (!newRouteIsSubpage && oldRouteIsSubpage) { | 364 if (!newRouteIsSubpage && oldRouteIsSubpage) { |
| 352 var section = this.getSection_(oldRoute.section); | 365 var section = this.getSection_(oldRoute.section); |
| 353 if (section) | 366 if (section) |
| 354 this.collapseSection(section); | 367 this.collapseSection(section); |
| 355 } else if (newRouteIsSubpage && | 368 } else if (newRouteIsSubpage && |
| 356 (!oldRouteIsSubpage || newRoute.section != oldRoute.section)) { | 369 (!oldRouteIsSubpage || newRoute.section != oldRoute.section)) { |
| 357 var section = this.getSection_(newRoute.section); | 370 var section = this.getSection_(newRoute.section); |
| 358 if (section) | 371 if (section) |
| 359 this.expandSection(section); | 372 this.expandSection(section); |
| 373 } else if (newRoute && newRoute.section) { | |
| 374 this.scrollToSection(newRoute.section); | |
| 360 } | 375 } |
| 361 }, | 376 }, |
| 362 | 377 |
| 363 /** | 378 /** |
| 364 * Helper function to get a section from the local DOM. | 379 * Helper function to get a section from the local DOM. |
| 365 * @param {string} section Section name of the element to get. | 380 * @param {string} section Section name of the element to get. |
| 366 * @return {?SettingsSectionElement} | 381 * @return {?SettingsSectionElement} |
| 367 * @private | 382 * @private |
| 368 */ | 383 */ |
| 369 getSection_: function(section) { | 384 getSection_: function(section) { |
| 370 return /** @type {?SettingsSectionElement} */( | 385 return /** @type {?SettingsSectionElement} */( |
| 371 this.$$('[section=' + section + ']')); | 386 this.$$('[section=' + section + ']')); |
| 372 }, | 387 }, |
| 373 }; | 388 }; |
| 374 | 389 |
| 390 | |
| 375 /** @polymerBehavior */ | 391 /** @polymerBehavior */ |
| 376 var RoutableBehavior = [ | 392 var RoutableBehavior = [ |
| 377 MainPageBehavior, | 393 MainPageBehavior, |
| 378 RoutableBehaviorImpl | 394 RoutableBehaviorImpl |
| 379 ]; | 395 ]; |
| OLD | NEW |