PageSourceSearch

https://www.montenews.com/wp-content/plugins/cherryroad-media-paywall/public/assets/js/checkout.js?ver=1.8.0

js montenews.com collected 2026-09-26 05:45:12 UTC 18,487 bytes, 486 lines download raw bytes

1$("#sticky").modal({
2  escapeClose: false,
3  clickClose: false,
4  showClose: false
5});
6
7$('.plan_btn').click(function(){
8    $('#header').hide();
9});
10
11$('#sub_history_link').click(function(){
12    $('#sub_history').show();
13});
14
15var checkout_shipping = {};
16
17jQuery(document).ready(function($){
18    "use strict";
19
20	// checkout form
21    checkout_shipping = {
22        init: function() {
23            
24        	this.field_names = [ 'firstname', 'lastname', 'address1', 'address2', 'phone', 'country', 'city', 'state', 'zipcode'  ];
25            this.notsameas_checkbox = $('#notsameasbilling');
26            this.fields = $('#shipping-fields');
27			this.show_notsameas_timer = null;
28			
29            var self = this;			
30			
31			//hide the fields by default
32			self.fields.hide();
33
34			//hide/show shipping fields and copy when clicking notsameas
35            self.notsameas_checkbox.unbind('change').on('change', function() {              
36				//maybe copy
37				self.maybe_copy_data( this );
38            });
39			
40			//hide the notsameas button if the billing address is not visible
41			self.checkBillingAddressVisibilityForNotSameAsCheckbox();
42        },
43        maybe_copy_data: function( element ) {
44
45            var self = this;
46            
47            if (element.checked) {	
48				// clear the fields
49		    	$.each( self.field_names, function( index, field_name ) {
50	          		$( '#s' + field_name  ).val();
51	          	});
52
53				//show the fields
54				self.fields.show();	
55            } else {				
56				//hide the fields
57				self.fields.hide();
58				
59				/***
60				// Integrate with State dropdown, convert #sstate to text input.
61            	if ( $( '#bcountry.crs-country' ).length > 0 ) {
62	            	$('#sstate').replaceWith( '<input type="text" id="sstate" name="sstate"></input>');
63	            }
64				***/
65
66				//copy the fields			
67		    	$.each( self.field_names, function( index, field_name ) {
68	          		$( '#s' + field_name  ).val( $('#b' + field_name ).val() );  // Set shipping field equal to each billing field.
69	          	});
70			}
71        },
72		checkBillingAddressVisibilityForNotSameAsCheckbox: function() {
73			// need to cleaup this function
74			return true;
75			
76			/***
77			var baddress = $('#baddress1');
78			var checkout_shipping_address_fields = $('#checkout_shipping_address_fields');
79			
80			var self = this;
81			
82			if(this.notsameas_checkbox.is(':checked')) {					
83				this.fields.hide();
84			}
85
86			if(baddress.length && baddress.is(':visible')) {
87				$('#notsameasbilling_wrapper').show();
88			}
89			else if (checkout_shipping_address_fields.is(':visible'))
90			{
91				this.notsameas_checkbox.attr('checked', false);
92				$('#notsameasbilling_wrapper').hide();						
93				this.fields.show();
94			}
95			//check again in .2 seconds
96			this.show_notsameas_timer = setTimeout(function(){self.checkBillingAddressVisibilityForNotSameAsCheckbox();}, 200);
97			***/
98		}			
99    };
100
101    checkout_shipping.init();			
102
103	$("#useexistingcard").change(function() {
104		if($(this).prop('checked')) {
105			$('#newcard').hide();
106			$('#pci_iframe').hide();
107			document.getElementById("checkout_submit_span").style.visibility = "visible";
108			document.getElementById("checkout_btn").style.visibility = "visible";
109			document.getElementById("checkout_btn").disabled = false;
110		} else {
111			$('#newcard').show();
112			$('#pci_iframe').show();
113			document.getElementById("checkout_submit_span").style.visibility = "hidden";
114			document.getElementById("checkout_btn").style.visibility = "hidden";
115			document.getElementById("checkout_btn").disabled = true;
116		}
117	});
118
119    let $checkout_form = document.querySelector("#checkout_form");
120    let $logout_link = document.querySelector("#logout_link");
121    let croad_auth_url = window.location.origin + '/wp-json/croad-auth';
122
123	if ($checkout_form) {
124	   $checkout_form.addEventListener("submit", function (e) {
125            e.preventDefault();
126
127			// set default values for form fields
128			////document.getElementById('username').value = document.getElementById('bemail').value;
129
130			document.getElementById("processing").style.visibility = "visible";
131			document.getElementById("checkout_btn").disabled = true;
132			document.getElementById('required_errors').innerHTML = "";
133			document.getElementById('validation_errors').innerHTML = "";
134			document.getElementById('crm_errors').innerHTML = "";
135			
136            let checkout_data_submit = new FormData($checkout_form);
137            let parsed_data_submit = new URLSearchParams(checkout_data_submit);
138
139		   // fetch("/index.php/wp-json/cr-crm/checkout", {
140            fetch(croad_auth_url + '/checkout', {
141                method: "POST",
142                body: parsed_data_submit,
143            }).then((res) => res.json())
144            .then((json) => {
145                //alert(json);
146                if (json.status == "review") {
147					var obj = json.message;
148					var pci = 0;
149					var sid = 0;
150					var ssid = 0;
151					for (var key in obj) {
152						//alert(key + ' ' + obj[key]);
153						if(key == 'subtotal') {
154							document.getElementById('subtotal').innerHTML = '$' + obj[key];
155						}
156						if(key == 'tax') {
157							document.getElementById('tax').innerHTML = '$' + obj[key];
158						}
159						if(key == 'total') {
160							document.getElementById('total').innerHTML = '$' + obj[key];
161						}
162						if(key == 'pci') {
163							pci = obj[key];
164						}
165						if(key == 'sid') {
166							sid = obj[key];
167						}
168						console.log('review sid: ' + sid);
169						if(key == 'ssid') {
170							ssid = obj[key];
171						}
172						console.log('review ssid: ' + ssid);
173					}
174
175					$("#review").val('0');
176					
177					$("#checkout_fields").hide();
178					$("#checkout_review_fields").show();
179					
180					$("#checkout_btn").prop('value', 'Proceed');
181					$("#checkout_btn").prop('style', 'background-color: #008000 !important;');
182
183					document.getElementById("processing").style.visibility = "hidden";
184					
185					if(pci == 1 || pci == 'yes') {
186						//alert('You will be taken to a secure online payment form to complete your transaction.');
187						document.getElementById("checkout_submit_span").style.visibility = "hidden";
188						document.getElementById("checkout_btn").style.visibility = "hidden";
189						
190						// reload pci form iframe
191						document.getElementById('pci_form').src += sid;
192						//document.getElementById('pci_form').contentDocument.location.reload(true);
193					}
194					else {
195						document.getElementById("checkout_btn").disabled = false;
196					}
197					
198					$("#top").scrollTop(0);
199					
200					return true;
201				}					
202                else if (json.status != "success") {
203					var obj = json.message;
204					for (var key in obj) {
205						//alert(key + ' ' + obj[key]);
206						if(key == 'required_errors' && obj[key].length > 0) {
207							// var required_errors = obj[key].split(',');
208							var required_errors_html = "";
209							required_errors_html += '<div role="alert" id="checkout_message" class="checkout_message checkout_error 12-at-font 12-at-size"><p><strong>Please complete all fields. The following fields are required.</strong></p><ul>';
210							for(var i=0; i<obj[key].length; i++){
211								required_errors_html += "<li>" + obj[key][i]+"</li>";
212							}
213							required_errors_html += '</ul></div>';
214							
215							document.getElementById('required_errors').innerHTML = required_errors_html;
216						}
217						
218						if(key == 'validation_errors' && obj[key].length > 0) {
219							// var validation_errors = obj[key].split(',');
220							var validation_errors_html = "";
221							validation_errors_html += '<div role="alert" id="checkout_message" class="checkout_message checkout_error 12-at-font 12-at-size"><p><strong>Please enter valid data for the following fields.</strong></p><ul>';
222							for(var i=0; i<obj[key].length; i++){
223								validation_errors_html += "<li>" + obj[key][i]+"</li>";
224							}
225							validation_errors_html += '</ul></div>';
226							
227							document.getElementById('validation_errors').innerHTML = validation_errors_html;
228						}
229
230						if(key == 'crm_errors' && obj[key].length > 0) {
231							// var crm_errors = obj[key].split(',');
232							var crm_errors_html = "";
233							crm_errors_html += '<div role="alert" id="checkout_message" class="checkout_message checkout_error 12-at-font 12-at-size"><p><strong>We were unable to process your request due to the following error(s).</strong></p><ul>';
234							for(var i=0; i<obj[key].length; i++){
235								crm_errors_html += "<li>" + obj[key][i]+"</li>";
236							}
237							crm_errors_html += '</ul><p><em>Please try again or contact our support team via the Contact Us page for help with creating your subscription.</em></p></div>';
238							
239							document.getElementById('crm_errors').innerHTML = crm_errors_html;
240						}
241
242					}
243					
244					$("#review").val('1');
245					
246					$("#checkout_fields").show();
247					$("#checkout_review_fields").hide();
248					
249					$("#checkout_btn").prop('value', 'Review Order');
250					$("#checkout_btn").prop('style', 'background-color: #A31F34 !important;');
251
252					let errordiv = document.getElementById('checkout_form_wrapper');
253					errordiv.scrollIntoView(true);
254
255					document.getElementById("processing").style.visibility = "hidden";
256					document.getElementById("checkout_btn").disabled = false;
257
258					return false;
259					
260					//return alert(json.message);
261				}
262				else {
263					////alert("Successfully processed subscription");
264				}
265				
266                //return window.location.reload(true);
267				//return (window.location.href = "/dashboard?checkout=success");
268				return (window.location.href = json.next_url);
269            }).catch((err) => {
270                //alert('Error: ${err}');
271                console.log(`Error: ${err}`);
272            });
273
274		});
275
276	   if($logout_link) {
277        $logout_link.addEventListener("click", function (e) {
278			e.preventDefault();
279
280			let checkout_data_logout = new FormData($checkout_form);
281            let parsed_data_logout = new URLSearchParams(checkout_data_logout);
282            let redirect_url_logout = $checkout_form.querySelector("#logout_redirect_url").value;
283
284            fetch(croad_auth_url + '/logout', {
285                method: "POST",
286                body: parsed_data_logout,
287            })
288            .then((res) => res.json())
289            .then((json) => {
290                if (json.status != "success") {
291                    return alert(json.message);
292                }
293
294                return (window.location.href = redirect_url_logout);
295            }).catch((err) => {
296                console.log('Error: ${err}');
297            });
298			
299        });
300	   }
301   }
302
303
304    let $signup_form = document.querySelector("#signup_form");
305
306	if ($signup_form) {
307	   $signup_form.addEventListener("submit", function (e) {
308            e.preventDefault();
309
310			document.getElementById("processing").style.visibility = "visible";
311			document.getElementById("checkout_btn").disabled = true;
312			document.getElementById('required_errors').innerHTML = "";
313			document.getElementById('validation_errors').innerHTML = "";
314			document.getElementById('crm_errors').innerHTML = "";
315			
316            let checkout_data_submit = new FormData($signup_form);
317            let parsed_data_submit = new URLSearchParams(checkout_data_submit);
318
319		   // fetch("/index.php/wp-json/cr-crm/signup", {
320            fetch(croad_auth_url + '/signup', {
321                method: "POST",
322                body: parsed_data_submit,
323            }).then((res) => res.json())
324            .then((json) => {
325                //alert(json);
326
327                if (json.status != "success") {
328					var obj = json.message;
329					for (var key in obj) {
330						//alert(key + ' ' + obj[key]);
331						if(key == 'required_errors' && obj[key].length > 0) {
332							// var required_errors = obj[key].split(',');
333							var required_errors_html = "";
334							required_errors_html += '<div role="alert" id="checkout_message" class="checkout_message checkout_error 12-at-font 12-at-size"><p><strong>Please complete all fields. The following fields are required.</strong></p><ul>';
335							for(var i=0; i<obj[key].length; i++){
336								required_errors_html += "<li>" + obj[key][i]+"</li>";
337							}
338							required_errors_html += '</ul></div>';
339							
340							document.getElementById('required_errors').innerHTML = required_errors_html;
341						}
342						
343						if(key == 'validation_errors' && obj[key].length > 0) {
344							// var validation_errors = obj[key].split(',');
345							var validation_errors_html = "";
346							validation_errors_html += '<div role="alert" id="checkout_message" class="checkout_message checkout_error 12-at-font 12-at-size"><p><strong>Please enter valid data for the following fields.</strong></p><ul>';
347							for(var i=0; i<obj[key].length; i++){
348								validation_errors_html += "<li>" + obj[key][i]+"</li>";
349							}
350							validation_errors_html += '</ul></div>';
351							
352							document.getElementById('validation_errors').innerHTML = validation_errors_html;
353						}
354
355						if(key == 'crm_errors' && obj[key].length > 0) {
356							// var crm_errors = obj[key].split(',');
357							var crm_errors_html = "";
358							crm_errors_html += '<div role="alert" id="checkout_message" class="checkout_message checkout_error 12-at-font 12-at-size"><p><strong>We were unable to process your request due to the following error(s).</strong></p><ul>';
359							for(var i=0; i<obj[key].length; i++){
360								crm_errors_html += "<li>" + obj[key][i]+"</li>";
361							}
362							crm_errors_html += '</ul><p><em>Please try again or contact our support team via the Contact Us page for help with creating your account.</em></p></div>';
363							
364							document.getElementById('crm_errors').innerHTML = crm_errors_html;
365						}
366
367					}
368					
369					let errordiv = document.getElementById('checkout_form_wrapper');
370					errordiv.scrollIntoView(true);
371
372				document.getElementById("processing").style.visibility = "hidden";
373				document.getElementById("checkout_btn").disabled = false;
374
375					return false;
376					
377					//return alert(json.message);
378				}				
379				else {
380					////alert("Successfully processed subscription");
381				}
382				
383                //return window.location.reload(true);
384				return (window.location.href = "/dashboard?signup=success");
385            }).catch((err) => {
386                alert('Error: ${err}');
387                //console.log(`Error: ${err}`);
388            });
389
390		});
391   }
392
393
394    let $cancel_form = document.querySelector("#cancel_form");
395	
396	if ($cancel_form) {
397		alert('cancel form');
398
399	   $cancel_form.addEventListener("submit", function (e) {
400            e.preventDefault();
401
402			document.getElementById("processing").style.visibility = "visible";
403			document.getElementById("checkout_btn").disabled = true;
404			document.getElementById('required_errors').innerHTML = "";
405			document.getElementById('validation_errors').innerHTML = "";
406			document.getElementById('crm_errors').innerHTML = "";
407			
408            let checkout_data_submit = new FormData($cancel_form);
409            let parsed_data_submit = new URLSearchParams(checkout_data_submit);
410
411		   // fetch("/index.php/wp-json/cr-crm/cancel", {
412            fetch(croad_auth_url + '/cancel', {
413                method: "POST",
414                body: parsed_data_submit,
415            }).then((res) => res.json())
416            .then((json) => {
417                //alert(json);
418
419                if (json.status != "success") {
420					var obj = json.message;
421					for (var key in obj) {
422						//alert(key + ' ' + obj[key]);
423						if(key == 'required_errors' && obj[key].length > 0) {
424							// var required_errors = obj[key].split(',');
425							var required_errors_html = "";
426							required_errors_html += '<div role="alert" id="checkout_message" class="checkout_message checkout_error 12-at-font 12-at-size"><p><strong>Please complete all fields. The following fields are required.</strong></p><ul>';
427							for(var i=0; i<obj[key].length; i++){
428								required_errors_html += "<li>" + obj[key][i]+"</li>";
429							}
430							required_errors_html += '</ul></div>';
431							
432							document.getElementById('required_errors').innerHTML = required_errors_html;
433						}
434						
435						if(key == 'validation_errors' && obj[key].length > 0) {
436							// var validation_errors = obj[key].split(',');
437							var validation_errors_html = "";
438							validation_errors_html += '<div role="alert" id="checkout_message" class="checkout_message checkout_error 12-at-font 12-at-size"><p><strong>Please enter valid data for the following fields.</strong></p><ul>';
439							for(var i=0; i<obj[key].length; i++){
440								validation_errors_html += "<li>" + obj[key][i]+"</li>";
441							}
442							validation_errors_html += '</ul></div>';
443							
444							document.getElementById('validation_errors').innerHTML = validation_errors_html;
445						}
446
447						if(key == 'crm_errors' && obj[key].length > 0) {
448							// var crm_errors = obj[key].split(',');
449							var crm_errors_html = "";
450							crm_errors_html += '<div role="alert" id="checkout_message" class="checkout_message checkout_error 12-at-font 12-at-size"><p><strong>We were unable to process your request due to the following error(s).</strong></p><ul>';
451							for(var i=0; i<obj[key].length; i++){
452								crm_errors_html += "<li>" + obj[key][i]+"</li>";
453							}
454							crm_errors_html += '</ul><p><em>Please try again or contact our support team via the Contact Us page for help with creating your account.</em></p></div>';
455							
456							document.getElementById('crm_errors').innerHTML = crm_errors_html;
457						}
458
459					}
460					
461					let errordiv = document.getElementById('checkout_form_wrapper');
462					errordiv.scrollIntoView(true);
463
464				document.getElementById("processing").style.visibility = "hidden";
465				document.getElementById("checkout_btn").disabled = false;
466
467					return false;
468					
469					//return alert(json.message);
470				}				
471				else {
472					////alert("Successfully processed subscription");
473				}
474				
475                //return window.location.reload(true);
476				return (window.location.href = "/dashboard?cancel=success2");
477            }).catch((err) => {
478                alert('Error: ${err}');
479                //console.log(`Error: ${err}`);
480            });
481
482		});
483   }
484
485
486});

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.