()
| 4 | |
| 5 | window.customElements.define('draw-signature', class extends HTMLElement { |
| 6 | connectedCallback () { |
| 7 | this.setCanvasSize() |
| 8 | |
| 9 | this.pad = new SignaturePad(this.canvas) |
| 10 | |
| 11 | this.resizeObserver = new ResizeObserver(() => { |
| 12 | requestAnimationFrame(() => { |
| 13 | if (!this.canvas) return |
| 14 | if (!this.canvas.parentNode?.clientWidth) return |
| 15 | |
| 16 | const { width, height } = this.canvas |
| 17 | |
| 18 | this.setCanvasSize() |
| 19 | |
| 20 | if (this.canvas.width !== width || this.canvas.height !== height) { |
| 21 | this.redrawCanvas(width, height) |
| 22 | } |
| 23 | }) |
| 24 | }) |
| 25 | |
| 26 | this.resizeObserver.observe(this.canvas.parentNode) |
| 27 | |
| 28 | if (this.dataset.color) { |
| 29 | this.pad.penColor = this.dataset.color |
| 30 | } |
| 31 | |
| 32 | this.pad.addEventListener('endStroke', () => { |
| 33 | this.updateSubmitButtonVisibility() |
| 34 | }) |
| 35 | |
| 36 | this.clearButton.addEventListener('click', (e) => { |
| 37 | e.preventDefault() |
| 38 | |
| 39 | this.clearSignaturePad() |
| 40 | }) |
| 41 | |
| 42 | this.form.addEventListener('submit', (e) => { |
| 43 | e.preventDefault() |
| 44 | |
| 45 | this.submitButton.disabled = true |
| 46 | |
| 47 | this.submitImage().then((data) => { |
| 48 | this.valueInput.value = data.uuid |
| 49 | |
| 50 | return fetch(this.form.action, { |
| 51 | method: 'PUT', |
| 52 | body: new FormData(this.form) |
| 53 | }).then((response) => { |
| 54 | this.form.classList.add('hidden') |
| 55 | this.success.classList.remove('hidden') |
| 56 | |
| 57 | return response |
| 58 | }) |
| 59 | }).catch(error => { |
| 60 | console.log(error) |
| 61 | }).finally(() => { |
| 62 | this.submitButton.disabled = false |
| 63 | }) |
nothing calls this directly
no test coverage detected