| 1 |
(function () { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
/* Link in Bio — minimal frontend: hover is CSS only; this script |
| 5 |
adds optional click analytics hook and keyboard accessibility. */ |
| 6 |
|
| 7 |
document.addEventListener('DOMContentLoaded', function () { |
| 8 |
document.querySelectorAll('.bkbg-lib-wrapper').forEach(function (wrapper) { |
| 9 |
var links = wrapper.querySelectorAll('.bkbg-lib-btn'); |
| 10 |
|
| 11 |
links.forEach(function (link) { |
| 12 |
/* Keyboard: Enter / Space already works for <a> natively. |
| 13 |
This is a safety net for any edge cases. */ |
| 14 |
link.addEventListener('keydown', function (e) { |
| 15 |
if (e.key === 'Enter' || e.key === ' ') { |
| 16 |
e.preventDefault(); |
| 17 |
link.click(); |
| 18 |
} |
| 19 |
}); |
| 20 |
|
| 21 |
/* Fire custom event so developers can hook analytics */ |
| 22 |
link.addEventListener('click', function () { |
| 23 |
var event = new CustomEvent('bkbg:lib:click', { |
| 24 |
bubbles: true, |
| 25 |
detail: { label: link.textContent.trim(), href: link.href } |
| 26 |
}); |
| 27 |
link.dispatchEvent(event); |
| 28 |
}); |
| 29 |
}); |
| 30 |
}); |
| 31 |
}); |
| 32 |
})(); |
| 33 |
|