Skip to content

Commit

Permalink
* Rename copy link to duplicate
Browse files Browse the repository at this point in the history
* Add button / icon that show / hide on hover / blur and let user copy code to the clipboard
  • Loading branch information
MaximilianoRicoTabo committed Dec 16, 2024
1 parent 3956e82 commit 8a98984
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
23 changes: 19 additions & 4 deletions classes/class-pmpro-discount-code-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ public function column_discount_code( $item ) {

?>
<strong><a title="<?php echo esc_attr( sprintf( __( 'Edit Code: %s', 'paid-memberships-pro' ), $item->id ) ); ?>" href="<?php echo esc_url( add_query_arg( array( 'page' => 'pmpro-discountcodes', 'edit' => $item->id ), admin_url('admin.php' ) ) ); ?>"><?php echo esc_html( $item->code ); ?></a></strong>
<button title="<?php echo esc_attr__('Copy code to the clipboard', 'paid-memberships-pro' ) ?>" type="button"
class="pmpro_copy_discount_code button-link edit-filters" style="display:none">
<span class="dashicons dashicons-clipboard" aria-hidden="true"></span>
</button>
<div class="row-actions">
<?php
$delete_text = esc_html(
Expand Down Expand Up @@ -410,10 +414,21 @@ public function column_discount_code( $item ) {
esc_html__( 'Edit', 'paid-memberships-pro' )
),
'copy' => sprintf(
'<button type="button" title="%1$s" class="%2$s">%3$s</button>',
esc_attr__( 'Copy code to the clipboard', 'paid-memberships-pro' ),
esc_attr__('pmpro_copy_discount_code button-link edit-filters', 'paid-memberships-pro'),
esc_html__( 'Copy', 'paid-memberships-pro' )

'<a title="%1$s" href="%2$s">%3$s</a>',
esc_attr__( 'Copy', 'paid-memberships-pro' ),
esc_url(
add_query_arg(
[
'page' => 'pmpro-discountcodes',
'edit' => - 1,
'copy' => $item->id,
],
admin_url( 'admin.php' )
)
),
esc_html__( 'Duplicate', 'paid-memberships-pro' )

),
'delete' => sprintf(
'<a title="%1$s" href="%2$s">%3$s</a>',
Expand Down
11 changes: 11 additions & 0 deletions css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,17 @@ table.pmprommpu_levels tr.remove_level td {background: #F2DEDE; }
-moz-osx-font-smoothing: grayscale;
}

.pmpro_admin tr td button.pmpro_copy_discount_code .dashicons:not(.button .dashicons) {
padding-top: unset;
font-size: 14px;
line-height: 1.4;
}

.pmpro_admin tr td button.pmpro_copy_discount_code:hover {
color: #043959;
}


/**
* Payment Settings
*/
Expand Down
33 changes: 29 additions & 4 deletions js/pmpro-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1004,20 +1004,45 @@ jQuery(document).ready(function () {
});

jQuery(document).ready(function ($) {

/**
* If it's mouseenter show the clipboard icon hider otherwise
*
* @param {Event} evt The event object
* @returns {void}
* @since TBD
*/
$('table.discountcodes tr').on( "mouseenter mouseleave focus", function ( evt ) {
$(this).find('td.column-discount_code .pmpro_copy_discount_code').hide();
if (evt.type === 'mouseenter' ) {
$(this).find('.pmpro_copy_discount_code').show();
}
});

/**
* If focus on the code show the clipboard icon for accessibility sake
*
* @param {Event} evt The event object
* @returns {void}
* @since TBD
*/
$('td.column-discount_code a').on( "focus", function ( evt ) {
$(this).closest( 'td' ).find( '.pmpro_copy_discount_code' ).show();
});

/**
* Copy Discount Code to Clipboard
*
* @param {Event} event The click event
* @param {Event} evt The click event
* @returns {void}
* @since TBD
*/
$('.pmpro_copy_discount_code').on('click', function (event) {
$('.pmpro_copy_discount_code').on('click', function ( evt ) {
// Find first link text
const code = $(this).closest('td').find('a').first().text();

// Check for Clipboard API support
// Bail if Clipboard API isn't supported
if ( ! navigator.clipboard ) {
console.error('Navigator Clipboard API not supported');
return;
}

Expand Down

0 comments on commit 8a98984

Please sign in to comment.