forked from lgarron/clipboard-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
112 lines (97 loc) · 3.35 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>clipboard-polyfill</title>
<link rel="stylesheet" href="index.css">
<script src="dist/clipboard-polyfill.promise.js"></script>
<script>
// Workaround for:
// - IE9 (can't bind console functions directly), and
// - Edge Issue #14495220 (referencing `console` without F12 Developer Tools can cause an exception)
var infoOrLog = function() {
(console.info || console.log).apply(console, arguments);
};
clipboard.setDebugLog(infoOrLog);
</script>
<style>
.editable {
min-width: 20px;
min-height: 1em;
border: 1px solid #AAA;
}
</style>
</head>
<body>
<div class="header">
<a href="https://github.com/lgarron/clipboard-polyfill">clipboard-polyfill</a>
</div>
<div class="ribbon"></div>
<div class="content">
<h2>Plain Text</h2>
<button id="plain-copy">Copy text (plain)</button>
<span id="plain-copy-result"></span>
<script>
document.getElementById("plain-copy").addEventListener("click", function() {
var resultField = document.getElementById("plain-copy-result");
clipboard.writeText("This text is plain.").then(function(){
resultField.textContent = "success";
}, function(err){
resultField.textContent = err;
});
});
</script>
<h2>Markup</h2>
<button id="markup-copy">Copy text (markup)</button>
<span id="markup-copy-result"></span>
<script>
document.getElementById("markup-copy").addEventListener("click", function() {
var resultField = document.getElementById("markup-copy-result");
var dt = new clipboard.DT();
dt.setData("text/html", "<i>Markup</i> <b>text</b>. Paste me into a rich text editor.");
dt.setData("text/plain", "Fallback markup text. Paste me into a rich text editor.");
clipboard.write(dt).then(function(){
resultField.textContent = "success";
}, function(err){
resultField.textContent = err;
});
});
</script>
<h2>DOM node</h2>
<button id="markup-dom-copy">Copy markup (DOM node → markup)</button>
<span id="markup-dom-copy-result"></span>
<br>
<span id="markup-dom-copy-source" style="font-family: Helvetica;"><i><span style="font-size: 150%">T</span>his</i> <span style="background: orange; padding: 0px 2px">will be</span> <b>copied</b>.</span>
<script>
document.getElementById("markup-dom-copy").addEventListener("click", function() {
var resultField = document.getElementById("markup-dom-copy-result");
var dt = new clipboard.DT();
dt.setData("text/html", new XMLSerializer().serializeToString(document.getElementById("markup-dom-copy-source")));
dt.setData("text/plain", document.getElementById("markup-dom-copy-source").innerText);
clipboard.write(dt).then(function(){
resultField.textContent = "success";
}, function(err){
resultField.textContent = err;
});
});
</script>
<h2>Paste Text</h2>
<button id="paste">Paste Text</button>
<span id="paste-result"></span>
<script>
document.getElementById("paste").addEventListener("click", function() {
var resultField = document.getElementById("paste-result");
clipboard.readText().then(function(result) {
resultField.textContent = result;
}, function(err) {
resultField.textContent = err;
});
});
</script>
<br>
<br>
<h2>Paste Area</h2>
<div contenteditable="true" class="editable"></div>
</div>
</body>
</html>