Chromium Code Reviews| Index: chrome/browser/resources/settings/settings_page/main_page_behavior.js |
| diff --git a/chrome/browser/resources/settings/settings_page/main_page_behavior.js b/chrome/browser/resources/settings/settings_page/main_page_behavior.js |
| index 207870de836c56230eebf82cf9ac933d9fabe641..defa310b3dfcda50d1f1cad97fe39f08e25db0c2 100644 |
| --- a/chrome/browser/resources/settings/settings_page/main_page_behavior.js |
| +++ b/chrome/browser/resources/settings/settings_page/main_page_behavior.js |
| @@ -8,21 +8,18 @@ var EXPAND_DURATION = 350; |
| /** |
| * Workaround for scrolling an element into view when using Polymer. |
|
michaelpg
2016/06/28 13:58:08
fix comment
Dan Beam
2016/06/28 19:16:40
Done.
|
| - * @param {function():Element} containerCallback Return parent of element. |
| - * @param {function():Element} elementCallback Return element to scroll to. |
| + * @param {function():boolean} readyTest |
| + * @param {!Function} readyCallback |
| */ |
| -function scrollWhenReady(containerCallback, elementCallback) { |
| - // TODO(dschuyler): Determine whether this setTimeout can be removed. |
| +function doWhenReady(readyTest, readyCallback) { |
|
michaelpg
2016/06/28 13:58:08
doWhenTrue?
Dan Beam
2016/06/28 19:16:40
I don't think it's really unclear
Dan Beam
2016/06/28 19:18:28
and if you change it to "doWhenTrue", it might be
|
| + // TODO(dschuyler): Determine whether this hack can be removed. |
| // See also: https://github.com/Polymer/polymer/issues/3629 |
| - setTimeout(function pollForScrollHeight() { |
| - var container = containerCallback(); |
| - if (!container || container.scrollHeight == 0) { |
| - setTimeout(pollForScrollHeight.bind(this), 10); |
| - return; |
| + var intervalId = setInterval(function() { |
| + if (readyTest()) { |
| + clearInterval(intervalId); |
| + readyCallback(); |
| } |
| - |
| - elementCallback().scrollIntoView(); |
| - }.bind(this)); |
| + }, 10); |
| } |
| /** |
| @@ -369,14 +366,14 @@ var RoutableBehaviorImpl = { |
| /** @private */ |
| scrollToSection_: function() { |
| - scrollWhenReady( |
| + doWhenReady( |
| function() { |
| - return this; |
| + return this.scrollHeight > 0; |
| }.bind(this), |
| function() { |
| // If the current section changes while we are waiting for the page to |
| // be ready, scroll to the newest requested section. |
| - return this.getSection_(this.currentRoute.section); |
| + this.getSection_(this.currentRoute.section).scrollIntoView(); |
| }.bind(this)); |
| }, |