Sha256: 7f1ba6884982b8e202ba0d6fcc1331dd1c66ed4efa670a8050aed410cba37651

Contents?: true

Size: 1.06 KB

Versions: 17

Compression:

Stored size: 1.06 KB

Contents

import '@github/clipboard-copy-element'

const CLIPBOARD_COPY_TIMER_DURATION = 2000

function toggleSVG(svg: SVGElement) {
  if (svg.style.display === '' || svg.style.display === 'block') {
    svg.style.display = 'none'
  } else {
    svg.style.display = 'block'
  }
}

// Toggle a copy button.
function toggleCopyButton(button: HTMLElement) {
  const [clippyIcon, checkIcon] = button.querySelectorAll<SVGElement>('.octicon')

  if (!clippyIcon || !checkIcon) return

  toggleSVG(clippyIcon)
  toggleSVG(checkIcon)
}

const clipboardCopyElementTimers = new WeakMap<HTMLElement, number>()

document.addEventListener('clipboard-copy', function ({target}) {
  if (!(target instanceof HTMLElement)) return
  if (!target.hasAttribute('data-view-component')) return

  const currentTimeout = clipboardCopyElementTimers.get(target)

  if (currentTimeout) {
    clearTimeout(currentTimeout)
    clipboardCopyElementTimers.delete(target)
  } else {
    toggleCopyButton(target)
  }

  clipboardCopyElementTimers.set(target, setTimeout(toggleCopyButton, CLIPBOARD_COPY_TIMER_DURATION, target))
})

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
primer_view_components-0.0.57 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.56 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.55 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.54 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.53 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.52 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.51 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.50 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.49 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.48 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.47 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.46 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.45 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.44 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.43 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.42 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.41 app/components/primer/clipboard_copy_component.ts