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

Side by Side Diff: ui/webui/resources/cr_elements/cr_scrollable_behavior.js

Issue 2441173002: MD Settings: Ensure iron-lists are populated and sized correctly.
Patch Set: Undo Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Behavior for scrollable containers with <iron-list>. 6 * @fileoverview Behavior for scrollable containers with <iron-list>.
7 * 7 *
8 * Any containers with the 'scrollable' attribute set will have the following 8 * Any containers with the 'scrollable' attribute set will have the following
9 * classes toggled appropriately: can-scroll, is-scrolled, scrolled-to-bottom. 9 * classes toggled appropriately: can-scroll, is-scrolled, scrolled-to-bottom.
10 * These classes are used to style the container div and list elements 10 * These classes are used to style the container div and list elements
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 'scroll', this.updateScrollEvent_.bind(this)); 58 'scroll', this.updateScrollEvent_.bind(this));
59 } 59 }
60 }, 60 },
61 61
62 /** 62 /**
63 * Called any time the contents of a scrollable container may have changed. 63 * Called any time the contents of a scrollable container may have changed.
64 * This ensures that the <iron-list> contents of dynamically sized 64 * This ensures that the <iron-list> contents of dynamically sized
65 * containers are resized correctly. 65 * containers are resized correctly.
66 */ 66 */
67 updateScrollableContents() { 67 updateScrollableContents() {
68 let nodeList = this.root.querySelectorAll('[scrollable] iron-list'); 68 this.async(function() {
69 // Use setTimeout to avoid initial render / sizing issues. 69 let lists = this.root.querySelectorAll('[scrollable] iron-list');
70 let intervalId = setInterval(function() { 70 for (list of lists)
71 let unreadyNodes = []; 71 list.fire('iron-resize');
72 for (let node of nodeList) { 72 }.bind(this));
stevenjb 2016/10/24 21:35:35 Assuming this works, then sweet, lgtm! See comment
dpapad 2016/10/24 22:24:34 Yes, the bind() call works as expected.
73 if (node.parentNode.scrollHeight == 0) {
74 unreadyNodes.push(node);
75 continue;
76 }
77 let ironList = /** @type {!IronListElement} */ (node);
78 ironList.notifyResize();
79 }
80 if (unreadyNodes.length == 0)
81 clearInterval(intervalId);
82 else
83 nodeList = unreadyNodes;
84 }, 10);
85 }, 73 },
86 74
87 /** 75 /**
88 * Event wrapper for updateScroll_. 76 * Event wrapper for updateScroll_.
89 * @param {!Event} event 77 * @param {!Event} event
90 * @private 78 * @private
91 */ 79 */
92 updateScrollEvent_(event) { 80 updateScrollEvent_(event) {
93 let scrollable = /** @type {!HTMLElement} */ (event.target); 81 let scrollable = /** @type {!HTMLElement} */ (event.target);
94 this.updateScroll_(scrollable); 82 this.updateScroll_(scrollable);
95 }, 83 },
96 84
97 /** 85 /**
98 * This gets called once intially and any time a scrollable container scrolls. 86 * This gets called once intially and any time a scrollable container scrolls.
99 * @param {!HTMLElement} scrollable 87 * @param {!HTMLElement} scrollable
100 * @private 88 * @private
101 */ 89 */
102 updateScroll_(scrollable) { 90 updateScroll_(scrollable) {
103 scrollable.classList.toggle( 91 scrollable.classList.toggle(
104 'can-scroll', scrollable.clientHeight < scrollable.scrollHeight); 92 'can-scroll', scrollable.clientHeight < scrollable.scrollHeight);
105 scrollable.classList.toggle('is-scrolled', scrollable.scrollTop > 0); 93 scrollable.classList.toggle('is-scrolled', scrollable.scrollTop > 0);
106 scrollable.classList.toggle( 94 scrollable.classList.toggle(
107 'scrolled-to-bottom', scrollable.scrollTop + scrollable.clientHeight >= 95 'scrolled-to-bottom', scrollable.scrollTop + scrollable.clientHeight >=
108 scrollable.scrollHeight); 96 scrollable.scrollHeight);
109 }, 97 },
110 }; 98 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698