PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.11
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.11
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / assets / js / charitable-notices.js

charitable-notices.js in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.11, at assets/js/charitable-notices.js

119 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global jQuery, userSettings */
2
3 /**
4 * WordPress dependencies
5 */
6 import domReady from '@wordpress/dom-ready';
7
8 /**
9 * Opens the "Upgrade to Pro" menu item in a new tab.
10 */
11 function upgradeToProLink() {
12 const upgradeLinkEl = document.querySelector(
13 '#adminmenu a[href^="https://wpcharitable.com/lite-vs-pro"]'
14 );
15
16 if ( ! upgradeLinkEl ) {
17 return;
18 }
19
20 upgradeLinkEl.setAttribute( 'target', '_blank' );
21 }
22
23 /**
24 * Binds navigation buttons/links in the "Five Star Rating" admin notice.
25 */
26 function fiveStarRatingNotice() {
27 const steps = document.querySelectorAll(
28 '.charitable-admin-notice-five-star-rating'
29 );
30
31 steps.forEach( ( stepEl ) => {
32 const navigationEls = stepEl.querySelectorAll( '[data-navigate]' );
33
34 if ( ! navigationEls ) {
35 return;
36 }
37
38 navigationEls.forEach( ( navigationEl ) => {
39 navigationEl.addEventListener( 'click', ( { target } ) => {
40 const step = target.dataset.navigate;
41 const stepToShow = document.querySelector(
42 `.charitable-admin-notice-five-star-rating[data-step="${ step }"]`
43 );
44 const stepsToHide = document.querySelectorAll(
45 `.charitable-admin-notice-five-star-rating:not([data-step="${ step }"])`
46 );
47
48 if ( stepToShow ) {
49 stepToShow.style.display = 'block';
50 }
51
52 if ( stepsToHide.length > 0 ) {
53 stepsToHide.forEach( ( stepToHide ) => {
54 stepToHide.style.display = 'none';
55 } );
56 }
57 } );
58 } );
59 } );
60 }
61
62 /**
63 * Handle AJAX dismissal of notices.
64 *
65 * Uses jQuery because the `.notice-dismiss` button is added to the DOM
66 * via jQuery when the notice loads.
67 */
68 domReady( () => {
69 fiveStarRatingNotice();
70 upgradeToProLink();
71
72 jQuery( '.charitable-notice' ).each( function () {
73 const notice = jQuery( this );
74 const noticeId = notice.data( 'id' );
75 const nonce = notice.data( 'nonce' );
76 const lifespan = notice.data( 'lifespan' );
77
78 notice.on( 'click', '.notice-dismiss, .charitable-notice-dismiss', () => {
79 wp.ajax.send( 'charitable_dismiss_admin_notice', {
80 data: {
81 notice_id: noticeId,
82 nonce,
83 lifespan,
84 },
85 success() {
86 notice.slideUp( 'fast' );
87
88 // Remove previously set "seen" local storage.
89 const { uid = 0 } = userSettings;
90 const seenKey = `charitable-notice-${ noticeId }-seen-${ uid }`;
91 window.localStorage.removeItem( seenKey );
92 },
93 } );
94 } );
95 } );
96
97 // Move "Top of Page" promos to the top of content (before Help/Screen Options).
98 const topOfPageNotice = jQuery( '.charitable-admin-notice-top-of-page' );
99
100 if ( topOfPageNotice.length > 0 ) {
101 const topOfPageNoticeEl = topOfPageNotice.detach();
102
103 jQuery( '#wpbody-content' ).prepend( topOfPageNoticeEl );
104
105 const { uid = 0 } = userSettings;
106 const noticeId = topOfPageNoticeEl.data( 'id' );
107 const seenKey = `charitable-notice-${ noticeId }-seen-${ uid }`;
108
109 if ( window.localStorage.getItem( seenKey ) ) {
110 topOfPageNoticeEl.show();
111 } else {
112 setTimeout( () => {
113 window.localStorage.setItem( seenKey, true );
114 topOfPageNotice.slideDown();
115 }, 1500 );
116 }
117 }
118 } );
119