Replace all frontend inline onclick handlers
This commit is contained in:
parent
112c6614c2
commit
41909556e5
@ -1124,7 +1124,7 @@ if ( ! function_exists( 'fictioneer_user_menu_items' ) ) {
|
||||
ob_start();
|
||||
// Start HTML ---> ?>
|
||||
<li class="menu-item hide-if-logged-out">
|
||||
<a href="<?php echo fictioneer_get_logout_url(); ?>" data-logout rel="noopener noreferrer nofollow"><?php echo fcntr( 'logout' ) ?></a>
|
||||
<a href="<?php echo fictioneer_get_logout_url(); ?>" data-click="logout" rel="noopener noreferrer nofollow"><?php echo fcntr( 'logout' ) ?></a>
|
||||
</li>
|
||||
<?php // <--- End HTML
|
||||
$output['logout'] = ob_get_clean();
|
||||
@ -1285,8 +1285,8 @@ if ( ! function_exists( 'fictioneer_get_card_controls' ) ) {
|
||||
if ( $can_follows ) {
|
||||
ob_start();
|
||||
// Start HTML ---> ?>
|
||||
<button class="popup-action-follow" onclick="fcn_inlineToggleFollow(<?php echo $story_id; ?>)"><?php echo fcntr( 'follow' ); ?></button>
|
||||
<button class="popup-action-unfollow" onclick="fcn_inlineToggleFollow(<?php echo $story_id; ?>)"><?php echo fcntr( 'unfollow' ); ?></button>
|
||||
<button class="popup-action-follow" data-click="card-toggle-follow" data-story-id="<?php echo $story_id; ?>"><?php echo fcntr( 'follow' ); ?></button>
|
||||
<button class="popup-action-unfollow" data-click="card-toggle-follow" data-story-id="<?php echo $story_id; ?>"><?php echo fcntr( 'unfollow' ); ?></button>
|
||||
<?php // <--- End HTML
|
||||
$menu['follow'] = ob_get_clean();
|
||||
}
|
||||
@ -1294,8 +1294,8 @@ if ( ! function_exists( 'fictioneer_get_card_controls' ) ) {
|
||||
if ( $can_reminders ) {
|
||||
ob_start();
|
||||
// Start HTML ---> ?>
|
||||
<button class="popup-action-reminder" onclick="fcn_inlineToggleReminder(<?php echo $story_id; ?>)"><?php echo fcntr( 'read_later' ); ?></button>
|
||||
<button class="popup-action-forget" onclick="fcn_inlineToggleReminder(<?php echo $story_id; ?>)"><?php echo fcntr( 'forget' ); ?></button>
|
||||
<button class="popup-action-reminder" data-click="card-toggle-reminder" data-story-id="<?php echo $story_id; ?>"><?php echo fcntr( 'read_later' ); ?></button>
|
||||
<button class="popup-action-forget" data-click="card-toggle-reminder" data-story-id="<?php echo $story_id; ?>"><?php echo fcntr( 'forget' ); ?></button>
|
||||
<?php // <--- End HTML
|
||||
$menu['reminder'] = ob_get_clean();
|
||||
}
|
||||
@ -1303,8 +1303,8 @@ if ( ! function_exists( 'fictioneer_get_card_controls' ) ) {
|
||||
if ( $can_checkmarks ) {
|
||||
ob_start();
|
||||
// Start HTML ---> ?>
|
||||
<button class="popup-action-mark-read" onclick="fcn_inlineToggleCheckmark(<?php echo $story_id; ?>, '<?php echo $type; ?>', <?php echo $chapter_id ? $chapter_id : 'null'; ?>, 'set')"><?php echo fcntr( 'mark_read' ); ?></button>
|
||||
<button class="popup-action-mark-unread" onclick="fcn_inlineToggleCheckmark(<?php echo $story_id; ?>, '<?php echo $type; ?>', <?php echo $chapter_id ? $chapter_id : 'null'; ?>, 'unset')"><?php echo fcntr( 'mark_unread' ); ?></button>
|
||||
<button class="popup-action-mark-read" data-click="card-toggle-checkmarks" data-story-id="<?php echo $story_id; ?>" data-type="<?php echo $type; ?>" data-chapter-id="<?php echo $chapter_id ?: 'null'; ?>" data-mode="set"><?php echo fcntr( 'mark_read' ); ?></button>
|
||||
<button class="popup-action-mark-unread" data-click="card-toggle-checkmarks" data-story-id="<?php echo $story_id; ?>" data-type="<?php echo $type; ?>" data-chapter-id="<?php echo $chapter_id ?: 'null'; ?>" data-mode="unset"><?php echo fcntr( 'mark_unread' ); ?></button>
|
||||
<?php // <--- End HTML
|
||||
$menu['checkmark'] = ob_get_clean();
|
||||
}
|
||||
|
@ -1130,7 +1130,7 @@ function fcntr( $key, $escape = false ) {
|
||||
'bbcode_ins' => _x( '<code>[ins]</code><ins>Insert</ins><code>[/ins]</code> more bad puns!', 'BBCode example.', 'fictioneer' ),
|
||||
'bbcode_del' => _x( '<code>[del]</code><del>Delete</del><code>[/del]</code> your browser history!', 'BBCode example.', 'fictioneer' ),
|
||||
'log_in_with' => _x( 'Enter your details or log in with:', 'Comment form login note.', 'fictioneer' ),
|
||||
'logged_in_as' => _x( '<span>Logged in as <strong><a href="%1$s">%2$s</a></strong>. <a class="logout-link" href="%3$s" data-logout>Log out?</a></span>', 'Comment form logged-in note.', 'fictioneer' ),
|
||||
'logged_in_as' => _x( '<span>Logged in as <strong><a href="%1$s">%2$s</a></strong>. <a class="logout-link" href="%3$s" data-click="logout">Log out?</a></span>', 'Comment form logged-in note.', 'fictioneer' ),
|
||||
'accept_privacy_policy' => _x( 'I accept the <b><a class="link" href="%s" target="_blank">privacy policy</a></b>.', 'Comment form privacy checkbox.', 'fictioneer' ),
|
||||
'save_in_cookie' => _x( 'Save in cookie for next time.', 'Comment form cookie checkbox.', 'fictioneer' ),
|
||||
);
|
||||
|
@ -653,9 +653,10 @@ if ( ! function_exists( 'fictioneer_theme_comment' ) ) {
|
||||
type="button"
|
||||
class="comment-inline-edit-submit button"
|
||||
data-enabled="<?php echo esc_attr_x( 'Submit Changes', 'Comment inline edit submit button.', 'fictioneer' ); ?>"
|
||||
data-disabled="<?php esc_attr_e( 'Updating…', 'fictioneer' ); ?>" onclick="fcn_submitInlineCommentEdit(this)"
|
||||
data-disabled="<?php esc_attr_e( 'Updating…', 'fictioneer' ); ?>"
|
||||
data-click="submit-inline-comment-edit"
|
||||
><?php _ex( 'Submit Changes', 'Comment inline edit submit button.', 'fictioneer' ); ?></button>
|
||||
<button type="button" class="comment-inline-edit-cancel button _secondary" onclick="fcn_cancelInlineCommentEdit(this)"><?php _ex( 'Cancel', 'Comment inline edit cancel button.', 'fictioneer' ); ?></button>
|
||||
<button type="button" class="comment-inline-edit-cancel button _secondary" data-click="cancel-inline-comment-edit"><?php _ex( 'Cancel', 'Comment inline edit cancel button.', 'fictioneer' ); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
@ -741,7 +742,7 @@ if ( ! function_exists( 'fictioneer_theme_comment' ) ) {
|
||||
class="fictioneer-comment__edit-toggle hide-on-edit tooltipped hide-if-logged-out"
|
||||
type="button"
|
||||
data-tooltip="<?php echo esc_attr_x( 'Edit', 'Edit comment inline.'. 'fictioneer' ); ?>"
|
||||
onclick="fcn_triggerInlineCommentEdit(this)"
|
||||
data-click="trigger-inline-comment-edit"
|
||||
<?php echo $ajax_in_progress && $is_editable ? '' : 'hidden'; ?>
|
||||
><i class="fa-solid fa-pen"></i></button>
|
||||
<?php endif; ?>
|
||||
@ -764,7 +765,7 @@ if ( ! function_exists( 'fictioneer_theme_comment' ) ) {
|
||||
); ?>"
|
||||
data-dialog-confirm="<?php echo esc_attr_x( 'delete', 'Prompt confirm deletion string.', 'fictioneer' ); ?>"
|
||||
data-tooltip="<?php echo esc_attr_x( 'Delete', 'Delete comment inline.'. 'fictioneer' ); ?>"
|
||||
onclick="fcn_deleteMyComment(this)"
|
||||
data-click="delete-my-comment"
|
||||
<?php echo $ajax_in_progress ? '' : 'hidden'; ?>
|
||||
><i class="fa-solid fa-ban"></i></button>
|
||||
<?php endif; ?>
|
||||
@ -792,7 +793,7 @@ if ( ! function_exists( 'fictioneer_theme_comment' ) ) {
|
||||
<?php if ( fictioneer_show_auth_content() && $is_reportable ) : ?>
|
||||
<button
|
||||
class="fictioneer-report-comment-button hide-if-logged-out tooltipped <?php echo $flag_classes ?> <?php echo $is_flagged_by_current_user ? 'on' : ''; ?>"
|
||||
onclick="fcn_flagComment(this)"
|
||||
data-click="flag-comment"
|
||||
data-tooltip="<?php echo esc_attr_x( 'Report', 'Report this comment.', 'fictioneer' ); ?>"
|
||||
><i class="fa-solid fa-flag"></i></button>
|
||||
<?php endif; ?>
|
||||
|
@ -484,7 +484,7 @@ if ( ! function_exists( 'fictioneer_mobile_user_menu' ) ) {
|
||||
if ( fictioneer_show_auth_content() ) {
|
||||
ob_start();
|
||||
// Start HTML ---> ?>
|
||||
<a href="<?php echo fictioneer_get_logout_url(); ?>" data-logout rel="noopener noreferrer nofollow" class="hide-if-logged-out">
|
||||
<a href="<?php echo fictioneer_get_logout_url(); ?>" data-click="logout" rel="noopener noreferrer nofollow" class="hide-if-logged-out">
|
||||
<?php fictioneer_icon( 'fa-logout', 'mobile-menu__item-icon', '', 'style="transform: translateY(-1px);"' ); ?>
|
||||
<?php echo fcntr( 'logout' ); ?>
|
||||
</a>
|
||||
|
2
js/application.min.js
vendored
2
js/application.min.js
vendored
File diff suppressed because one or more lines are too long
2
js/comments.min.js
vendored
2
js/comments.min.js
vendored
File diff suppressed because one or more lines are too long
@ -12,7 +12,7 @@
|
||||
|
||||
<section class="cookies">
|
||||
<div class="cookies__actions">
|
||||
<button type="button" onclick="fcn_deleteCookie('fcn_cookie_consent'); location.reload();" class="button"><?php _e( 'Reset Consent', 'fictioneer' ); ?></button>
|
||||
<button type="button" onclick="fcn_deleteAllCookies(); alert('<?php _e( 'Cookies and local storage have been cleared. To keep it that way, you should leave the site.', 'fictioneer' ); ?>');" class="button"><?php _e( 'Clear Cookies', 'fictioneer' ); ?></button>
|
||||
<button type="button" data-click="reset-consent" class="button"><?php _e( 'Reset Consent', 'fictioneer' ); ?></button>
|
||||
<button type="button" data-click="clear-cookies" data-message="<?php _e( 'Cookies and local storage have been cleared. To keep it that way, you should leave the site.', 'fictioneer' ); ?>" class="button"><?php _e( 'Clear Cookies', 'fictioneer' ); ?></button>
|
||||
</div>
|
||||
</section>
|
||||
|
@ -135,7 +135,7 @@ if ( $profile_page && $profile_page > 0 ) {
|
||||
<a
|
||||
href="<?php echo fictioneer_get_logout_url(); ?>"
|
||||
title="<?php esc_attr_e( 'Logout', 'fictioneer' ) ?>"
|
||||
data-logout
|
||||
data-click="logout"
|
||||
class="icon-menu__item button--logout hide-if-logged-out"
|
||||
rel="noopener noreferrer nofollow"
|
||||
aria-label="<?php esc_attr_e( 'Click to log out', 'fictioneer' ) ?>"
|
||||
|
@ -127,7 +127,7 @@ $entries = new WP_Query( $query_args );
|
||||
$spoiler_note = str_repeat( _x( '· ', 'Chapter preview obfuscation character.', 'fictioneer' ), intval( strlen( $excerpt ) ) );
|
||||
?>
|
||||
<?php if ( ! $args['spoiler'] ) : ?>
|
||||
<span data-toggle-obfuscation tabindex="0">
|
||||
<span data-click="toggle-obfuscation" tabindex="0">
|
||||
<span class="obfuscated"> <?php echo $spoiler_note; ?></span>
|
||||
<span class="clean">— <?php echo $excerpt; ?></span>
|
||||
</span>
|
||||
|
@ -61,7 +61,7 @@
|
||||
</div>
|
||||
|
||||
<div class="modal__row">
|
||||
<input type="text" value="<?php the_permalink(); ?>" data-copy-to-clipboard data-message="<?php _e( 'Link copied to clipboard!', 'fictioneer' ); ?>" name="permalink" readonly>
|
||||
<input type="text" value="<?php the_permalink(); ?>" data-click="copy-to-clipboard" data-message="<?php _e( 'Link copied to clipboard!', 'fictioneer' ); ?>" name="permalink" readonly>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -330,11 +330,6 @@ window.addEventListener('resize.rAF', fcn_throttle(fcn_updateViewportVariables,
|
||||
// =============================================================================
|
||||
|
||||
fcn_theBody.addEventListener('click', e => {
|
||||
// Handle logout cleanup
|
||||
if (e.target.closest('[data-logout]')) {
|
||||
fcn_cleanupWebStorage();
|
||||
}
|
||||
|
||||
// Handle last click
|
||||
const lastClickTarget = e.target.closest('.toggle-last-clicked');
|
||||
|
||||
@ -367,20 +362,54 @@ fcn_theBody.addEventListener('click', e => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle obfuscation
|
||||
const obfuscationTarget = e.target.closest('[data-toggle-obfuscation]');
|
||||
// === DATA CLICK HANDLERS ===================================================
|
||||
|
||||
if (obfuscationTarget) {
|
||||
obfuscationTarget.closest('[data-obfuscation-target]').classList.toggle('_obfuscated');
|
||||
return;
|
||||
}
|
||||
const clickTarget = e.target.closest('[data-click]'),
|
||||
clickAction = clickTarget?.dataset.click;
|
||||
|
||||
// Handle copy input to clipboard
|
||||
const copyTarget = e.target.closest('input[data-copy-to-clipboard]');
|
||||
if (!clickAction) return;
|
||||
|
||||
if (copyTarget) {
|
||||
copyTarget.select();
|
||||
fcn_copyToClipboard(copyTarget.value, copyTarget.dataset.message);
|
||||
switch (clickAction) {
|
||||
case 'copy-to-clipboard':
|
||||
// Handle copy input to clipboard
|
||||
clickTarget.select();
|
||||
fcn_copyToClipboard(clickTarget.value, clickTarget.dataset.message);
|
||||
break;
|
||||
case 'reset-consent':
|
||||
// Handle consent reset
|
||||
fcn_deleteCookie('fcn_cookie_consent');
|
||||
location.reload();
|
||||
break;
|
||||
case 'clear-cookies':
|
||||
// Handle clear all cookies
|
||||
fcn_deleteAllCookies();
|
||||
alert(clickTarget.dataset.message);
|
||||
break;
|
||||
case 'logout':
|
||||
// Handle logout cleanup
|
||||
fcn_cleanupWebStorage();
|
||||
break;
|
||||
case 'card-toggle-follow':
|
||||
// Handle toggle card Follow
|
||||
fcn_inlineToggleFollow(clickTarget.dataset.storyId);
|
||||
break;
|
||||
case 'card-toggle-reminder':
|
||||
// Handle toggle card Reminder
|
||||
fcn_inlineToggleReminder(clickTarget.dataset.storyId);
|
||||
break;
|
||||
case 'card-toggle-checkmarks':
|
||||
// Handle toggle card Checkmark(s)
|
||||
fcn_inlineToggleCheckmark(
|
||||
parseInt(clickTarget.dataset.storyId),
|
||||
clickTarget.dataset.type,
|
||||
parseInt(clickTarget.dataset.chapterId),
|
||||
clickTarget.dataset.mode
|
||||
);
|
||||
break;
|
||||
case 'toggle-obfuscation':
|
||||
// Handle obfuscation
|
||||
clickTarget.closest('[data-obfuscation-target]').classList.toggle('_obfuscated');
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
@ -1129,7 +1158,7 @@ fcn_updateThemeColor();
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Helper to toggle story Reminder with onclick attribute.
|
||||
* Helper to toggle story Reminder.
|
||||
*
|
||||
* @since 5.0
|
||||
* @see fcn_toggleReminder()
|
||||
@ -1152,7 +1181,7 @@ function fcn_inlineToggleReminder(storyId) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to toggle story Follow with onclick attribute.
|
||||
* Helper to toggle story Follow.
|
||||
*
|
||||
* @since 5.0
|
||||
* @see fcn_toggleFollow()
|
||||
@ -1175,7 +1204,7 @@ function fcn_inlineToggleFollow(storyId) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to toggle story checkmark with onclick attribute.
|
||||
* Helper to toggle story checkmark.
|
||||
*
|
||||
* @since 5.0
|
||||
* @see fcn_toggleCheckmark()
|
||||
|
@ -909,3 +909,32 @@ function fcn_getCommentForm() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// EVENT DELEGATES
|
||||
// =============================================================================
|
||||
|
||||
_$('.fictioneer-comments')?.addEventListener('click', event => {
|
||||
const clickTarget = event.target.closest('[data-click]'),
|
||||
clickAction = clickTarget?.dataset.click;
|
||||
|
||||
if (!clickAction) return;
|
||||
|
||||
switch (clickAction) {
|
||||
case 'submit-inline-comment-edit':
|
||||
fcn_submitInlineCommentEdit(clickTarget);
|
||||
break;
|
||||
case 'cancel-inline-comment-edit':
|
||||
fcn_cancelInlineCommentEdit(clickTarget);
|
||||
break;
|
||||
case 'trigger-inline-comment-edit':
|
||||
fcn_triggerInlineCommentEdit(clickTarget);
|
||||
break;
|
||||
case 'delete-my-comment':
|
||||
fcn_deleteMyComment(clickTarget);
|
||||
break;
|
||||
case 'flag-comment':
|
||||
fcn_flagComment(clickTarget);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user