feat(pay): show 点击复制{copy name} tooltip on the remark button
Hovering the remark gave no affordance hint that it copies anything. The
reference theme titles the same button 点击复制{copy name} and omits the
tooltip entirely when no copy name is configured.
Emit data-toggle="tooltip" with that title on both copy buttons, gated on a
non-empty copy name, and mirror it on the paid-card helper so the two
surfaces agree. Bootstrap's tooltip init already runs in auto_fun() on load,
which is where the clipboard lib is required too.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
63b5edd901
commit
7f60071460
3 files changed
+15
-1
No files matched your search
@@ -1491,7 +1491,8 @@ if (!function_exists('aksrt_get_paid_download_actions_html')) {
|
|||||||
$buttons .= '<a class="mr10 but ' . esc_attr($button_class) . '" href="' . esc_url($url) . '" target="_blank" rel="nofollow noopener">';
|
$buttons .= '<a class="mr10 but ' . esc_attr($button_class) . '" href="' . esc_url($url) . '" target="_blank" rel="nofollow noopener">';
|
||||||
$buttons .= $icon_html . esc_html($label) . '</a>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
$buttons .= $icon_html . esc_html($label) . '</a>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
if ($copy_value !== '') {
|
if ($copy_value !== '') {
|
||||||
$buttons .= '<button type="button" class="but" data-clipboard-tag="' . esc_attr($copy_key !== '' ? $copy_key : __('内容', 'aksrt')) . '" data-clipboard-text="' . esc_attr($copy_value) . '">' . esc_html($copy_label) . '</button>';
|
$tooltip = $copy_key !== '' ? ' data-toggle="tooltip" title="' . esc_attr(sprintf(__('点击复制%s', 'aksrt'), $copy_key)) . '"' : '';
|
||||||
|
$buttons .= '<button type="button" class="but"' . $tooltip . ' data-clipboard-tag="' . esc_attr($copy_key !== '' ? $copy_key : __('内容', 'aksrt')) . '" data-clipboard-text="' . esc_attr($copy_value) . '">' . esc_html($copy_label) . '</button>';
|
||||||
} elseif ($extract_code !== '') {
|
} elseif ($extract_code !== '') {
|
||||||
$buttons .= '<span class="badg">' . esc_html($extract_code) . '</span>';
|
$buttons .= '<span class="badg">' . esc_html($extract_code) . '</span>';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -390,6 +390,7 @@ if ($is_need_purchase && $user_amount > 0) {
|
|||||||
</a>
|
</a>
|
||||||
<?php if ($has_extract || $has_copy) : ?>
|
<?php if ($has_extract || $has_copy) : ?>
|
||||||
<button type="button" class="resource-download-box__btn resource-download-box__btn--extract"
|
<button type="button" class="resource-download-box__btn resource-download-box__btn--extract"
|
||||||
|
<?php if ($has_copy && $copy_key !== '') : ?>data-toggle="tooltip" title="<?php echo esc_attr(sprintf(__('点击复制%s', 'aksrt'), $copy_key)); ?>"<?php endif; ?>
|
||||||
data-clipboard-tag="<?php echo esc_attr($has_copy ? ($copy_key !== '' ? $copy_key : __('内容', 'aksrt')) : __('提取码', 'aksrt')); ?>"
|
data-clipboard-tag="<?php echo esc_attr($has_copy ? ($copy_key !== '' ? $copy_key : __('内容', 'aksrt')) : __('提取码', 'aksrt')); ?>"
|
||||||
data-clipboard-text="<?php echo esc_attr($has_copy ? $copy_val : $extract_code); ?>"
|
data-clipboard-text="<?php echo esc_attr($has_copy ? $copy_val : $extract_code); ?>"
|
||||||
><?php echo esc_html($has_extract ? $extract_code : ($copy_key !== '' ? $copy_key : __('复制内容', 'aksrt'))); ?></button>
|
><?php echo esc_html($has_extract ? $extract_code : ($copy_key !== '' ? $copy_key : __('复制内容', 'aksrt'))); ?></button>
|
||||||
|
|||||||
@@ -62,6 +62,18 @@ test('the download box renders direct anchors with inline extract codes', () =>
|
|||||||
// Mobile download bar scopes its own copy-button rule.
|
// Mobile download bar scopes its own copy-button rule.
|
||||||
assert.match(css, /\.resource-mobile-download-bar \.resource-download-box__btn--extract \{/);
|
assert.match(css, /\.resource-mobile-download-bar \.resource-download-box__btn--extract \{/);
|
||||||
|
|
||||||
|
// Hovering the remark shows 点击复制{copy name}, matching the reference theme,
|
||||||
|
// and only when a copy name exists.
|
||||||
|
assert.match(box, /\$has_copy && \$copy_key !== ''\) : \?>/);
|
||||||
|
assert.match(box, /sprintf\(__\('点击复制%s', 'aksrt'\), \$copy_key\)/);
|
||||||
|
assert.match(box, /data-toggle="tooltip"/);
|
||||||
|
const pay = read('inc/helpers/aksrt-pay.php');
|
||||||
|
assert.match(pay, /sprintf\(__\('点击复制%s', 'aksrt'\), \$copy_key\)/);
|
||||||
|
// Bootstrap tooltips must be initialized for the attribute to do anything.
|
||||||
|
const main = read('assets/js/runtime/main.js');
|
||||||
|
assert.match(main, /jQuery\("\[data-toggle='tooltip'\]"\)\.tooltip\(/);
|
||||||
|
assert.match(main, /^auto_fun\(\);/m);
|
||||||
|
|
||||||
// The login gate keeps its own anchor.
|
// The login gate keeps its own anchor.
|
||||||
assert.match(box, /\$btn_href = \$login_url;/);
|
assert.match(box, /\$btn_href = \$login_url;/);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user