mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
|
/**
|
||
|
* Simple image spoiler functionality.
|
||
|
*/
|
||
|
|
||
|
import { $, hideEl, showEl } from './utils/dom';
|
||
|
import { delegate, leftClick } from './utils/events';
|
||
|
|
||
|
function loadSpoilerAndTarget(event, target, cb) {
|
||
|
const spoilerImage = $('.js-spoiler-image', target);
|
||
|
const targetImage = $('.js-spoiler-target', target);
|
||
|
|
||
|
if (!spoilerImage || !targetImage) return;
|
||
|
|
||
|
event.preventDefault();
|
||
|
|
||
|
cb(spoilerImage, targetImage);
|
||
|
}
|
||
|
|
||
|
function unspoiler(event, target) {
|
||
|
loadSpoilerAndTarget(event, target, (spoilerImage, targetImage) => {
|
||
|
hideEl(spoilerImage);
|
||
|
showEl(targetImage);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function spoiler(event, target) {
|
||
|
loadSpoilerAndTarget(event, target, (spoilerImage, targetImage) => {
|
||
|
showEl(spoilerImage);
|
||
|
hideEl(targetImage);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export function configureSpoilers() {
|
||
|
switch (window.booru.spoilerType) {
|
||
|
case 'click':
|
||
|
delegate(document, 'click', {'.image-container': leftClick(unspoiler)});
|
||
|
delegate(document, 'mouseleave', {'.image-container': spoiler});
|
||
|
break;
|
||
|
case 'hover':
|
||
|
delegate(document, 'mouseenter', {'.image-container': unspoiler});
|
||
|
delegate(document, 'mouseleave', {'.image-container': spoiler});
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|