Chromium Code Reviews| Index: ui/webui/resources/cr_elements/cr_scrollable_behavior.js |
| diff --git a/ui/webui/resources/cr_elements/cr_scrollable_behavior.js b/ui/webui/resources/cr_elements/cr_scrollable_behavior.js |
| index 1858ccffd07cde6c343ae84479f8a9c344b99457..ba34a8fd78dcc5cc8240b161820667e4c08f8577 100644 |
| --- a/ui/webui/resources/cr_elements/cr_scrollable_behavior.js |
| +++ b/ui/webui/resources/cr_elements/cr_scrollable_behavior.js |
| @@ -36,10 +36,17 @@ |
| /** @polymerBehavior */ |
| var CrScrollableBehavior = { |
| - properties: { |
| - /** @private {number|null} */ |
| - intervalId_: {type: Number, value: null} |
| - }, |
| + |
| + /** @private {number|null} */ |
| + intervalId_: null, |
| + |
| + /** |
| + * A dictionary of integer arrays, one entry per scrollable contianer id. |
| + * Each array keeps a queue of scroll positions. This ensures that multiple |
| + * calls to save/restore scroll do not interfere with each other. |
| + * @private {!Object<!Array<number>>} |
| + */ |
| + saveScrollTop_: {}, |
| ready: function() { |
| var scrollableElements = this.root.querySelectorAll('[scrollable]'); |
| @@ -93,6 +100,25 @@ var CrScrollableBehavior = { |
| }.bind(this), 10); |
| }, |
| + /** @param {!IronListElement} list */ |
| + saveScroll: function(list) { |
| + let target = list.scrollTarget; |
|
Dan Beam
2017/02/01 06:13:17
no let until we vulcanize
stevenjb
2017/02/02 01:17:47
Oops, missed that. Will vulcanize be part of the b
Dan Beam
2017/02/02 04:18:00
yes
|
| + this.saveScrollTop_[target.id] = this.saveScrollTop_[target.id] || []; |
|
Dan Beam
2017/02/01 06:13:17
just save on the list itself, i.e.
list.prevScrol
stevenjb
2017/02/02 01:17:47
The C++ programmer in me cringes at decorating ano
|
| + this.saveScrollTop_[target.id].push(target.scrollTop); |
| + }, |
| + |
| + /** @param {!IronListElement} list */ |
| + restoreScroll: function(list) { |
| + let target = list.scrollTarget; |
| + this.async(function() { |
| + let scrollTop = this.saveScrollTop_[target.id].shift(); |
| + // Ignore scrollTop of 0 in case it was intermittent (we do not need to |
| + // explicity scroll to 0). |
| + if (scrollTop != 0) |
| + list.scroll(0, scrollTop); |
| + }); |
| + }, |
| + |
| /** |
| * Event wrapper for updateScroll_. |
| * @param {!Event} event |