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

Unified Diff: ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js

Issue 2815623005: MD Settings: in cr_dialog, prevent intersectionObserver from firing early. (Closed)
Patch Set: use mutationObserver to not mess with native dialog.open Created 3 years, 8 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_dialog/cr_dialog.js
diff --git a/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js b/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js
index c98c75ac4053eda397cdc7758103f9edb91fd87d..3879b397f77bb1cd4a9543250d52f4ea0c7e4932 100644
--- a/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js
+++ b/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js
@@ -48,6 +48,9 @@ Polymer({
/** @private {?IntersectionObserver} */
intersectionObserver_: null,
+ /** @private {?MutationObserver} */
+ mutationObserver_: null,
+
/** @override */
ready: function() {
// If the active history entry changes (i.e. user clicks back button),
@@ -64,6 +67,34 @@ Polymer({
/** @override */
attached: function() {
if (this.showScrollBorders) {
+ this.mutationObserver_ = new MutationObserver(function() {
+ if (this.open) {
+ this.addIntersectionObserver_();
+ } else {
+ this.removeIntersectionObserver_();
+ }
+ }.bind(this));
+
+ var observerConfig = {
dpapad 2017/04/13 20:31:39 Nit (optional): Since this is only used once below
scottchen 2017/04/13 21:46:04 Done.
+ attributes: true,
+ attributeFilter: ['open'],
+ };
+
+ this.mutationObserver_.observe(this, observerConfig);
+ }
+ },
+
+ /** @override */
+ detached: function() {
+ if (this.mutationObserver_) {
+ this.mutationObserver_.disconnect();
+ this.mutationObserver_ = null;
+ }
dpapad 2017/04/13 20:31:39 Previous code was removing the IntersectionObserve
scottchen 2017/04/13 21:46:04 Yes, will leak. Fixed.
+ },
+
+ /** @private */
+ addIntersectionObserver_: function() {
+ if (!this.intersectionObserver_) {
var bodyContainer = this.$$('.body-container');
var bottomMarker = this.$.bodyBottomMarker;
@@ -89,13 +120,14 @@ Polymer({
root: bodyContainer,
threshold: 0,
}));
+
dpapad 2017/04/13 20:31:39 Nit (optional): Revert this?
scottchen 2017/04/13 21:46:04 Done.
this.intersectionObserver_.observe(bottomMarker);
this.intersectionObserver_.observe(topMarker);
}
},
- /** @override */
- detached: function() {
+ /** @private */
+ removeIntersectionObserver_: function() {
if (this.intersectionObserver_) {
this.intersectionObserver_.disconnect();
this.intersectionObserver_ = null;

Powered by Google App Engine
This is Rietveld 408576698