• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / blurts-server / 24612810-8aa7-46bc-a7ef-4e72040ccf0f

pending completion
24612810-8aa7-46bc-a7ef-4e72040ccf0f

push

circleci

GitHub
Merge pull request #2806 from mozilla/MNTOR-1019/dialog-add-email

282 of 1295 branches covered (21.78%)

Branch coverage included in aggregate %.

39 of 39 new or added lines in 6 files covered. (100.0%)

959 of 3494 relevant lines covered (27.45%)

4.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/client/js/dialog-handler.js
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4

5
const triggerBtns = document.querySelectorAll('button[data-dialog]')
×
6
let contentMap, dialogEl // expect a single dialog on page at any time
7

8
function init () {
9
  contentMap = new Map()
×
10
  dialogEl = document.createElement('dialog')
×
11
  document.body.append(dialogEl)
×
12

13
  triggerBtns.forEach(btn => btn.addEventListener('click', handleEvent))
×
14
}
15

16
function handleEvent (e) {
17
  switch (true) {
×
18
    case e.target.matches('button[data-dialog]'):
19
      openDialog(e.target.dataset.dialog)
×
20
      break
×
21
    case e.target.matches('dialog button.close'):
22
      dialogEl.close()
×
23
      break
×
24
  }
25
}
26

27
async function openDialog (partialName) {
28
  dialogEl.showModal() // provide immediate UI response by showing ::backdrop regardless of content load
×
29
  dialogEl.addEventListener('click', handleEvent)
×
30
  dialogEl.addEventListener('close', resetDialog)
×
31

32
  const content = contentMap.get(partialName) ?? await fetchContent(partialName)
×
33

34
  if (content) {
×
35
    dialogEl.insertAdjacentHTML('beforeend', content)
×
36
  } else {
37
    dialogEl.close()
×
38
  }
39
}
40

41
async function fetchContent (partialName) {
42
  let content
43
  try {
×
44
    const res = await fetch(`/dialog/${partialName}`)
×
45

46
    if (!res.ok) throw new Error('Bad fetch response')
×
47

48
    content = await res.text()
×
49
    contentMap.set(partialName, content)
×
50
  } catch (e) {
51
    console.error('Could not load dialog:', e)
×
52
  }
53
  return content
×
54
}
55

56
function resetDialog () {
57
  dialogEl.removeEventListener('click', handleEvent)
×
58
  dialogEl.removeEventListener('close', resetDialog)
×
59
  dialogEl.replaceChildren()
×
60
}
61

62
if (triggerBtns.length) init()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc