| 1 |
( function( $ ) { |
| 2 |
const dismissNotice = function dismissNotice( notice, options ) { |
| 3 |
const hooks = wp.hooks; |
| 4 |
|
| 5 |
options = $.extend( { el: null }, options || {} ); |
| 6 |
|
| 7 |
hooks && hooks.doAction( 'before-dismiss-notice', 'LP', notice, options ); |
| 8 |
$.ajax( { |
| 9 |
url: '', |
| 10 |
data: $.extend( { 'lp-dismiss-notice': notice }, options.data || {} ), |
| 11 |
dataType: 'text', |
| 12 |
success: ( response ) => { |
| 13 |
response = LP.parseJSON( response ); |
| 14 |
|
| 15 |
if ( response.dismissed === notice ) { |
| 16 |
$( options.el ).fadeOut(); |
| 17 |
} |
| 18 |
|
| 19 |
hooks && hooks.doAction( 'dismissed-notice', 'LP', notice, options ); |
| 20 |
}, |
| 21 |
} ); |
| 22 |
}; |
| 23 |
|
| 24 |
$( document ).on( 'click', '.lp-notice [data-dismiss-notice]', function() { |
| 25 |
const data = $( this ).data(); |
| 26 |
const notice = data.dismissNotice; |
| 27 |
|
| 28 |
delete data.dismissNotice; |
| 29 |
|
| 30 |
dismissNotice( notice, { data, el: $( this ).closest( '.lp-notice' ) } ); |
| 31 |
} ); |
| 32 |
}( jQuery ) ); |
| 33 |
|