| 1 |
/* global jQuery, ajaxurl, woo_additional_terms_params */ |
| 2 |
|
| 3 |
( function ( wp, $, ajaxurl, l10n ) { |
| 4 |
'use strict'; |
| 5 |
|
| 6 |
if ( ! wp ) { |
| 7 |
return; |
| 8 |
} |
| 9 |
|
| 10 |
const dismiss = { |
| 11 |
/** |
| 12 |
* Cache. |
| 13 |
* |
| 14 |
* @since 1.6.0 |
| 15 |
*/ |
| 16 |
cache() { |
| 17 |
this.vars = {}; |
| 18 |
this.vars.dismiss = '.notice[id^="woo-additional-terms-dismiss"] [class*="notice-dismiss"]'; |
| 19 |
this.vars.rated = '#woo-additional-terms-dismiss-rate .already-rated'; |
| 20 |
}, |
| 21 |
|
| 22 |
/** |
| 23 |
* Initialize. |
| 24 |
* |
| 25 |
* @since 1.6.0 |
| 26 |
*/ |
| 27 |
init() { |
| 28 |
this.cache(); |
| 29 |
this.bindEvents(); |
| 30 |
}, |
| 31 |
|
| 32 |
/** |
| 33 |
* Bind events. |
| 34 |
* |
| 35 |
* @since 1.6.0 |
| 36 |
*/ |
| 37 |
bindEvents() { |
| 38 |
$( document.body ) |
| 39 |
.on( 'click', this.vars.dismiss, this.handleOnDismiss ) |
| 40 |
.on( 'click', this.vars.rated, ( event ) => this.handleOnDismiss( event, 'rated' ) ); |
| 41 |
}, |
| 42 |
|
| 43 |
/** |
| 44 |
* Handle on dismiss. |
| 45 |
* |
| 46 |
* @since 1.6.0 |
| 47 |
* |
| 48 |
* @param {Object} event Event object. |
| 49 |
* @param {string} action Action to perform. |
| 50 |
*/ |
| 51 |
handleOnDismiss( event, action = '' ) { |
| 52 |
const $this = $( event.target ); |
| 53 |
|
| 54 |
if ( ! $this.attr( 'href' ) ) { |
| 55 |
event.preventDefault(); |
| 56 |
} |
| 57 |
|
| 58 |
$.ajax( { |
| 59 |
type: 'POST', |
| 60 |
url: ajaxurl, |
| 61 |
dataType: 'json', |
| 62 |
data: { |
| 63 |
_ajax_nonce: l10n.dismiss_nonce, |
| 64 |
action: `woo_additional_terms_dismiss_${ action || $this.closest( '.notice' ).data( 'action' ) }`, |
| 65 |
}, |
| 66 |
} ).always( () => { |
| 67 |
$this.closest( 'div.notice:visible' ).hide(); |
| 68 |
} ); |
| 69 |
}, |
| 70 |
}; |
| 71 |
|
| 72 |
dismiss.init(); |
| 73 |
} )( window.wp, jQuery, ajaxurl, woo_additional_terms_params ); |
| 74 |
|