| 1 |
/* global jQuery, ajaxurl, watVars */ |
| 2 |
|
| 3 |
( function ( wp, $ ) { |
| 4 |
'use strict'; |
| 5 |
|
| 6 |
if ( ! wp ) { |
| 7 |
return; |
| 8 |
} |
| 9 |
|
| 10 |
const watAdmin = { |
| 11 |
cache() { |
| 12 |
this.vars = {}; |
| 13 |
this.vars.rate = '#woo-additional-terms-dismiss-rate .notice-dismiss'; |
| 14 |
this.vars.rate += ', #woo-additional-terms-dismiss-rate .notice-dismiss-later'; |
| 15 |
this.vars.rated = '#woo-additional-terms-dismiss-rate .notice-dismiss-rated'; |
| 16 |
this.vars.upsell = '#woo-additional-terms-dismiss-upsell .notice-dismiss'; |
| 17 |
}, |
| 18 |
|
| 19 |
init() { |
| 20 |
this.cache(); |
| 21 |
this.bindEvents(); |
| 22 |
}, |
| 23 |
|
| 24 |
bindEvents() { |
| 25 |
$( document.body ) |
| 26 |
.on( 'click', this.vars.rate, ( event ) => this.handleOnDismiss( event, 'rate' ) ) |
| 27 |
.on( 'click', this.vars.rated, ( event ) => this.handleOnDismiss( event, 'rated' ) ) |
| 28 |
.on( 'click', this.vars.upsell, ( event ) => this.handleOnDismiss( event, 'upsell' ) ); |
| 29 |
}, |
| 30 |
|
| 31 |
handleOnDismiss( event, action ) { |
| 32 |
const $this = $( event.target ); |
| 33 |
|
| 34 |
if ( ! $this.attr( 'href' ) ) { |
| 35 |
event.preventDefault(); |
| 36 |
} |
| 37 |
|
| 38 |
$.ajax( { |
| 39 |
type: 'POST', |
| 40 |
url: ajaxurl, |
| 41 |
dataType: 'json', |
| 42 |
data: { |
| 43 |
_ajax_nonce: watVars.dismiss_nonce, |
| 44 |
action: `woo_additional_terms_dismiss_${ action }`, |
| 45 |
}, |
| 46 |
} ).always( () => { |
| 47 |
$this.closest( 'div.notice:visible' ).slideUp(); |
| 48 |
} ); |
| 49 |
}, |
| 50 |
}; |
| 51 |
|
| 52 |
watAdmin.init(); |
| 53 |
} )( window.wp, jQuery ); |
| 54 |
|