Replace inline onclick obfuscation handler

This commit is contained in:
Tetrakern 2023-06-17 23:21:24 +02:00
parent 40c65a89a5
commit 09ca5ebfe5
3 changed files with 11 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -108,7 +108,7 @@ $entries = new WP_Query( $query_args );
?></a></h3>
<div class="card__content _small cell-desc">
<div class="truncate _3-3 <?php if ( ! $args['spoiler'] ) echo '_obfuscated'; ?>">
<div class="truncate _3-3 <?php if ( ! $args['spoiler'] ) echo '_obfuscated'; ?>" data-obfuscation-target>
<?php if ( get_option( 'fictioneer_show_authors' ) && $args['source'] ) : ?>
<span class="card__by-author"><?php
printf( _x( 'by %s', 'Small card: by {Author}.', 'fictioneer' ), fictioneer_get_author_node() );
@ -127,7 +127,7 @@ $entries = new WP_Query( $query_args );
$spoiler_note = str_repeat( _x( '&#183; ', 'Chapter preview obfuscation character.', 'fictioneer' ), intval( strlen( $excerpt ) ) );
?>
<?php if ( ! $args['spoiler'] ) : ?>
<span onclick="this.parentElement.classList.toggle('_obfuscated');" tabindex="0">
<span data-toggle-obfuscation tabindex="0">
<span class="obfuscated">&nbsp;<?php echo $spoiler_note; ?></span>
<span class="clean"> <?php echo $excerpt; ?></span>
</span>

View File

@ -366,6 +366,14 @@ fcn_theBody.addEventListener('click', e => {
if (typeof fct_spoiler === 'function') fct_spoiler(spoilerTarget);
return;
}
// Handle obfuscation
const obfuscationTarget = e.target.closest('[data-toggle-obfuscation]');
if (obfuscationTarget) {
obfuscationTarget.closest('[data-obfuscation-target]').classList.toggle('_obfuscated');
return;
}
});
// =============================================================================