# blockenberg/2.0.7/blocks/read-more/frontend.js

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

- Page: https://pluginprobe.com/plugins/blockenberg/2.0.7/code/blocks/read-more/frontend.js
- Raw: https://pluginprobe.com/plugins/blockenberg/2.0.7/raw/blocks/read-more/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/read-more/frontend.js#L10-L20`.

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

    function initReadMore(wrap) {
        var content = wrap.querySelector('.bkrm-content');
        var btn     = wrap.querySelector('.bkrm-btn');
        var label   = wrap.querySelector('.bkrm-label');

        if (!content || !btn) return;

        var readMoreText = label ? label.textContent : (btn.dataset.readMore || 'Read more');
        var showLessText = btn.dataset.showLess || 'Show less';

        // Read data-attributes set by block (fallback to CSS var)
        if (btn.dataset) {
            // labels may be stored in data attributes or scanned from DOM at build time
        }

        btn.addEventListener('click', function () {
            var isExpanded = content.classList.contains('bkrm-expanded');

            if (isExpanded) {
                // Collapse: set fixed height first, then remove class
                content.style.maxHeight = content.scrollHeight + 'px';
                requestAnimationFrame(function () {
                    requestAnimationFrame(function () {
                        content.classList.remove('bkrm-expanded');
                        content.classList.add('bkrm-collapsed');
                        btn.setAttribute('aria-expanded', 'false');
                        if (label) label.textContent = readMoreText;
                    });
                });
            } else {
                // Expand: set max-height to scrollHeight for transition
                content.classList.remove('bkrm-collapsed');
                content.classList.add('bkrm-expanded');
                content.style.maxHeight = content.scrollHeight + 'px';
                btn.setAttribute('aria-expanded', 'true');
                if (label) label.textContent = showLessText;

                // After transition remove inline style so it stays open
                var transEnd = function () {
                    content.style.maxHeight = '';
                    content.removeEventListener('transitionend', transEnd);
                };
                content.addEventListener('transitionend', transEnd);
            }
        });

        // Check if content is actually taller than collapsed height — hide btn if not
        var collapsedPx = parseFloat(getComputedStyle(content).getPropertyValue('--bkrm-collapsed') || '180');
        var text = content.querySelector('.bkrm-text');
        if (text && text.scrollHeight <= collapsedPx + 10) {
            // Content fits — remove collapse, hide button
            content.classList.remove('bkrm-collapsed');
            content.classList.add('bkrm-expanded');
            var btnWrap = wrap.querySelector('.bkrm-btn-wrap');
            if (btnWrap) btnWrap.style.display = 'none';
        }
    }

    function init() {
        document.querySelectorAll('.bkrm-wrap').forEach(initReadMore);
    }

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

}());

```
