gitile.js
1 | window.onload = function() { |
2 | buttons = document.getElementsByClassName('copy') |
3 | |
4 | function mycopy(button) { |
5 | alert(button) |
6 | data = button.dataset.clipboardCopy |
7 | while(data == undefined) { |
8 | button = button.parentElement |
9 | data = button.dataset.clipboardCopy |
10 | } |
11 | alert(data) |
12 | i = document.createElement('input') |
13 | i.type = 'text' |
14 | i.value = data |
15 | i.display = 'none' |
16 | button.appendChild(i) |
17 | i.select() |
18 | i.setSelectionRange(0, 99999); /* For mobile devices */ |
19 | document.execCommand("copy") |
20 | button.removeChild(i) |
21 | } |
22 | |
23 | |
24 | for(i=0;i<buttons.length;i++) { |
25 | buttons[i].addEventListener('click', function(e) { |
26 | mycopy(e.target) |
27 | }) |
28 | } |
29 | } |
30 |