fix(single): author card follow and identity parity
Add follow CTA to after-box author card, wrap bar label in span, and harden follow.js label updates when span is missing.
This commit is contained in:
1 parent
2c31da1454
commit
9b98080daf
3 files changed
+32
-4
No files matched your search
+14
-2
@@ -68,16 +68,28 @@
|
|||||||
function updateFollowButton(btn, isFollowing, count) {
|
function updateFollowButton(btn, isFollowing, count) {
|
||||||
var icon = btn.querySelector('i');
|
var icon = btn.querySelector('i');
|
||||||
var text = btn.querySelector('span');
|
var text = btn.querySelector('span');
|
||||||
|
function setLabel(label) {
|
||||||
|
if (text) {
|
||||||
|
text.textContent = label;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Fallback when markup has bare text nodes next to the icon.
|
||||||
|
var nodes = Array.prototype.slice.call(btn.childNodes);
|
||||||
|
var textNode = nodes.filter(function (n) { return n.nodeType === 3 && n.textContent.trim() !== ''; })[0];
|
||||||
|
if (textNode) {
|
||||||
|
textNode.textContent = ' ' + label + ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isFollowing) {
|
if (isFollowing) {
|
||||||
btn.classList.add('is-following');
|
btn.classList.add('is-following');
|
||||||
if (icon) icon.className = 'fas fa-heart';
|
if (icon) icon.className = 'fas fa-heart';
|
||||||
if (text) text.textContent = '已关注';
|
setLabel('已关注');
|
||||||
btn.title = '点击取消关注';
|
btn.title = '点击取消关注';
|
||||||
} else {
|
} else {
|
||||||
btn.classList.remove('is-following');
|
btn.classList.remove('is-following');
|
||||||
if (icon) icon.className = 'far fa-heart';
|
if (icon) icon.className = 'far fa-heart';
|
||||||
if (text) text.textContent = '关注';
|
setLabel('关注');
|
||||||
btn.title = '关注该用户';
|
btn.title = '关注该用户';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -321,13 +321,15 @@ if (!function_exists('aksrt_single_render_author_card')) :
|
|||||||
'order' => 'DESC',
|
'order' => 'DESC',
|
||||||
'no_found_rows' => true,
|
'no_found_rows' => true,
|
||||||
]);
|
]);
|
||||||
|
$is_self = is_user_logged_in() && get_current_user_id() === $author_id;
|
||||||
|
$login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(get_permalink());
|
||||||
?>
|
?>
|
||||||
<div class="user-card author zib-widget">
|
<div class="user-card author zib-widget">
|
||||||
<div class="card-content mt10 relative">
|
<div class="card-content mt10 relative">
|
||||||
<div class="user-content">
|
<div class="user-content">
|
||||||
<div class="user-avatar"><?php echo $avatar; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
|
<div class="user-avatar"><?php echo $avatar; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
|
||||||
<div class="user-info mt20 mb10">
|
<div class="user-info mt20 mb10">
|
||||||
<div class="user-name flex jc">
|
<div class="user-name flex jc ac">
|
||||||
<a class="display-name" href="<?php echo esc_url($author_url); ?>"><?php echo esc_html($author_name); ?></a>
|
<a class="display-name" href="<?php echo esc_url($author_url); ?>"><?php echo esc_html($author_name); ?></a>
|
||||||
<?php if ($identity_chips !== '') : ?>
|
<?php if ($identity_chips !== '') : ?>
|
||||||
<?php echo $identity_chips; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
<?php echo $identity_chips; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||||
@@ -337,6 +339,17 @@ if (!function_exists('aksrt_single_render_author_card')) :
|
|||||||
<div class="user-desc mt10 muted-2-color em09"><?php echo esc_html($bio); ?></div>
|
<div class="user-desc mt10 muted-2-color em09"><?php echo esc_html($bio); ?></div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<div class="user-btns mt20">
|
<div class="user-btns mt20">
|
||||||
|
<?php if (!$is_self) : ?>
|
||||||
|
<?php if (is_user_logged_in()) : ?>
|
||||||
|
<button type="button" class="but pw-1em mr6 c-red follow" data-aksrt-follow="<?php echo (int) $author_id; ?>">
|
||||||
|
<i class="fa fa-heart em09" aria-hidden="true"></i> <span><?php esc_html_e('关注', 'aksrt'); ?></span>
|
||||||
|
</button>
|
||||||
|
<?php else : ?>
|
||||||
|
<a href="<?php echo esc_url($login_url); ?>" class="but pw-1em mr6 c-red follow">
|
||||||
|
<i class="fa fa-heart em09" aria-hidden="true"></i> <span><?php esc_html_e('关注', 'aksrt'); ?></span>
|
||||||
|
</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endif; ?>
|
||||||
<a class="but pw-1em mr6 jb-blue" href="<?php echo esc_url($author_url); ?>"><?php esc_html_e('个人主页', 'aksrt'); ?></a>
|
<a class="but pw-1em mr6 jb-blue" href="<?php echo esc_url($author_url); ?>"><?php esc_html_e('个人主页', 'aksrt'); ?></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -351,11 +364,14 @@ if (!function_exists('aksrt_single_render_author_card')) :
|
|||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
<?php else : ?>
|
||||||
|
<div class="user-card-posts mt10 muted-2-color em09 text-center"><?php esc_html_e('暂无更多文章', 'aksrt'); ?></div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
if (!function_exists('aksrt_single_render_prevnext')) :
|
if (!function_exists('aksrt_single_render_prevnext')) :
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ $identity_chips = function_exists('aksrt_render_user_identity_chips')
|
|||||||
<?php if (!$is_self) : ?>
|
<?php if (!$is_self) : ?>
|
||||||
<?php if (is_user_logged_in()) : ?>
|
<?php if (is_user_logged_in()) : ?>
|
||||||
<button type="button" class="px12-sm ml10 follow but c-red" data-aksrt-follow="<?php echo (int) $author_id; ?>">
|
<button type="button" class="px12-sm ml10 follow but c-red" data-aksrt-follow="<?php echo (int) $author_id; ?>">
|
||||||
<i class="fa fa-heart em09" aria-hidden="true"></i> <?php esc_html_e('关注', 'aksrt'); ?>
|
<i class="fa fa-heart em09" aria-hidden="true"></i> <span><?php esc_html_e('关注', 'aksrt'); ?></span>
|
||||||
</button>
|
</button>
|
||||||
<?php if ($aksrt_pm_on && $aksrt_msg_url !== '') : ?>
|
<?php if ($aksrt_pm_on && $aksrt_msg_url !== '') : ?>
|
||||||
<a href="<?php echo esc_url(add_query_arg('msg_type', 'conversation', $aksrt_msg_url)); ?>" class="ml6 but c-blue px12-sm">
|
<a href="<?php echo esc_url(add_query_arg('msg_type', 'conversation', $aksrt_msg_url)); ?>" class="ml6 but c-blue px12-sm">
|
||||||
|
|||||||
Reference in new issue
Block a user