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

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: Nits 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..6e5dd3d28e98336c346a21a1f47051c47d298e8d 100644
--- a/ui/webui/resources/cr_elements/cr_scrollable_behavior.js
+++ b/ui/webui/resources/cr_elements/cr_scrollable_behavior.js
@@ -36,10 +36,9 @@
/** @polymerBehavior */
var CrScrollableBehavior = {
- properties: {
- /** @private {number|null} */
- intervalId_: {type: Number, value: null}
- },
+
+ /** @private {number|null} */
+ intervalId_: null,
ready: function() {
var scrollableElements = this.root.querySelectorAll('[scrollable]');
@@ -93,6 +92,26 @@ var CrScrollableBehavior = {
}.bind(this), 10);
},
+ /** @param {!IronListElement} list */
+ saveScroll: function(list) {
+ // Store a FIFO of saved scroll positions so that multiple updates in a
+ // frame are applied correctly. Specifically we need to track when '0' is
+ // saved (but not apply it), and still handle patterns like [30, 0, 32].
+ list.savedScrollTops = list.savedScrollTops || [];
+ list.savedScrollTops.push(list.scrollTarget.scrollTop);
+ },
+
+ /** @param {!IronListElement} list */
+ restoreScroll: function(list) {
+ this.async(function() {
+ var scrollTop = list.savedScrollTops.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