(function ($) { const CTCCore = { /** * Init */ init: function () { this._bind(); }, /** * Binds events */ _bind: function () { $( document ).on( 'click', '.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'), content = block.find('.ctc-copy-content').val(); 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. CTC.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);