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

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: Use scrollTop 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 d0f4b0265ea93def612096690337cea623eef010..df9e5c5bc218109abad7601915a23446668369a9 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]');
@@ -90,6 +97,26 @@ var CrScrollableBehavior = {
}.bind(this), 10);
},
+ /** @param {!IronListElement} list */
+ saveScroll(list) {
+ 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;
+ 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);
+ });
+ },
+
/**
* Event wrapper for updateScroll_.
* @param {!Event} event

Powered by Google App Engine
This is Rietveld 408576698