PageSourceSearch

https://shsthepapercut.com/wp-content/plugins/sno-donate/assets/script/sno-donate-script_ver-1.2.1.js

js shsthepapercut.com collected 2026-10-04 09:16:10 UTC 8,402 bytes, 275 lines download raw bytes

1jQuery(document).ready(function($) {
2	var stripe = Stripe('pk_live_MGUOGsdhVYRXiYZIo4IJijSg');
3
4	'use strict';
5
6	function registerElements(elements, exampleName) {
7  		var formClass = '.' + exampleName;
8	  var example = document.querySelector(formClass);
9
10	  var form = example.querySelector('form');
11	  var error = form.querySelector('.error');
12	  var errorMessage = error.querySelector('.message');
13
14	  function enableInputs() {
15	    Array.prototype.forEach.call(
16	      form.querySelectorAll(
17	        "input[type='text'], input[type='email'], input[type='tel']"
18	      ),
19	      function(input) {
20	        input.removeAttribute('disabled');
21	      }
22	    );
23	  }
24
25	  function disableInputs() {
26	    Array.prototype.forEach.call(
27	      form.querySelectorAll(
28	        "input[type='text'], input[type='email'], input[type='tel']"
29	      ),
30	      function(input) {
31	        input.setAttribute('disabled', 'true');
32	      }
33	    );
34	  }
35
36	  function triggerBrowserValidation() {
37	    // The only way to trigger HTML5 form validation UI is to fake a user submit
38	    // event.
39	    var submit = document.createElement('input');
40	    submit.type = 'submit';
41	    submit.style.display = 'none';
42	    form.appendChild(submit);
43	    submit.click();
44	    submit.remove();
45	  }
46
47	  // Listen for errors from each Element, and show error messages in the UI.
48	  var savedErrors = {};
49	  elements.forEach(function(element, idx) {
50	    element.on('change', function(event) {
51	      if (event.error) {
52	        error.classList.add('visible');
53	        savedErrors[idx] = event.error.message;
54	        errorMessage.innerText = event.error.message;
55	      } else {
56	        savedErrors[idx] = null;
57
58	        // Loop over the saved errors and find the first one, if any.
59	        var nextError = Object.keys(savedErrors)
60	          .sort()
61	          .reduce(function(maybeFoundError, key) {
62	            return maybeFoundError || savedErrors[key];
63	          }, null);
64
65	        if (nextError) {
66	          // Now that they've fixed the current error, show another one.
67	          errorMessage.innerText = nextError;
68	        } else {
69	          // The user fixed the last error; no more errors.
70	          error.classList.remove('visible');
71	        }
72	      }
73	    });
74	  });
75
76	  // Listen on the form's 'submit' handler...
77	  $('#sno-donate-modal').on('click', '#sno-donate-form-submit', function(e) {
78		    e.preventDefault();
79
80		    // Trigger HTML5 validation UI on the form if any of the inputs fail
81		    // validation.
82		    var plainInputsValid = true;
83		    Array.prototype.forEach.call(form.querySelectorAll('input'), function(
84		      input
85		    ) {
86		      if (input.checkValidity && !input.checkValidity()) {
87		        plainInputsValid = false;
88		        return;
89		      }
90		    });
91		    if (!plainInputsValid) {
92		      triggerBrowserValidation();
93		      return;
94		    }
95
96		    var name = $('#sno-donate-name').val();
97         	var email = $('#sno-donate-email').val();
98         	if (!name.trim()) {
99         		error.classList.add('visible');
100		        errorMessage.innerText = "Please enter your full name."
101		        return
102         	}
103         	var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
104         	if (!email.trim() || !regex.test(email)) {
105         		error.classList.add('visible');
106		        errorMessage.innerText = "Please enter a valid email address."
107		        return
108         	}
109         	var donation_amount = $('#donation-amount').val();
110     		if (donation_amount == -1) {
111     			donation_amount = $('#custom-donation-amount').val().replace('$', '');
112     			if (!donation_amount) {
113	     			error.classList.add('visible');
114			        errorMessage.innerText = "Please enter a donation amount."
115			        return
116     			}
117     		}
118     		var agree_to_terms = $('#sno-donate-agree').is(':checked');
119     		if (!agree_to_terms) {
120     			error.classList.add('visible');
121		        errorMessage.innerText = "Please agree to the terms of service."
122		        return
123     		}
124
125		    // Show a loading screen...
126		    $('.sno-donate-submit-form').hide();
127   			$('.sno-donate-submitting').show();
128
129		    // Disable all inputs.
130		    disableInputs();
131
132		    // Gather additional customer data we may have collected in our form.		   
133		    var additionalData = {
134		      name: name,
135		      email: email
136		    };
137
138		    // Use Stripe.js to create a token. We only need to pass in one Element
139		    // from the Element group in order to create a token. We can also pass
140		    // in the additional customer data we collected in our form.
141		    stripe.createToken(elements[0], additionalData).then(function(result) {
142		      // Stop loading!
143		      example.classList.remove('submitting');
144
145		      if (result.token) {
146		        // If we received a token, show the token ID.
147		        var token = result.token.id;
148
149         		var donation_amount = $('#donation-amount').val();
150         		if (donation_amount == -1) {
151         			donation_amount = $('#custom-donation-amount').val().replace('$', '');
152         		} else {
153         			donation_amount = donation_amount[0]
154         		}
155
156         		var name = $('#sno-donate-name').val();
157         		var email = $('#sno-donate-email').val();
158         		var anonymous = $('#sno-donate-anonymous').is(':checked');
159
160
161    	      	var data = {
162    	  			action: 'submit_donation',
163    	  			name: name,
164    	  			email: email,
165    	  			amount: donation_amount,
166    	  			anonymous: anonymous,
167    	  			token: token
168    	  		};
169    	  				
170    	  		jQuery.post(ajax_object.ajax_url, data, function(response) {
171    	  			$('.sno-donate-submitting').hide();
172    	  			resp = JSON.parse(response)
173    	  			if (resp.success) {
174    	  				$('.sd-goal-progress').width(resp.goal_progress_percent);
175    	  				$('.sd-goal-contributed-amount').html('$' + resp.goal_progress_amount);
176    	  				$('.sno-donate-success').show();
177    	  			} else {
178    	  				$('.sno-donate-failure').show();
179    	  			}
180    	  		});
181
182		      } else {
183		        // Otherwise, un-disable inputs.'
184		        enableInputs();
185		        error.classList.add('visible');
186		        errorMessage.innerText = result.error.message
187		        $('.sno-donate-submitting').hide();
188		        $('.sno-donate-submit-form').show();
189   				
190		      }
191		    });
192		  });
193	}
194
195	  var elements = stripe.elements({
196	    fonts: [
197	      {
198	        cssSrc: '//fonts.googleapis.com/css?family=Roboto',
199	      },
200	    ],
201	    // Stripe's examples are localized to specific languages, but if
202	    // you wish to have Elements automatically detect your user's locale,
203	    // use `locale: 'auto'` instead.
204	    locale: window.__exampleLocale
205	  });
206
207	  var card = elements.create('card', {
208	    iconStyle: 'solid',
209	    style: {
210	    	base: {
211	    		fontSize: '16px',
212	    		lineHeight: '30px',
213	    		backgroundColor: '#fafafa',
214	    	}
215	    }
216	  });
217	  card.mount('#sno-donate-card');
218
219	  registerElements([card], 'sno-donate-submit-form');
220
221	$('.sno-donate-open-button').click(function() {
222		$('#sno-donate-modal').fadeIn();
223	});
224
225	$('#donation-amount').change(function() {
226		let value = $(this).val()
227		if (value == -1) {
228			$('.sno-donate-custom-amount').slideDown();
229		} else {
230			$('.sno-donate-custom-amount').slideUp();
231		}
232		if( !$('.sd-cc-row').is(':visible') ) {
233			$('.sd-cc-row').slideDown();
234			$('.sd-terms-row').slideDown();
235			$('.sno-donate-button-wrap').slideDown();
236		}
237
238	});
239
240	$('#custom-donation-amount').change(function() {
241		let value = $(this).val().replace('$', '');
242		var error = false;
243		var error_message = '';
244		if (!$.isNumeric(value)) {
245			error = true
246			error_message = "Please enter a valid donation amount."
247		}
248		if (value < 10) {
249			error = true
250			error_message = "Donation amount must be at least $10.00"
251		}
252		if (error) {
253			$(this).val('');
254 			$('.sno-donate-submit-form .error').addClass('visible');
255	        $('.sno-donate-submit-form .error .message').html(error_message);
256		    return;
257		}
258
259		$('.sno-donate-submit-form .error').removeClass('visible');
260	    $('.sno-donate-submit-form .error .message').html("");
261		
262		value = '$' + parseFloat(value).toFixed(0);
263		$(this).val(value);
264	})
265
266	$('#sno-donate-form-close').click(function() {
267		$('#sno-donate-modal').css('display', 'none');
268	});
269	
270	$('body').on('click', '#sno-donate-modal', function(e) {
271		if(e.target !== e.currentTarget) return;
272		$(this).fadeOut();
273	});
274   
275});

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.