| 1 |
/* global jQuery */ |
| 2 |
|
| 3 |
( function ( wp, $ ) { |
| 4 |
'use strict'; |
| 5 |
|
| 6 |
if ( ! wp ) { |
| 7 |
return; |
| 8 |
} |
| 9 |
|
| 10 |
const admin = { |
| 11 |
/** |
| 12 |
* Cache. |
| 13 |
* |
| 14 |
* @since 1.0.0 |
| 15 |
*/ |
| 16 |
cache() { |
| 17 |
this.els = {}; |
| 18 |
this.vars = {}; |
| 19 |
this.els.$required = $( '[name="woo_additional_terms_options[required]"]' ); |
| 20 |
this.els.$error = $( '[name="woo_additional_terms_options[error]"]' ); |
| 21 |
}, |
| 22 |
|
| 23 |
/** |
| 24 |
* Initialize. |
| 25 |
* |
| 26 |
* @since 1.0.0 |
| 27 |
*/ |
| 28 |
init() { |
| 29 |
this.cache(); |
| 30 |
this.bindEvents(); |
| 31 |
this.handleRequiredToggle(); // Check on page load. |
| 32 |
}, |
| 33 |
|
| 34 |
/** |
| 35 |
* Bind events. |
| 36 |
* |
| 37 |
* @since 1.0.0 |
| 38 |
* |
| 39 |
* @return {void} |
| 40 |
*/ |
| 41 |
bindEvents() { |
| 42 |
this.els.$required.on( 'change', this.handleRequiredToggle ); |
| 43 |
}, |
| 44 |
|
| 45 |
/** |
| 46 |
* Handle required toggle. |
| 47 |
* |
| 48 |
* @since 1.0.0 |
| 49 |
* |
| 50 |
* @return {void} |
| 51 |
*/ |
| 52 |
handleRequiredToggle() { |
| 53 |
const isChecked = admin.els.$required.is( ':checked' ); |
| 54 |
admin.els.$error.closest( 'tr' ).toggle( isChecked ); |
| 55 |
}, |
| 56 |
}; |
| 57 |
|
| 58 |
admin.init(); |
| 59 |
} )( window.wp, jQuery ); |
| 60 |
|