[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 // Use the bp global. 2 window.bp = window.bp || {}; 3 4 /** 5 * Use an XHR request to dismiss admin notices. 6 * 7 * @since 10.0.0 8 */ 9 bp.DismissibleAdminNotices = class { 10 constructor( settings ) { 11 this.settings = settings || {}; 12 } 13 14 start() { 15 const { url, nonce } = this.settings; 16 17 if ( ! url || ! nonce ) { 18 return; 19 } 20 21 document.querySelectorAll( '.bp-is-dismissible' ).forEach( ( notice ) => { 22 notice.addEventListener( 'click', ( event ) => { 23 event.preventDefault(); 24 25 const noticeLink = event.target; 26 if ( noticeLink.classList.contains( 'loading' ) ) { 27 return; 28 } 29 30 // Prevent multiple clicks. 31 noticeLink.classList.add( 'loading' ); 32 33 // Set the notice ID & notice container. 34 const { notice_id } = noticeLink.dataset; 35 const noticeContainer = noticeLink.closest( '.bp-notice-container' ); 36 37 // Set notice headers. 38 const noticeHeaders = new Headers( { 39 'X-BP-Nonce' : nonce, 40 } ); 41 42 // Set notice data. 43 const noticeData = new FormData(); 44 noticeData.append( 'action', 'bp_dismiss_notice' ); 45 noticeData.append( 'notice_id', notice_id ); 46 47 fetch( url, { 48 method: 'POST', 49 headers: noticeHeaders, 50 body: noticeData, 51 } ).then( ( response ) => { 52 return response.json(); 53 } ).then( ( data ) => { 54 const { success } = data; 55 56 if ( success ) { 57 noticeContainer.remove(); 58 } else { 59 noticeLink.classList.remove( 'loading' ); 60 } 61 } ); 62 } ); 63 } ); 64 } 65 } 66 67 const settings = window.bpDismissibleAdminNoticesSettings || {}; 68 const bpDismissibleAdminNotices = new bp.DismissibleAdminNotices( settings ); 69 70 if ( 'loading' === document.readyState ) { 71 document.addEventListener( 'DOMContentLoaded', bpDismissibleAdminNotices.start() ); 72 } else { 73 bpDismissibleAdminNotices.start(); 74 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri May 5 01:01:24 2023 | Cross-referenced by PHPXref 0.7.1 |