| 1 |
jQuery( document ).ready( function ( $ ) { |
| 2 |
|
| 3 |
function bbp_ajax_call( action, object, type, nonce, update_selector ) { |
| 4 |
var $data = { |
| 5 |
action : action, |
| 6 |
id : object, |
| 7 |
type : type, |
| 8 |
nonce : nonce |
| 9 |
}; |
| 10 |
|
| 11 |
$.post( bbpEngagementJS.bbp_ajaxurl, $data, function ( response ) { |
| 12 |
if ( response.success ) { |
| 13 |
$( update_selector ).html( response.content ); |
| 14 |
} else { |
| 15 |
if ( !response.content ) { |
| 16 |
response.content = bbpEngagementJS.generic_ajax_error; |
| 17 |
} |
| 18 |
window.alert( response.content ); |
| 19 |
} |
| 20 |
} ); |
| 21 |
} |
| 22 |
|
| 23 |
$( '#favorite-toggle' ).on( 'click', 'span a.favorite-toggle', function( e ) { |
| 24 |
e.preventDefault(); |
| 25 |
bbp_ajax_call( |
| 26 |
'favorite', |
| 27 |
$( this ).data( 'bbp-object-id' ), |
| 28 |
$( this ).data( 'bbp-object-type' ), |
| 29 |
$( this ).data( 'bbp-nonce' ), |
| 30 |
'#favorite-toggle' |
| 31 |
); |
| 32 |
} ); |
| 33 |
|
| 34 |
$( '#subscription-toggle' ).on( 'click', 'span a.subscription-toggle', function( e ) { |
| 35 |
e.preventDefault(); |
| 36 |
bbp_ajax_call( |
| 37 |
'subscription', |
| 38 |
$( this ).data( 'bbp-object-id' ), |
| 39 |
$( this ).data( 'bbp-object-type' ), |
| 40 |
$( this ).data( 'bbp-nonce' ), |
| 41 |
'#subscription-toggle' |
| 42 |
); |
| 43 |
} ); |
| 44 |
|
| 45 |
$( '.bbp-alert-outer' ).on( 'click', '.bbp-alert-close', function( e ) { |
| 46 |
e.preventDefault(); |
| 47 |
$( this ).closest( '.bbp-alert-outer' ).fadeOut(); |
| 48 |
} ); |
| 49 |
|
| 50 |
$( '.bbp-alert-outer' ).on( 'click', function( e ) { |
| 51 |
if ( this === e.target ) { |
| 52 |
$( this ).closest( '.bbp-alert-outer' ).fadeOut(); |
| 53 |
} |
| 54 |
} ); |
| 55 |
|
| 56 |
$( document ).keyup( function( e ) { |
| 57 |
if ( e.keyCode === 27 ) { |
| 58 |
$( '.bbp-alert-outer .bbp-alert-close' ).click(); |
| 59 |
} |
| 60 |
} ); |
| 61 |
} ); |
| 62 |
|