Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Unified Diff: ui/webui/resources/cr_elements/cr_scrollable_behavior.js

Issue 2627373002: MD Settings: Save and restore scroll position in iron-list (Closed)
Patch Set: Rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 5589c18ed448bc8ab46ad12fd051340f5f9d6e78..f304876854c1ecf27bf7502c07c9da63c7dd26a9 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,26 @@ var CrScrollableBehavior = {
}.bind(this), 10);
},
+ /** @param {!IronListElement} list */
+ saveScroll(list) {
Dan Beam 2017/01/31 04:06:44 drop ES6 stuff
stevenjb 2017/01/31 18:43:09 Done.
+ let target = list.scrollTarget;
+ // Ignore scrollTop of 0 in case it is intermittent (we do not need to
+ // explicity scroll to 0).
+ let scroll = target.scrollTop || -1;
Dan Beam 2017/01/31 04:06:44 why wouldn't we just do list.prevScrollTop_ = lis
stevenjb 2017/01/31 18:43:09 Code evolution. Done.
+ this.saveScrollTop_[target.id] = this.saveScrollTop_[target.id] || [];
+ this.saveScrollTop_[target.id].push(scroll);
+ },
+
+ /** @param {!IronListElement} list */
+ restoreScroll(list) {
+ let target = list.scrollTarget;
+ this.async(function() {
+ let scroll = this.saveScrollTop_[target.id].shift();
+ if (scroll != -1)
+ list.scroll(0, scroll);
Dan Beam 2017/01/31 04:06:44 if (list.prevScrollTop_) list.scroll(0, list.pre
stevenjb 2017/01/31 18:43:09 Done.
+ });
+ },
+
/**
* Event wrapper for updateScroll_.
* @param {!Event} event

Powered by Google App Engine
This is Rietveld 408576698