| Conditions | 7 |
| Total Lines | 36 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | // @ts-check |
||
| 6 | connectedCallback() { |
||
| 7 | const dialogId = this.getAttribute('dialog'); |
||
| 8 | |||
| 9 | if (!dialogId) { |
||
| 10 | throw new Error('"dialog" attribute is required'); |
||
| 11 | } |
||
| 12 | |||
| 13 | const dialog = /** @type {HTMLDialogElement|null} */ (document.getElementById( |
||
| 14 | dialogId |
||
| 15 | )); |
||
| 16 | |||
| 17 | if (!dialog) { |
||
| 18 | throw new Error(`element "${dialogId}" does not exist`); |
||
| 19 | } |
||
| 20 | |||
| 21 | const button = this.querySelector('button'); |
||
| 22 | |||
| 23 | if (!button) { |
||
| 24 | return; |
||
| 25 | } |
||
| 26 | |||
| 27 | const submitValue = this.getAttribute('submitValue') || 'submit'; |
||
| 28 | |||
| 29 | button.addEventListener('click', event => { |
||
| 30 | event.preventDefault(); |
||
| 31 | dialog.showModal(); |
||
| 32 | }); |
||
| 33 | |||
| 34 | dialog.addEventListener('close', () => { |
||
| 35 | if (dialog.returnValue === submitValue) { |
||
| 36 | this.dispatchEvent( |
||
| 37 | new CustomEvent('dialog-trigger:submit', { bubbles: true }) |
||
| 38 | ); |
||
| 39 | } |
||
| 40 | }); |
||
| 41 | } |
||
| 42 | } |
||
| 44 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.