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

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 + feedback + clang format 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 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

Powered by Google App Engine
This is Rietveld 408576698