|
89 | 89 | return true; |
90 | 90 | } |
91 | 91 |
|
| 92 | + /** |
| 93 | + * Create a table row for a blocked term. |
| 94 | + * |
| 95 | + * @param {string} type - The type of block (domain or keyword) |
| 96 | + * @param {string} value - The blocked value |
| 97 | + * @param {string} context - The context (user or site) |
| 98 | + * @return {jQuery} The constructed table row |
| 99 | + */ |
| 100 | + function createBlockedTermRow( type, value, context ) { |
| 101 | + var $button = $( '<button>', { |
| 102 | + type: 'button', |
| 103 | + 'class': 'button button-small remove-' + context + '-block-btn', |
| 104 | + 'data-type': type, |
| 105 | + 'data-value': value, |
| 106 | + text: __( 'Remove', 'activitypub' ) |
| 107 | + } ); |
| 108 | + |
| 109 | + return $( '<tr>' ).append( $( '<td>' ).text( value ), $( '<td>' ).append( $button ) ); |
| 110 | + } |
| 111 | + |
92 | 112 | /** |
93 | 113 | * Helper function to add a blocked term to the UI |
94 | 114 | */ |
|
104 | 124 | table = $( '<table class="widefat striped activitypub-blocked-' + type + '" role="presentation" style="max-width: 500px; margin: 15px 0;"><tbody></tbody></table>' ); |
105 | 125 | container.find( '#new_user_' + type ).closest( '.add-user-block-form' ).before( table ); |
106 | 126 | } |
107 | | - table.append( '<tr><td>' + value + '</td><td style="width: 80px;"><button type="button" class="button button-small remove-user-block-btn" data-type="' + type + '" data-value="' + value + '">Remove</button></td></tr>' ); |
| 127 | + table.find( 'tbody' ).append( createBlockedTermRow( type, value, context ) ); |
108 | 128 | } else if ( context === 'site' ) { |
109 | 129 | // For site moderation, add to the table inside the details element |
110 | 130 | var details = $( '.activitypub-site-block-details[data-type="' + type + '"]' ); |
|
116 | 136 | details.find( 'summary' ).after( table ); |
117 | 137 | } |
118 | 138 |
|
119 | | - table.find( 'tbody' ).append( '<tr><td>' + value + '</td><td><button type="button" class="button button-small remove-site-block-btn" data-type="' + type + '" data-value="' + value + '">Remove</button></td></tr>' ); |
| 139 | + table.find( 'tbody' ).append( createBlockedTermRow( type, value, context ) ); |
120 | 140 |
|
121 | 141 | updateSiteBlockSummary( type ); |
122 | 142 | } |
|
0 commit comments