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 / admin / charitable-admin-2.0.js

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

907 lines 46.9 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 },
380
381 /**
382 * Replace the text "Notifications" with "Notification".
383 * This is used in the AM notifications.
384 *
385 * @param {string} selector The selector of the element to replace the text.
386 *
387 * @return {void}
388 *
389 * @since 1.8.3
390 */
391 replaceNotifications: function( selector ) {
392 $(selector).each(function() {
393 // Get the current text
394 var currentText = $(this).text();
395 // Replace "Notifications" with "Notification"
396 var newText = currentText.replace(/Notifications/g, "Notification");
397 // Update the element's text
398 $(this).text(newText);
399 });
400 },
401
402 replaceNotification: function( selector ) {
403 $(selector).each(function() {
404 // Get the current text
405 var currentText = $(this).text();
406 // Replace "Notifications" with "Notification"
407 var newText = currentText.replace(/Notification/g, "Notifications");
408 // Update the element's text
409 $(this).text(newText);
410 });
411 },
412
413 /**
414 * Move the notification to the dismissed section.
415 *
416 * @param {object} $notification The jQuery object of the notification.
417 *
418 * @since 1.8.3
419 *
420 * @return {void}
421 */
422 moveAMNotificationToDismissed: function( $notification ) {
423
424 // remove the "no dismissed notifications" title.
425 if ( $('.notification-no-dismissed-title').length > 0 ) {
426 $('.notification-no-dismissed-title').closest('.notification-card').remove();
427 }
428
429 // Remove the dismiss button in the notification that is being dismissed.
430 $notification.find('.dismiss').remove();
431
432 // mmove $notification to the dismissed section - it should be the last child inside the parent of charitable-notification-cards.notification-cards-dismissed.
433 $notification.appendTo('#charitable-plugin-notifications .notification-cards-dismissed').show();
434
435 // if we are on the dashboard make sure this notification is also removed from the dashboard notifications pane.
436 if ( $('#charitable-dashboard-report-sections').length > 0 ) {
437 $('#charitable-dashboard-report-sections').find('.charitable-dashboard-notifications .charitable-notification[data-notification-id="' + $notification.data('notification-id') + '"]').remove();
438 }
439
440 // return accurate counts of the notifications in the sidebar.
441 var active_notification_count = $('#charitable-plugin-notifications .notification-cards-active .charitable-notification').length,
442 dismissed_notification_count = $('#charitable-plugin-notifications .notification-cards-dismissed .charitable-notification').length;
443
444 return { active_notification_count: active_notification_count, dismissed_notification_count: dismissed_notification_count };
445
446 },
447
448 /**
449 * Initialize the notifications.
450 *
451 * @return {void}
452 *
453 * @since 1.8.2
454 *
455 */
456 initNotifications: function() {
457
458 // when a prev or next button is clicked inside the notification navigation.
459 $('body .charitable-dashboard-notification-navigation').on( 'click', 'a', function( e ) {
460 e.preventDefault();
461
462 var $this = $(this),
463 $container = $this.closest('.charitable-dashboard-notifications'),
464 $current = $container.find('.charitable-dashboard-notification:not(.charitable-hidden)'),
465 notification_number = $current.data('notification-number'),
466 notification_count = $container.find('.charitable-dashboard-notification').length,
467 new_number = notification_number;
468
469 if ( $this.hasClass('next') ) {
470 new_number++;
471 if ( new_number > notification_count ) {
472 new_number = 1;
473 }
474 } else if ( $this.hasClass('prev') ) {
475 new_number--;
476 if ( new_number < 1 ) {
477 new_number = notification_count;
478 }
479 }
480
481 // Fade out current, then fade in next.
482 $current.fadeOut( 200, function() {
483 $current.addClass('charitable-hidden').removeAttr('style');
484 $container.find('.charitable-dashboard-notification[data-notification-number="' + new_number + '"]').hide().removeClass('charitable-hidden').fadeIn( 200 );
485 });
486
487 // Update the counter text.
488 $container.find('.charitable-dashboard-notification-counter').text( new_number + ' of ' + notification_count );
489 }
490 );
491
492 // when the close button is clicked, remove the notificaiton from the HTML and do an ajax call removing the notficaition from the database.
493 $('body .charitable-dashboard-notifications').on( 'click', '.charitable-remove-dashboard-notification', function( e ) {
494 e.preventDefault();
495
496 var $this = $(this),
497 $container = $this.closest('.charitable-dashboard-notifications'),
498 notification_id = $container.find('.charitable-dashboard-notification:not(.charitable-hidden)').data('notification-id');
499
500 // ajax call to diable the notification.
501 $.ajax({
502 type: 'POST',
503 url: ajaxurl, // eslint-disable-line no-undef
504 data: {
505 action: 'charitable_disable_dashboard_notification',
506 notification_id: notification_id,
507 nonce: charitable_admin.nonce // eslint-disable-line no-undef
508 },
509 success: function( response ) {
510 if ( response.success ) {
511 var $dismissed = $container.find('.charitable-dashboard-notification[data-notification-id="' + notification_id + '"]');
512
513 $dismissed.fadeOut( 200, function() {
514 $dismissed.remove();
515 // count the number of notifications that are left.
516 var notification_count = $container.find('.charitable-dashboard-notification').length;
517 // if there are no more notifications, remove the entire container.
518 if ( notification_count === 0 ) {
519 $container.fadeOut( 200, function() { $container.remove(); });
520 } else {
521 // Show the first remaining notification with fade.
522 $container.find('.charitable-dashboard-notification').first().removeClass('charitable-hidden').hide().fadeIn( 200 );
523
524 if ( notification_count <= 1 ) {
525 // Hide navigation when only one notification remains.
526 $container.find('.charitable-dashboard-notification-navigation').html('');
527 } else {
528 // Update the counter text.
529 var current_number = $container.find('.charitable-dashboard-notification:not(.charitable-hidden)').first().data('notification-number');
530 $container.find('.charitable-dashboard-notification-counter').text( current_number + ' of ' + notification_count );
531 }
532 }
533 });
534 }
535 }
536 });
537
538 });
539
540 },
541
542 /**
543 * Scroll to anchor.
544 * If the url has a hash, scroll to the anchor.
545 *
546 * @return {void}
547 *
548 * @since 1.8.2
549 */
550 scrollToAnchor: function() {
551 // get the hash from the url.
552 var hash = window.location.hash;
553 hash = hash.substring(1);
554
555 if ( hash ) {
556
557 // santitize the hash.
558 hash = hash.replace(/[^a-zA-Z0-9-_]/g, '');
559
560 var $target = $( 'a#wpchr-' + hash ),
561 $container = false;
562
563 if ( $target.length ) {
564 $container = $target.length ? $target.closest('.charitable-growth-content') : false;
565 }
566
567 // remove all css classes 'charitable-selected' from all containers.
568 $('.charitable-growth-content').removeClass('charitable-selected');
569
570 if ( $target.length ) {
571 // scroll to the target.
572 $('html, body').animate({
573 scrollTop: $target.offset().top - 100
574 }, 1000);
575 // after 2 seconds, slowly fade the background color to white.
576 $container.addClass('charitable-selected');
577 }
578 }
579 },
580
581 /**
582 * Create a new campaign popup (deprecated).
583 *
584 */
585 newCampaignPopup: function() {
586
587 var admin_url = typeof charitable_admin !== "undefined" && typeof charitable_admin.admin_url !== "undefined" ? charitable_admin.admin_url : '/wp-admin/', // eslint-disable-line no-undef
588 box_width = $(window).width() * .50;
589
590 if ( box_width > 770 ) {
591 box_width = 770;
592 }
593
594 $.confirm( {
595 title: 'Create Campaign',
596 content: '' +
597 '<form id="create-campaign-form" method="POST" action="' + admin_url + 'admin.php?page=charitable-campaign-builder&view=template" class="formName">' +
598 '<div class="form-group">' +
599 '<label>Name:</label>' +
600 '<input type="text" placeholder="Campaign Name" value="My New Campaign" name="campaign_name" class="name campaign_name form-control" required />' +
601 '</div>' +
602 '</form>',
603 closeIcon: true,
604 boxWidth: box_width + 'px',
605 useBootstrap: false,
606 type: 'create-campaign',
607 animation: 'none',
608 buttons: {
609 formSubmit: {
610 text: 'Create Campaign',
611 btnClass: 'btn-green',
612 action: function () {
613 var campaign_name = this.$content.find('.campaign_name').val().trim();
614 if ( ! campaign_name ){
615 $.alert('Please provide a valid campaign name.');
616 return false;
617 } else {
618 $('.jconfirm-buttons button.btn').html('Creating...');
619 $('#create-campaign-form').submit();
620 return false;
621 }
622 }
623 }
624 },
625 onContentReady: function () {
626
627 }
628 } );
629
630 },
631
632 /**
633 * Create a new campaign popup.
634 * This is the new campaign popup that is used in the campaign list page.
635 *
636 * @since 1.8.2
637 *
638 * @return {void}
639 */
640 campaignListBannerPopup: function() {
641
642 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
643
644 $.confirm( {
645 title: false,
646 content: '' +
647 '<div class="charitable-lite-pro-popup">' +
648 '<div class="charitable-lite-pro-popup-left" >' +
649 '<h1>The Ambassadors Extension is only available for Charitable Pro users.</h1>' +
650 '<h2>Harness the power of supporter networks and friends to reach more people and raise more money for your cause.</h2>' +
651 '<ul>' +
652 '<li><p>Create a crowdfunding platform (similar to GoFundMe)</p></li>' +
653 '<li><p>Simplified fundraiser creation and management</p></li>' +
654 '<li><p>Let supporters fundraise together through our Teams feature</p></li>' +
655 '<li><p>Integrate with email marketing to follow up with campaign creators</p></li>' +
656 '<li><p>Give people a place to fundraise for their own cause</p></li>' +
657 '</ul>' +
658 '<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>' +
659 '<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>' +
660 '</div>' +
661 '<div class="charitable-lite-pro-popup-right" >' +
662 '<img src="' + plugin_asset_dir + 'images/lite-to-pro/ambassador.png" alt="Charitable Ambassador Extension" >' +
663 '</img>' +
664 '</div>',
665 closeIcon: true,
666 alignMiddle: true,
667 boxWidth: '986px',
668 useBootstrap: false,
669 animation: 'none',
670 buttons: false,
671 type: 'lite-pro-ad',
672 onContentReady: function () {
673
674 }
675 } );
676
677 },
678
679 /**
680 * Welcome activation page.
681 *
682 */
683 initWelcome: function() {
684
685 // Open modal and play video.
686 $( document ).on( 'click', '#charitable-welcome .play-video', function( event ) {
687 event.preventDefault();
688
689 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>';
690
691 if ( typeof jconfirm !== 'undefined' ) {
692
693 // jquery-confirm defaults.
694 jconfirm.defaults = {
695 closeIcon: true,
696 backgroundDismiss: false,
697 escapeKey: true,
698 animationBounce: 1,
699 useBootstrap: false,
700 theme: 'modern',
701 animateFromElement: false
702 };
703
704 $.dialog( {
705 title: false,
706 content: video,
707 closeIcon: true,
708 boxWidth: '1300'
709 } );
710
711 }
712
713 } );
714 },
715
716 /**
717 * Initialize the upgrade modal.
718 *
719 * @since 1.8.1.15
720 *
721 * @return {void}
722 *
723 */
724 initUpgradeModal: function() {
725
726 // Upgrade information modal for upgrade links.
727 $( document ).on( 'click', '.charitable-upgrade-modal', function() {
728
729 $.alert( {
730 title : charitable_admin.thanks_for_interest, // eslint-disable-line no-undef
731 content : charitable_admin.upgrade_modal, // eslint-disable-line no-undef
732 icon : 'fa fa-info-circle',
733 type : 'blue',
734 boxWidth : '550px',
735 useBootstrap : false,
736 theme : 'modern,charitable-install-form',
737 closeIcon : false,
738 draggable : false,
739 buttons: {
740 confirm: {
741 text: charitable_admin.ok, // eslint-disable-line no-undef
742 btnClass: 'btn-confirm',
743 keys: [ 'enter' ],
744 }, // eslint-disable-line
745 },
746 } );
747 } );
748
749 },
750
751 /**
752 * Initialize the Square legacy modal.
753 *
754 * @since 1.8.7
755 *
756 * @return {void}
757 *
758 */
759 initSquareLegacyModal: function() {
760
761 // Check if we're on the gateway settings page and Square Core enable button is clicked.
762 $( document ).on( 'click', 'a[href*="charitable_action=enable_gateway"][href*="gateway_id=square_core"]', function( e ) {
763
764 // Check if Square Legacy is active and Square Core is not active.
765 if ( typeof CHARITABLE !== 'undefined' && CHARITABLE.square_legacy_active && !CHARITABLE.square_core_active ) {
766 e.preventDefault();
767
768 $.alert( {
769 title: CHARITABLE.heads_up,
770 content: CHARITABLE.square_legacy_modal_message,
771 icon: 'fa fa-exclamation-circle',
772 type: 'orange',
773 buttons: {
774 confirm: {
775 text: CHARITABLE.ok,
776 btnClass: 'btn-confirm',
777 keys: [ 'enter' ],
778 action: function() {
779 // Perform AJAX call to switch gateways.
780 $.post( CHARITABLE.ajax_url, {
781 action: 'charitable_switch_square_gateways',
782 nonce: CHARITABLE.nonce
783 }, function( response ) {
784 if ( response.success ) {
785 window.location.href = response.data.redirect_url;
786 } else {
787 // Show error message if AJAX fails.
788 $.alert( {
789 title: CHARITABLE.oops,
790 content: CHARITABLE.square_legacy_switch_error,
791 icon: 'fa fa-exclamation-circle',
792 type: 'red',
793 buttons: {
794 confirm: {
795 text: CHARITABLE.ok,
796 btnClass: 'btn-confirm',
797 keys: [ 'enter' ]
798 }
799 }
800 } );
801 }
802 } ).fail( function() {
803 // Show error message if AJAX request fails.
804 $.alert( {
805 title: CHARITABLE.oops,
806 content: CHARITABLE.square_legacy_switch_error,
807 icon: 'fa fa-exclamation-circle',
808 type: 'red',
809 buttons: {
810 confirm: {
811 text: CHARITABLE.ok,
812 btnClass: 'btn-confirm',
813 keys: [ 'enter' ]
814 }
815 }
816 } );
817 } );
818 }
819 },
820 cancel: {
821 text: CHARITABLE.cancel,
822 keys: [ 'esc' ]
823 }
824 }
825 } );
826 }
827 } );
828
829 // Check if we're on the gateway settings page and Square Legacy enable button is clicked.
830 $( document ).on( 'click', 'a[href*="charitable_action=enable_gateway"][href*="gateway_id=square"]', function( e ) {
831
832 // Check if Square Core is active and Square Legacy is not active.
833 if ( typeof CHARITABLE !== 'undefined' && CHARITABLE.square_core_active && !CHARITABLE.square_legacy_active ) {
834 e.preventDefault();
835
836 $.alert( {
837 title: CHARITABLE.heads_up,
838 content: CHARITABLE.square_core_modal_message,
839 icon: 'fa fa-exclamation-circle',
840 type: 'orange',
841 buttons: {
842 confirm: {
843 text: CHARITABLE.ok,
844 btnClass: 'btn-confirm',
845 keys: [ 'enter' ],
846 action: function() {
847 // Perform AJAX call to switch gateways.
848 $.post( CHARITABLE.ajax_url, {
849 action: 'charitable_switch_square_core_to_legacy',
850 nonce: CHARITABLE.nonce
851 }, function( response ) {
852 if ( response.success ) {
853 window.location.href = response.data.redirect_url;
854 } else {
855 // Show error message if AJAX fails.
856 $.alert( {
857 title: CHARITABLE.oops,
858 content: CHARITABLE.square_legacy_switch_error,
859 icon: 'fa fa-exclamation-circle',
860 type: 'red',
861 buttons: {
862 confirm: {
863 text: CHARITABLE.ok,
864 btnClass: 'btn-confirm',
865 keys: [ 'enter' ]
866 }
867 }
868 } );
869 }
870 } ).fail( function() {
871 // Show error message if AJAX request fails.
872 $.alert( {
873 title: CHARITABLE.oops,
874 content: CHARITABLE.square_legacy_switch_error,
875 icon: 'fa fa-exclamation-circle',
876 type: 'red',
877 buttons: {
878 confirm: {
879 text: CHARITABLE.ok,
880 btnClass: 'btn-confirm',
881 keys: [ 'enter' ]
882 }
883 }
884 } );
885 } );
886 }
887 },
888 cancel: {
889 text: CHARITABLE.cancel,
890 keys: [ 'esc' ]
891 }
892 }
893 } );
894 }
895 } );
896
897 },
898
899 };
900
901 // Provide access to public functions/properties.
902 return app;
903
904 }( document, window, jQuery ) ); // eslint-disable-line no-undef
905
906 CharitableAdminUI.init();
907