(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" ); // Convert the

tags into new line. content = content.replace( //gi, "\n\n" ); // Convert the

  • tags into new line. content = content.replace( //gi, "\n" ); // Remove all tags. content = content.replace( /(<([^>]+)>)/ig, '' ); // Remove white spaces. content = content.replace( new RegExp( "/^\s+$/" ), "" ); } // Remove first and last new line. content = $.trim( content ); // Support for IOS devices too. CTCWP.copy( content ); } if ( btn.hasClass( 'ctc-block-copy-icon' ) ) { // Copied! btn.addClass( 'copied' ); setTimeout( function () { btn.removeClass( 'copied' ) }, 1000 ); } else { // Copied! btnText.text( copiedText ); block.addClass( 'copied' ) setTimeout( function () { btnText.text( oldText ) block.removeClass( 'copied' ) }, 1000 ); } } }; /** * Initialization */ $( function () { CTCCore.init(); } ); })( jQuery );