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 /** | |
| 34 * True if the dialog should ignore 'Enter' keypresses. | |
| 35 */ | |
| 36 ignoreEnterKey: { | |
| 37 type: Boolean, | |
| 38 value: false, | |
| 39 }, | |
| 32 }, | 40 }, |
| 33 | 41 |
| 34 /** @override */ | 42 /** @override */ |
| 35 ready: function() { | 43 ready: function() { |
| 36 // If the active history entry changes (i.e. user clicks back button), | 44 // If the active history entry changes (i.e. user clicks back button), |
| 37 // all open dialogs should be cancelled. | 45 // all open dialogs should be cancelled. |
| 38 window.addEventListener('popstate', function() { | 46 window.addEventListener('popstate', function() { |
| 39 if (!this.ignorePopstate && this.open) | 47 if (!this.ignorePopstate && this.open) |
| 40 this.cancel(); | 48 this.cancel(); |
| 41 }.bind(this)); | 49 }.bind(this)); |
| 50 | |
| 51 if (!this.ignoreEnterKey) | |
| 52 this.addEventListener('keypress', this.onKeypress_.bind(this)); | |
| 42 }, | 53 }, |
| 43 | 54 |
| 44 cancel: function() { | 55 cancel: function() { |
| 45 this.fire('cancel'); | 56 this.fire('cancel'); |
| 46 HTMLDialogElement.prototype.close.call(this, ''); | 57 HTMLDialogElement.prototype.close.call(this, ''); |
| 47 }, | 58 }, |
| 48 | 59 |
| 49 /** | 60 /** |
| 50 * @param {string=} opt_returnValue | 61 * @param {string=} opt_returnValue |
| 51 * @override | 62 * @override |
| 52 */ | 63 */ |
| 53 close: function(opt_returnValue) { | 64 close: function(opt_returnValue) { |
| 54 HTMLDialogElement.prototype.close.call(this, 'success'); | 65 HTMLDialogElement.prototype.close.call(this, 'success'); |
| 55 }, | 66 }, |
| 56 | 67 |
| 57 /** @return {!PaperIconButtonElement} */ | 68 /** @return {!PaperIconButtonElement} */ |
| 58 getCloseButton: function() { | 69 getCloseButton: function() { |
| 59 return this.$.close; | 70 return this.$.close; |
| 60 }, | 71 }, |
| 72 | |
| 73 /** | |
| 74 * @param {!KeyboardEvent} e | |
| 75 * @private | |
| 76 */ | |
| 77 onKeypress_: function(e) { | |
| 78 if (e.target != this) | |
|
tommycli
2017/03/31 00:16:55
This is more conservative than the Options equival
| |
| 79 return; | |
| 80 if (e.key != 'Enter') | |
| 81 return; | |
| 82 | |
| 83 var actionButton = this.querySelector('.action-button'); | |
|
dpapad
2017/03/31 02:08:29
Should we add an assertion() for this, instead of
tommycli
2017/04/03 16:53:34
Hey demetrios, here's an example where there's no
| |
| 84 if (actionButton && !actionButton.disabled) { | |
|
dpapad
2017/03/31 02:08:29
Do we need to check for |disabled| at all? I belie
tommycli
2017/04/03 16:53:34
Hi, disabled buttons can still be 'click()' ed. Se
dpapad
2017/04/03 18:20:07
Ok. I recall having problems "clicking" disabled b
| |
| 85 actionButton.click(); | |
| 86 e.preventDefault(); | |
| 87 } | |
| 88 }, | |
| 61 }); | 89 }); |
| OLD | NEW |