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 11 matching lines...) Expand all Loading... |
22 closeText: String, | 22 closeText: String, |
23 | 23 |
24 /** | 24 /** |
25 * True if the dialog should remain open on 'popstate' events. This is used | 25 * True if the dialog should remain open on 'popstate' events. This is used |
26 * for navigable dialogs that have their separate navigation handling code. | 26 * for navigable dialogs that have their separate navigation handling code. |
27 */ | 27 */ |
28 ignorePopstate: { | 28 ignorePopstate: { |
29 type: Boolean, | 29 type: Boolean, |
30 value: false, | 30 value: false, |
31 }, | 31 }, |
| 32 |
| 33 showScrollBorders: Boolean |
32 }, | 34 }, |
33 | 35 |
| 36 /** @private {?IntersectionObserver} */ |
| 37 intersectionObserver_: null, |
| 38 |
34 /** @override */ | 39 /** @override */ |
35 ready: function() { | 40 ready: function() { |
36 // If the active history entry changes (i.e. user clicks back button), | 41 // If the active history entry changes (i.e. user clicks back button), |
37 // all open dialogs should be cancelled. | 42 // all open dialogs should be cancelled. |
38 window.addEventListener('popstate', function() { | 43 window.addEventListener('popstate', function() { |
39 if (!this.ignorePopstate && this.open) | 44 if (!this.ignorePopstate && this.open) |
40 this.cancel(); | 45 this.cancel(); |
41 }.bind(this)); | 46 }.bind(this)); |
42 }, | 47 }, |
43 | 48 |
| 49 /** @override */ |
| 50 attached: function() { |
| 51 if (this.showScrollBorders) { |
| 52 var bodyContainer = this.$$('.body-container'); |
| 53 |
| 54 var callback = function(entries) { |
| 55 assert(entries.length == 1); |
| 56 entries[0].intersectionRatio == 0 ? |
| 57 bodyContainer.classList.add('bottom-scrollable') : |
| 58 bodyContainer.classList.remove('bottom-scrollable'); |
| 59 }; |
| 60 |
| 61 this.intersectionObserver_ = new IntersectionObserver(callback, { |
| 62 root: bodyContainer, |
| 63 threshold: 0, |
| 64 }); |
| 65 this.intersectionObserver_.observe(this.$.bodyBottomMarker); |
| 66 } |
| 67 }, |
| 68 |
| 69 /** @override */ |
| 70 detached: function() { |
| 71 if (this.intersectionObserver_) { |
| 72 this.intersectionObserver_.disconnect(); |
| 73 this.intersectionObserver_ = null; |
| 74 } |
| 75 }, |
| 76 |
44 cancel: function() { | 77 cancel: function() { |
45 this.fire('cancel'); | 78 this.fire('cancel'); |
46 HTMLDialogElement.prototype.close.call(this, ''); | 79 HTMLDialogElement.prototype.close.call(this, ''); |
47 }, | 80 }, |
48 | 81 |
49 /** | 82 /** |
50 * @param {string=} opt_returnValue | 83 * @param {string=} opt_returnValue |
51 * @override | 84 * @override |
52 */ | 85 */ |
53 close: function(opt_returnValue) { | 86 close: function(opt_returnValue) { |
54 HTMLDialogElement.prototype.close.call(this, 'success'); | 87 HTMLDialogElement.prototype.close.call(this, 'success'); |
55 }, | 88 }, |
56 | 89 |
57 /** @return {!PaperIconButtonElement} */ | 90 /** @return {!PaperIconButtonElement} */ |
58 getCloseButton: function() { | 91 getCloseButton: function() { |
59 return this.$.close; | 92 return this.$.close; |
60 }, | 93 }, |
61 }); | 94 }); |
OLD | NEW |