| 1 |
(function () { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
function init() { |
| 5 |
var blocks = document.querySelectorAll('.bkbg-pb-outer'); |
| 6 |
|
| 7 |
blocks.forEach(function (block) { |
| 8 |
var btn = block.querySelector('.bkbg-pb-btn'); |
| 9 |
if (!btn) return; |
| 10 |
|
| 11 |
// ── Hover color swap ─────────────────────────────────────────────── |
| 12 |
var hoverBg = btn.dataset.pbBgHover; |
| 13 |
var hoverText = btn.dataset.pbTextHover; |
| 14 |
|
| 15 |
if (hoverBg || hoverText) { |
| 16 |
var cachedBg = btn.style.background || btn.style.backgroundColor; |
| 17 |
var cachedColor = btn.style.color; |
| 18 |
var cachedFilter = btn.style.filter; |
| 19 |
|
| 20 |
btn.addEventListener('mouseenter', function () { |
| 21 |
if (hoverBg) { btn.style.background = hoverBg; } |
| 22 |
if (hoverText) { btn.style.color = hoverText; } |
| 23 |
btn.style.filter = ''; // disable CSS brightness override during colour swap |
| 24 |
}); |
| 25 |
|
| 26 |
btn.addEventListener('mouseleave', function () { |
| 27 |
btn.style.background = cachedBg; |
| 28 |
btn.style.color = cachedColor; |
| 29 |
btn.style.filter = cachedFilter; |
| 30 |
}); |
| 31 |
} |
| 32 |
|
| 33 |
// ── Reduced-motion: pause pulse animations ───────────────────────── |
| 34 |
var pulseWrap = block.querySelector('.bkbg-pb-pulse-wrap'); |
| 35 |
if (pulseWrap) { |
| 36 |
var mq = window.matchMedia('(prefers-reduced-motion: reduce)'); |
| 37 |
|
| 38 |
function applyMotionPref() { |
| 39 |
var paused = mq.matches ? 'paused' : 'running'; |
| 40 |
pulseWrap.style.setProperty('animation-play-state', paused); |
| 41 |
var before = window.getComputedStyle(pulseWrap, '::before'); |
| 42 |
// set it on the wrapper's pseudo-element via a class toggle |
| 43 |
if (mq.matches) { |
| 44 |
pulseWrap.classList.add('bkbg-pb-reduced-motion'); |
| 45 |
} else { |
| 46 |
pulseWrap.classList.remove('bkbg-pb-reduced-motion'); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
applyMotionPref(); |
| 51 |
try { mq.addEventListener('change', applyMotionPref); } |
| 52 |
catch (e) { mq.addListener(applyMotionPref); } // Safari 13 compat |
| 53 |
} |
| 54 |
}); |
| 55 |
} |
| 56 |
|
| 57 |
// ── Boot ─────────────────────────────────────────────────────────────────── |
| 58 |
if (document.readyState === 'loading') { |
| 59 |
document.addEventListener('DOMContentLoaded', init); |
| 60 |
} else { |
| 61 |
init(); |
| 62 |
} |
| 63 |
|
| 64 |
}()); |
| 65 |
|