(function ($) {
const CTCCore = {
/**
* Init
*/
init: function () {
this._bind();
},
/**
* Binds events
*/
_bind: function () {
$( document ).on( 'click', 'body:not(.block-editor-page) .ctc-block-copy', this.doCopy );
},
/**
* Do Copy to Clipboard
*/
doCopy: function (event) {
event.preventDefault();
let btn = $( this ),
btnText = btn.find( '.ctc-button-text' ),
oldText = btnText.text(),
copiedText = btn.attr( 'data-copied' ) || 'Copied',
copyAsRaw = btn.attr( 'copy-as-raw' ) || '',
block = btn.parents( '.ctc-block' ),
textarea = block.find( '.ctc-copy-content' ),
content = textarea.val(),
selectionTarget = textarea.attr( 'selection-target' ) || ''
// Copy as selection.
if ( selectionTarget ) {
const source = $( selectionTarget )
if ( ! source.length ) {
return
}
CTCWP.copySelection( source )
} else {
if ( ! copyAsRaw ) {
// Convert the
tags into new line.
content = content.replace( /
/gi, "\n" );
// Convert the
tags into new line. content = content.replace( /
/gi, "\n\n" ); // Convert the