PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
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 / admin / charitable-admin-2.0.js

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

940 lines 48.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global charitable_builder, jconfirm, charitable_panel_switch, Choices, Charitable, CharitableCampaignEmbedWizard, wpCookies, tinyMCE, CharitableUtils, List */ // eslint-disable-line no-unused-vars
2
3 var CharitableAdminUI = window.CharitableAdminUI || ( function( document, window, $ ) {
4
5 var s = {};
6
7 var elements = {};
8
9 var app = {
10
11 settings: {
12 clickWatch: false
13 },
14
15 init: function() {
16
17 // charitable_panel_switch = true;
18 s = this.settings;
19
20 // Document ready.
21 $( app.ready );
22
23 },
24
25 ready: function() {
26
27 // Move navigation elements on certain pages.
28 app.moveNavigationElements();
29
30 elements.$addNewCampaignButton = $( 'body.post-type-campaign .page-title-action' );
31
32 // Bind all actions.
33 app.bindUIActions();
34
35 var urlParams = new URLSearchParams(window.location.search);
36
37 if ( urlParams.has('create') && 'campaign' === urlParams.get('create') ) {
38 app.newCampaignPopup();
39 urlParams.delete('create');
40 window.history.pushState({}, '', '/wp-admin/edit.php?' + urlParams.toString() );
41 }
42
43 // upon loading the page or a change of a hash - view the hash in the url and if that anchor exists, scroll to it.
44 $(document).ready(function() {
45 app.scrollToAnchor();
46 }
47 );
48 $(window).on('hashchange', function() {
49 app.scrollToAnchor();
50 });
51
52 // if the body tag has the css class charitable_page_charitable-dashboard and the notification container has a notification in it, show the notifications.
53 if ( $('body').hasClass('charitable_page_charitable-dashboard') && $('#charitable-plugin-notifications').find('.notification-cards-active .charitable-notification').length > 0 ) {
54 // check if charitable_admin.autoshow_notifications is not undefined and is true.
55 if ( typeof charitable_admin.autoshow_plugin_notifications !== 'undefined' && charitable_admin.autoshow_plugin_notifications ) { // eslint-disable-line no-undef
56 $('body').addClass('charitable-show-notifications');
57 $("#charitable-plugin-notifications").addClass("in");
58 $('body').find('.charitable-notifications-overlay').fadeIn();
59 }
60 }
61
62 },
63
64 /**
65 * Move navigation elements on certain pages.
66 *
67 * @return {void}
68 *
69 * @since 1.8.2
70 */
71 moveNavigationElements: function() {
72
73 // if the body class has the class 'post-type-charitable' and 'edit-tags-php' then move the navigation elements "#charitable-tools-nav" right after form.search-form.
74 if ( $('body.post-type-charitable.edit-tags-php').length > 0 ) {
75 $('#charitable-tools-nav').insertBefore('h1.wp-heading-inline');
76 }
77
78 },
79
80 /**
81 * Bind all UI actions.
82 *
83 * @return {void}
84 *
85 */
86 bindUIActions: function() {
87
88 // Deprecated.
89 // $('body.post-type-campaign').on( 'click', '.page-title-action', function( e ) {
90 // e.preventDefault();
91 // app.newCampaignPopup();
92 // } );
93
94 $('body.post-type-campaign').on( 'click', '.charitable-campaign-list-banner a.button-link', function( e ) {
95 e.preventDefault();
96 app.campaignListBannerPopup();
97 } );
98
99 $('body.post-type-campaign').on( 'click', '.jconfirm-closeIcon', function( e ) { // eslint-disable-line no-unused-vars
100 s.clickWatch = false;
101 } );
102 if ( s.clickWatch === false ) {
103 $('body.post-type-campaign').on( 'click', 'input.campaign_name', function( e ) {
104 e.preventDefault();
105 $(this).select();
106 s.clickWatch = true;
107 } );
108 }
109
110 // Blank slate create new campaign button.
111 if ( $('.charitable-blank-slate-create-campaign').length > 0 ) {
112
113 $('body.post-type-campaign').on( 'click', '.charitable-blank-slate-create-campaign', function( e ) {
114 e.preventDefault();
115 app.newCampaignPopup();
116 } );
117
118 }
119
120 // Welcome activation page.
121 app.initWelcome();
122
123 // Upgrade Modal.
124 app.initUpgradeModal();
125
126 // Notifications (Dashboard)
127 app.initNotifications();
128
129 // Notifications (AM)
130 app.initAMNotifications();
131
132 // Square Legacy Modal.
133 app.initSquareLegacyModal();
134
135 },
136
137 /**
138 * Initialize the AM notifications.
139 *
140 * @return {void}
141 *
142 * @since 1.8.3
143 *
144 */
145 initAMNotifications: function() {
146
147 if ( $('.charitable-notification-inbox').length > 0 ) {
148 // on click add body class charitable-notifications-open.
149 $('body').on( 'click', '.charitable-notification-inbox, .charitable-close, #toplevel_page_charitable li.notifications, .charitable-report-card.charitable-dashboard-notifications .more a, p.charitable-view-notifications a', function( e ) {
150 e.preventDefault();
151 $('body').toggleClass('charitable-show-notifications');
152 $("#charitable-plugin-notifications").toggleClass("in");
153 $('body').find('.charitable-notifications-overlay').fadeToggle();
154 });
155 }
156
157 if ( $('.charitable-notifications-overlay').length > 0 ) {
158 // click on overlay, the notifications will close.
159 $('body').on( 'click', '.charitable-notifications-overlay', function( e ) {
160 e.preventDefault();
161 $('body').removeClass('charitable-show-notifications');
162 $("#charitable-plugin-notifications").removeClass("in");
163 $('body').find('.charitable-notifications-overlay').fadeOut();
164 });
165 // dismiss a single notification.
166 $('.charitable-notification').on( 'click', 'a.dismiss', function( e ) {
167 e.preventDefault();
168 var $this = $(this),
169 notification_id = $this.closest('.charitable-notification').data('notification-id');
170
171 // ajax call to diable the notification.
172 $.ajax({
173 type: 'POST',
174 url: ajaxurl, // eslint-disable-line no-undef
175 data: {
176 action: 'charitable_notification_dismiss',
177 notification_id: notification_id,
178 nonce: charitable_admin.nonce, // eslint-disable-line no-undef
179 },
180 success: function( response ) {
181 if ( response.success ) {
182 // Remove the element that has the notification id.
183 // Because the dismiss button might be in multiple locations, for each element that has the data-notification-id attribute and find the 'charitable-notification' element in it's children.
184 // $('body').find('.charitable-notification[data-notification-id="' + notification_id + '"]').fadeOut(400, function() { app.moveAMNotificationToDismissed( $(this) ) });
185 // do the same thing but remove the fadeOut but reference the app.moveAMNotificationToDismissed function.
186 var the_counts = app.moveAMNotificationToDismissed( $('body').find('#charitable-plugin-notifications .charitable-notification[data-notification-id="' + notification_id + '"]') ),
187 active_notification_count = the_counts.active_notification_count,
188 dismissed_notification_count = the_counts.dismissed_notification_count;
189
190 if ( active_notification_count === 0 ) {
191 // remove the notifications which should be none but still.
192 $('.charitable-notification-cards.notification-cards-active .charitable-notification').remove();
193 // ..same for the dashboard notifications, if it exists.
194 if ( $('#charitable-dashboard-report-sections').length > 0 ) {
195 $('#charitable-dashboard-report-sections').find('.charitable-dashboard-notification').remove();
196 }
197
198 // For the dashboard notifications, if there are no more notifications, show the no-items message.
199 $('.charitable-dashboard-notifications').find('.no-items').removeClass('charitable-hidden');
200 $('.charitable-dashboard-notifications').find('.the-list').addClass('charitable-hidden');
201
202 // change the text at the top of the notifications.
203 $('#charitable-plugin-notifications .new-notifications').html('No new notifications');
204 // change the text of the dashboard notifications, if it exists.
205 $('#charitable-dashboard-report-sections').find('.charitable-dashboard-notifications .header h4').html('Notifications');
206
207 // Set up the "no active notifications" message on dashboard.
208 $('#charitable-dashboard-report-sections').find('.charitable-dashboard-notifications').find('.charitable-report-ui').html('<div class="no-items"><p><strong>There is currently no active notifications.</strong></p><p class="link charitable-view-notifications"><a href="#">View Notification<img src="/wp-content/plugins/charitable/assets/images/icons/east.svg"></a></p></div>');
209
210 // remove the red dot from notifications icon and the WP admin menu.
211 $('.charitable-notification-inbox').find('.number').remove();
212 $('#toplevel_page_charitable').find('li.notifications .charitable-menu-notification-indicator').remove();
213
214 // remove dismiss all link.
215 $('#charitable-plugin-notifications').find('.dismiss-all').remove();
216 } else {
217 $('#charitable-plugin-notifications').find('#new-notifications-count').html( active_notification_count );
218
219 // Update the header badge count
220 $('.charitable-notification-inbox').find('.number').html( active_notification_count );
221
222 // Get the number of active notifications for the dashboard.
223 var active_notification_count_dashboard = $('#charitable-dashboard-report-sections').find('.charitable-dashboard-notifications .charitable-notification').length;
224
225 if ( active_notification_count > active_notification_count_dashboard ) {
226 if ( active_notification_count === 1 ) {
227 $('#charitable-dashboard-report-sections').find('#new-notifications-count-dashboard').html( active_notification_count + '+' );
228 // Insert HTML into .charitable-report-ui of this id.
229 $('#charitable-dashboard-report-sections').find('.charitable-dashboard-notifications').find('.charitable-report-ui').html('<div class="no-items"><p><strong>There is currently one active notification.</strong></p><p class="link charitable-view-notifications"><a href="#">View Notification<img src="/wp-content/plugins/charitable/assets/images/icons/east.svg"></a></p></div>');
230 } else {
231 $('#charitable-dashboard-report-sections').find('#new-notifications-count-dashboard').html( active_notification_count_dashboard + '+' );
232 }
233 } else {
234 $('#charitable-dashboard-report-sections').find('#new-notifications-count-dashboard').html( active_notification_count_dashboard );
235 }
236 }
237
238 var active_notification_count_dashboard = $('#charitable-dashboard-report-sections').find('.charitable-dashboard-notifications .charitable-notification').length;
239
240 $('#charitable-plugin-notifications').find('#new-notifications-count').html( active_notification_count );
241
242 if ( active_notification_count > active_notification_count_dashboard ) {
243 if ( active_notification_count === 1 ) {
244 $('#charitable-dashboard-report-sections').find('#new-notifications-count-dashboard').html( active_notification_count + '+' );
245 // Insert HTML into .charitable-report-ui of this id.
246 $('#charitable-dashboard-report-sections').find('.charitable-dashboard-notifications').find('.charitable-report-ui').html('<div class="no-items"><p><strong>There is currently one active notification.</strong></p><p class="link charitable-view-notifications"><a href="#">View Notification<img src="/wp-content/plugins/charitable/assets/images/icons/east.svg"></a></p></div>');
247 } else {
248 $('#charitable-dashboard-report-sections').find('#new-notifications-count-dashboard').html( active_notification_count_dashboard + '+' );
249 }
250 } else {
251 $('#charitable-dashboard-report-sections').find('#new-notifications-count-dashboard').html( active_notification_count_dashboard );
252 }
253
254 // if active is only one, use the singular form... otherwise use the plural form.
255 if ( active_notification_count === 1 ) {
256 app.replaceNotifications(".new-notifications.notifications-visible");
257 // check to see if the h4 element exists in the dashboard notifications and replace the text.
258 if ( $('#charitable-dashboard-report-sections').length > 0 ) {
259 app.replaceNotifications(".charitable-dashboard-notifications .header h4");
260 }
261 }
262
263 // Replace the number inside the count div.
264 $('#charitable-plugin-notifications').find('#dismissed-notifications-count').text( dismissed_notification_count );
265
266 if ( dismissed_notification_count === 1 ) {
267 app.replaceNotifications('#charitable-plugin-notifications .old-notifications strong');
268 } else {
269 app.replaceNotification('#charitable-plugin-notifications .old-notifications strong');
270 }
271 }
272 }
273 });
274 });
275 // dismiss all notifications.
276 $('.charitable-plugin-notifications .notification-menu').on( 'click', '.dismiss-all a.dismiss', function( e ) {
277 e.preventDefault();
278 var $this = $(this),
279 notification_ids = [];
280
281 // get all the notification ids.
282 $('.charitable-notification').each(function() {
283 notification_ids.push( $(this).data('notification-id') );
284 });
285
286 // ajax call to diable the notification.
287 $.ajax({
288 type: 'POST',
289 url: ajaxurl, // eslint-disable-line no-undef
290 data: {
291 action: 'charitable_notification_dismiss_multiple',
292 notification_ids: notification_ids,
293 nonce: charitable_admin.nonce, // eslint-disable-line no-undef
294 },
295 success: function( response ) {
296 if ( response.success ) {
297 // remove all elements.
298 $this.remove();
299
300 var active_notification_count = 0,
301 dismissed_notification_count = 0;
302
303 // foreach notification in #charitable-plugin-notifications .charitable-notification, move it to the dismissed section.
304 $('#charitable-plugin-notifications .charitable-notification').each(function() {
305 var the_counts = app.moveAMNotificationToDismissed( $(this) );
306 active_notification_count = the_counts.active_notification_count,
307 dismissed_notification_count = the_counts.dismissed_notification_count;
308 });
309
310 // remove the notifications which should be none but still.
311 $('.charitable-notification-cards.notification-cards-active .charitable-notification').remove();
312 // ..same for the dashboard notifications, if it exists.
313 if ( $('#charitable-dashboard-report-sections').length > 0 ) {
314 $('#charitable-dashboard-report-sections').find('.charitable-dashboard-notification').remove();
315 }
316
317 // For the dashboard notifications, if there are no more notifications, show the no-items message.
318 $('.charitable-dashboard-notifications').find('.no-items').removeClass('charitable-hidden');
319 $('.charitable-dashboard-notifications').find('.the-list').addClass('charitable-hidden');
320
321 // change the text at the top of the notifications.
322 $('#charitable-plugin-notifications .new-notifications').html('No new notifications');
323 // change the text of the dashboard notifications, if it exists.
324 $('#charitable-dashboard-report-sections').find('.charitable-dashboard-notifications .header h4').html('Notifications');
325
326 // remove the red dot from notifications icon and the WP admin menu.
327 $('.charitable-notification-inbox').find('.number').remove();
328 $('#toplevel_page_charitable').find('li.notifications .charitable-menu-notification-indicator').remove();
329
330 $('#charitable-plugin-notifications').find('#new-notifications-count').html( active_notification_count );
331 $('#charitable-dashboard-report-sections').find('#new-notifications-count-dashboard').html( active_notification_count );
332
333 $('#charitable-plugin-notifications').find('#dismissed-notifications-count').html( dismissed_notification_count );
334
335 $('#charitable-dashboard-report-sections').find('.charitable-dashboard-notifications').find('.charitable-report-ui').html('<div class="no-items"><p><strong>There is currently no active notifications.</strong></p><p class="link charitable-view-notifications"><a href="#">View Notification<img src="/wp-content/plugins/charitable/assets/images/icons/east.svg"></a></p></div>');
336
337 }
338 }
339 });
340 });
341 // switch between active and dismissed notifications.
342 $('.charitable-plugin-notifications .notification-menu').on( 'click', '.dismissed-notifications a', function( e ) {
343 e.preventDefault();
344 var $this = $(this),
345 $container = $this.closest('.notification-menu'),
346 $dismissed = $container.find('.notification-cards-dismissed'),
347 $active = $container.find('.notification-cards-active'),
348 $new_notifications_title = $container.find('.new-notifications'),
349 $old_notifications_title = $container.find('.old-notifications'),
350 $dismiss_all_element = $container.find('.dismiss-all a.dismiss'),
351 active_notification_count = $('#charitable-plugin-notifications .notification-cards-active .charitable-notification').length,
352 dismissed_notification_count = $('#charitable-plugin-notifications .notification-cards-dismissed .charitable-notification').length;
353
354 if ( $this.data('status') !== 'active' ) {
355 // if active is only one, use the singular form... otherwise use the plural form.
356 if ( active_notification_count === 1 ) {
357 $this.html('Active Notification');
358 } else {
359 $this.html('Active Notifications');
360 }
361 $this.data('status', 'active');
362 } else {
363 // if dismissed is only one, use the singular form... otherwise use the plural form.
364 if ( dismissed_notification_count === 1 ) {
365 $this.html('Dismissed Notification');
366 } else {
367 $this.html('Dismissed Notification');
368 }
369 $this.data('status', 'dismissed');
370 }
371
372 $active.toggleClass('notification-cards-visible');
373 $dismissed.toggleClass('notification-cards-visible');
374 $new_notifications_title.toggleClass('notifications-visible');
375 $old_notifications_title.toggleClass('notifications-visible');
376 $dismiss_all_element.toggleClass('charitable-hidden');
377 });
378
379 // Gear icon — toggle settings panel.
380 $( document ).on( 'click', '#charitable-notif-gear-btn', function( e ) {
381 e.preventDefault();
382 e.stopPropagation();
383 var $panel = $( '#charitable-notif-settings-panel' );
384 var $btn = $( this );
385 var open = $panel.is( ':visible' );
386 $panel.slideToggle( 150 );
387 $btn.attr( 'aria-expanded', open ? 'false' : 'true' );
388 } );
389
390 // Settings toggles — save on change.
391 $( document ).on( 'change', '#charitable-notif-settings-panel input[type="checkbox"]', function() {
392 var settings = {};
393 $( '#charitable-notif-settings-panel input[type="checkbox"]' ).each( function() {
394 settings[ $( this ).data( 'category' ) ] = $( this ).is( ':checked' );
395 } );
396
397 $.post(
398 typeof ajaxurl !== 'undefined' ? ajaxurl : charitable_admin.ajax_url, // eslint-disable-line no-undef
399 {
400 action : 'charitable_save_notification_settings',
401 nonce : CHARITABLE.nonce, // eslint-disable-line no-undef
402 settings: JSON.stringify( settings )
403 },
404 function( res ) {
405 if ( ! res.success ) {
406 console.log( 'Notification settings save failed', res ); // eslint-disable-line no-console
407 }
408 }
409 );
410 } );
411 }
412 },
413
414 /**
415 * Replace the text "Notifications" with "Notification".
416 * This is used in the AM notifications.
417 *
418 * @param {string} selector The selector of the element to replace the text.
419 *
420 * @return {void}
421 *
422 * @since 1.8.3
423 */
424 replaceNotifications: function( selector ) {
425 $(selector).each(function() {
426 // Get the current text
427 var currentText = $(this).text();
428 // Replace "Notifications" with "Notification"
429 var newText = currentText.replace(/Notifications/g, "Notification");
430 // Update the element's text
431 $(this).text(newText);
432 });
433 },
434
435 replaceNotification: function( selector ) {
436 $(selector).each(function() {
437 // Get the current text
438 var currentText = $(this).text();
439 // Replace "Notifications" with "Notification"
440 var newText = currentText.replace(/Notification/g, "Notifications");
441 // Update the element's text
442 $(this).text(newText);
443 });
444 },
445
446 /**
447 * Move the notification to the dismissed section.
448 *
449 * @param {object} $notification The jQuery object of the notification.
450 *
451 * @since 1.8.3
452 *
453 * @return {void}
454 */
455 moveAMNotificationToDismissed: function( $notification ) {
456
457 // remove the "no dismissed notifications" title.
458 if ( $('.notification-no-dismissed-title').length > 0 ) {
459 $('.notification-no-dismissed-title').closest('.notification-card').remove();
460 }
461
462 // Remove the dismiss button in the notification that is being dismissed.
463 $notification.find('.dismiss').remove();
464
465 // mmove $notification to the dismissed section - it should be the last child inside the parent of charitable-notification-cards.notification-cards-dismissed.
466 $notification.appendTo('#charitable-plugin-notifications .notification-cards-dismissed').show();
467
468 // if we are on the dashboard make sure this notification is also removed from the dashboard notifications pane.
469 if ( $('#charitable-dashboard-report-sections').length > 0 ) {
470 $('#charitable-dashboard-report-sections').find('.charitable-dashboard-notifications .charitable-notification[data-notification-id="' + $notification.data('notification-id') + '"]').remove();
471 }
472
473 // return accurate counts of the notifications in the sidebar.
474 var active_notification_count = $('#charitable-plugin-notifications .notification-cards-active .charitable-notification').length,
475 dismissed_notification_count = $('#charitable-plugin-notifications .notification-cards-dismissed .charitable-notification').length;
476
477 return { active_notification_count: active_notification_count, dismissed_notification_count: dismissed_notification_count };
478
479 },
480
481 /**
482 * Initialize the notifications.
483 *
484 * @return {void}
485 *
486 * @since 1.8.2
487 *
488 */
489 initNotifications: function() {
490
491 // when a prev or next button is clicked inside the notification navigation.
492 $('body .charitable-dashboard-notification-navigation').on( 'click', 'a', function( e ) {
493 e.preventDefault();
494
495 var $this = $(this),
496 $container = $this.closest('.charitable-dashboard-notifications'),
497 $current = $container.find('.charitable-dashboard-notification:not(.charitable-hidden)'),
498 notification_number = $current.data('notification-number'),
499 notification_count = $container.find('.charitable-dashboard-notification').length,
500 new_number = notification_number;
501
502 if ( $this.hasClass('next') ) {
503 new_number++;
504 if ( new_number > notification_count ) {
505 new_number = 1;
506 }
507 } else if ( $this.hasClass('prev') ) {
508 new_number--;
509 if ( new_number < 1 ) {
510 new_number = notification_count;
511 }
512 }
513
514 // Fade out current, then fade in next.
515 $current.fadeOut( 200, function() {
516 $current.addClass('charitable-hidden').removeAttr('style');
517 $container.find('.charitable-dashboard-notification[data-notification-number="' + new_number + '"]').hide().removeClass('charitable-hidden').fadeIn( 200 );
518 });
519
520 // Update the counter text.
521 $container.find('.charitable-dashboard-notification-counter').text( new_number + ' of ' + notification_count );
522 }
523 );
524
525 // when the close button is clicked, remove the notificaiton from the HTML and do an ajax call removing the notficaition from the database.
526 $('body .charitable-dashboard-notifications').on( 'click', '.charitable-remove-dashboard-notification', function( e ) {
527 e.preventDefault();
528
529 var $this = $(this),
530 $container = $this.closest('.charitable-dashboard-notifications'),
531 notification_id = $container.find('.charitable-dashboard-notification:not(.charitable-hidden)').data('notification-id');
532
533 // ajax call to diable the notification.
534 $.ajax({
535 type: 'POST',
536 url: ajaxurl, // eslint-disable-line no-undef
537 data: {
538 action: 'charitable_disable_dashboard_notification',
539 notification_id: notification_id,
540 nonce: charitable_admin.nonce // eslint-disable-line no-undef
541 },
542 success: function( response ) {
543 if ( response.success ) {
544 var $dismissed = $container.find('.charitable-dashboard-notification[data-notification-id="' + notification_id + '"]');
545
546 $dismissed.fadeOut( 200, function() {
547 $dismissed.remove();
548 // count the number of notifications that are left.
549 var notification_count = $container.find('.charitable-dashboard-notification').length;
550 // if there are no more notifications, remove the entire container.
551 if ( notification_count === 0 ) {
552 $container.fadeOut( 200, function() { $container.remove(); });
553 } else {
554 // Show the first remaining notification with fade.
555 $container.find('.charitable-dashboard-notification').first().removeClass('charitable-hidden').hide().fadeIn( 200 );
556
557 if ( notification_count <= 1 ) {
558 // Hide navigation when only one notification remains.
559 $container.find('.charitable-dashboard-notification-navigation').html('');
560 } else {
561 // Update the counter text.
562 var current_number = $container.find('.charitable-dashboard-notification:not(.charitable-hidden)').first().data('notification-number');
563 $container.find('.charitable-dashboard-notification-counter').text( current_number + ' of ' + notification_count );
564 }
565 }
566 });
567 }
568 }
569 });
570
571 });
572
573 },
574
575 /**
576 * Scroll to anchor.
577 * If the url has a hash, scroll to the anchor.
578 *
579 * @return {void}
580 *
581 * @since 1.8.2
582 */
583 scrollToAnchor: function() {
584 // get the hash from the url.
585 var hash = window.location.hash;
586 hash = hash.substring(1);
587
588 if ( hash ) {
589
590 // santitize the hash.
591 hash = hash.replace(/[^a-zA-Z0-9-_]/g, '');
592
593 var $target = $( 'a#wpchr-' + hash ),
594 $container = false;
595
596 if ( $target.length ) {
597 $container = $target.length ? $target.closest('.charitable-growth-content') : false;
598 }
599
600 // remove all css classes 'charitable-selected' from all containers.
601 $('.charitable-growth-content').removeClass('charitable-selected');
602
603 if ( $target.length ) {
604 // scroll to the target.
605 $('html, body').animate({
606 scrollTop: $target.offset().top - 100
607 }, 1000);
608 // after 2 seconds, slowly fade the background color to white.
609 $container.addClass('charitable-selected');
610 }
611 }
612 },
613
614 /**
615 * Create a new campaign popup (deprecated).
616 *
617 */
618 newCampaignPopup: function() {
619
620 var admin_url = typeof charitable_admin !== "undefined" && typeof charitable_admin.admin_url !== "undefined" ? charitable_admin.admin_url : '/wp-admin/', // eslint-disable-line no-undef
621 box_width = $(window).width() * .50;
622
623 if ( box_width > 770 ) {
624 box_width = 770;
625 }
626
627 $.confirm( {
628 title: 'Create Campaign',
629 content: '' +
630 '<form id="create-campaign-form" method="POST" action="' + admin_url + 'admin.php?page=charitable-campaign-builder&view=template" class="formName">' +
631 '<div class="form-group">' +
632 '<label>Name:</label>' +
633 '<input type="text" placeholder="Campaign Name" value="My New Campaign" name="campaign_name" class="name campaign_name form-control" required />' +
634 '</div>' +
635 '</form>',
636 closeIcon: true,
637 boxWidth: box_width + 'px',
638 useBootstrap: false,
639 type: 'create-campaign',
640 animation: 'none',
641 buttons: {
642 formSubmit: {
643 text: 'Create Campaign',
644 btnClass: 'btn-green',
645 action: function () {
646 var campaign_name = this.$content.find('.campaign_name').val().trim();
647 if ( ! campaign_name ){
648 $.alert('Please provide a valid campaign name.');
649 return false;
650 } else {
651 $('.jconfirm-buttons button.btn').html('Creating...');
652 $('#create-campaign-form').submit();
653 return false;
654 }
655 }
656 }
657 },
658 onContentReady: function () {
659
660 }
661 } );
662
663 },
664
665 /**
666 * Create a new campaign popup.
667 * This is the new campaign popup that is used in the campaign list page.
668 *
669 * @since 1.8.2
670 *
671 * @return {void}
672 */
673 campaignListBannerPopup: function() {
674
675 var plugin_asset_dir = typeof charitable_admin.plugin_asset_dir !== "undefined" ? charitable_admin.plugin_asset_dir : '/wp-content/plugins/charitable/assets'; // eslint-disable-line no-undef
676
677 $.confirm( {
678 title: false,
679 content: '' +
680 '<div class="charitable-lite-pro-popup">' +
681 '<div class="charitable-lite-pro-popup-left" >' +
682 '<h1>The Ambassadors Extension is only available for Charitable Pro users.</h1>' +
683 '<h2>Harness the power of supporter networks and friends to reach more people and raise more money for your cause.</h2>' +
684 '<ul>' +
685 '<li><p>Create a crowdfunding platform (similar to GoFundMe)</p></li>' +
686 '<li><p>Simplified fundraiser creation and management</p></li>' +
687 '<li><p>Let supporters fundraise together through our Teams feature</p></li>' +
688 '<li><p>Integrate with email marketing to follow up with campaign creators</p></li>' +
689 '<li><p>Give people a place to fundraise for their own cause</p></li>' +
690 '</ul>' +
691 '<a href="https://wpcharitable.com/lite-vs-pro/?utm_source=WordPress&utm_medium=Ambassadors+Campaign+Modal+Unlock&utm_campaign=WP+Charitable" target="_blank" class="charitable-lite-pro-popup-button">Unlock Peer-to-Peer Fundraising</a>' +
692 '<a href="https://wpcharitable.com/lite-vs-pro/?utm_source=WordPress&utm_medium=Ambassadors+Campaign+Modal+More&utm_campaign=WP+Charitable" target="_blank" class="charitable-lite-pro-popup-link">Or learn more about the Ambassadors extension &rarr;</a>' +
693 '</div>' +
694 '<div class="charitable-lite-pro-popup-right" >' +
695 '<img src="' + plugin_asset_dir + 'images/lite-to-pro/ambassador.png" alt="Charitable Ambassador Extension" >' +
696 '</img>' +
697 '</div>',
698 closeIcon: true,
699 alignMiddle: true,
700 boxWidth: '986px',
701 useBootstrap: false,
702 animation: 'none',
703 buttons: false,
704 type: 'lite-pro-ad',
705 onContentReady: function () {
706
707 }
708 } );
709
710 },
711
712 /**
713 * Welcome activation page.
714 *
715 */
716 initWelcome: function() {
717
718 // Open modal and play video.
719 $( document ).on( 'click', '#charitable-welcome .play-video', function( event ) {
720 event.preventDefault();
721
722 const video = '<div class="video-container"><iframe width="1280" height="720" src="https://www.youtube-nocookie.com/embed/834h3huzzk8?rel=0&amp;showinfo=0&amp;autoplay=1" frameborder="0" allowfullscreen></iframe></div>';
723
724 if ( typeof jconfirm !== 'undefined' ) {
725
726 // jquery-confirm defaults.
727 jconfirm.defaults = {
728 closeIcon: true,
729 backgroundDismiss: false,
730 escapeKey: true,
731 animationBounce: 1,
732 useBootstrap: false,
733 theme: 'modern',
734 animateFromElement: false
735 };
736
737 $.dialog( {
738 title: false,
739 content: video,
740 closeIcon: true,
741 boxWidth: '1300'
742 } );
743
744 }
745
746 } );
747 },
748
749 /**
750 * Initialize the upgrade modal.
751 *
752 * @since 1.8.1.15
753 *
754 * @return {void}
755 *
756 */
757 initUpgradeModal: function() {
758
759 // Upgrade information modal for upgrade links.
760 $( document ).on( 'click', '.charitable-upgrade-modal', function() {
761
762 $.alert( {
763 title : charitable_admin.thanks_for_interest, // eslint-disable-line no-undef
764 content : charitable_admin.upgrade_modal, // eslint-disable-line no-undef
765 icon : 'fa fa-info-circle',
766 type : 'blue',
767 boxWidth : '550px',
768 useBootstrap : false,
769 theme : 'modern,charitable-install-form',
770 closeIcon : false,
771 draggable : false,
772 buttons: {
773 confirm: {
774 text: charitable_admin.ok, // eslint-disable-line no-undef
775 btnClass: 'btn-confirm',
776 keys: [ 'enter' ],
777 }, // eslint-disable-line
778 },
779 } );
780 } );
781
782 },
783
784 /**
785 * Initialize the Square legacy modal.
786 *
787 * @since 1.8.7
788 *
789 * @return {void}
790 *
791 */
792 initSquareLegacyModal: function() {
793
794 // Check if we're on the gateway settings page and Square Core enable button is clicked.
795 $( document ).on( 'click', 'a[href*="charitable_action=enable_gateway"][href*="gateway_id=square_core"]', function( e ) {
796
797 // Check if Square Legacy is active and Square Core is not active.
798 if ( typeof CHARITABLE !== 'undefined' && CHARITABLE.square_legacy_active && !CHARITABLE.square_core_active ) {
799 e.preventDefault();
800
801 $.alert( {
802 title: CHARITABLE.heads_up,
803 content: CHARITABLE.square_legacy_modal_message,
804 icon: 'fa fa-exclamation-circle',
805 type: 'orange',
806 buttons: {
807 confirm: {
808 text: CHARITABLE.ok,
809 btnClass: 'btn-confirm',
810 keys: [ 'enter' ],
811 action: function() {
812 // Perform AJAX call to switch gateways.
813 $.post( CHARITABLE.ajax_url, {
814 action: 'charitable_switch_square_gateways',
815 nonce: CHARITABLE.nonce
816 }, function( response ) {
817 if ( response.success ) {
818 window.location.href = response.data.redirect_url;
819 } else {
820 // Show error message if AJAX fails.
821 $.alert( {
822 title: CHARITABLE.oops,
823 content: CHARITABLE.square_legacy_switch_error,
824 icon: 'fa fa-exclamation-circle',
825 type: 'red',
826 buttons: {
827 confirm: {
828 text: CHARITABLE.ok,
829 btnClass: 'btn-confirm',
830 keys: [ 'enter' ]
831 }
832 }
833 } );
834 }
835 } ).fail( function() {
836 // Show error message if AJAX request fails.
837 $.alert( {
838 title: CHARITABLE.oops,
839 content: CHARITABLE.square_legacy_switch_error,
840 icon: 'fa fa-exclamation-circle',
841 type: 'red',
842 buttons: {
843 confirm: {
844 text: CHARITABLE.ok,
845 btnClass: 'btn-confirm',
846 keys: [ 'enter' ]
847 }
848 }
849 } );
850 } );
851 }
852 },
853 cancel: {
854 text: CHARITABLE.cancel,
855 keys: [ 'esc' ]
856 }
857 }
858 } );
859 }
860 } );
861
862 // Check if we're on the gateway settings page and Square Legacy enable button is clicked.
863 $( document ).on( 'click', 'a[href*="charitable_action=enable_gateway"][href*="gateway_id=square"]', function( e ) {
864
865 // Check if Square Core is active and Square Legacy is not active.
866 if ( typeof CHARITABLE !== 'undefined' && CHARITABLE.square_core_active && !CHARITABLE.square_legacy_active ) {
867 e.preventDefault();
868
869 $.alert( {
870 title: CHARITABLE.heads_up,
871 content: CHARITABLE.square_core_modal_message,
872 icon: 'fa fa-exclamation-circle',
873 type: 'orange',
874 buttons: {
875 confirm: {
876 text: CHARITABLE.ok,
877 btnClass: 'btn-confirm',
878 keys: [ 'enter' ],
879 action: function() {
880 // Perform AJAX call to switch gateways.
881 $.post( CHARITABLE.ajax_url, {
882 action: 'charitable_switch_square_core_to_legacy',
883 nonce: CHARITABLE.nonce
884 }, function( response ) {
885 if ( response.success ) {
886 window.location.href = response.data.redirect_url;
887 } else {
888 // Show error message if AJAX fails.
889 $.alert( {
890 title: CHARITABLE.oops,
891 content: CHARITABLE.square_legacy_switch_error,
892 icon: 'fa fa-exclamation-circle',
893 type: 'red',
894 buttons: {
895 confirm: {
896 text: CHARITABLE.ok,
897 btnClass: 'btn-confirm',
898 keys: [ 'enter' ]
899 }
900 }
901 } );
902 }
903 } ).fail( function() {
904 // Show error message if AJAX request fails.
905 $.alert( {
906 title: CHARITABLE.oops,
907 content: CHARITABLE.square_legacy_switch_error,
908 icon: 'fa fa-exclamation-circle',
909 type: 'red',
910 buttons: {
911 confirm: {
912 text: CHARITABLE.ok,
913 btnClass: 'btn-confirm',
914 keys: [ 'enter' ]
915 }
916 }
917 } );
918 } );
919 }
920 },
921 cancel: {
922 text: CHARITABLE.cancel,
923 keys: [ 'esc' ]
924 }
925 }
926 } );
927 }
928 } );
929
930 },
931
932 };
933
934 // Provide access to public functions/properties.
935 return app;
936
937 }( document, window, jQuery ) ); // eslint-disable-line no-undef
938
939 CharitableAdminUI.init();
940