Files
@ c41c973f99e5
Branch filter:
Location: website/www/conservancy/static/js/supporter-page.js
c41c973f99e5
13.4 KiB
application/javascript
Clarify this sentence.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | /* Copyright (C) 2012-2013 Denver Gingerich,
** Copyright (C) 2013-2014 Bradley M. Kuhn.
** License: GPLv3-or-later
** Find a copy of GPL at https://sfconservancy.org/GPLv3
*/
$(document).ready(function() {
var siteFinalGoal = $('span#site-fundraiser-final-goal').text();
var noCommaSiteFinalGoal = parseInt(siteFinalGoal.replace(/,/g, ""));
var siteMiddleGoal = $('span#site-fundraiser-middle-goal').text();
var noCommaSiteMiddleGoal = parseInt(siteMiddleGoal.replace(/,/g, ""));
var siteSoFar = $('span#site-fundraiser-so-far').text();
var noCommaSiteSoFar = parseInt(siteSoFar.replace(/,/g, ""));
var siteMatchCount = $('span#site-fundraiser-match-count').text();
var noCommaSiteMatchCount = parseInt(siteMatchCount.replace(/,/g, ""));
if (! noCommaSiteMatchCount) {
noCommaSiteMatchCount = "0";
}
var noCommaMatchFinalGoal = noCommaSiteFinalGoal - noCommaSiteMatchCount;
var goal = $('span#fundraiser-goal').text();
var soFar = $('span#fundraiser-so-far').text();
var donationCount = $('span#fundraiser-donation-count').text();
var noCommaGoal = parseFloat(goal.replace(/,/g, ""));
var noCommaSoFar = parseFloat(soFar.replace(/,/g, ""));
var noCommaDonationCount = parseInt(donationCount.replace(/,/g, ""));
var percentage = (parseFloat(noCommaSoFar) / parseFloat(noCommaGoal)) * 100;
var curValue = 0.00;
var incrementSoFar = 0.00;
var curDonationCount = 0;
var riseLevelPercent = 0.5;
var incrementDonationCount = Math.round( (riseLevelPercent / 100) * noCommaDonationCount );
$('#siteprogressbar').empty();
if (noCommaSiteSoFar >= noCommaSiteMiddleGoal) {
// We've got
var leftOver = noCommaMatchFinalGoal - noCommaSiteSoFar;
$('#siteprogressbar').
multiprogressbar({ parts: [
{ value: (noCommaSiteSoFar / noCommaSiteFinalGoal) * 100,
text: noCommaSiteSoFar.toLocaleString() + " have joined!",
barClass: "progress", textClass: "soFarText" },
{ value:
((noCommaMatchFinalGoal - noCommaSiteMiddleGoal) / noCommaSiteFinalGoal) * 100,
text: leftOver.toLocaleString() + " more needed to save license compliance work.",
barClass: "final-goal", textClass: "goalText" },
{ value: 100,
text: siteMatchCount + " matched!",
barClass: "progress", textClass: "soFarText" },
]});
} else {
$('#siteprogressbar').
multiprogressbar({ parts: [
{ value: (noCommaSiteSoFar / noCommaSiteFinalGoal) * 100,
text: siteSoFar + " joined!",
barClass: "progress", textClass: "soFarText" },
{ value: ((noCommaSiteMiddleGoal - noCommaSiteSoFar) / noCommaSiteFinalGoal) * 100,
text: siteMiddleGoal + " will save our basic work",
barClass: "middle-goal", textClass: "goalText" },
{ value:
((noCommaMatchFinalGoal - noCommaSiteMiddleGoal) / noCommaSiteFinalGoal) * 100,
text: noCommaMatchFinalGoal.toLocaleString() + " will save license compliance",
barClass: "final-goal", textClass: "goalText" },
{ value: 100,
text: siteMatchCount + " matched!",
barClass: "progress", textClass: "soFarText" },
]});
}
$('span#fundraiser-percentage').css({ 'color' : 'green',
'font-weight' : 'bold',
'float' : 'right',
'margin-right' : '40%',
'margin-top' : '2.5%',
'text-align' : 'inherit'});
function riseDonationProgressBar() {
if (curValue >= percentage) {
$('span#fundraiser-so-far').text(soFar);
$("#progressbar").progressbar({ value : percentage });
$('span#fundraiser-percentage').text(percentage.toFixed(1) + "%");
} else {
var newVal = (curValue / 100.00) * noCommaGoal;
$("#progressbar").progressbar({ value: curValue });
$('span#fundraiser-so-far').text(newVal.toLocaleString());
curValue += riseLevelPercent;
setTimeout(riseDonationProgressBar, 50);
}
}
function riseDonationCount() {
if (curDonationCount >= noCommaDonationCount) {
$('span#fundraiser-donation-count').text(donationCount);
} else {
$('span#fundraiser-donation-count').text(curDonationCount.toLocaleString());
curDonationCount += incrementDonationCount;
setTimeout(riseDonationCount, 50);
}
}
if (noCommaDonationCount > 0) {
$('span#fundraiser-donation-count').text("");
riseDonationCount();
}
if (noCommaSoFar > 0.00 && noCommaGoal > 0.00) {
$('span#fundraiser-percentage').text("");
$("#progressbar").progressbar({ value: curValue });
riseDonationProgressBar();
}
$('.toggle-content').hide();
$('.toggle-control')
.addClass('clickable')
.bind('click', function() {
var $control = $(this);
var $parent = $control.parents('.toggle-unit');
$parent.toggleClass('expanded');
$parent.find('.toggle-content').slideToggle();
// if control has HTML5 data attributes, use to update text
if ($parent.hasClass('expanded')) {
$control.html($control.attr('data-expanded-text'));
} else {
$control.html($control.attr('data-text'));
}
});
$('a.donate-now')
.addClass('clickable')
.bind('click', function() {
var $control = $('#donate-box');
var $otherTextControl = $('.donate-sidebar');
setTimeout(function() { $control.find('.toggle-content').slideUp(100);
$control.toggleClass('expanded');
$control.find('.toggle-content').slideDown(800).fadeOut(10);
$otherTextControl.find('.donate-box-highlight').fadeOut(100);
}, 300);
setTimeout(function() { $control.find('.toggle-content').fadeIn(2000);
$otherTextControl.find('.donate-box-highlight')
.css({'font-weight': 'bold', 'font-size' : '110%' });
$otherTextControl.find('.donate-box-highlight').fadeIn(10000);
}, 500);
});
$(".t-shirt-size-selector").hide();
$('input[name=on0]:radio').change(function() {
var input=$(this);
var tShirtSelector = input.parent().children('.t-shirt-size-selector')
var noShippingSelector = input.parent().children('input#no_shipping');
var value = input.val();
if (value == "wantGiftYes") {
tShirtSelector.show();
noShippingSelector.val("2");
} else {
tShirtSelector.hide();
noShippingSelector.val("0");
}
});
// Forms start in "invalid" form, with the errors shown, so that
// non-Javascript users see the errors by default and know what they must
// enter. The following two lines correct that.
$('*#amount').addClass("valid");
$('.supporter-form-inputs .form-error-show')
.removeClass('form-error-show').addClass('form-error');
$('.dinner-form-inputs .form-error-show')
.removeClass('form-error-show').addClass('form-error');
$('*#amount').on('input', function() {
var input=$(this);
var value = input.val();
var errorElement=$("span#error", input.parent());
var noCommaValue = value;
noCommaValue = value.replace(/,/g, "");
var re = /^((\d{1,3}(,?\d{3})*?(\.\d{0,2})?)|\d+(\.\d{0,2})?)$/;
var isValid = ( re.test(value) &&
parseInt(noCommaValue) >= parseInt(input.attr("minimum")));
if (isValid) {
input.removeClass("invalid").addClass("valid");
errorElement.removeClass("form-error-show").addClass("form-error");
$("#form-correction-needed").removeClass("form-error-show").addClass("form-error");
}
else {
input.removeClass("valid").addClass("invalid");
errorElement.removeClass("form-error").addClass("form-error-show");
}
});
var validateFormAtSubmission = function(element, event) {
var valid = element.hasClass("valid");
if (! valid) {
$("#form-correction-needed").removeClass("form-error").addClass("form-error-show")
.css("font-weight", "bold").css("font-size", "150%");
event.preventDefault();
} else {
$("#form-correction-needed").removeClass("form-error-show").addClass("form-error");
}
};
$(".supporter-form-submit#monthly").click(function (event) {
validateFormAtSubmission($(".supporter-form#monthly input#amount"), event);
});
$(".supporter-form-submit#annual").click(function (event) {
validateFormAtSubmission($(".supporter-form#annual input#amount"), event);
});
$(".supporter-form-submit#renewal").click(function (event) {
validateFormAtSubmission($(".supporter-form#renewal input#amount"), event);
});
$(".dinner-form-submit").click(function (event) {
validateFormAtSubmission($(".dinner-form input#amount"), event);
});
/* Handle toggling of annual/monthly form selections */
$('.supporter-type-selection#monthly').hide();
$('.supporter-type-selection#renewal').hide();
$('#annualSelector').css("font-weight", "bold").css("font-size", "127%");
$("a[href$='monthly']").bind('click', function() {
$('.supporter-type-selection#annual').hide();
$('.supporter-type-selection#renewal').hide();
$('.supporter-type-selection#monthly').show();
$('#monthlySelector').css("font-weight", "bold").css("font-size", "127%");
$('#annualSelector').css("font-weight", "normal").css("font-size", "125%");
$('#renewalSelector').css("font-weight", "normal").css("font-size", "125%");
$("#form-correction-needed").removeClass("form-error-show").addClass("form-error");
});
$("a[href$='annual']").bind('click', function() {
$('.supporter-type-selection#renewal').hide();
$('.supporter-type-selection#monthly').hide();
$('.supporter-type-selection#annual').show();
$('#annualSelector').css("font-weight", "bold").css("font-size", "127%");
$('#renewalSelector').css("font-weight", "normal").css("font-size", "125%");
$('#monthlySelector').css("font-weight", "normal").css("font-size", "125%");
});
$("a[href$='renewal']").bind('click', function() {
$('.supporter-type-selection#annual').hide();
$('.supporter-type-selection#monthly').hide();
$('.supporter-type-selection#renewal').show();
$('#renewalSelector').css("font-weight", "bold").css("font-size", "127%");
$('#monthlySelector').css("font-weight", "normal").css("font-size", "125%");
$('#annualSelector').css("font-weight", "normal").css("font-size", "125%");
});
$( ".footnote-mark" ).tooltip({
items: "a",
hide: { duration: 5000 },
position: {
my: "center bottom-20",
at: "center left",
using: function( position, feedback ) {
$( this ).css( position );
$( "<div>" )
.addClass( "arrow" )
.addClass( feedback.vertical )
.addClass( feedback.horizontal )
.appendTo( this );
}
},
content: function() {
return $('.footnote-1-text').text();
}
});
});
$(window).load(function () {
verifySelctionCorrectOnPageLoad = function() {
var ourURL = document.URL;
if (ourURL.search("#monthly") > 0) {
$('.supporter-type-selection#annual').hide();
$('.supporter-type-selection#monthly').show();
$('#monthlySelector').css("font-weight", "bold").css("font-size", "127%");
$('#annualSelector').css("font-weight", "normal").css("font-size", "125%");
$('#renewalSelector').css("font-weight", "normal").css("font-size", "125%");
}
if (ourURL.search("#annual") > 0) {
$('.supporter-type-selection#monthly').hide();
$('.supporter-type-selection#annual').show();
$('#annualSelector').css("font-weight", "bold").css("font-size", "127%");
$('#monthlySelector').css("font-weight", "normal").css("font-size", "125%");
$('#renewalSelector').css("font-weight", "normal").css("font-size", "125%");
}
if (ourURL.search("#renewal") > 0) {
$('.supporter-type-selection#monthly').hide();
$('.supporter-type-selection#annual').hide();
$('.supporter-type-selection#renewal').show();
$('#renewalSelector').css("font-weight", "bold").css("font-size", "127%");
$('#monthlySelector').css("font-weight", "normal").css("font-size", "125%");
$('#annualSelector').css("font-weight", "normal").css("font-size", "125%");
}
}
if (location.hash) {
setTimeout(verifySelctionCorrectOnPageLoad, 1);
}
window.addEventListener("hashchange", verifySelctionCorrectOnPageLoad);
});
|