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

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

Issue 2522783003: MD Settings: Fix CrScrollableBehavior (Closed)
Patch Set: Created 4 years 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 for (let scrollable of scrollableElements) 49 for (let scrollable of scrollableElements)
50 this.updateScroll_(scrollable); 50 this.updateScroll_(scrollable);
51 }.bind(this)); 51 }.bind(this));
52 52
53 // Listen to the 'scroll' event for each scrollable container. 53 // Listen to the 'scroll' event for each scrollable container.
54 for (let scrollable of scrollableElements) 54 for (let scrollable of scrollableElements)
55 scrollable.addEventListener('scroll', this.updateScrollEvent_.bind(this)); 55 scrollable.addEventListener('scroll', this.updateScrollEvent_.bind(this));
56 }, 56 },
57 57
58 detached: function() { 58 detached: function() {
59 if (this.intervalId_) 59 if (this.intervalId_ !== undefined)
60 clearInterval(this.intervalId_); 60 clearInterval(this.intervalId_);
61 }, 61 },
62 62
63 /** 63 /**
64 * Called any time the contents of a scrollable container may have changed. 64 * Called any time the contents of a scrollable container may have changed.
65 * This ensures that the <iron-list> contents of dynamically sized 65 * This ensures that the <iron-list> contents of dynamically sized
66 * containers are resized correctly. 66 * containers are resized correctly.
67 */ 67 */
68 updateScrollableContents() { 68 updateScrollableContents() {
69 let nodeList = this.root.querySelectorAll('[scrollable] iron-list'); 69 let nodeList = this.root.querySelectorAll('[scrollable] iron-list');
70 // Use setTimeout to avoid initial render / sizing issues. 70 // Use setTimeout to avoid initial render / sizing issues.
71 this.intervalId_ = setInterval(function() { 71 if (this.intervalId_ === undefined)
dpapad 2016/11/23 01:12:51 Shouldn't this be the opposite? if (this.interval
stevenjb 2016/11/23 18:07:01 Er, ugh, yes. I must already be in vacation mode.
72 return;
73 this.intervalId_ = window.setInterval(function() {
72 let unreadyNodes = []; 74 let unreadyNodes = [];
73 for (let node of nodeList) { 75 for (let node of nodeList) {
74 if (node.parentNode.scrollHeight == 0) { 76 if (node.parentNode.scrollHeight == 0) {
75 unreadyNodes.push(node); 77 unreadyNodes.push(node);
76 continue; 78 continue;
77 } 79 }
78 let ironList = /** @type {!IronListElement} */ (node); 80 let ironList = /** @type {!IronListElement} */ (node);
79 ironList.notifyResize(); 81 ironList.notifyResize();
80 } 82 }
81 if (unreadyNodes.length == 0) 83 if (unreadyNodes.length == 0) {
82 clearInterval(this.intervalId_); 84 window.clearInterval(this.intervalId_);
83 else 85 this.intervalId_ = undefined;
dpapad 2016/11/23 01:12:51 Setting something to |undefined| is counter intuit
stevenjb 2016/11/23 18:07:01 It seems odd to me to set a Number to null, but I
86 } else {
84 nodeList = unreadyNodes; 87 nodeList = unreadyNodes;
88 }
85 }.bind(this), 10); 89 }.bind(this), 10);
86 }, 90 },
87 91
88 /** 92 /**
89 * Event wrapper for updateScroll_. 93 * Event wrapper for updateScroll_.
90 * @param {!Event} event 94 * @param {!Event} event
91 * @private 95 * @private
92 */ 96 */
93 updateScrollEvent_(event) { 97 updateScrollEvent_(event) {
94 let scrollable = /** @type {!HTMLElement} */ (event.target); 98 let scrollable = /** @type {!HTMLElement} */ (event.target);
95 this.updateScroll_(scrollable); 99 this.updateScroll_(scrollable);
96 }, 100 },
97 101
98 /** 102 /**
99 * This gets called once intially and any time a scrollable container scrolls. 103 * This gets called once intially and any time a scrollable container scrolls.
100 * @param {!HTMLElement} scrollable 104 * @param {!HTMLElement} scrollable
101 * @private 105 * @private
102 */ 106 */
103 updateScroll_(scrollable) { 107 updateScroll_(scrollable) {
104 scrollable.classList.toggle( 108 scrollable.classList.toggle(
105 'can-scroll', scrollable.clientHeight < scrollable.scrollHeight); 109 'can-scroll', scrollable.clientHeight < scrollable.scrollHeight);
106 scrollable.classList.toggle('is-scrolled', scrollable.scrollTop > 0); 110 scrollable.classList.toggle('is-scrolled', scrollable.scrollTop > 0);
107 scrollable.classList.toggle( 111 scrollable.classList.toggle(
108 'scrolled-to-bottom', scrollable.scrollTop + scrollable.clientHeight >= 112 'scrolled-to-bottom', scrollable.scrollTop + scrollable.clientHeight >=
109 scrollable.scrollHeight); 113 scrollable.scrollHeight);
110 }, 114 },
111 }; 115 };
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