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: { |
| 34 type: Boolean, |
| 35 value: false, |
| 36 reflectToAttribute: true, |
| 37 }, |
32 }, | 38 }, |
33 | 39 |
| 40 /** @private {?IntersectionObserver} */ |
| 41 intersectionObserver_: null, |
| 42 |
34 /** @override */ | 43 /** @override */ |
35 ready: function() { | 44 ready: function() { |
36 // If the active history entry changes (i.e. user clicks back button), | 45 // If the active history entry changes (i.e. user clicks back button), |
37 // all open dialogs should be cancelled. | 46 // all open dialogs should be cancelled. |
38 window.addEventListener('popstate', function() { | 47 window.addEventListener('popstate', function() { |
39 if (!this.ignorePopstate && this.open) | 48 if (!this.ignorePopstate && this.open) |
40 this.cancel(); | 49 this.cancel(); |
41 }.bind(this)); | 50 }.bind(this)); |
42 }, | 51 }, |
43 | 52 |
| 53 /** @override */ |
| 54 attached: function() { |
| 55 if (this.showScrollBorders) { |
| 56 var bodyContainer = this.$$('.body-container'); |
| 57 |
| 58 var callback = function(entries) { |
| 59 assert(entries.length == 1); |
| 60 bodyContainer.classList.toggle( |
| 61 'bottom-scrollable', entries[0].intersectionRatio == 0); |
| 62 }; |
| 63 |
| 64 this.intersectionObserver_ = new IntersectionObserver( |
| 65 callback, |
| 66 /** @type {IntersectionObserverInit} */ ({ |
| 67 root: bodyContainer, |
| 68 threshold: 0, |
| 69 })); |
| 70 this.intersectionObserver_.observe(this.$.bodyBottomMarker); |
| 71 } |
| 72 }, |
| 73 |
| 74 /** @override */ |
| 75 detached: function() { |
| 76 if (this.intersectionObserver_) { |
| 77 this.intersectionObserver_.disconnect(); |
| 78 this.intersectionObserver_ = null; |
| 79 } |
| 80 }, |
| 81 |
44 cancel: function() { | 82 cancel: function() { |
45 this.fire('cancel'); | 83 this.fire('cancel'); |
46 HTMLDialogElement.prototype.close.call(this, ''); | 84 HTMLDialogElement.prototype.close.call(this, ''); |
47 }, | 85 }, |
48 | 86 |
49 /** | 87 /** |
50 * @param {string=} opt_returnValue | 88 * @param {string=} opt_returnValue |
51 * @override | 89 * @override |
52 */ | 90 */ |
53 close: function(opt_returnValue) { | 91 close: function(opt_returnValue) { |
54 HTMLDialogElement.prototype.close.call(this, 'success'); | 92 HTMLDialogElement.prototype.close.call(this, 'success'); |
55 }, | 93 }, |
56 | 94 |
57 /** @return {!PaperIconButtonElement} */ | 95 /** @return {!PaperIconButtonElement} */ |
58 getCloseButton: function() { | 96 getCloseButton: function() { |
59 return this.$.close; | 97 return this.$.close; |
60 }, | 98 }, |
61 }); | 99 }); |
OLD | NEW |