`. * */ function wpbr_truncate_support_print() { static $printed = false; if ($printed) return; $printed = true; $l10n = array( 'show' => __('Show the rest', 'wpbr-bulk-replace'), 'hide' => __('Show less', 'wpbr-bulk-replace'), ); wpbr_inline_open('script'); echo "var wpbrTruncateL10n = " . wp_json_encode($l10n, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT) . ";"; ?> (function(){ var L = wpbrTruncateL10n; function watch(el){ var row = el.parentNode; var btn = document.createElement('button'); btn.type = 'button'; btn.className = 'wpbr-trunc-toggle'; btn.textContent = '⋯'; btn.hidden = true; btn.setAttribute('aria-expanded', 'false'); if (el.id) { btn.setAttribute('aria-controls', el.id); } row.appendChild(btn); function open(){ return el.classList.contains('wpbr-trunc-open'); } function label(){ btn.setAttribute('aria-label', (open() ? L.hide : L.show) + ': ' + el.textContent); } function check(){ var cut = !open() && el.scrollWidth > el.clientWidth + 1; btn.hidden = !(cut || open()); label(); } btn.addEventListener('click', function(){ var on = !open(); el.classList.toggle('wpbr-trunc-open', on); btn.setAttribute('aria-expanded', on ? 'true' : 'false'); check(); }); new MutationObserver(check).observe(el, { childList: true, characterData: true, subtree: true }); window.addEventListener('resize', check); check(); } Array.prototype.forEach.call(document.querySelectorAll('[data-wpbr-truncate]'), watch); })();