| 1 |
/* Hotspot Image — frontend.js */ |
| 2 |
( function () { |
| 3 |
function init() { |
| 4 |
document.querySelectorAll( '.bkhi-wrap' ).forEach( function ( wrap ) { |
| 5 |
const trigger = wrap.dataset.trigger || 'hover'; |
| 6 |
const pins = Array.from( wrap.querySelectorAll( '.bkhi-pin' ) ); |
| 7 |
|
| 8 |
if ( trigger === 'click' ) { |
| 9 |
pins.forEach( function ( pin ) { |
| 10 |
pin.querySelector( '.bkhi-dot' ).addEventListener( 'click', function (e) { |
| 11 |
e.stopPropagation(); |
| 12 |
const isActive = pin.classList.contains( 'bkhi-active' ); |
| 13 |
// close all |
| 14 |
pins.forEach( p => p.classList.remove( 'bkhi-active' ) ); |
| 15 |
if ( ! isActive ) pin.classList.add( 'bkhi-active' ); |
| 16 |
} ); |
| 17 |
} ); |
| 18 |
// click outside closes |
| 19 |
document.addEventListener( 'click', function () { |
| 20 |
pins.forEach( p => p.classList.remove( 'bkhi-active' ) ); |
| 21 |
} ); |
| 22 |
} |
| 23 |
// hover is handled by CSS :hover |
| 24 |
} ); |
| 25 |
} |
| 26 |
|
| 27 |
if ( document.readyState === 'loading' ) { |
| 28 |
document.addEventListener( 'DOMContentLoaded', init ); |
| 29 |
} else { |
| 30 |
init(); |
| 31 |
} |
| 32 |
}() ); |
| 33 |
|