1 | ;
|
2 | /*-----------------------------------------------------------------------------
|
3 | | Copyright (c) 2014-2019, PhosphorJS Contributors
|
4 | |
|
5 | | Distributed under the terms of the BSD 3-Clause License.
|
6 | |
|
7 | | The full license is in the file LICENSE, distributed with this software.
|
8 | |----------------------------------------------------------------------------*/
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | /**
|
11 | * The namespace for clipboard related functionality.
|
12 | */
|
13 | var ClipboardExt;
|
14 | (function (ClipboardExt) {
|
15 | /**
|
16 | * Copy text to the system clipboard.
|
17 | *
|
18 | * @param text - The text to copy to the clipboard.
|
19 | */
|
20 | function copyText(text) {
|
21 | // Fetch the document body.
|
22 | var body = document.body;
|
23 | // Set up the clipboard event listener.
|
24 | var handler = function (event) {
|
25 | // Stop the event propagation.
|
26 | event.preventDefault();
|
27 | event.stopPropagation();
|
28 | // Set the clipboard data.
|
29 | event.clipboardData.setData('text', text);
|
30 | // Remove the event listener.
|
31 | body.removeEventListener('copy', handler, true);
|
32 | };
|
33 | // Add the event listener.
|
34 | body.addEventListener('copy', handler, true);
|
35 | // Trigger the event.
|
36 | document.execCommand('copy');
|
37 | }
|
38 | ClipboardExt.copyText = copyText;
|
39 | })(ClipboardExt = exports.ClipboardExt || (exports.ClipboardExt = {}));
|