| 1 |
/** |
| 2 |
* @version 1.0 |
| 3 |
* @desciption Dismiss Notices - Ajax handler |
| 4 |
* @usage Admin panel |
| 5 |
* @author wpdevelop |
| 6 |
* |
| 7 |
* @web-site https://oplugins.com/ |
| 8 |
* @email [email protected] |
| 9 |
* |
| 10 |
* @modified 2017-04-23 |
| 11 |
*/ |
| 12 |
|
| 13 |
/** Ajax Request - Dismiss */ |
| 14 |
jQuery( function ( $ ) { // Shortcut to jQuery(document).ready(function(){ ... }); |
| 15 |
|
| 16 |
jQuery( '.wpbm_is_dismissible' ).on( 'click', '.wpbm_dismiss', function ( event ) { // This delegated event, can be run, when DOM element added after page loaded |
| 17 |
|
| 18 |
var jq_el = jQuery( this ).closest( '.wpbm_is_dismissible' ); // Get dismissible HTML element |
| 19 |
|
| 20 |
var params_obj = {}; |
| 21 |
params_obj.id = jq_el.attr( 'id' ); |
| 22 |
params_obj.nonce = jq_el.attr( 'data-nonce' ); |
| 23 |
params_obj.user_id = jq_el.attr( 'data-user-id' ); |
| 24 |
|
| 25 |
jQuery.post( wpbm_ajaxurl, { |
| 26 |
action: 'WPBM_DISMISS', |
| 27 |
user_id: params_obj.user_id , |
| 28 |
nonce: params_obj.nonce, |
| 29 |
element_id: params_obj.id, |
| 30 |
is_closed: 1 |
| 31 |
}, |
| 32 |
function ( response_data, textStatus, jqXHR ) { // success |
| 33 |
// console.log( response_data ); console.log( textStatus); console.log( jqXHR ); // Debug |
| 34 |
// jQuery( '#ajax_respond' ).html( response_data ); // For ability to show response, add such DIV element to page |
| 35 |
} |
| 36 |
).fail( function ( jqXHR, textStatus, errorThrown ) { if ( window.console && window.console.log ){ console.log( 'Ajax_Error', jqXHR, textStatus, errorThrown ); } }) |
| 37 |
// .done( function ( data, textStatus, jqXHR ) { if ( window.console && window.console.log ){ console.log( 'second success', data, textStatus, jqXHR ); } }) |
| 38 |
// .always( function ( data_jqXHR, textStatus, jqXHR_errorThrown ) { if ( window.console && window.console.log ){ console.log( 'always finished', data_jqXHR, textStatus, jqXHR_errorThrown ); } }) |
| 39 |
; |
| 40 |
|
| 41 |
}); |
| 42 |
|
| 43 |
}); |
| 44 |
|
| 45 |
|
| 46 |
/* Hide */ |
| 47 |
jQuery( function ( $ ) { // Shortcut to jQuery(document).ready(function(){ ... }); |
| 48 |
|
| 49 |
jQuery( '.wpbm_is_hideable' ).on( 'click', '.wpbm_dismiss', function ( event ) { // This delegated event, can be run, when DOM element added after page loaded |
| 50 |
|
| 51 |
var jq_el = jQuery( this ).closest( '.wpbm_is_hideable' ); // Get hideable HTML element |
| 52 |
|
| 53 |
jq_el.hide(); |
| 54 |
|
| 55 |
}); |
| 56 |
|
| 57 |
}); |