| 1 |
/** |
| 2 |
* Charitable External Banner |
| 3 |
* |
| 4 |
* Handles positioning, display, and dismissal of Charitable banners |
| 5 |
* on non-Charitable admin screens. |
| 6 |
* |
| 7 |
* @since 1.8.10 |
| 8 |
*/ |
| 9 |
( function( $ ) { |
| 10 |
|
| 11 |
$( document ).ready( function() { |
| 12 |
|
| 13 |
var $banner = $( '.charitable-external-banner' ); |
| 14 |
|
| 15 |
if ( ! $banner.length ) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
// Reposition the banner before the main content area. |
| 20 |
// GiveWP React pages use root divs like #give-admin-campaigns-root. |
| 21 |
// Traditional pages use .wrap containers. |
| 22 |
var $target = $( '#wpbody-content' ).children( '[id^="give-admin-"], [id="reports-app"], .wrap' ).first(); |
| 23 |
|
| 24 |
if ( $target.length ) { |
| 25 |
$banner.detach().insertBefore( $target ); |
| 26 |
} else { |
| 27 |
// Fallback: prepend to #wpbody-content. |
| 28 |
$banner.detach().prependTo( '#wpbody-content' ); |
| 29 |
} |
| 30 |
|
| 31 |
// Slide the banner down. |
| 32 |
var bannerId = $banner.data( 'banner-id' ); |
| 33 |
var seenKey = 'charitable-ext-banner-' + bannerId + '-seen'; |
| 34 |
|
| 35 |
if ( window.localStorage.getItem( seenKey ) ) { |
| 36 |
$banner.show(); |
| 37 |
} else { |
| 38 |
setTimeout( function() { |
| 39 |
window.localStorage.setItem( seenKey, true ); |
| 40 |
$banner.slideDown( 300 ); |
| 41 |
}, 800 ); |
| 42 |
} |
| 43 |
|
| 44 |
// Dismiss handler. |
| 45 |
$banner.on( 'click', '.charitable-external-banner-dismiss', function( e ) { |
| 46 |
e.preventDefault(); |
| 47 |
|
| 48 |
var nonce = $banner.data( 'nonce' ); |
| 49 |
|
| 50 |
$.ajax( { |
| 51 |
type: 'POST', |
| 52 |
url: charitable_external_banner.ajaxurl, |
| 53 |
data: { |
| 54 |
action: 'charitable_dismiss_external_banner', |
| 55 |
banner_id: bannerId, |
| 56 |
nonce: nonce, |
| 57 |
}, |
| 58 |
dataType: 'json', |
| 59 |
success: function() { |
| 60 |
$banner.slideUp( 'fast', function() { |
| 61 |
$banner.remove(); |
| 62 |
} ); |
| 63 |
window.localStorage.removeItem( seenKey ); |
| 64 |
}, |
| 65 |
} ); |
| 66 |
} ); |
| 67 |
} ); |
| 68 |
|
| 69 |
} )( jQuery ); |
| 70 |
|