Optimize commend inline edit

Use template instead of putting the whole form into each comment.
This commit is contained in:
Tetrakern 2023-06-19 03:42:36 +02:00
parent a17903aa70
commit df0601c797
4 changed files with 26 additions and 11 deletions

View File

@ -78,6 +78,24 @@ $logout_url = fictioneer_get_logout_url( get_permalink() );
</ol>
<?php // <--- End HTML
// Edit template
if ( get_option( 'fictioneer_enable_user_comment_editing' ) ) {
// Start HTML ---> ?>
<template class="comment-edit-actions-template">
<div class="fictioneer-comment__edit-actions">
<button
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' ); ?>"
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" data-click="cancel-inline-comment-edit"><?php _ex( 'Cancel', 'Comment inline edit cancel button.', 'fictioneer' ); ?></button>
</div>
</template>
<?php // <--- End HTML
}
// Pagination
$pag_args = [];

View File

@ -648,16 +648,6 @@ if ( ! function_exists( 'fictioneer_theme_comment' ) ) {
<?php if ( ( $can_edit && $is_editable ) || ( $is_caching && ! $is_deleted_by_owner) ) : ?>
<div class="fictioneer-comment__edit" hidden>
<textarea class="comment-inline-edit-content"><?php echo $comment->comment_content; ?></textarea>
<div class="fictioneer-comment__edit-actions">
<button
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' ); ?>"
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" data-click="cancel-inline-comment-edit"><?php _ex( 'Cancel', 'Comment inline edit cancel button.', 'fictioneer' ); ?></button>
</div>
</div>
<?php endif; ?>
<?php

2
js/comments.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -564,6 +564,8 @@ fcn_bindAJAXCommentSubmit();
// AJAX INLINE COMMENT EDIT
// =============================================================================
const /** @const {HTMLElement} */ fcn_commentEditActionsTemplate = _$('.comment-edit-actions-template');
var /** @type {Object} */ fcn_commentEditUndos = {};
/**
@ -588,6 +590,9 @@ function fcn_triggerInlineCommentEdit(source) {
edit = red.querySelector('.fictioneer-comment__edit'),
textarea = red.querySelector('.comment-inline-edit-content');
// Append buttons
edit.appendChild(fcn_commentEditActionsTemplate.content.cloneNode(true));
// Save unedited content
fcn_commentEditUndos[red.id] = textarea.value;
@ -698,7 +703,9 @@ function fcn_cancelInlineCommentEdit(source) {
function fcn_restoreComment(target, undo = false, update = null) {
target.querySelector('.fictioneer-comment__content').hidden = false;
target.querySelector('.fictioneer-comment__edit').hidden = true;
target.querySelector('.fictioneer-comment__edit-actions')?.remove();
target.classList.remove('_editing');
if (undo && fcn_commentEditUndos[target.id]) {
target.querySelector('.comment-inline-edit-content').value = fcn_commentEditUndos[target.id];
} else if (update) {