/* PostRender */ var myPostRender = function(vals) { (function ($) { // Check to see if the Progress Meter exists. If it does, replace the iframe's meter with constructed progress meter. if ( $("article .at.ngp-form header.MeterHtml").length ) { // Use a function to make properly formatted versions of the Progress Meter's numbers function numberWithCommas(number) { var parts = number.toString().split("."); parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); return parts.join("."); } var fullURL = window.location.href; // Create a variable of the full URL, used for the share icons var urlPiece = window.location.pathname.split("/")[1]; // Grab the first section of the URL after the initial slash so you can figure out if it's a P2P page if (urlPiece == "P2P") {pageType = " p2p-page"} else {pageType = " non-p2p-page"} // Create a pageType variable to expose if it's an individual P2P page $("main article header.HeaderHtml").addClass(pageType); // Add the page type class to the HeaderHtml const progressMeterURL = $("main article header.MeterHtml iframe").attr("src"); // Get the full URL const progressMeterPathname =new URL(progressMeterURL).pathname.split('/'); // Grab just the pathname, from this URL object const progressMeterID = progressMeterPathname.pop() || progressMeterPathname.pop(); // Handle potential trailing slash jsonURL = "https://secure.everyaction.com/v2/forms/" + progressMeterID + "/progress"; // grab the URL of the form we're getting the data from $.getJSON(jsonURL, function( data ) { // grab the data from the .json file meterProgressType = data.progressType; // figure out which type of progress meter it is - Submission or Contribution? meterProgress = data.progressOutOfOneHundred; // set a value for the progress on the meter meterShowAllProgress = data.showAllProgress; meterProgressAmount = "$" + numberWithCommas(parseFloat(data.totalContributionProgress)); // set a value for the amount raised, with the appropriate separators meterSubmissions = data.totalSubmissionProgress; // create a variable for the number of submissions if (meterProgressType == "Contribution") { // if it's a contribution progress meter if (meterShowAllProgress == true) { // and the "Also display the count of submissions" is checked meterSubmittersDetails = "Amount Raised: " + meterProgressAmount + " (" + meterSubmissions + " supporters)"; // provide the amount raised and the number of supporters } else { // if the "Also display the count of submissions" isn't checked meterSubmittersDetails = "Amount Raised: " + meterProgressAmount + ""; // provide just the amount raised } meterTarget = "$" + numberWithCommas(parseFloat(data.targetAmount)); // and set a value for the goal, with the appropriate separators } else { // if it's a submissions progress meter if (meterShowAllProgress == false) { // and it's not a contribution progress meter, or the "Also display the contribution amount" isn't checked meterSubmittersDetails = "Current Supporters: " + meterSubmissions + ""; // provide the number of supporters } else { // it's a contribution progress meter, and the "Also display the contribution amount" is checked meterSubmittersDetails = "Current Supporters: " + meterSubmissions + " (" + meterProgressAmount + ")"; // provide the number of supporters, but also the amount raised } meterTarget = numberWithCommas(parseFloat(data.targetAmount)); // set a value for the goal, with the appropriate separators } $("article .at.ngp-form header.MeterHtml").append(''); // Inject the progress meter into the form $("main article header.HeaderHtml.p2p-page").append('
'); // Add the share icons to the header, but only on P2P pages }); } // End of if statement for Progress Meter logic }(jQuery)); }; var nvtag_callbacks = nvtag_callbacks || {}; nvtag_callbacks.postRender = nvtag_callbacks.postRender || []; nvtag_callbacks.postRender.push(myPostRender);