Chromium Code Reviews| 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 entries[0].intersectionRatio == 0 ? | |
|
dpapad
2017/03/30 18:25:00
Can you simplify this, similar to https://coderevi
scottchen
2017/03/30 19:24:34
Done.
| |
| 61 bodyContainer.classList.add('bottom-scrollable') : | |
| 62 bodyContainer.classList.remove('bottom-scrollable'); | |
| 63 }; | |
| 64 | |
| 65 this.intersectionObserver_ = new IntersectionObserver(callback, { | |
| 66 root: bodyContainer, | |
| 67 threshold: 0, | |
| 68 }); | |
| 69 this.intersectionObserver_.observe(this.$.bodyBottomMarker); | |
| 70 } | |
| 71 }, | |
| 72 | |
| 73 /** @override */ | |
| 74 detached: function() { | |
| 75 if (this.intersectionObserver_) { | |
| 76 this.intersectionObserver_.disconnect(); | |
| 77 this.intersectionObserver_ = null; | |
| 78 } | |
| 79 }, | |
| 80 | |
| 44 cancel: function() { | 81 cancel: function() { |
| 45 this.fire('cancel'); | 82 this.fire('cancel'); |
| 46 HTMLDialogElement.prototype.close.call(this, ''); | 83 HTMLDialogElement.prototype.close.call(this, ''); |
| 47 }, | 84 }, |
| 48 | 85 |
| 49 /** | 86 /** |
| 50 * @param {string=} opt_returnValue | 87 * @param {string=} opt_returnValue |
| 51 * @override | 88 * @override |
| 52 */ | 89 */ |
| 53 close: function(opt_returnValue) { | 90 close: function(opt_returnValue) { |
| 54 HTMLDialogElement.prototype.close.call(this, 'success'); | 91 HTMLDialogElement.prototype.close.call(this, 'success'); |
| 55 }, | 92 }, |
| 56 | 93 |
| 57 /** @return {!PaperIconButtonElement} */ | 94 /** @return {!PaperIconButtonElement} */ |
| 58 getCloseButton: function() { | 95 getCloseButton: function() { |
| 59 return this.$.close; | 96 return this.$.close; |
| 60 }, | 97 }, |
| 61 }); | 98 }); |
| OLD | NEW |