gitile/assets/js/gitile.js

gitile.js

1
// SPDX-FileCopyrightText: 2021 Julien Lepiller <julien@lepiller.eu>
2
//
3
// SPDX-License-Identifier: AGPL-3.0-or-later
4
5
window.onload = function() {
6
  buttons = document.getElementsByClassName('copy')
7
8
  function mycopy(button) {
9
    alert(button)
10
    data = button.dataset.clipboardCopy
11
    while(data == undefined) {
12
          button = button.parentElement
13
          data = button.dataset.clipboardCopy
14
    }
15
    alert(data)
16
    i = document.createElement('input')
17
    i.type = 'text'
18
    i.value = data
19
    i.display = 'none'
20
    button.appendChild(i)
21
    i.select()
22
    i.setSelectionRange(0, 99999); /* For mobile devices */
23
    document.execCommand("copy")
24
    button.removeChild(i)
25
  }
26
27
28
  for(i=0;i<buttons.length;i++) {
29
    buttons[i].addEventListener('click', function(e) {
30
      mycopy(e.target)
31
    })
32
  }
33
}
34