# j-Clipboard

> j-Clipboard: It works as singleton; Uses navigator.clipboard.writeText() or document.execCommand('copy') as fallback

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: 82080a68b47aa642d392c7a681fd8845a68edede928d9bce5ff17e578d9cb2bc
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

- It works as singleton
- Uses `navigator.clipboard.writeText()` or `document.execCommand('copy')` as fallback


__Methods__:

- `SETTER('clipboard/copy', 'TEXT TO CLIPBOARD')` or `FIND('clipboard').copy('TEXT TO CLIPBOARD')`

__Configuration__:

- `oncopy {String}` a link to the `function(value)`
- `native {Boolean}` enables native clipboard (default: `false`)

Use it with `<ui-component name="clipboard">`. When the component is not loaded yet, jComponent downloads it on first use from the address in `DEF.fallback` (the Componentator CDN by default). Author: Peter Širka. Source: the Componentator components repository, MIT license.

```html example.html
<ui-component name="clipboard"></ui-component>
<div style="cursor:pointer">Copy to clipboard: My value to clipboard</div>
<div style="cursor:pointer">Copy to clipboard: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium, voluptatem?</div>

<script>
	$('div').on('click', function() {
		var el = $(this);

		el.css('background-color', '#E0E0E0');
		setTimeout(function() {
			el.css('background-color', 'transparent');
		}, 200);

		// Copy to clipboard
		SETTER('clipboard/copy', el.html());
	});
</script>
```
