Skip to content

Commit

Permalink
Replace jQuery with plain JavaScript for (de)select buttons
Browse files Browse the repository at this point in the history
Fixes 'jQuery.fn.click() event shorthand is deprecated' warning
  • Loading branch information
ocean90 committed Mar 26, 2023
1 parent 44a6e42 commit 375a615
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions views/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@
</h2>
<?php endif; ?>

<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
$( '#wp_widget_disable_select_all, #wp_widget_disable_deselect_all' ).click( function() {
var isChecked = 'wp_widget_disable_select_all' === $( this ).attr( 'id' );
$( this ).parents( 'td' ).find( 'input' ).each( function() {
$( this ).get( 0 ).checked = isChecked;
} );
} );
} );
</script>

<form method="post" action="<?php echo esc_url( $form_action ); ?>" class="wp-widget-disable-form">
<?php
settings_fields( $active_tab );
Expand All @@ -66,3 +55,16 @@
?>
</form>
</div>

<script>
const toggleButtons = document.querySelectorAll( '#wp_widget_disable_select_all, #wp_widget_disable_deselect_all' );
toggleButtons.forEach( function( button ) {
button.addEventListener( 'click', function() {
const isChecked = 'wp_widget_disable_select_all' === button.id;
const inputs = button.closest( 'td' ).querySelectorAll( 'input' );
inputs.forEach( function( input ) {
input.checked = isChecked;
} );
} );
} );
</script>

0 comments on commit 375a615

Please sign in to comment.