1$ = jQuery; 2 3let flag = true; 4 5function wcDonationIsCampaignPreview() { 6 if (jQuery("body").hasClass("wcd-campaign-preview-body")) { 7 return true; 8 } 9 if (jQuery("body").attr("data-wcd-campaign-preview") === "1") { 10 return true; 11 } 12 if ( 13 typeof wcOrderScript !== "undefined" && 14 wcOrderScript.donationToOrder && 15 wcOrderScript.donationToOrder.is_campaign_preview 16 ) { 17 return true; 18 } 19 return false; 20} 21 22function wcDonationFeesTypeFor($checkbox) { 23 if (!$checkbox || !$checkbox.length) { 24 return wcOrderScript.donationToOrder.fees_type; 25 } 26 var t = $checkbox.data("fee-type"); 27 if (t === "percentage" || t === "fixed") { 28 return t; 29 } 30 return wcOrderScript.donationToOrder.fees_type; 31} 32 33function wcDonationCalcProcessingFee(amount, procFees, feesType) { 34 var amt = parseFloat(amount); 35 var fee = parseFloat(procFees); 36 if (isNaN(amt) || isNaN(fee)) { 37 return 0; 38 } 39 if (feesType === "percentage") { 40 return amt * (fee / 100); 41 } 42 return fee; 43} 44 45function wcDonationUpdateProcessingFeeSummary($checkbox) { 46 if (!$checkbox || !$checkbox.length) { 47 return; 48 } 49 var id = $checkbox.data("id"); 50 var campid = $checkbox.data("camp"); 51 if (!id || !campid) { 52 return; 53 } 54 var procFees = $checkbox.val(); 55 var wcdonationprice = jQuery("#wc-donation-price-" + campid).val(); 56 var feesType = wcDonationFeesTypeFor($checkbox); 57 var donation_card_fee = wcDonationCalcProcessingFee( 58 wcdonationprice, 59 procFees, 60 feesType, 61 ); 62 var donation_summary_total = 63 parseFloat(wcdonationprice) + parseFloat(donation_card_fee); 64 65 if (donation_summary_total > 0 && donation_summary_total != "") { 66 jQuery( 67 "#wc-donation-summary-" + campid + " .wc-donation-currency-symbol", 68 ).attr("style", "display: inline-block !important"); 69 jQuery( 70 "#wc-donation-summary-" + campid + " .wc-donation-charge .wc-donation-amt", 71 ).text(parseFloat(wcdonationprice).toFixed(2)); 72 jQuery( 73 "#wc-donation-summary-" + 74 campid + 75 " .wc-donation-fee-summary .wc-donation-amt", 76 ).text(parseFloat(donation_card_fee).toFixed(2)); 77 jQuery( 78 "#wc-donation-summary-" + 79 campid + 80 " .wc-donation-summary-total .wc-donation-amt", 81 ).text(parseFloat(donation_summary_total).toFixed(2)); 82 } 83 if ($checkbox.is(":checked")) { 84 jQuery("#wc-donation-summary-" + campid).show(); 85 jQuery("#wc-donation-" + id).val(procFees); 86 } else { 87 jQuery("#wc-donation-summary-" + campid).hide(); 88 jQuery("#wc-donation-" + id).val(""); 89 } 90} 91 92function wcDonationPbHasDonationFormBlock(campaignId) { 93 if (campaignId) { 94 var $form = jQuery("#wc-donation-pb-form-" + campaignId); 95 return ( 96 $form.length > 0 && !$form.hasClass("wc-donation-pb-donation-form--empty") 97 ); 98 } 99 return ( 100 jQuery( 101 "[id^='wc-donation-pb-form-']:not(.wc-donation-pb-donation-form--empty)", 102 ).length > 0 103 ); 104} 105 106function wcDonationGetPbDonorScope(campaign_id, $parents) { 107 if (!wcDonationPbHasDonationFormBlock(campaign_id)) { 108 return jQuery(); 109 } 110 111 var $scopes = jQuery(); 112 if (campaign_id) { 113 var $formScope = jQuery("#wc-donation-pb-form-scope-" + campaign_id); 114 if ($formScope.length) { 115 $scopes = $scopes.add($formScope); 116 } 117 } 118 if ($parents && $parents.length) { 119 var $parentScope = $parents.closest(".wc-donation-pb-donation-form__scope"); 120 if ($parentScope.length) { 121 $scopes = $scopes.add($parentScope); 122 } 123 if ($parents.find(".wc-donation-pb-donor-field").length) { 124 $scopes = $scopes.add($parents); 125 } 126 } 127 if (!$scopes.length && campaign_id) { 128 $scopes = jQuery("#wc-donation-pb-form-scope-" + campaign_id); 129 } 130 return $scopes; 131} 132 133function wcDonationCollectPbDonorFields(campaign_id, $parents) { 134 if (!wcDonationPbHasDonationFormBlock(campaign_id)) { 135 return {}; 136 } 137 138 var donor = {}; 139 var $scope = wcDonationGetPbDonorScope(campaign_id, $parents); 140 $scope.find(".wc-donation-pb-donor-field").each(function () { 141 var $f = jQuery(this); 142 var key = 143 $f.attr("data-wc-donation-pb-field") || 144 $f.data("wcDonationPbField") || 145 ""; 146 if (!key) { 147 return; 148 } 149 var val = 150 $f.val() !== null && $f.val() !== undefined ? String($f.val()).trim() : ""; 151 donor[key] = val; 152 }); 153 return donor; 154} 155 156function wcDonationValidateFormDonorFields(btnEl) { 157 var $btn = jQuery(btnEl); 158 var campaign_id = $btn.siblings(".wc_donation_camp").val(); 159 if (!campaign_id) { 160 var $formRoot = $btn.closest("[id^='wc-donation-pb-form-']"); 161 if ($formRoot.length) { 162 var match = String($formRoot.attr("id") || "").match( 163 /wc-donation-pb-form-(\d+)/, 164 ); 165 if (match) { 166 campaign_id = match[1]; 167 } 168 } 169 } 170 if (!wcDonationPbHasDonationFormBlock(campaign_id)) { 171 return true; 172 } 173 174 var $parents = $btn.closest(".wc-donation-in-action"); 175 var $scope = wcDonationGetPbDonorScope(campaign_id, $parents); 176 if (!$scope.find(".wc-donation-pb-donor-field").length) { 177 return true; 178 } 179 180 var firstInvalid = null; 181 $scope 182 .find('.wc-donation-pb-donor-field[data-required="1"]') 183 .each(function () { 184 var $field = jQuery(this); 185 var val = ($field.val() || "").trim(); 186 if (val === "") { 187 $field.addClass("wc-donation-pb-field-error"); 188 if (!firstInvalid) { 189 firstInvalid = $field; 190 } 191 } else { 192 $field.removeClass("wc-donation-pb-field-error"); 193 } 194 }); 195 196 if (firstInvalid) { 197 var label = firstInvalid 198 .closest(".wc-donation-pb-form-field") 199 .find(".wc-donation-pb-form-field__label-inner") 200 .text() 201 .replace(/\s*\*\s*$/, "") 202 .trim(); 203 var msg = label 204 ? label + " is required." 205 : "Please fill in all required fields."; 206 alert(msg); 207 firstInvalid.focus(); 208 return false;
209 } 210 211 return true; 212} 213 214function wcDonationGetPbValidationScope(campaign_id, $parents) { 215 var $scopes = jQuery(); 216 if (campaign_id) { 217 var $form = jQuery("#wc-donation-pb-form-" + campaign_id); 218 if ($form.length) { 219 $scopes = $scopes.add($form); 220 } 221 var $formScope = jQuery("#wc-donation-pb-form-scope-" + campaign_id); 222 if ($formScope.length) { 223 $scopes = $scopes.add($formScope); 224 } 225 var $canvas = jQuery( 226 '.wc-donation-pb-canvas[data-campaign-id="' + campaign_id + '"]', 227 ); 228 if ($canvas.length) { 229 $scopes = $scopes.add($canvas); 230 } 231 } 232 if ($parents && $parents.length) { 233 $scopes = $scopes.add($parents); 234 var $parentScope = $parents.closest(".wc-donation-pb-donation-form__scope"); 235 if ($parentScope.length) { 236 $scopes = $scopes.add($parentScope); 237 } 238 } 239 return $scopes; 240} 241 242function wcDonationValidateTermsBeforeDonate(btnEl) { 243 var $btn = jQuery(btnEl); 244 var campaign_id = $btn.siblings(".wc_donation_camp").val(); 245 if (!campaign_id) { 246 var $formRoot = $btn.closest("[id^='wc-donation-pb-form-']"); 247 if ($formRoot.length) { 248 var match = String($formRoot.attr("id") || "").match( 249 /wc-donation-pb-form-(\d+)/, 250 ); 251 if (match) { 252 campaign_id = match[1]; 253 } 254 } 255 } 256 if (!campaign_id) { 257 var $canvas = $btn.closest(".wc-donation-pb-canvas[data-campaign-id]"); 258 if ($canvas.length) { 259 campaign_id = $canvas.attr("data-campaign-id"); 260 } 261 } 262 263 var $parents = $btn.closest(".wc-donation-in-action"); 264 var $scope = wcDonationGetPbValidationScope(campaign_id, $parents); 265 var $required = $scope.find( 266 '.wc-donation-pb-terms__checkbox[data-required="1"]', 267 ); 268 269 if (!$required.length && campaign_id) { 270 $required = jQuery( 271 '.wc-donation-pb-canvas[data-campaign-id="' + 272 campaign_id + 273 '"] .wc-donation-pb-terms__checkbox[data-required="1"], ' + 274 '#wc-donation-pb-form-' + 275 campaign_id + 276 ' .wc-donation-pb-terms__checkbox[data-required="1"], ' + 277 '#wc-donation-pb-form-scope-' + 278 campaign_id + 279 ' .wc-donation-pb-terms__checkbox[data-required="1"]', 280 ); 281 } 282 283 if (!$required.length) { 284 return true; 285 } 286 287 var unchecked = $required.filter(function () { 288 return !jQuery(this).is(":checked"); 289 }); 290 291 if (unchecked.length) { 292 alert("Please accept the terms and conditions to continue."); 293 unchecked.first().focus(); 294 return false; 295 } 296 297 return true; 298} 299 300function wcDonationValidateCauseBeforeDonate(btnEl, campaign_id, rand_id) { 301 var $btn = jQuery(btnEl); 302 var $parents = $btn.closest(".wc-donation-in-action"); 303 var $scope = wcDonationGetPbValidationScope(campaign_id, $parents); 304 var $requiredCauses = $scope.find('.wc-donation-pb-cause[data-required="1"]'); 305 306 if (!$requiredCauses.length && campaign_id) { 307 $requiredCauses = jQuery('.wc-donation-pb-cause[data-required="1"]').filter( 308 function () { 309 return ( 310 jQuery(this).closest("#wc-donation-pb-form-" + campaign_id).length > 311 0 || 312 jQuery(this).find('[id^="wc-donation-cause-' + campaign_id + '_"]') 313 .length > 0 314 ); 315 }, 316 ); 317 } 318 319 if (!$requiredCauses.length) { 320 return true; 321 } 322 323 var fields = wcDonationReadCauseHiddenFields(campaign_id, rand_id); 324 var hasCause = 325 (fields.cause_id && String(fields.cause_id).trim() !== "") || 326 (fields.cause && String(fields.cause).trim() !== ""); 327 328 if (!hasCause && campaign_id) { 329 jQuery( 330 '[id^="wc-donation-cause-id-' + 331 campaign_id + 332 '_"], [class*="donate_cause_id_' + 333 campaign_id + 334 '_"]', 335 ).each(function () { 336 var val = jQuery(this).val(); 337 if (val !== null && val !== undefined && String(val).trim() !== "") { 338 hasCause = true; 339 return false; 340 } 341 }); 342 } 343 344 if (!hasCause) { 345 alert("Please select a cause."); 346 var $dropdown = $requiredCauses.first().find("ul.causes-dropdown .init"); 347 if ($dropdown.length) { 348 $dropdown.trigger("focus"); 349 } 350 return false; 351 } 352 353 return true; 354} 355 356if ( 357 jQuery("form.woocommerce-checkout").length > 0 && 358 !jQuery("form.woocommerce-checkout").hasClass("wc-roundoff") 359) { 360 jQuery("form.woocommerce-checkout").addClass("wc-roundoff"); 361} 362dispaly_socialshare_links(jQuery); 363 364jQuery(document).on( 365 "input change", 366 ".wc-donation-pb-donor-field.wc-donation-pb-field-error", 367 function () { 368 jQuery(this).removeClass("wc-donation-pb-field-error"); 369 }, 370); 371 372jQuery(window).on("load", function () { 373 if ( 374 wcOrderScript.donationToOrder.is_checkout && 375 wcOrderScript.donationToOrder.is_roundOff == "yes" 376 ) { 377 jQuery(".wc-block-components-checkout-place-order-button").on( 378 "click", 379 function (e) { 380 if (flag) { 381 e.stopPropagation(); 382 add_popup_before_order(); 383 } 384 }, 385 ); 386 } 387}); 388 389function wcDonationGetDateRangeCountdownSeconds(clockElement) { 390 var endTs = parseInt(clockElement.data("countdown-end"), 10); 391 if (!endTs) { 392 return 0; 393 } 394 var nowSec = Math.floor(Date.now() / 1000); 395 return Math.max(endTs - nowSec, 0); 396} 397 398function wcDonationInitFlipClockFromTimeStrings(clockElement) { 399 var startTimeStr = clockElement.data("start-time"); 400 var endTimeStr = clockElement.data("end-time"); 401 if (!startTimeStr || !endTimeStr) { 402 return; 403 } 404 405 var endTimeArr = String(endTimeStr).split(":"); 406 var startTimeArr = String(startTimeStr).split(":"); 407 var now = new Date(); 408 var endTime = new Date( 409 now.getFullYear(), 410 now.getMonth(), 411 now.getDate(), 412 parseInt(endTimeArr[0], 10), 413 parseInt(endTimeArr[1], 10), 414 0, 415 ); 416 417 if (endTime.getTime() < now.getTime()) { 418 endTime.setDate(endTime.getDate() + 1); 419 } 420 421 var diff = endTime.getTime() / 1000 - now.getTime() / 1000; 422 diff = Math.max(diff, 0); 423 clockElement.addClass("non-clickable"); 424 var clock = clockElement.FlipClock(diff, { 425 clockFace: "HourlyCounter", 426 countdown: true, 427 }); 428 429 var interval = null; 430 if (diff > 0) { 431 interval = setInterval(function () { 432 if (clock.getTime().time <= 0) { 433 clearInterval(interval); 434 location.reload(); 435 } 436 }, 1000); 437 } 438 439 clock.setTime(diff); 440 clock.start(); 441} 442 443function wcDonationInitFlipClockFromDateRange(clockElement) { 444 var diff = wcDonationGetDateRangeCountdownSeconds(clockElement); 445 clockElement.addClass("non-clickable wc-donation-timer-date-range"); 446 var clock = clockElement.FlipClock(diff, { 447 clockFace: "DailyCounter", 448 countdown: true, 449 }); 450 451 // Expired date range: render zeros and do not reload (avoids infinite loop). 452 if (diff > 0) { 453 var interval = setInterval(function () { 454 var remaining = wcDonationGetDateRangeCountdownSeconds(clockElement); 455 if (remaining <= 0) { 456 clearInterval(interval); 457 location.reload(); 458 return; 459 } 460 clock.setTime(remaining); 461 }, 1000); 462 } 463 464 clock.setTime(diff); 465 if (diff > 0) { 466 clock.start(); 467 } 468} 469 470jQuery(window).on("load", function () { 471 jQuery(".flip-clock").each(function () { 472 var clockElement = jQuery(this); 473 if ("date" === clockElement.data("timer-mode")) { 474 wcDonationInitFlipClockFromDateRange(clockElement); 475 return; 476 } 477 wcDonationInitFlipClockFromTimeStrings(clockElement); 478 }); 479 480 // Initialize Pomodoro clock instances (single centered ProgressBar text â no .timer-label markup). 481 jQuery(".pomodoro-clock-container").each(function () { 482 var container = this; 483 var $container = jQuery(container); 484 485 // Ensure a clean container (ProgressBar owns SVG + text). 486 $container.empty().css({ 487 position: "relative", 488 width: "200px", 489 height: "200px", 490 margin: "0 auto", 491 display: "block", 492 }); 493 494 var now = new Date(); 495 var start; 496 var end; 497 var duration; 498 var remainingTime; 499 var isDateRange = "date" === $container.data("timer-mode"); 500 501 if (isDateRange) { 502 var startTs = parseInt($container.data("countdown-start"), 10) || 0; 503 var endTs = parseInt($container.data("countdown-end"), 10) || 0; 504 if (!endTs) { 505 return; 506 } 507 start = new Date(startTs * 1000); 508 end = new Date(endTs * 1000); 509 duration = Math.max((end - start) / 1000, 1); 510 remainingTime = Math.max((end - now) / 1000, 0); 511 } else { 512 var startTimeStr = $container.data("start-time"); 513 var endTimeStr = $container.data("end-time"); 514 if (!startTimeStr || !endTimeStr) { 515 return; 516 } 517 518 var startTimeParts = String(startTimeStr).split(":"); 519 var endTimeParts = String(endTimeStr).split(":"); 520 521 start = new Date( 522 now.getFullYear(), 523 now.getMonth(), 524 now.getDate(), 525 startTimeParts[0], 526 startTimeParts[1], 527 0, 528 ); 529 end = new Date( 530 now.getFullYear(), 531 now.getMonth(), 532 now.getDate(), 533 endTimeParts[0], 534 endTimeParts[1], 535 0, 536 ); 537 538 if (end < start) { 539 end.setDate(end.getDate() + 1); 540 } 541 542 duration = (end - start) / 1000; 543 var elapsedTime = (now - start) / 1000; 544 remainingTime = duration - elapsedTime; 545 546 var storedRemainingTime = localStorage.getItem("remainingTime"); 547 var lastSaved = localStorage.getItem("lastSaved"); 548 if (storedRemainingTime && lastSaved) { 549 var elapsedSinceLastSave = 550 (now.getTime() - new Date(lastSaved).getTime()) / 1000; 551 remainingTime = Math.max(0, storedRemainingTime - elapsedSinceLastSave); 552 } 553 554 var totalSecondsInDay = 24 * 60 * 60; 555 remainingTime = remainingTime % totalSecondsInDay; 556 } 557 558 if (!(duration >
558 0)) { 559 duration = 1; 560 } 561 remainingTime = Math.max(remainingTime, 0); 562 var startedWithTime = remainingTime > 0; 563 564 var bar = new ProgressBar.Circle(container, { 565 color: "#EFBBBE", 566 trailColor: "#BF5252", 567 trailWidth: 5, 568 duration: remainingTime * 1000, 569 easing: "linear", 570 strokeWidth: 5, 571 from: { color: "#EFBBBE", width: 5 }, 572 to: { color: "#EFBBBE", width: 5 }, 573 text: { 574 value: formatDuration(remainingTime), 575 className: "progressbar-text wc-donation-pomodoro-time", 576 style: { 577 color: "#374151", 578 position: "absolute", 579 left: "50%", 580 top: "50%", 581 padding: 0, 582 margin: 0, 583 fontSize: "20px", 584 fontWeight: "600", 585 lineHeight: "1.2", 586 whiteSpace: "nowrap", 587 transform: { 588 prefix: true, 589 value: "translate(-50%, -50%)", 590 }, 591 }, 592 }, 593 svgStyle: { 594 display: "block", 595 width: "100%", 596 height: "100%", 597 position: "absolute", 598 left: "0", 599 top: "0", 600 }, 601 step: function (state, circle) { 602 var elapsed = (1.0 - circle.value()) * duration; 603 var remaining = Math.max(duration - elapsed, 0); 604 circle.setText(formatDuration(remaining)); 605 circle.path.setAttribute("stroke", state.color); 606 circle.path.setAttribute("stroke-width", state.width); 607 }, 608 }); 609 610 function updateProgressBar() { 611 bar.set(remainingTime / duration); 612 if (remainingTime <= 0) { 613 clearInterval(progressInterval); 614 } 615 } 616 617 var progressInterval = setInterval(updateProgressBar, 1100); 618 updateProgressBar(); 619 620 var interval = setInterval(function () { 621 now = new Date(); 622 if (isDateRange) { 623 remainingTime = Math.max((end - now) / 1000, 0); 624 } else { 625 var elapsed = (now - start) / 1000; 626 remainingTime = Math.max(duration - elapsed, 0); 627 remainingTime = remainingTime % (24 * 60 * 60); 628 localStorage.setItem("remainingTime", remainingTime); 629 localStorage.setItem("lastSaved", new Date().toISOString()); 630 } 631 bar.setText(formatDuration(remainingTime)); 632 633 // Only reload when a live countdown finishes â not when already expired on load. 634 if (remainingTime <= 1 && startedWithTime) { 635 clearInterval(interval); 636 location.reload(); 637 } else if (remainingTime <= 0) { 638 clearInterval(interval); 639 } 640 }, 1000); 641 642 if (!isDateRange) { 643 jQuery(window).on("beforeunload", function () { 644 now = new Date(); 645 var elapsedOnUnload = (now - start) / 1000; 646 var remainingOnUnload = Math.max(duration - elapsedOnUnload, 0); 647 remainingOnUnload = remainingOnUnload % (24 * 60 * 60); 648 localStorage.setItem("remainingTime", remainingOnUnload); 649 localStorage.setItem("lastSaved", new Date().toISOString()); 650 }); 651 } 652 }); 653 654 jQuery("<style>") 655 .prop("type", "text/css") 656 .html( 657 "\ 658 .wc-donation-pb-timer-clocks .flip-clock-wrapper .flip-clock-days,\ 659 .wc-donation-timer .flip-clock-wrapper .flip-clock-days {\ 660 display: none;\ 661 }\ 662 .wc-donation-pb-timer-clocks .flip-clock-wrapper.wc-donation-timer-date-range .flip-clock-days,\ 663 .wc-donation-timer .flip-clock-wrapper.wc-donation-timer-date-range .flip-clock-days {\ 664 display: block;\ 665 }\ 666 .pomodoro-clock-container {\ 667 position: relative !important;\ 668 width: 200px !important;\ 669 height: 200px !important;\ 670 margin: 0 auto !important;\ 671 display: block !important;\ 672 }\ 673 .pomodoro-clock-container > svg {\ 674 position: absolute !important;\ 675 left: 0 !important;\ 676 top: 0 !important;\ 677 width: 100% !important;\ 678 height: 100% !important;\ 679 }\ 680 .pomodoro-clock-container .progressbar-text,\ 681 .pomodoro-clock-container .wc-donation-pomodoro-time {\ 682 position: absolute !important;\ 683 left: 50% !important;\ 684 top: 50% !important;\ 685 transform: translate(-50%, -50%) !important;\ 686 -webkit-transform: translate(-50%, -50%) !important;\ 687 margin: 0 !important;\ 688 padding: 0 !important;\ 689 z-index: 3 !important;\ 690 text-align: center !important;\ 691 white-space: nowrap !important;\ 692 pointer-events: none !important;\ 693 }\ 694 ", 695 ) 696 .appendTo("head"); 697}); 698
699function formatTime(date) { 700 var hours = date.getHours(); 701 var minutes = date.getMinutes(); 702 return ( 703 (hours < 10 ? "0" : "") + hours + ":" + (minutes < 10 ? "0" : "") + minutes 704 ); 705} 706 707function formatDuration(seconds) { 708 var hours = Math.floor(seconds / 3600); 709 seconds %= 3600; 710 var minutes = Math.floor(seconds / 60); 711 var sec = Math.floor(seconds % 60); 712 return ( 713 (hours < 10 ? "0" : "") + 714 hours + 715 ":" + 716 (minutes < 10 ? "0" : "") + 717 minutes + 718 ":" + 719 (sec < 10 ? "0" : "") + 720 sec 721 ); 722} 723//WC Donation Tabs Frontend 724jQuery(document).on( 725 "click", 726 ".wc-donation-tabs-wrap ul.tab-nav > li", 727 function (event) { 728 event.preventDefault(); 729 jQuery(this).siblings().removeClass("active"); 730 jQuery(this).addClass("active"); 731 var content = jQuery(this).data("tab"); 732 jQuery(".wc-donation-tab-content").removeClass("active"); 733 jQuery(`.wc-donation-tab-content.${content}`).addClass("active"); 734 }, 735); 736 737function add_popup_before_order() { 738 jQuery.ajax({ 739 url: wcOrderScript.donationToOrder.ajaxUrl, 740 type: "POST", 741 dataType: "json", 742 data: { 743 action: "add_popup_before_order", 744 nonce: wcOrderScript.donationToOrder.nonce, 745 }, 746 beforeSend: function () { 747 //if loader needs to add put here 748 }, 749 success: function (response) { 750 if (response["status"] == "success") { 751 jQuery(".wc-donation-popup") 752 .find("#wc-donation-price-" + response["campaign_id"]) 753 .val(response["donation"]); 754 var text = jQuery(".wc-donation-popup").find(".donation_text").text(); 755 var res = text.replace("%amount%", response["donation"]); 756 jQuery(".wc-donation-popup").find(".donation_text").text(res); 757 jQuery(".wc-donation-popup:not(.cart-campaign-popup)").addClass( 758 "wc-popup-show", 759 ); 760 } else { 761 flag = false; 762 jQuery(".wc-block-components-checkout-place-order-button").trigger( 763 "click", 764 ); 765 jQuery("form.woocommerce-checkout").submit(); 766 } 767 }, 768 }); 769} 770 771if ( 772 wcOrderScript.donationToOrder.is_checkout && 773 !wcOrderScript.donationToOrder.is_order_pay 774) { 775 /* when click on place order*/ 776 jQuery(document).on("click", "#place_order", function (e) { 777 if ( 778 wcOrderScript.donationToOrder.is_checkout && 779 wcOrderScript.donationToOrder.is_roundOff == "yes" 780 ) { 781 e.preventDefault(); 782 add_popup_before_order(); 783 } 784 }); 785} 786 787function NumbersOnly(myfield, e, dec) { 788 var allowNegativeNumber = false; 789 var key; 790 var keychar; 791 792 if (window.event) key = window.event.keyCode; 793 else if (e) key = e.which; 794 else return true; 795 keychar = String.fromCharCode(key); 796 var srcEl = e.srcElement ? e.srcElement : e.target; 797 798 // control keys 799 if (key == null || key == 0 || key == 9 || key == 13 || key == 27) { 800 return true; 801 } 802 803 // numbers 804 if ("0123456789".indexOf(keychar) > -1) return true; 805 // decimal point jump 806 else if (dec && keychar == ".") { 807 //myfield.form.elements[dec].focus(); 808 return srcEl.value.indexOf(".") == -1; 809 } else if (dec && keychar == ",") { 810 return srcEl.value.indexOf(",") == -1; 811 } 812 813 //allow negative numbers 814 else if (allowNegativeNumber && keychar == "-") { 815 return srcEl.value.length == 0 || srcEl.value == "0.00"; 816 } else return false; 817} 818 819jQuery(document).on("focusout", ".grab-donation", function () { 820 var This = jQuery(this); 821 var min = This.data("min"); 822 var max = This.data("max"); 823 var id = This.data("campaign_id"); 824 var rand_id = This.data("rand_id"); 825 var priceEl = document.getElementById( 826 "wc-donation-price-" + id + "_" + rand_id, 827 ); 828 var val = This.val(); 829 830 if (max <= 0 && max != "any") { 831 max = val; 832 } 833 834 if ((min == "any" && max == "any") || (val >= min && val <= max)) { 835 var $feeCb = jQuery("#processing-fees-" + id + "_" + rand_id); 836 var procFees = $feeCb.val(); 837 var feesType = wcDonationFeesTypeFor($feeCb); 838 var donation_card_fee = wcDonationCalcProcessingFee(val, procFees, feesType); 839 840 var donation_summary_total = 841 parseFloat(val) + parseFloat(donation_card_fee); 842 843 if (donation_summary_total > 0 && donation_summary_total != "") { 844 jQuery( 845 "#wc-donation-summary-" + 846 id + 847 "_" + 848 rand_id + 849 " .wc-donation-currency-symbol", 850 ).attr("style", "display: inline-block !important"); 851 jQuery( 852 "#wc-donation-summary-" + 853 id + 854 "_" + 855 rand_id + 856 " .wc-donation-charge .wc-donation-amt", 857 ).text(parseFloat(val).toFixed(2)); 858 jQuery( 859 "#wc-donation-summary-" + 860 id + 861 "_" + 862 rand_id + 863 " .wc-donation-fee-summary .wc-donation-amt", 864 ).text(parseFloat(donation_card_fee).toFixed(2)); 865 jQuery( 866 "#wc-donation-summary-" + 867 id + 868 "_" + 869 rand_id + 870 " .wc-donation-summary-total .wc-donation-amt", 871 ).text(parseFloat(donation_summary_total).toFixed(2)); 872 } else { 873 jQuery( 874 "#wc-donation-summary-" + 875 id + 876 "_" + 877 rand_id + 878 " .wc-donation-currency-symbol", 879 ).attr("style", "display: inline-block !important"); 880 jQuery( 881 "#wc-donation-summary-" + 882 id + 883 "_" + 884 rand_id + 885 " .wc-donation-charge .wc-donation-amt", 886 ).text(parseFloat(0).toFixed(2)); 887 jQuery( 888 "#wc-donation-summary-" + 889 id + 890 "_" + 891 rand_id + 892 " .wc-donation-fee-summary .wc-donation-amt", 893 ).text(parseFloat(0).toFixed(2)); 894 jQuery( 895 "#wc-donation-summary-" + 896 id + 897 "_" + 898 rand_id + 899 " .wc-donation-summary-total .wc-donation-amt", 900 ).text(parseFloat(0).toFixed(2)); 901 } 902 priceEl.value = val; 903 } else { 904 priceEl.value = ""; 905 This.val(""); 906 } 907}); 908 909jQuery(document).on("click", ".wc-donation-pb-form-modal-close", function () { 910 jQuery(this).closest(".wc-donation-popup").removeClass("wc-popup-show"); 911}); 912 913jQuery(document).on("click", ".wc-close", function () { 914 jQuery(this).parents(".wc-donation-popup").removeClass("wc-popup-show"); 915 if (jQuery("body").hasClass("stopScroll")) { 916 jQuery("body").removeClass("stopScroll"); 917 } 918}); 919 920function wcDonationValidateSubscriptionBeforeDonate(e) { 921 if (!jQuery("#wps_sfw_subscription_number").length) { 922 return true; 923 } 924 925 var subscriptionNumber = parseInt( 926 jQuery("#wps_sfw_subscription_number").val(), 927 10, 928 ); 929 var expiryNumber = parseInt( 930 jQuery("#wps_sfw_subscription_expiry_number").val(), 931 10, 932 ); 933 934 if (jQuery(".donation-is-recurring").is(":checked")) { 935 if (isNaN(subscriptionNumber) || subscriptionNumber === "") { 936 alert("Please enter the number of subscriptions per interval."); 937 e.preventDefault(); 938 return false;
939 } 940 } 941 942 if (subscriptionNumber < 1 || expiryNumber < 1) { 943 alert("Interval cannot be negative."); 944 e.preventDefault(); 945 return false; 946 } 947 948 if (subscriptionNumber > expiryNumber) { 949 alert( 950 "Subscriptions Per Interval must not be greater than Subscriptions Expiry Interval.", 951 ); 952 e.preventDefault(); 953 return false; 954 } 955 956 return true; 957} 958 959function addDonationToOrder( 960 type, 961 amount, 962 min_amount, 963 max_amount, 964 campaign_id, 965 is_recurring, 966 new_period, 967 new_length, 968 new_interval, 969 tracker, 970 donation_type, 971 cause, 972 cause_id = "", 973 fees, 974 gift_aid = "", 975 tribute = "", 976 tribute_message = "", 977 e_card_email, 978 cc_processing_fee, 979 _this, 980 wps_sfw_sub_number, 981 wps_sfw_sub_interval, 982 wps_sfw_sub_exp_number, 983 wps_sfw_sub_exp_interval, 984 selectedLabel, 985 wc_donation_pb_donor = {}, 986 donation_anonymous = "", 987 terms_accepted = "", 988 fee_calc_type = "", 989) { 990 if (wcDonationIsCampaignPreview()) { 991 return false; 992 } 993 994 let skip = false; 995 996 if (type === "roundoff-skip") { 997 flag = false; 998 jQuery(".wc-block-components-checkout-place-order-button").trigger("click"); 999 jQuery("form.woocommerce-checkout").submit(); 1000 return true; 1001 } 1002 if (amount != 0 && amount != null && amount > 0) { 1003 jQuery.ajax({ 1004 url: wcOrderScript.donationToOrder.ajaxUrl, 1005 type: "POST", 1006 dataType: "json", 1007 data: { 1008 action: wcOrderScript.donationToOrder.action, 1009 nonce: wcOrderScript.donationToOrder.nonce, 1010 campaign_id: campaign_id, 1011 amount: amount, 1012 selectedLabel: selectedLabel, 1013 cause: cause, 1014 cause_id: cause_id, 1015 fees: fees, 1016 type: type, 1017 tribute: tribute, 1018 tribute_message: tribute_message, 1019 e_card_email: e_card_email, 1020 gift_aid: gift_aid, 1021 is_recurring: is_recurring, 1022 new_period: new_period, 1023 new_length: new_length, 1024 new_interval: new_interval, 1025 cc_processing_fee: cc_processing_fee, 1026 wps_sfw_subscription_number: wps_sfw_sub_number, 1027 wps_sfw_subscription_interval: wps_sfw_sub_interval, 1028 wps_sfw_subscription_expiry_number: wps_sfw_sub_exp_number, 1029 wps_sfw_subscription_expiry_interval: wps_sfw_sub_exp_interval, 1030 wc_donation_pb_donor: wc_donation_pb_donor, 1031 donation_anonymous: donation_anonymous, 1032 terms_accepted: terms_accepted, 1033 fee_calc_type: fee_calc_type, 1034 }, 1035 beforeSend: function () { 1036 jQuery(_this) 1037 .parents(".wc_donation_on_cart") 1038 .append( 1039 '<div class="wc-donation-loader-css"><div class="wc-donation-blur-effect"></div><div class="wc-donation-loader" style="display:block;"></div></div>', 1040 ); 1041 jQuery(_this) 1042 .parents(".widget_wc-donation-widget") 1043 .append( 1044 '<div class="wc-donation-loader-css"><div class="wc-donation-blur-effect"></div><div class="wc-donation-loader" style="display:block;"></div></div>', 1045 ); 1046 }, 1047 success: function (response) { 1048 if (response["response"] == "success") { 1049 jQuery(`input[value="${campaign_id}"]`) 1050 .closest(".wc_donation_on_cart") 1051 .find("div.wc-donation-loader-css") 1052 .remove(); 1053 jQuery(`input[value="${campaign_id}"]`) 1054 .closest(".widget_wc-donation-widget") 1055 .find("div.wc-donation-loader-css") 1056 .remove(); 1057 jQuery("[name='update_cart']").prop("disabled", false); 1058 jQuery("[name='update_cart']").trigger("click"); 1059 1060 if (type === "roundoff") { 1061 jQuery(".wc-donation-popup").removeClass("wc-popup-show"); 1062 } 1063 1064 jQuery("body").trigger("update_checkout"); 1065 if ( 1066 typeof wc !== "undefined" && 1067 typeof wc.blocksCheckout !== "undefined" 1068 ) { 1069 flag = false; 1070 const { extensionCartUpdate } = wc.blocksCheckout; 1071 extensionCartUpdate({ 1072 namespace: "dfw", 1073 data: {}, 1074 }); 1075 } 1076 1077 if (jQuery("#wc-donation-woocommerce-notices-wrapper").length) { 1078 jQuery("#wc-donation-woocommerce-notices-wrapper").show(); 1079 document 1080 .getElementById("wc-donation-woocommerce-notices-wrapper") 1081 .scrollIntoView({ behavior: "smooth" }); 1082 } 1083 if (!wcDonationIsCampaignPreview() && response["cart_url"] != "") { 1084 window.location.href = response["cart_url"]; 1085 } 1086 1087 if (!wcDonationIsCampaignPreview() && response["checkoutUrl"] != "") { 1088 window.location.href = response["checkoutUrl"]; 1089 } 1090 1091 jQuery("body").trigger("wc_donation_checkout_event"); 1092 } 1093 if ("failed" === response["response"]) { 1094 jQuery(`input[value="${campaign_id}"]`) 1095 .closest(".wc_donation_on_cart") 1096 .find("div.wc-donation-loader-css") 1097 .remove(); 1098 jQuery(`input[value="${campaign_id}"]`) 1099 .closest(".widget_wc-donation-widget") 1100 .find("div.wc-donation-loader-css") 1101 .remove(); 1102 1103 if ( 1104 !jQuery(`input[value="${campaign_id}"]`) 1105 .siblings("div") 1106 .hasClass("cc-require-message") 1107 ) { 1108 var messageElement = jQuery( 1109 '<div class="cc-require-message">' + response.message + "</div>", 1110 ); 1111 jQuery(`input[value="${campaign_id}"]`) 1112 .siblings("button") 1113 .after(messageElement); 1114 } 1115 } 1116 if ("error" === response["response"]) { 1117 alert( 1118 response.message || 1119 "Unable to complete your donation. Please try again.", 1120 ); 1121 } 1122 }, 1123 }); 1124 setTimeout(function () { 1125 jQuery(".cc-require-message").remove(); 1126 }, 7000); 1127 } else { 1128 var text = wcOrderScript.donationToOrder.other_amount_placeholder; 1129 text = text.replace("%min%", min_amount); 1130 text = text.replace("%max%", max_amount); 1131 if (donation_type == "both" || donation_type == "predefined") { 1132 if (tracker == 1) { 1133 alert(`${text}`); 1134 } else { 1135 alert(`Please select amount`); 1136 } 1137 } else { 1138 alert(`${text}`); 1139 } 1140 return true; 1141 } 1142} 1143 1144jQuery(document).on( 1145 "click", 1146 ".wc-donation-f-submit-donation, #wc-donation-round-f-submit-donation, #wc-donation-round-f-submit-skip-donation", 1147 function (e) { 1148 e.preventDefault(); 1149 1150 if (wcDonationIsCampaignPreview()) { 1151 return false;
1152 } 1153 1154 var _this = jQuery(this); 1155 var campaign_id = jQuery(this).siblings(".wc_donation_camp").val(); 1156 if (!campaign_id) { 1157 var $formRoot = jQuery(this).closest("[id^='wc-donation-pb-form-']"); 1158 if ($formRoot.length) { 1159 var idMatch = String($formRoot.attr("id") || "").match( 1160 /wc-donation-pb-form-(\d+)/, 1161 ); 1162 if (idMatch) { 1163 campaign_id = idMatch[1]; 1164 } 1165 } 1166 } 1167 1168 var pbFormCfg = 1169 typeof wcDonationPbGetFormConfig === "function" 1170 ? wcDonationPbGetFormConfig(campaign_id) 1171 : null; 1172 if (pbFormCfg && typeof wcDonationPbSyncPageToModal === "function") { 1173 wcDonationPbSyncPageToModal(campaign_id); 1174 } 1175 1176 if (!wcDonationValidateSubscriptionBeforeDonate(e)) { 1177 return; 1178 } 1179 if (!wcDonationValidateFormDonorFields(this)) { 1180 return; 1181 } 1182 if (!wcDonationValidateTermsBeforeDonate(this)) { 1183 return; 1184 } 1185 1186 var isFormDonate = jQuery(this).data("pb-donate-source") === "form"; 1187 var isCampaignPbDonate = 1188 jQuery(this).data("pb-donate-source") === "campaign" || 1189 jQuery(this).hasClass("wc-donation-pb-campaign-donate-btn"); 1190 var $pbFormScope = campaign_id 1191 ? jQuery("#wc-donation-pb-form-scope-" + campaign_id) 1192 : jQuery(); 1193 var usePbFormScope = 1194 $pbFormScope.length > 0 && 1195 (isFormDonate || (isCampaignPbDonate && pbFormCfg)); 1196 1197 var parents = jQuery(this).parents(".wc-donation-in-action"); 1198 var restrictPbGlobal = usePbFormScope; 1199 if (restrictPbGlobal) { 1200 var $formInAction = $pbFormScope.find(".wc-donation-in-action").first(); 1201 if ($formInAction.length) { 1202 parents = $formInAction; 1203 } 1204 } 1205 1206 var type = jQuery(this).data("type"); 1207 var button_rand_id = jQuery(this).siblings(".wp_rand").val(); 1208 var resolvedRand = wcDonationPbResolveDonateRand( 1209 campaign_id, 1210 button_rand_id, 1211 pbFormCfg, 1212 ); 1213 var rand_id = resolvedRand.rand_id; 1214 if (!wcDonationValidateCauseBeforeDonate(this, campaign_id, rand_id)) { 1215 return; 1216 } 1217 var is_recurring = false; 1218 var new_period = "day"; 1219 var new_length = "1"; 1220 var new_interval = "1"; 1221 var min_amount = 0; 1222 var max_amount = 0; 1223 var donation_type = jQuery(parents).data("donation-type"); 1224 var tracker = jQuery(parents).find(".wc-opened").length; 1225 if (!tracker && restrictPbGlobal) { 1226 tracker = $pbFormScope.find(".wc-opened").length; 1227 } 1228 var tracker2 = jQuery(parents).find( 1229 ".wc-donation-f-donation-other-value", 1230 ).length; 1231 var selectBox = jQuery(parents).find("select.wc-label-select"); 1232 if (!selectBox.length && !restrictPbGlobal) { 1233 selectBox = jQuery("select.wc-label-select"); 1234 } 1235 selectedLabel = ""; 1236 if (selectBox.length && selectBox.find("option:selected").val()) { 1237 selectedLabel = selectBox.find("option:selected").text().trim(); 1238 } 1239 1240 if (!selectedLabel) { 1241 var selectedRadio = jQuery(parents).find( 1242 'input[name="wc_label_price"]:checked', 1243 ); 1244 if (!selectedRadio.length && !restrictPbGlobal) { 1245 selectedRadio = jQuery('input[name="wc_label_price"]:checked'); 1246 } 1247 if (selectedRadio.length) { 1248 selectedLabel = selectedRadio.closest("label").text().trim(); 1249 } 1250 } 1251 if (jQuery(this).data("min-value")) { 1252 min_amount = jQuery(this).data("min-value"); 1253 } 1254 1255 if (jQuery(this).data("max-value")) { 1256 max_amount = jQuery(this).data("max-value"); 1257 } 1258 1259 var $recurEl = jQuery(parents).find(".donation-is-recurring"); 1260 if (!$recurEl.length && !restrictPbGlobal) { 1261 $recurEl = jQuery(".donation-is-recurring"); 1262 } 1263 if ($recurEl.length > 0 && $recurEl.is(":checked")) { 1264 is_recurring = $recurEl.val(); 1265 var $recurScope = $recurEl.closest(".wc-donation-in-action, .wc-donation-pb-recurring__scope, .wc_donation_subscription_table"); 1266 new_period = $recurScope.find("._subscription_period").val(); 1267 new_length = $recurScope.find("#_subscription_length").val(); 1268 new_interval = $recurScope.find("#_subscription_period_interval").val(); 1269 if (!restrictPbGlobal) { 1270 new_period = new_period || jQuery("._subscription_period").val(); 1271 new_length = new_length || jQuery("#_subscription_length").val(); 1272 new_interval = 1273 new_interval || jQuery("#_subscription_period_interval").val(); 1274 } 1275 if (!new_period && $recurScope.find("#wps_sfw_subscription_interval").length) { 1276 new_period = $recurScope.find("#wps_sfw_subscription_interval").val(); 1277 new_interval = $recurScope.find("#wps_sfw_subscription_number").val() || "1"; 1278 new_length = $recurScope.find("#wps_sfw_subscription_expiry_number").val() || "1"; 1279 } 1280 } else { 1281 is_recurring = "no"; 1282 } 1283 1284 if (type == "roundoff" || type == "roundoff-skip") { 1285 jQuery(".wc-donation-popup").removeClass("wc-popup-show"); 1286 var amount = jQuery(".roundoff-donation-price").val(); 1287 } else { 1288 var amount = resolvedRand.amount; 1289 if (!amount || parseFloat(amount) <= 0) { 1290 amount = wcDonationPbReadDonationAmount(campaign_id, rand_id); 1291 } 1292 if ( 1293 (!amount || parseFloat(amount) <= 0) && 1294 (donation_type == "both" || donation_type == "predefined") 1295 ) { 1296 tracker = 0; 1297 } else if (amount && parseFloat(amount) > 0 && tracker < 1) { 1298 tracker = 1; 1299 } 1300 } 1301 var causeFields = wcDonationReadCauseHiddenFields(campaign_id, rand_id); 1302 var cause = causeFields.cause; 1303 var cause_id = causeFields.cause_id; 1304 var feeCheck = ".donate_fees_" + campaign_id + "_" + rand_id; 1305 var $feeCb = jQuery("#processing-fees-" + campaign_id + "_" + rand_id); 1306 if ($feeCb.length) { 1307 if ($feeCb.is(":checked")) { 1308 jQuery(feeCheck).val($feeCb.val()); 1309 } else { 1310 jQuery(feeCheck).val(""); 1311 } 1312 } 1313 1314 var fees = jQuery(feeCheck).val(); 1315 var fee_calc_type = ""; 1316 if ($feeCb.length && $feeCb.is(":checked")) { 1317 fee_calc_type = wcDonationFeesTypeFor($feeCb); 1318 } 1319 1320 var cc_processing_fee = ""; 1321 if (jQuery(feeCheck).length && jQuery(feeCheck).data("require") !== "") { 1322 if ( 1323 false == 1324 jQuery("#processing-fees-" + campaign_id + "_" + rand_id).prop( 1325 "checked", 1326 ) 1327 ) { 1328 cc_processing_fee = "require"; 1329 } 1330 } 1331 1332 var gift_aid = ""; 1333 1334 if ( 1335 jQuery("#wc_donation_gift_aid_checkbox_" + campaign_id + "_" + rand_id) 1336 .length > 0 && 1337 jQuery("#wc_donation_gift_aid_checkbox_" + campaign_id + "_" + rand_id).is( 1338 ":checked", 1339 ) 1340 ) { 1341 gift_aid = "yes"; 1342 } 1343 1344 if ( 1345 !gift_aid && 1346 jQuery(parents).find(".wc-donation-pb-gift-aid__checkbox:checked").length 1347 ) { 1348 gift_aid = "yes"; 1349 } 1350 if ( 1351 !gift_aid && 1352 !restrictPbGlobal && 1353 jQuery(".wc-donation-pb-gift-aid__checkbox:checked").length 1354 ) { 1355 gift_aid = "yes"; 1356 } 1357 1358 var tribute = ""; 1359 var tribute_message = ""; 1360 1361 var $tributeCheckbox = restrictPbGlobal 1362 ? $pbFormScope.find("input[name='wc_donation_tribute_checkbox']:checked") 1363 : jQuery("input[name='wc_donation_tribute_checkbox']:checked"); 1364 1365 if ( 1366 jQuery("#_hidden_tribute_" + campaign_id + "_" + rand_id).length > 0 && 1367 $tributeCheckbox.length && 1368 jQuery("#_hidden_tribute_" + campaign_id + "_" + rand_id).val() != "" 1369 ) { 1370 tribute = jQuery("#_hidden_tribute_" + campaign_id + "_" + rand_id).val(); 1371 } 1372 1373 if ( 1374 jQuery("#wc_donation_trubte_message_" + campaign_id + "_" + rand_id) 1375 .length > 0 && 1376 $tributeCheckbox.length && 1377 jQuery("#wc_donation_trubte_message_" + campaign_id + "_" + rand_id).val() != 1378 "" 1379 ) { 1380 tribute_message = jQuery( 1381 "#wc_donation_trubte_message_" + campaign_id + "_" + rand_id, 1382 ).val(); 1383 } 1384 1385 if ( 1386 !tribute && 1387 jQuery(parents).find(".wc-donation-pb-tribute__checkbox:checked").length 1388 ) { 1389 var pbTributeName = jQuery(parents).find(".wc-donation-pb-tribute__name").val(); 1390 tribute = pbTributeName ? String(pbTributeName).trim() : "yes"; 1391 } 1392 if ( 1393 !tribute && 1394 !restrictPbGlobal && 1395 jQuery(".wc-donation-pb-tribute__checkbox:checked").length 1396 ) { 1397 var pbTributeNameGlobal = jQuery(".wc-donation-pb-tribute__name").val(); 1398 tribute = pbTributeNameGlobal 1399 ? String(pbTributeNameGlobal).trim() 1400 : "yes"; 1401 } 1402 1403 if ( 1404 !tribute_message && 1405 jQuery(parents).find(".wc-donation-pb-tribute__message").length 1406 ) { 1407 tribute_message = jQuery(parents).find(".wc-donation-pb-tribute__message").val(); 1408 } 1409 if ( 1410 !tribute_message && 1411 !restrictPbGlobal && 1412 jQuery(".wc-donation-pb-tribute__message").length 1413 ) { 1414 tribute_message = jQuery(".wc-donation-pb-tribute__message").val(); 1415 } 1416 1417 var e_card_email = ""; 1418 if ( 1419 jQuery("#wc_donation_e_card_email_" + campaign_id).length > 0 && 1420 jQuery("#wc_donation_e_card_email_" + campaign_id).val() != "" 1421 ) { 1422 e_card_email = jQuery("#wc_donation_e_card_email_" + campaign_id).val(); 1423 } 1424 1425 var wps_sfw_sub_number = ""; 1426 var wps_sfw_sub_interval = ""; 1427 var wps_sfw_sub_exp_number = ""; 1428 var wps_sfw_sub_exp_interval = ""; 1429 1430 var $subTable = restrictPbGlobal 1431 ? $pbFormScope.find(".wc_donation_subscription_table") 1432 : jQuery(".wc_donation_subscription_table"); 1433 if ($subTable.length) { 1434 wps_sfw_sub_number = $subTable.find(".wps_sfw_subscription_number").val(); 1435 wps_sfw_sub_interval = $subTable 1436 .find(".wps_sfw_subscription_interval") 1437 .val(); 1438 wps_sfw_sub_exp_number = $subTable 1439 .find(".wps_sfw_subscription_expiry_number") 1440 .val(); 1441 wps_sfw_sub_exp_interval = $subTable 1442 .find(".wps_sfw_subscription_expiry_interval") 1443 .val(); 1444 } 1445 1446 var wc_donation_pb_donor = wcDonationCollectPbDonorFields( 1447 campaign_id, 1448 parents, 1449 ); 1450 1451 var donation_anonymous = ""; 1452 if ( 1453 jQuery(parents).find(".wc-donation-pb-anonymous__checkbox:checked").length 1454 ) { 1455 donation_anonymous = "yes"; 1456 } 1457 if ( 1458 !donation_anonymous && 1459 !restrictPbGlobal && 1460 jQuery(".wc-donation-pb-anonymous__checkbox:checked").length 1461 ) { 1462 donation_anonymous = "yes"; 1463 } 1464 1465 var terms_accepted = ""; 1466 if (jQuery(parents).find(".wc-donation-pb-terms__checkbox:checked").length) { 1467 terms_accepted = "1"; 1468 } 1469 if ( 1470 !terms_accepted && 1471 !restrictPbGlobal && 1472 jQuery(".wc-donation-pb-terms__checkbox:checked").length 1473 ) { 1474 terms_accepted = "1"; 1475 } 1476 1477 addDonationToOrder( 1478 type, 1479 amount, 1480 min_amount, 1481 max_amount, 1482 campaign_id, 1483 is_recurring, 1484 new_period, 1485 new_length, 1486 new_interval, 1487 tracker, 1488 donation_type, 1489 cause, 1490 cause_id, 1491 fees, 1492 gift_aid, 1493 tribute, 1494 tribute_message, 1495 e_card_email, 1496 cc_processing_fee, 1497 _this, 1498 wps_sfw_sub_number, 1499 wps_sfw_sub_interval, 1500 wps_sfw_sub_exp_number, 1501 wps_sfw_sub_exp_interval, 1502 selectedLabel, 1503 wc_donation_pb_donor, 1504 donation_anonymous, 1505 terms_accepted, 1506 fee_calc_type, 1507 ); 1508 }, 1509); 1510 1511jQuery(document).on( 1512 "click",
1513 'label.wc-label-button input[type="radio"][name="wc_label_price"], label.wc-label-button input[type="radio"][name="wc_label_cause"]', 1514 function () { 1515 if (jQuery(this).is(":checked")) { 1516 //alert('I clicked'); 1517 jQuery(this) 1518 .parent(".wc-label-button") 1519 .siblings() 1520 .removeClass("wc-active"); 1521 jQuery(this).parent(".wc-label-button").addClass("wc-active"); 1522 } 1523 }, 1524); 1525 1526jQuery(document).on( 1527 "click", 1528 'label.wc-label-radio input[type="radio"][name="wc_donation_tribute_checkbox"]', 1529 function () { 1530 //debugger; 1531 if (jQuery(this).is(":checked")) { 1532 jQuery(this) 1533 .parent() 1534 .siblings(".wc_donation_trubte_name") 1535 .prop("type", "text"); 1536 jQuery(this) 1537 .parent() 1538 .siblings(".wc_donation_trubte_message") 1539 .prop("type", "text"); 1540 } 1541 }, 1542); 1543 1544jQuery(document).on( 1545 "copy paste keyup click", 1546 ".wc_donation_trubte_name", 1547 function () { 1548 var tribute_name = jQuery(this).val(); 1549 var tribute_check_value = jQuery(this) 1550 .siblings("label.wc-label-radio") 1551 .find('input[name="wc_donation_tribute_checkbox"]:checked') 1552 .val(); 1553 if ( 1554 jQuery.trim(tribute_name) != "" && 1555 jQuery.trim(tribute_check_value) != "" 1556 ) { 1557 jQuery(this) 1558 .siblings('input[name="tribute"]') 1559 .val(`${tribute_check_value} ${tribute_name}`); 1560 } else { 1561 jQuery(this).siblings('input[name="tribute"]').val(""); 1562 } 1563 }, 1564); 1565 1566jQuery(document).on("change", "input.donation-processing-fees", function () { 1567 wcDonationUpdateProcessingFeeSummary(jQuery(this)); 1568}); 1569jQuery(document).on("click", "ul.causes-dropdown .init", function () { 1570 jQuery(this).parent().children("li:not(.init)").toggle(); 1571 jQuery(this).parent().toggleClass("active"); 1572 if (jQuery(this).parent().hasClass("active")) { 1573 if (jQuery(this).parents(".wc-donation-container").length) { 1574 var i = 75 * jQuery(this).parent().children("li:not(.init)").length; 1575 jQuery(this).parents(".wc-donation-cause").css("margin-bottom", `${i}px`); 1576 } 1577 } else { 1578 jQuery(this).parents(".wc-donation-cause").css("margin-bottom", `0px`); 1579 } 1580}); 1581 1582function wcDonationSetCauseHiddenFields(campaignId, randSuffix, causeName, causeId) { 1583 if (!campaignId || !randSuffix) { 1584 return; 1585 } 1586 var key = String(campaignId) + "_" + String(randSuffix); 1587 jQuery("#wc-donation-cause-" + key + ", .donate_cause_" + key).val( 1588 causeName || "", 1589 ); 1590 jQuery("#wc-donation-cause-id-" + key + ", .donate_cause_id_" + key).val( 1591 causeId || "", 1592 ); 1593} 1594 1595function wcDonationReadCauseHiddenFieldsFromKey(key) { 1596 var causeName = ""; 1597 var causeId = ""; 1598 var $nameByClass = jQuery(".donate_cause_" + key); 1599 var $nameById = jQuery("#wc-donation-cause-" + key); 1600 if ($nameByClass.length) { 1601 causeName = $nameByClass.first().val(); 1602 } else if ($nameById.length) { 1603 causeName = $nameById.val(); 1604 } 1605 var $idByClass = jQuery(".donate_cause_id_" + key); 1606 var $idById = jQuery("#wc-donation-cause-id-" + key); 1607 if ($idByClass.length) { 1608 causeId = $idByClass.first().val(); 1609 } else if ($idById.length) { 1610 causeId = $idById.val(); 1611 } 1612 return { cause: causeName, cause_id: causeId }; 1613} 1614 1615function wcDonationReadCauseHiddenFields(campaignId, randSuffix) { 1616 var key = String(campaignId) + "_" + String(randSuffix); 1617 var result = wcDonationReadCauseHiddenFieldsFromKey(key); 1618 if (result.cause || result.cause_id) { 1619 return result; 1620 } 1621 1622 var pbCfg = 1623 typeof wcDonationPbGetFormConfig === "function" 1624 ? wcDonationPbGetFormConfig(campaignId) 1625 : typeof wcDonationPbGetModalConfig === "function" 1626 ? wcDonationPbGetModalConfig(campaignId) 1627 : null; 1628 if (!pbCfg) { 1629 return result; 1630 } 1631 1632 var fallbacks = [pbCfg.formRand, pbCfg.pageRand]; 1633 for (var i = 0; i < fallbacks.length; i++) { 1634 if (!fallbacks[i] || String(fallbacks[i]) === String(randSuffix)) { 1635 continue; 1636 } 1637 var alt = wcDonationReadCauseHiddenFieldsFromKey( 1638 String(campaignId) + "_" + String(fallbacks[i]), 1639 ); 1640 if (alt.cause || alt.cause_id) { 1641 return alt; 1642 } 1643 } 1644 1645 return result; 1646} 1647 1648function wcDonationPbReadDonationAmount(campaignId, randSuffix) { 1649 var key = String(campaignId) + "_" + String(randSuffix); 1650 var amount = 1651 jQuery("#wc-donation-price-" + key).val() || 1652 jQuery(".donate_" + key).val() || 1653 ""; 1654 if (amount !== "" && amount != null && parseFloat(amount) > 0) { 1655 return amount; 1656 } 1657 return ""; 1658} 1659 1660function wcDonationPbResolveDonateRand(campaignId, buttonRand, pbFormCfg) { 1661 var amount = wcDonationPbReadDonationAmount(campaignId, buttonRand); 1662 if (amount && parseFloat(amount) > 0) { 1663 return { rand_id: buttonRand, amount: amount }; 1664 } 1665 1666 if (!pbFormCfg) { 1667 return { rand_id: buttonRand, amount: amount }; 1668 } 1669 1670 var candidates = [pbFormCfg.formRand, pbFormCfg.pageRand]; 1671 for (var i = 0; i < candidates.length; i++) { 1672 if (!candidates[i] || String(candidates[i]) === String(buttonRand)) { 1673 continue; 1674 } 1675 var altAmount = wcDonationPbReadDonationAmount(campaignId, candidates[i]); 1676 if (altAmount && parseFloat(altAmount) > 0) { 1677 return { rand_id: candidates[i], amount: altAmount }; 1678 } 1679 } 1680 1681 return { rand_id: buttonRand, amount: amount }; 1682} 1683 1684jQuery(document).on("click", "ul.causes-dropdown li:not(.init)", function () { 1685 var allOptions = jQuery(this).parent().children("li:not(.init)"); 1686 var id = jQuery(this).attr("data-id") || jQuery(this).data("id"); 1687 var causeName = jQuery(this).attr("data-name") || jQuery(this).data("name"); 1688 var causeId = 1689 jQuery(this).attr("data-cause-id") || 1690 jQuery(this).data("causeId") || 1691 jQuery(this).data("cause-id") || 1692 ""; 1693 if (id) { 1694 jQuery("#wc-donation-" + id).val(causeName); 1695 var causeKey = String(id).replace(/^cause-/, ""); 1696 if (causeKey) { 1697 var parts = causeKey.split("_"); 1698 if (parts.length >= 2) { 1699 wcDonationSetCauseHiddenFields(parts[0], parts[1], causeName, causeId); 1700 } 1701 } 1702 } 1703 allOptions.removeClass("selected"); 1704 jQuery(this).addClass("selected"); 1705 jQuery(this).parent().removeClass("active"); 1706 jQuery(this).parent().children(".init").html(jQuery(this).html()); 1707 allOptions.toggle(); 1708}); 1709 1710jQuery(document.body).mousedown(function (event) { 1711 var target = jQuery(event.target); 1712 if ( 1713 jQuery("ul.causes-dropdown").hasClass("active") && 1714 !target.parents().andSelf().is("ul.causes-dropdown") 1715 ) { 1716 // Clicked outside 1717 jQuery("ul.causes-dropdown").removeClass("active"); 1718 jQuery("ul.causes-dropdown").children("li:not(.init)").toggle(); 1719 } 1720}); 1721 1722// jQuery(document).on('change', '.wc-label-radio input.donation-processing-fees', function(){ 1723// if(jQuery(this).is('checked')){ 1724// var id = jQuery(this).data('id'); 1725// jQuery('#wc-donation-' + id).val(jQuery(this).val()); 1726// } 1727// else{ 1728// jQuery('#wc-donation-' + id).val(''); 1729// } 1730// }); 1731 1732jQuery(document).on( 1733 "change copy paste click", 1734 ".wc-label-button input, .wc-label-radio input, .wc-label-select", 1735 function () { 1736 var id = jQuery(this).data("id"); 1737 1738 jQuery("#wc-donation-price-" + id).val(jQuery(this).val()); 1739 if (jQuery(this).val() == "wc-donation-other-amount") { 1740 jQuery("#wc-donation-f-donation-other-value-" + id).show(); 1741 jQuery("#wc-donation-f-donation-other-value-" + id).addClass("wc-opened"); 1742 // jQuery("#wc-donation-f-donation-other-value-" + id).siblings('.wc-donation-tooltip').show(); 1743 jQuery(".other-price-wrapper-" + id).show(); 1744 jQuery(".other-price-wrapper-" + id) 1745 .siblings(".wc-donation-tooltip") 1746 .show(); 1747 } else { 1748 jQuery("#wc-donation-f-donation-other-value-" + id).hide(); 1749 jQuery("#wc-donation-f-donation-other-value-" + id).removeClass( 1750 "wc-opened", 1751 ); 1752 // jQuery("#wc-donation-f-donation-other-value-" + id).siblings('.wc-donation-tooltip').hide(); 1753 jQuery(".other-price-wrapper-" + id) 1754 .siblings(".wc-donation-tooltip") 1755 .hide(); 1756 jQuery(".other-price-wrapper-" + id).hide(); 1757 } 1758 var $feeCb = jQuery("#processing-fees-" + id); 1759 var procFees = $feeCb.val(); 1760 var wcdonationprice = jQuery("#wc-donation-price-" + id).val(); 1761 var feesType = wcDonationFeesTypeFor($feeCb); 1762 var donation_card_fee = wcDonationCalcProcessingFee( 1763 wcdonationprice, 1764 procFees, 1765 feesType, 1766 ); 1767 var donation_summary_total = 1768 parseFloat(wcdonationprice) + parseFloat(donation_card_fee); 1769 if (donation_summary_total > 0 && donation_summary_total != "") { 1770 jQuery( 1771 "#wc-donation-summary-" + id + " .wc-donation-currency-symbol", 1772 ).attr("style", "display: inline-block !important"); 1773 jQuery( 1774 "#wc-donation-summary-" + id + " .wc-donation-charge .wc-donation-amt", 1775 ).text(parseFloat(wcdonationprice).toFixed(2)); 1776 jQuery( 1777 "#wc-donation-summary-" + 1778 id + 1779 " .wc-donation-fee-summary .wc-donation-amt", 1780 ).text(parseFloat(donation_card_fee).toFixed(2)); 1781 jQuery( 1782 "#wc-donation-summary-" + 1783 id + 1784 " .wc-donation-summary-total .wc-donation-amt", 1785 ).text(parseFloat(donation_summary_total).toFixed(2)); 1786 } 1787 }, 1788); 1789 1790jQuery(document).on("change", "._subscription_period", function () { 1791 var $this = jQuery(this); 1792 var subscription_field = $this 1793 .parents(".wc-donation-in-action") 1794 .find('select[name="_subscription_length"]'); 1795 var period = $this.val(); 1796 1797 jQuery.ajax({ 1798 url: wcOrderScript.donationToOrder.ajaxUrl, 1799 type: "POST", 1800 dataType: "json", 1801 data: {
1802 action: "wc_donation_get_sub_length_by_sub_period", 1803 period: period, 1804 nonce: wcOrderScript.donationToOrder.nonce, 1805 }, 1806 beforeSend: function () { 1807 jQuery(subscription_field).css({ 1808 "pointer-events": "none", 1809 opacity: "0.5", 1810 }); 1811 }, 1812 success: function (response) { 1813 if (response.range != "") { 1814 jQuery(subscription_field).html(""); 1815 jQuery.each(response.range, function (index, val) { 1816 jQuery(subscription_field).append( 1817 '<option value="' + index + '">' + val + "</option>", 1818 ); 1819 }); 1820 1821 jQuery(subscription_field).removeAttr("style"); 1822 } 1823 }, 1824 }); 1825}); 1826 1827jQuery(function (jQuery) { 1828 jQuery(".donor-lists .give-grid__item").slice(0, 12).css("display", "flex"); 1829 jQuery(".anonymous-donor-lists .give-grid__item") 1830 .slice(0, 12) 1831 .css("display", "flex"); 1832 jQuery(".global-donor-lists .give-grid__item") 1833 .slice(0, 12) 1834 .css("display", "flex"); 1835 jQuery(".leaderboard-donor-lists .give-grid__item") 1836 .slice(0, 12) 1837 .css("display", "flex"); 1838 jQuery(".give-donor__load_more").on("click", function (e) { 1839 e.preventDefault(); 1840 jQuery(this) 1841 .siblings(".give-grid") 1842 .find(".give-grid__item:hidden") 1843 .slice(0, 4) 1844 .css("display", "flex"); 1845 if ( 1846 jQuery(this).siblings(".give-grid").find(".give-grid__item:hidden") 1847 .length == 0 1848 ) { 1849 jQuery(this).fadeOut(700); 1850 } 1851 }); 1852 1853 jQuery('input[name="wc_donation_tribute_checkbox"]').click(function () { 1854 var $radio = jQuery(this); 1855 if ($radio.data("waschecked") == true) { 1856 $radio.prop("checked", false); 1857 jQuery(".wc_donation_trubte_name").prop("type", "hidden"); 1858 jQuery(".wc_donation_trubte_message").prop("type", "hidden"); 1859 $radio.data("waschecked", false); 1860 } else { 1861 $radio.data("waschecked", true); 1862 } 1863 $radio 1864 .siblings('input[name="wc_donation_tribute_checkbox"]') 1865 .data("waschecked", false); 1866 }); 1867}); 1868 1869function dispaly_socialshare_links($) { 1870 jQuery(document).ready(function () { 1871 // Show the popup when the button is clicked 1872 jQuery(document).on("click", "#wc-donation-social-share", function () { 1873 jQuery("#social-share-popup") 1874 .css({ 1875 display: "flex", 1876 "justify-content": "center", 1877 "align-items": "center", 1878 overflow: "hidden", 1879 }) 1880 .show(); 1881 }); 1882 1883 // Hide the popup when the close button is clicked 1884 jQuery(".close").click(function () { 1885 jQuery("#social-share-popup").hide(); 1886 }); 1887 1888 // Hide the popup when clicking outside of the popup content 1889 jQuery(window).click(function (event) { 1890 if (jQuery(event.target).is("#social-share-popup")) { 1891 jQuery("#social-share-popup").hide(); 1892 } 1893 }); 1894 1895 // Copy link to clipboard 1896 jQuery("#copy-link").click(function (e) { 1897 e.preventDefault(); 1898 const url = jQuery(this).data("url"); 1899 const tempInput = jQuery("<input>"); 1900 jQuery("body").append(tempInput); 1901 tempInput.val(url).select(); 1902 document.execCommand("copy"); 1903 tempInput.remove(); 1904 alert("Link copied to clipboard!"); 1905 }); 1906 1907 // Trigger print dialog with custom content 1908 jQuery("#print-poster").click(function (e) { 1909 e.preventDefault(); 1910 1911 // Create a new window 1912 var printWindow = window.open("", "_blank"); 1913 1914 // Get the content to print 1915 var printContents = document.getElementById("print-section").innerHTML; 1916 1917 // Write the content into the new window 1918 printWindow.document.write("<html><head><title>Print Poster</title>"); 1919 printWindow.document.write("</head><body>"); 1920 printWindow.document.write(printContents); 1921 printWindow.document.write("</body></html>"); 1922 1923 // Close the document to trigger the print dialog 1924 printWindow.document.close(); 1925 1926 // Wait for the content to be fully loaded 1927 printWindow.onload = function () { 1928 printWindow.print(); 1929 printWindow.close(); 1930 }; 1931 }); 1932 }); 1933} 1934 1935document.addEventListener("DOMContentLoaded", function () { 1936 if (jQuery(".donation-is-recurring").length) { 1937 const recurringCheckbox = document.querySelector(".donation-is-recurring"); 1938 const donationSubscriptionDiv = document.querySelector( 1939 ".donation_subscription", 1940 ); 1941 1942 // Function to toggle visibility based on checkbox state 1943 function toggleSubscriptionVisibility() { 1944 if (recurringCheckbox.checked) { 1945 donationSubscriptionDiv.style.display = "block"; 1946 } else { 1947 donationSubscriptionDiv.style.display = "none"; 1948 } 1949 } 1950 1951 // Run on page load in case checkbox is already checked 1952 toggleSubscriptionVisibility(); 1953 1954 // Add event listener for changes to the checkbox 1955 recurringCheckbox.addEventListener("change", toggleSubscriptionVisibility); 1956 } 1957}); 1958 1959document.addEventListener("DOMContentLoaded", function () { 1960 if (jQuery(".donation-is-recurring").length) { 1961 const recurringCheckbox = document.querySelector(".donation-is-recurring"); 1962 const subscriptionOptions = document.querySelectorAll( 1963 ".subscription-options", 1964 ); 1965 1966 // Function to toggle visibility based on checkbox state 1967 function toggleSubscriptionOptions() { 1968 const display = recurringCheckbox.checked ? "table-row" : "none"; 1969 subscriptionOptions.forEach((row) => { 1970 row.style.display = display; 1971 }); 1972 } 1973 1974 // Run on page load to set initial state 1975 toggleSubscriptionOptions(); 1976 1977 // Add event listener for changes to the checkbox 1978 recurringCheckbox.addEventListener("change", toggleSubscriptionOptions); 1979 } 1980}); 1981 1982 1983jQuery(document).ready(function ($) { 1984 jQuery("#wps_sfw_subscription_interval").on("change", function () { 1985 var selectedInterval = jQuery(this).val(); 1986 1987 // Clear the Expiry Interval options 1988 jQuery("#wps_sfw_subscription_expiry_interval").empty(); 1989 1990 // Add the selected interval as the only option in Expiry Interval 1991 jQuery("#wps_sfw_subscription_expiry_interval").append( 1992 '<option value="' + 1993 selectedInterval + 1994 '">' + 1995 selectedInterval.charAt(0).toUpperCase() + 1996 selectedInterval.slice(1) + 1997 "(s)</option>", 1998 ); 1999 }); 2000 2001 // Trigger the change event on page load to set the initial state 2002 jQuery("#wps_sfw_subscription_interval").trigger("change"); 2003});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.