OLD | NEW |
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 'cr-dialog' is a component for showing a modal dialog. If the | 6 * @fileoverview 'cr-dialog' is a component for showing a modal dialog. If the |
7 * dialog is closed via close(), a 'close' event is fired. If the dialog is | 7 * dialog is closed via close(), a 'close' event is fired. If the dialog is |
8 * canceled via cancel(), a 'cancel' event is fired followed by a 'close' event. | 8 * canceled via cancel(), a 'cancel' event is fired followed by a 'close' event. |
9 * Additionally clients can inspect the dialog's |returnValue| property inside | 9 * Additionally clients can inspect the dialog's |returnValue| property inside |
10 * the 'close' event listener to determine whether it was canceled or just | 10 * the 'close' event listener to determine whether it was canceled or just |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 if (!this.ignoreEnterKey) | 60 if (!this.ignoreEnterKey) |
61 this.addEventListener('keypress', this.onKeypress_.bind(this)); | 61 this.addEventListener('keypress', this.onKeypress_.bind(this)); |
62 }, | 62 }, |
63 | 63 |
64 /** @override */ | 64 /** @override */ |
65 attached: function() { | 65 attached: function() { |
66 if (this.showScrollBorders) { | 66 if (this.showScrollBorders) { |
67 var bodyContainer = this.$$('.body-container'); | 67 var bodyContainer = this.$$('.body-container'); |
68 | 68 |
| 69 var bottomMarker = this.$.bodyBottomMarker; |
| 70 var topMarker = this.$.bodyTopMarker; |
| 71 |
69 var callback = function(entries) { | 72 var callback = function(entries) { |
70 assert(entries.length == 1); | 73 for (var i = 0; i < entries.length; i++) { |
71 bodyContainer.classList.toggle( | 74 var target = entries[i].target; |
72 'bottom-scrollable', entries[0].intersectionRatio == 0); | 75 assert(target == bottomMarker || target == topMarker); |
| 76 |
| 77 classToToggle = |
| 78 target == bottomMarker ? 'bottom-scrollable' : 'top-scrollable'; |
| 79 |
| 80 bodyContainer.classList.toggle( |
| 81 classToToggle, entries[i].intersectionRatio == 0); |
| 82 } |
73 }; | 83 }; |
74 | 84 |
75 this.intersectionObserver_ = new IntersectionObserver( | 85 this.intersectionObserver_ = new IntersectionObserver( |
76 callback, | 86 callback, |
77 /** @type {IntersectionObserverInit} */ ({ | 87 /** @type {IntersectionObserverInit} */ ({ |
78 root: bodyContainer, | 88 root: bodyContainer, |
79 threshold: 0, | 89 threshold: 0, |
80 })); | 90 })); |
81 this.intersectionObserver_.observe(this.$.bodyBottomMarker); | 91 this.intersectionObserver_.observe(bottomMarker); |
| 92 this.intersectionObserver_.observe(topMarker); |
82 } | 93 } |
83 }, | 94 }, |
84 | 95 |
85 /** @override */ | 96 /** @override */ |
86 detached: function() { | 97 detached: function() { |
87 if (this.intersectionObserver_) { | 98 if (this.intersectionObserver_) { |
88 this.intersectionObserver_.disconnect(); | 99 this.intersectionObserver_.disconnect(); |
89 this.intersectionObserver_ = null; | 100 this.intersectionObserver_ = null; |
90 } | 101 } |
91 }, | 102 }, |
(...skipping 27 matching lines...) Expand all Loading... |
119 return; | 130 return; |
120 | 131 |
121 var actionButton = | 132 var actionButton = |
122 this.querySelector('.action-button:not([disabled]):not([hidden])'); | 133 this.querySelector('.action-button:not([disabled]):not([hidden])'); |
123 if (actionButton) { | 134 if (actionButton) { |
124 actionButton.click(); | 135 actionButton.click(); |
125 e.preventDefault(); | 136 e.preventDefault(); |
126 } | 137 } |
127 }, | 138 }, |
128 }); | 139 }); |
OLD | NEW |