-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
72 lines (71 loc) · 4.24 KB
/
index.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="clipboard.svg">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<link rel="stylesheet" href="clipboard.css">
<title>Clipboard</title>
</head>
<body>
<header class="bg-dark text-light py-5 mb-5">
<div class="container">
<h1 class="display-1 mb-4"><i class="bi-clipboard-check"></i> Clipboard</h1>
<p class="lead mb-4">Super simple, completely configurable, copy to clipboard.</p>
<a class="btn btn-secondary" href="https://github.com/signified/clipboard" target="_blank"><i class="bi-github"></i> View on GitHub</a>
</div>
</header>
<main>
<div class="container">
<h2 class="display-6">Basic usage</h2>
<p>The below example adds a clipboard button with default styling provided by the default stylesheet (<a href="https://github.com/signified/clipboard/blob/main/clipboard.css" target="_blank">clipboard.css</a>).</p>
<pre class="mb-5 p-4 bg-light border rounded" id="example-1">clipboard('#example-1');</pre>
<h2 class="display-6">Advanced usage</h2>
<p>The below example makes use of the <code>options</code> parameter to add a custom <code>template</code> which uses <a href="https://getbootstrap.com/" target="_blank">Bootstrap</a> for styling and <a href="https://icons.getbootstrap.com/" target="_blank">Bootstrap Icons</a> for button content. It also makes use of the <code>callback</code> parameter to add a callback function with events that add <a href="https://getbootstrap.com/docs/5.0/components/tooltips/" target="_blank">Bootstrap Tooltips</a> and change the tooltip text and button icon when the button is clicked.</p>
<pre class="mb-5 p-4 bg-light border rounded" id="example-2">clipboard('#example-2', {
template: '<div class="position-relative float-end w-100 d-none d-md-block"><button class="position-absolute top-0 end-0 mt-3 me-3 d-block btn btn-sm btn-outline-primary" type="button" data-bs-toggle="tooltip" data-bs-placement="left" data-bs-title="Copy to clipboard"><i class="bi-clipboard"></i></button></div>'
}, function(clipboard, element) {
let button = clipboard.querySelector('button');
let tooltip = new bootstrap.Tooltip(button);
button.addEventListener('click', function() {
tooltip.setContent({
'.tooltip-inner': 'Copied!'
});
button.innerHTML = '<i class="bi-check-lg"></i>';
});
button.addEventListener('mouseleave', function() {
tooltip.setContent({
'.tooltip-inner': 'Copy to clipboard'
});
button.innerHTML = '<i class="bi-clipboard"></i>';
});
});</pre>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="clipboard.js"></script>
<script>
clipboard('#example-1');
clipboard('#example-2', {
template: '<div class="position-relative float-end w-100 d-none d-md-block"><button class="position-absolute top-0 end-0 mt-3 me-3 d-block btn btn-sm btn-outline-primary" type="button" data-bs-toggle="tooltip" data-bs-placement="left" data-bs-title="Copy to clipboard"><i class="bi-clipboard"></i></button></div>'
}, function(clipboard, element) {
let button = clipboard.querySelector('button');
let tooltip = new bootstrap.Tooltip(button);
button.addEventListener('click', function() {
tooltip.setContent({
'.tooltip-inner': 'Copied!'
});
button.innerHTML = '<i class="bi-check-lg"></i>';
});
button.addEventListener('mouseleave', function() {
tooltip.setContent({
'.tooltip-inner': 'Copy to clipboard'
});
button.innerHTML = '<i class="bi-clipboard"></i>';
});
});
</script>
</body>
</html>