ForgeComponents
en

Components

j-Clipboard

jComponent 20 · jcomponent@20 component Example loaded with jComponent 20
  • 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.

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>