| 1 |
( function( $ ){ |
| 2 |
|
| 3 |
/** |
| 4 |
* Binds navigation buttons/links in the "Five Star Rating" admin notice. |
| 5 |
*/ |
| 6 |
function fiveStarRatingNotice() { |
| 7 |
const steps = document.querySelectorAll( |
| 8 |
'.charitable-admin-notice-five-star-rating' |
| 9 |
); |
| 10 |
|
| 11 |
steps.forEach( ( stepEl ) => { |
| 12 |
const navigationEls = stepEl.querySelectorAll( '[data-navigate]' ); |
| 13 |
|
| 14 |
if ( ! navigationEls ) { |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
navigationEls.forEach( ( navigationEl ) => { |
| 19 |
navigationEl.addEventListener( 'click', ( { target } ) => { |
| 20 |
const step = target.dataset.navigate; |
| 21 |
const stepToShow = document.querySelector( |
| 22 |
`.charitable-admin-notice-five-star-rating[data-step="${ step }"]` |
| 23 |
); |
| 24 |
const stepsToHide = document.querySelectorAll( |
| 25 |
`.charitable-admin-notice-five-star-rating:not([data-step="${ step }"])` |
| 26 |
); |
| 27 |
|
| 28 |
if ( stepToShow ) { |
| 29 |
stepToShow.style.display = 'block'; |
| 30 |
} |
| 31 |
|
| 32 |
if ( stepsToHide.length > 0 ) { |
| 33 |
stepsToHide.forEach( ( stepToHide ) => { |
| 34 |
stepToHide.style.display = 'none'; |
| 35 |
} ); |
| 36 |
} |
| 37 |
} ); |
| 38 |
} ); |
| 39 |
} ); |
| 40 |
} |
| 41 |
|
| 42 |
$( document ).ready( function() { |
| 43 |
|
| 44 |
fiveStarRatingNotice(); |
| 45 |
|
| 46 |
$( '.charitable-notice.is-dismissible' ).each( function(){ |
| 47 |
var $el = $( this ), $button = $el.find( '.notice-dismiss' ); |
| 48 |
|
| 49 |
$button.on( 'click', function( event ) { |
| 50 |
event.preventDefault(); |
| 51 |
|
| 52 |
$.ajax({ |
| 53 |
type: "POST", |
| 54 |
data: { |
| 55 |
action : 'charitable_dismiss_notice', |
| 56 |
notice : $el.data( 'notice' ) |
| 57 |
}, |
| 58 |
dataType: "json", |
| 59 |
url: ajaxurl, |
| 60 |
xhrFields: { |
| 61 |
withCredentials: true |
| 62 |
}, |
| 63 |
success: function ( response ) { |
| 64 |
if ( window.console && window.console.log ) { |
| 65 |
console.log( response ); |
| 66 |
} |
| 67 |
}, |
| 68 |
error: function( error ) { |
| 69 |
if ( window.console && window.console.log ) { |
| 70 |
console.log( error ); |
| 71 |
} |
| 72 |
} |
| 73 |
}).fail(function ( response ) { |
| 74 |
if ( window.console && window.console.log ) { |
| 75 |
console.log( response ); |
| 76 |
} |
| 77 |
}); |
| 78 |
}); |
| 79 |
|
| 80 |
$el.css( 'position', 'relative' ); |
| 81 |
}); |
| 82 |
|
| 83 |
$( '.charitable-banner' ).each( function () { |
| 84 |
const banner = jQuery( this ); |
| 85 |
const bannerId = banner.data( 'id' ); |
| 86 |
const nonce = banner.data( 'nonce' ); |
| 87 |
const lifespan = banner.data( 'lifespan' ); |
| 88 |
|
| 89 |
banner.on( 'click', '.banner-dismiss, .charitable-banner-dismiss', () => { |
| 90 |
event.preventDefault(); |
| 91 |
$.ajax({ |
| 92 |
type: "POST", |
| 93 |
url: ajaxurl, |
| 94 |
data: { |
| 95 |
action: 'charitable_dismiss_admin_banner', |
| 96 |
banner_id: bannerId, |
| 97 |
nonce, |
| 98 |
lifespan, |
| 99 |
}, |
| 100 |
dataType: "json", |
| 101 |
success() { |
| 102 |
banner.slideUp( 'fast' ); |
| 103 |
|
| 104 |
// Remove previously set "seen" local storage. |
| 105 |
const uid = 0; |
| 106 |
const seenKey = `charitable-banner-${ bannerId }-seen-${ uid }`; |
| 107 |
window.localStorage.removeItem( seenKey ); |
| 108 |
}, |
| 109 |
} ); |
| 110 |
} ); |
| 111 |
} ); |
| 112 |
|
| 113 |
// Move "Top of Page" promos to the top of content (before Help/Screen Options). |
| 114 |
const topOfPageNotice = jQuery( '.charitable-admin-banner-top-of-page' ); |
| 115 |
|
| 116 |
if ( topOfPageNotice.length > 0 ) { |
| 117 |
const topOfPageNoticeEl = topOfPageNotice.detach(); |
| 118 |
|
| 119 |
jQuery( '#wpbody-content' ).prepend( topOfPageNoticeEl ); |
| 120 |
|
| 121 |
const uid = 0; |
| 122 |
const noticeId = topOfPageNoticeEl.data( 'id' ); |
| 123 |
const seenKey = `charitable-banner-${ noticeId }-seen-${ uid }`; |
| 124 |
|
| 125 |
if ( window.localStorage.getItem( seenKey ) ) { |
| 126 |
topOfPageNoticeEl.show(); |
| 127 |
} else { |
| 128 |
setTimeout( () => { |
| 129 |
window.localStorage.setItem( seenKey, true ); |
| 130 |
topOfPageNotice.slideDown(); |
| 131 |
}, 1500 ); |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
$( '.charitable-admin-notice-five-star-rating' ).each( function () { |
| 136 |
const notice = jQuery( this ); |
| 137 |
const bannerId = notice.data( 'id' ); |
| 138 |
|
| 139 |
notice.on( 'click', '.charitable-notice-dismiss', () => { |
| 140 |
$.ajax({ |
| 141 |
type: "POST", |
| 142 |
url: ajaxurl, |
| 143 |
data: { |
| 144 |
action: 'charitable_dismiss_admin_five_star_rating', |
| 145 |
banner_id: bannerId, |
| 146 |
}, |
| 147 |
success() { |
| 148 |
$('.notice-five-star-review').remove(); |
| 149 |
|
| 150 |
// Remove previously set "seen" local storage. |
| 151 |
// const uid = 0; |
| 152 |
// const seenKey = `charitable-banner-${ bannerId }-seen-${ uid }`; |
| 153 |
// window.localStorage.removeItem( seenKey ); |
| 154 |
}, |
| 155 |
} ); |
| 156 |
} ); |
| 157 |
} ); |
| 158 |
|
| 159 |
// Move "Top of Page" promos to the top of content (before Help/Screen Options). |
| 160 |
const fiveStarReviewNotice = jQuery( '.notice-five-star-review' ); |
| 161 |
|
| 162 |
if ( fiveStarReviewNotice.length > 0 ) { |
| 163 |
const fiveStarReviewNoticeEl = fiveStarReviewNotice.detach(); |
| 164 |
|
| 165 |
if ( jQuery('#screen-meta-links').length > 0 ) { |
| 166 |
jQuery( '#screen-meta-links' ).after( fiveStarReviewNoticeEl ); |
| 167 |
fiveStarReviewNoticeEl.addClass('screen-meta-space').show(); |
| 168 |
} else if ( topOfPageNotice.length > 0 ) { |
| 169 |
topOfPageNotice.after( fiveStarReviewNoticeEl ); |
| 170 |
fiveStarReviewNoticeEl.show(); |
| 171 |
} else { |
| 172 |
jQuery( '#wpbody-content' ).prepend( fiveStarReviewNoticeEl ); |
| 173 |
fiveStarReviewNoticeEl.show(); |
| 174 |
} |
| 175 |
|
| 176 |
// const uid = 0; |
| 177 |
// const noticeId = fiveStarReviewNoticeEl.data( 'id' ); |
| 178 |
// const seenKey = `charitable-banner-${ noticeId }-seen-${ uid }`; |
| 179 |
|
| 180 |
// if ( window.localStorage.getItem( seenKey ) ) { |
| 181 |
|
| 182 |
// } else { |
| 183 |
// setTimeout( () => { |
| 184 |
// window.localStorage.setItem( seenKey, true ); |
| 185 |
// fiveStarReviewNotice.slideDown(); |
| 186 |
// }, 1500 ); |
| 187 |
// } |
| 188 |
} |
| 189 |
|
| 190 |
}); |
| 191 |
|
| 192 |
} )( jQuery ); |