# blockenberg/2.0.7/blocks/code-block/frontend.js

Blockenberg — 600+ Advanced Gutenberg Blocks &amp; AI Agent for WordPress Block Editor, version 2.0.7. 61 lines.

- Page: https://pluginprobe.com/plugins/blockenberg/2.0.7/code/blocks/code-block/frontend.js
- Raw: https://pluginprobe.com/plugins/blockenberg/2.0.7/raw/blocks/code-block/frontend.js
- Modified: 2026-03-06T12:32:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/blockenberg/2.0.7/code/blocks/code-block/frontend.js#L10-L20`.

```javascript
(function () {
    'use strict';

    function initCodeBlock(wrap) {
        var copyBtn = wrap.querySelector('.bkbg-cb-copy-btn');
        var pre     = wrap.querySelector('.bkbg-cb-pre');

        if (copyBtn && pre) {
            var copyLabel   = copyBtn.dataset.copyLabel   || 'Copy';
            var copiedLabel = copyBtn.dataset.copiedLabel || 'Copied!';
            var labelEl     = copyBtn.querySelector('.bkbg-cb-copy-label');
            var timer;

            copyBtn.addEventListener('click', function () {
                var text = pre.textContent;
                var setCopied = function () {
                    clearTimeout(timer);
                    copyBtn.classList.add('is-copied');
                    if (labelEl) labelEl.textContent = copiedLabel;
                    timer = setTimeout(function () {
                        copyBtn.classList.remove('is-copied');
                        if (labelEl) labelEl.textContent = copyLabel;
                    }, 2000);
                };

                if (navigator.clipboard && navigator.clipboard.writeText) {
                    navigator.clipboard.writeText(text).then(setCopied).catch(function () {
                        fallbackCopy(text, setCopied);
                    });
                } else {
                    fallbackCopy(text, setCopied);
                }
            });
        }
    }

    function fallbackCopy(text, cb) {
        try {
            var ta = document.createElement('textarea');
            ta.value = text;
            ta.style.cssText = 'position:fixed;top:-9999px;left:-9999px;opacity:0;';
            document.body.appendChild(ta);
            ta.select();
            document.execCommand('copy');
            document.body.removeChild(ta);
            if (cb) cb();
        } catch (e) {}
    }

    function initAll() {
        var blocks = document.querySelectorAll('.bkbg-cb-wrap');
        blocks.forEach(initCodeBlock);
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initAll);
    } else {
        initAll();
    }
})();

```
