PluginProbe ʕ •ᴥ•ʔ
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / trunk
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz vtrunk
2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.1.2 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.13.0 1.13.1 1.13.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.2 2.6.0
sureforms / admin / assets / js / notice-response.js
sureforms / admin / assets / js Last commit date
notice-response.js 1 day ago sureforms-pointer.js 5 months ago
notice-response.js
86 lines
1 /* global srfmNoticeResponse */
2 ( function () {
3 const notices = {
4 'srfm-getting-started-notice': {
5 primary: 'go_to_dashboard',
6 snooze: 'maybe_later',
7 dismiss: 'dismissed',
8 },
9 'srfm-plugin-review-notice': {
10 primary: 'rate_sureforms',
11 snooze: 'maybe_later',
12 dismiss: 'dismissed',
13 },
14 };
15
16 function getAction( el, noticeId ) {
17 const config = notices[ noticeId ];
18 if ( ! config ) {
19 return null;
20 }
21
22 if (
23 el.classList.contains( 'button-primary' ) ||
24 ( el.classList.contains( 'astra-notice-close' ) &&
25 el.getAttribute( 'target' ) === '_blank' )
26 ) {
27 return config.primary;
28 }
29 if ( el.hasAttribute( 'data-repeat-notice-after' ) ) {
30 return config.snooze;
31 }
32 if ( el.classList.contains( 'astra-notice-close' ) ) {
33 return config.dismiss;
34 }
35 return null;
36 }
37
38 function sendResponse( noticeId, button ) {
39 const body = new FormData();
40 body.append( 'action', 'srfm_notice_response' );
41 body.append( 'nonce', srfmNoticeResponse.nonce );
42 body.append( 'notice_id', noticeId );
43 body.append( 'button', button );
44
45 fetch( srfmNoticeResponse.ajaxurl, { method: 'POST', body } ).catch(
46 () => {}
47 );
48 }
49
50 // Action-item notices declare what to record on the element itself, so a new
51 // one needs no entry in the map above. Delegated from the document because
52 // these render on every admin screen, not inside one known container.
53 document.addEventListener( 'click', function ( e ) {
54 const link = e.target.closest( '[data-srfm-notice-id][data-srfm-button]' );
55 if ( ! link ) {
56 return;
57 }
58
59 const noticeId = link.getAttribute( 'data-srfm-notice-id' );
60 const button = link.getAttribute( 'data-srfm-button' );
61
62 if ( noticeId && button ) {
63 sendResponse( noticeId, button );
64 }
65 } );
66
67 Object.keys( notices ).forEach( function ( noticeId ) {
68 const container = document.getElementById( noticeId );
69 if ( ! container ) {
70 return;
71 }
72
73 container.addEventListener( 'click', function ( e ) {
74 const link = e.target.closest( 'a' );
75 if ( ! link ) {
76 return;
77 }
78
79 const action = getAction( link, noticeId );
80 if ( action ) {
81 sendResponse( noticeId, action );
82 }
83 } );
84 } );
85 }() );
86