-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (32 loc) · 1.36 KB
/
index.js
File metadata and controls
45 lines (32 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
window.onload = function() {
'use strict';
document.querySelectorAll('img[src$="copy.png"]').forEach(function(el) {
var cell = el.parentElement,
scriptTag = getScriptTagInputEl(cell).value,
matches = scriptTag.match(/\/(\d+\.\d+\.\d+)\/build\/(.+\.js)/),
version = matches[1],
module = matches[2];
el.title = 'Copy <script> tag for ' + module + '@' + version + ' to clipboard.';
cell.addEventListener('click', handleClick);
});
function getScriptTagInputEl(cell) {
return cell.parentElement.firstElementChild.firstElementChild;
}
function handleClick(e) {
var cell = e.currentTarget;
getScriptTagInputEl(cell).select();
document.execCommand('copy');
feedback(cell);
}
var fb = document.querySelector('div.feedback');
function feedback(cell, text) {
var parentRect = cell.getBoundingClientRect();
var fbRect = fb.getBoundingClientRect();
var margin = (parentRect.height - fbRect.height) / 2;
if (text) { fb.innerText = text; }
fb.style.left = window.pageXOffset + parentRect.left - margin - fbRect.width + 'px';
fb.style.top = window.pageYOffset + parentRect.top + margin + 'px';
fb.style.opacity = .75;
setTimeout(function() { fb.style.opacity = 0; }, 1700);
}
};