| 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 |
$( '.charitable-campaign-list-banner' ).each( function () { |
| 114 |
const banner = jQuery( this ); |
| 115 |
const containerRow = banner.closest('tr.child'); |
| 116 |
const bannerId = banner.data( 'id' ); |
| 117 |
const nonce = banner.data( 'nonce' ); |
| 118 |
const lifespan = banner.data( 'lifespan' ); |
| 119 |
|
| 120 |
banner.on( 'click', '.banner-dismiss, .notice-dismiss, .charitable-close', () => { |
| 121 |
event.preventDefault(); |
| 122 |
$.ajax({ |
| 123 |
type: "POST", |
| 124 |
url: ajaxurl, |
| 125 |
data: { |
| 126 |
action: 'charitable_dismiss_admin_list_banner', |
| 127 |
banner_id: bannerId, |
| 128 |
nonce, |
| 129 |
lifespan, |
| 130 |
}, |
| 131 |
dataType: "json", |
| 132 |
success() { |
| 133 |
containerRow.fadeOut( 'fast' ); |
| 134 |
|
| 135 |
// Remove previously set "seen" local storage. |
| 136 |
const uid = 0; |
| 137 |
const seenKey = `charitable-banner-${ bannerId }-seen-${ uid }`; |
| 138 |
window.localStorage.removeItem( seenKey ); |
| 139 |
}, |
| 140 |
} ); |
| 141 |
} ); |
| 142 |
} ); |
| 143 |
|
| 144 |
// Move "Top of Page" promos to the top of content (before Help/Screen Options). |
| 145 |
const topOfPageNotice = jQuery( '.charitable-admin-banner-top-of-page' ); |
| 146 |
|
| 147 |
if ( topOfPageNotice.length > 0 ) { |
| 148 |
const topOfPageNoticeEl = topOfPageNotice.detach(); |
| 149 |
|
| 150 |
if ( jQuery( '#charitable-admin-header' ).length > 0 ) { |
| 151 |
jQuery( '#charitable-admin-header' ).before( topOfPageNoticeEl ); |
| 152 |
} else { |
| 153 |
jQuery( '#wpbody-content' ).prepend( topOfPageNoticeEl ); |
| 154 |
} |
| 155 |
|
| 156 |
const uid = 0; |
| 157 |
const noticeId = topOfPageNoticeEl.data( 'id' ); |
| 158 |
const seenKey = `charitable-banner-${ noticeId }-seen-${ uid }`; |
| 159 |
|
| 160 |
if ( window.localStorage.getItem( seenKey ) ) { |
| 161 |
topOfPageNoticeEl.show(); |
| 162 |
} else { |
| 163 |
setTimeout( () => { |
| 164 |
window.localStorage.setItem( seenKey, true ); |
| 165 |
topOfPageNotice.slideDown(); |
| 166 |
}, 1500 ); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
$( '.charitable-admin-notice-five-star-rating' ).each( function () { |
| 171 |
const notice = jQuery( this ); |
| 172 |
const bannerId = notice.data( 'id' ); |
| 173 |
|
| 174 |
notice.on( 'click', '.charitable-notice-dismiss', () => { |
| 175 |
$.ajax({ |
| 176 |
type: "POST", |
| 177 |
url: ajaxurl, |
| 178 |
data: { |
| 179 |
action: 'charitable_dismiss_admin_five_star_rating', |
| 180 |
banner_id: bannerId, |
| 181 |
}, |
| 182 |
success() { |
| 183 |
$('.notice-five-star-review').remove(); |
| 184 |
|
| 185 |
} |
| 186 |
} ); |
| 187 |
} ); |
| 188 |
} ); |
| 189 |
|
| 190 |
// Move "Top of Page" promos to the top of content (before Help/Screen Options). |
| 191 |
const fiveStarReviewNotice = jQuery( '.notice-five-star-review' ); |
| 192 |
|
| 193 |
if ( fiveStarReviewNotice.length > 0 ) { |
| 194 |
const fiveStarReviewNoticeEl = fiveStarReviewNotice.detach(), |
| 195 |
adminHeader = jQuery( '#charitable-admin-header' ); |
| 196 |
|
| 197 |
if ( jQuery('#screen-meta-links').length > 0 ) { |
| 198 |
jQuery( '#screen-meta-links' ).after( fiveStarReviewNoticeEl ); |
| 199 |
fiveStarReviewNoticeEl.addClass('screen-meta-space').show(); |
| 200 |
} else if ( adminHeader.length > 0 ) { |
| 201 |
adminHeader.after( fiveStarReviewNoticeEl ); |
| 202 |
fiveStarReviewNoticeEl.show(); |
| 203 |
} else if ( topOfPageNotice.length > 0 ) { |
| 204 |
topOfPageNotice.after( fiveStarReviewNoticeEl ); |
| 205 |
fiveStarReviewNoticeEl.show(); |
| 206 |
} else { |
| 207 |
jQuery( '#wpbody-content' ).prepend( fiveStarReviewNoticeEl ); |
| 208 |
fiveStarReviewNoticeEl.show(); |
| 209 |
} |
| 210 |
|
| 211 |
} |
| 212 |
|
| 213 |
/* #version 1.8.1.5 */ |
| 214 |
const genericCharitableNotice = jQuery( '.notice.charitable-notice' ); |
| 215 |
|
| 216 |
if ( genericCharitableNotice.length > 0 ) { |
| 217 |
const genericCharitableNoticeEl = genericCharitableNotice.detach(), |
| 218 |
adminHeader = jQuery( '#charitable-admin-header' ); |
| 219 |
|
| 220 |
if ( jQuery('#screen-meta-links').length > 0 ) { |
| 221 |
jQuery( '#screen-meta-links' ).after( genericCharitableNoticeEl ); |
| 222 |
genericCharitableNoticeEl.addClass('screen-meta-space').show(); |
| 223 |
} else if ( adminHeader.length > 0 ) { |
| 224 |
adminHeader.after( genericCharitableNoticeEl ); |
| 225 |
genericCharitableNoticeEl.show(); |
| 226 |
} else if ( topOfPageNotice.length > 0 ) { |
| 227 |
topOfPageNotice.after( genericCharitableNoticeEl ); |
| 228 |
genericCharitableNoticeEl.show(); |
| 229 |
} else { |
| 230 |
jQuery( '#wpbody-content' ).prepend( genericCharitableNoticeEl ); |
| 231 |
genericCharitableNoticeEl.show(); |
| 232 |
} |
| 233 |
|
| 234 |
} |
| 235 |
|
| 236 |
/* #version 1.8.1.6 */ |
| 237 |
|
| 238 |
/* important messages, like the one about the new dashboard */ |
| 239 |
const dashboardCharitableNotice = jQuery( '.charitable-remove-dashboard-notice, .charitable-remove-dashboard-notice-link' ); |
| 240 |
|
| 241 |
if ( dashboardCharitableNotice.length > 0 ) { |
| 242 |
const dashboardCharitableNoticeEl = dashboardCharitableNotice.closest('.charitable-important'); |
| 243 |
|
| 244 |
// update via AJAX to add the removed notice to the user meta. |
| 245 |
dashboardCharitableNotice.on( 'click', function( event ) { |
| 246 |
event.preventDefault(); |
| 247 |
|
| 248 |
$.ajax({ |
| 249 |
type: "POST", |
| 250 |
url: ajaxurl, |
| 251 |
data: { |
| 252 |
action: 'charitable_dismiss_dashboard_notice', |
| 253 |
notice_ids: dashboardCharitableNoticeEl.data( 'notice-ids' ), |
| 254 |
}, |
| 255 |
success() { |
| 256 |
// remove element from page completely. |
| 257 |
dashboardCharitableNoticeEl.remove(); |
| 258 |
}, |
| 259 |
} ); |
| 260 |
} ); |
| 261 |
|
| 262 |
} |
| 263 |
|
| 264 |
$('#charitable-growth-tools-notice').on('click', '.charitable-remove-growth-tools', function( event ) { |
| 265 |
event.preventDefault(); |
| 266 |
|
| 267 |
const dashboardRemovegrowthToolsNotice = $( this ), |
| 268 |
dashboardRemovegrowthToolsNoticeEl = dashboardRemovegrowthToolsNotice.closest('.charitable-growth-tools-notice'), |
| 269 |
dashboardRemovegrowthToolsNoticeAction = dashboardRemovegrowthToolsNoticeEl.hasClass('charitable-growth-tools-dashboard') ? 'charitable_dismiss_growth_tools_dashboard_notice' : 'charitable_dismiss_growth_tools_notice', |
| 270 |
dashboardRemovegrowthToolsNoticeNonce = dashboardRemovegrowthToolsNoticeEl.data( 'nonce' ); |
| 271 |
|
| 272 |
$.ajax({ |
| 273 |
type: "POST", |
| 274 |
url: ajaxurl, |
| 275 |
data: { |
| 276 |
action: dashboardRemovegrowthToolsNoticeAction, |
| 277 |
nonce: dashboardRemovegrowthToolsNoticeNonce, |
| 278 |
notice_type: dashboardRemovegrowthToolsNoticeEl.data( 'notice-type' ), |
| 279 |
}, |
| 280 |
success() { |
| 281 |
// fade and remove element. |
| 282 |
dashboardRemovegrowthToolsNoticeEl.fadeOut( 'fast', function() { |
| 283 |
dashboardRemovegrowthToolsNoticeEl.remove(); |
| 284 |
}); |
| 285 |
}, |
| 286 |
} ); |
| 287 |
} ); |
| 288 |
|
| 289 |
$('#charitable-growth-tools-notice').on('click', '.charitable-dashboard-notice-another-suggestion a', function( event ) { |
| 290 |
event.preventDefault(); |
| 291 |
|
| 292 |
const dashboardRemovegrowthToolsNoticeEl = $( this ).closest('.charitable-growth-tools-notice-interior'); |
| 293 |
|
| 294 |
$.ajax({ |
| 295 |
type : "POST", |
| 296 |
url : ajaxurl, |
| 297 |
data : { |
| 298 |
action: 'ajax_get_dashboard_notice_html', |
| 299 |
nonce: charitable_admin.nonce, // eslint-disable-line |
| 300 |
}, |
| 301 |
success( response ) { |
| 302 |
// if the response was successfull. |
| 303 |
if ( response.success ) { |
| 304 |
// fade and remove element. |
| 305 |
if ( response.data ) { |
| 306 |
// quickly fade out the current notice and when the fade is complete, update the HTML and fade back in. |
| 307 |
dashboardRemovegrowthToolsNoticeEl.fadeOut( 'fast', function() { |
| 308 |
dashboardRemovegrowthToolsNoticeEl.html( response.data ); |
| 309 |
dashboardRemovegrowthToolsNoticeEl.fadeIn( 'fast' ); |
| 310 |
}); |
| 311 |
} |
| 312 |
} |
| 313 |
}, |
| 314 |
|
| 315 |
} ); |
| 316 |
} ); |
| 317 |
|
| 318 |
|
| 319 |
}); |
| 320 |
|
| 321 |
} )( jQuery ); |