Download this file
| 1 | // busy.mjs — the busy rule (650ms) for a button the editor posts from |
| 2 | // itself: estilo's spinner in the button, aria-busy, and at least |
| 3 | // HOLD_MS before the answer is shown, so a quick save reads as a |
| 4 | // deliberate beat (busy.js does the same for the forms it sends). |
| 5 | |
| 6 | export const HOLD_MS = 650 |
| 7 | |
| 8 | export async function held (button, work) { |
| 9 | const spin = document.createElement('span') |
| 10 | spin.setAttribute('rst-spin', '') |
| 11 | spin.setAttribute('aria-hidden', 'true') |
| 12 | button.append(spin) |
| 13 | button.setAttribute('aria-busy', 'true') |
| 14 | button.disabled = true |
| 15 | try { |
| 16 | const [result] = await Promise.all([work(), new Promise(resolve => setTimeout(resolve, HOLD_MS))]) |
| 17 | return result |
| 18 | } finally { |
| 19 | spin.remove() |
| 20 | button.removeAttribute('aria-busy') |
| 21 | button.disabled = false |
| 22 | } |
| 23 | } |
| 24 | |