PageSourceSearch

https://www.damemagazine.com/wp-content/plugins/chargebee-wp-membe…/public/js/chargebee-membership-public.js

js damemagazine.com collected 2026-10-02 02:52:06 UTC 14,599 bytes, 406 lines download raw bytes

1(function( $, wp ) {
2	'use strict';
3
4	window.Chargebee_Membership = {
5
6		// Functions for Document Ready Event
7		init: function() {
8			this.register_account();
9			this.subscribe_product();
10			this.checkout_product();
11			this.reactivate_product();
12			this.validate_login_form();
13			this.validate_registration_form();
14			this.user_nofication_dialog();
15		},
16
17		// Functions for Window Load Event
18		initLoad: function() {
19			// Slide down notification dialog box and show the message.
20			$( '.cbm-user-notify-dialog' ).slideDown( "slow" );
21		},
22
23		// Validation of login form.
24		validate_login_form: function () {
25			var _this = this;
26			$( '#cbm_loginform' ).on( 'submit', function () {
27				var error_class = $( '.cbm_errors' );
28				var error_class_span = $( '.cbm_errors span.error' );
29				$( error_class ).css( 'display', 'none' );
30
31				// Get values of fields into variables
32				var username = $( '#cbm_user_login' ).val();
33				var password = $( '#cbm_user_pass' ).val();
34				var err_msg  = '';
35				// Empty error check for user name
36				if ( '' === username ) {
37					$( error_class ).css( 'display', 'block' );
38					err_msg = '';
39					if ( 'string' === typeof cbm_validation_msg.error_label ) {
40						err_msg += cbm_validation_msg.error_label + ' ';
41					}
42					if ( 'string' === typeof cbm_validation_msg.empty_username ) {
43						err_msg += cbm_validation_msg.empty_username;
44					}
45					$( error_class_span ).html( err_msg );
46					_this.scrollToError();
47					return false;
48				}else if ( '' === password ) {
49					// Empty check for email
50					$( error_class ).css( 'display', 'block' );
51					err_msg = '';
52					if ( 'string' === typeof cbm_validation_msg.error_label ) {
53						err_msg += cbm_validation_msg.error_label + ' ';
54					}
55					if ( 'string' === typeof cbm_validation_msg.empty_password ) {
56						err_msg += cbm_validation_msg.empty_password;
57					}
58					$( error_class_span ).html( err_msg );
59					_this.scrollToError();
60					return false;
61				}
62				return true;
63			})
64		},
65
66		// Auto hide and show on yes and no radio button click
67		register_account: function() {
68			$( '#cbm_customer_id' ).hide();
69			$( '#cbm_description' ).hide();
70
71			$( '#cbm_registration_form input[name=cbm_account]' ).change(function( ) {
72				var value = $( 'input[name=cbm_account]:checked', '#cbm_registration_form' ).val();
73				if ( 'yes' === value ) {
74					$( '#cbm_customer_id' ).show();
75					$( '#cbm_description' ).hide();
76				}else {
77					$( '#cbm_customer_id' ).hide();
78					$( '#cbm_description' ).show();
79				}
80			});
81		},
82
83		//Scroll to top while error
84		scrollToError: function() {
85			var cbm_errors = $( '.cbm_errors' );
86			if ( cbm_errors.length > 0 ) {
87				var cbm_errors_offset = cbm_errors.offset();
88				$( 'html,body' ).animate( {
89					                          scrollTop: cbm_errors_offset.top
90				                          }, 'slow' );
91			}
92		},
93
94		// Function to subscribe product.
95		subscribe_product: function() {
96			var error_class = $( '.cbm_errors' );
97			var error_class_span = $( '.cbm_errors span.error' );
98			var _this = this;
99			
100			$( '#cbm-cancel-redirect-payment-method' ).click(function(){
101				$( '#cbm-user-payment-popup-container' ).hide();
102			});
103
104			$("[data-cb-btn='cbm_subscribe_product']").click(function(){
105				// Parameters for ajax call for subscription
106				var current_url = window.location.href;
107                                var refUrl = $(this).attr('data-cb-reference-url');            
108				var product_nonce = $(this).attr('data-cb-subscribe-product-nonce');                                
109                                if(!refUrl || !product_nonce){
110                                    refUrl = current_url;
111                                }
112				var params = {
113					product_id:   $(this).attr('data-cb-product-id'),
114                                        product_nonce:product_nonce,
115					reference_url:  refUrl
116				};
117				// Ajax request for subscription of product.
118				var request = wp.ajax.post( 'cbm_subscribe_product', params );
119
120				request.done( function( data ) {
121                                        console.log(data);
122					var hosted_page_url = '';
123					if ( 'undefined' != typeof data.payment_hosted_page_url && '' != data.payment_hosted_page_url ) {
124						$( '#cbm-user-payment-popup-container' ).show();
125						$( '#cbm-confirm-redirect-payment-method' ).click(function(){
126							hosted_page_url = data.payment_hosted_page_url;
127							var win = window.open( hosted_page_url, '_blank' );
128							win.focus();
129							$( '#cbm-user-payment-popup-container' ).hide();
130						});
131					} else if ( 'undefined' != typeof data.subscribe_product_url && '' != data.subscribe_product_url ) {
132						hosted_page_url = data.subscribe_product_url;
133						window.location.replace( hosted_page_url );
134					}
135				}, 'json' );
136
137				request.fail( function( data ) {
138                                        console.log(data);
139					var err_msg = '';
140					if ( 'string' === typeof cbm_validation_msg.error_label ) {
141						err_msg += cbm_validation_msg.error_label + ' ';
142					}
143
144					if( 'not_logged_in' === data.error ) {
145						window.location.href = data.url;
146					} else if( '' !== data.error ) {
147                                               if($( error_class ).length){
148                                                    $( error_class ).css( 'display', 'block' );
149                                                    $( error_class_span ).html( err_msg + data.error );
150                                                     _this.scrollToError();
151                                                 }else{//If the error div is not present.
152                                                     alert(data.error);
153                                                 }
154					}
155				} );
156			});
157		},
158
159		// Checkout product to proceed to payment for selected subscription.
160		checkout_product: function () {
161			var error_class = $( '.cbm_errors' );
162			var error_class_span = $( '.cbm_errors span.error' );
163			var _this = this;
164
165			$( '#cbm_subscribe_product_checkout' ).click(function(){
166
167				var params = {
168					product_id:     $('#cbm_product_id').val(),
169					product_nonce:  $('#cbm_checkout_product_nonce').val(),
170				};
171
172				var checkout = wp.ajax.post( 'cbm_checkout_product', params );
173				checkout.done( function ( data ) {
174					if ( 'undefined' != typeof data.redirect_page_url && '' != data.redirect_page_url ) {
175						window.location.href = data.redirect_page_url;
176					}
177				}, 'json');
178
179				checkout.fail( function ( data ) {
180					var err_msg = '';
181					var validation_msg = '';
182					if ( 'string' === typeof cbm_validation_msg.error_label ) {
183						err_msg += cbm_validation_msg.error_label + ' ';
184					}
185					if ( 'undefined' != typeof data.error && '' != data.error ) {
186						// Display error messages if any.
187						if ( 'duplicate_entry' === data.error ) {
188							if ( 'string' === typeof cbm_validation_msg.existing_subscription ) {
189								validation_msg = err_msg + cbm_validation_msg.existing_subscription;
190							}
191							$( error_class ).css( 'display', 'block' );
192							$( error_class_span ).html( validation_msg );
193							_this.scrollToError();
194						} else if ( 'resource_not_found' === data.error ) {
195							if ( 'string' === typeof cbm_validation_msg.not_exist_product ) {
196								validation_msg = err_msg + cbm_validation_msg.not_exist_product;
197							}
198							$( error_class ).css( 'display', 'block' );
199							$( error_class_span ).html( validation_msg );
200							_this.scrollToError();
201						} else if ( 'payment_processing_failed' === data.error ) {
202							if ( 'string' === typeof cbm_validation_msg.payment_failed ) {
203								validation_msg = err_msg + cbm_validation_msg.payment_failed;
204							}
205							$( error_class ).css( 'display', 'block' );
206							$( error_class_span ).html( validation_msg );
207							_this.scrollToError();
208						} else if ( 'not_logged_in' === data.error ) {
209							window.location.href = data.url;
210						} else if ( '' !== data.error ) {
211                                                        
212							$( error_class ).css( 'display', 'block' );
213							$( error_class_span ).html( err_msg + data.error );
214							_this.scrollToError();
215						}
216					}
217				});
218			});
219		},
220
221		// Checkout product to proceed to payment for selected subscription.
222		reactivate_product: function () {
223			var error_class = $( '.cbm_errors' );
224			var error_class_span = $( '.cbm_errors span.error' );
225			var _this = this;
226
227			$( '#cbm_product_reactivate_checkout' ).click(function(){
228
229				var params = {
230					product_id: $('#cbm_product_id').val(),
231					reactivate_nonce: $('#cbm_product_reactivate_nonce').val(),
232					subscription_id: $('#cbm_subscription_id').val(),
233				};
234
235				var reactivate_checkout = wp.ajax.post( 'cbm_reactivate_product', params );
236				reactivate_checkout.done( function ( data ) {
237					if ( 'undefined' != typeof data.redirect_page_url && '' != data.redirect_page_url ) {
238						window.location.href = data.redirect_page_url;
239					}
240				}, 'json');
241
242				reactivate_checkout.fail( function ( data ) {
243					var err_msg = '';
244					var validation_msg = '';
245					if ( 'string' === typeof cbm_validation_msg.error_label ) {
246						err_msg += cbm_validation_msg.error_label + ' ';
247					}
248					if ( 'undefined' != typeof data.error && '' != data.error ) {
249						// Display error messages if any.
250						if ( 'duplicate_entry' === data.error ) {
251							if ( 'string' === typeof cbm_validation_msg.existing_subscription ) {
252								validation_msg = err_msg + cbm_validation_msg.existing_subscription;
253							}
254							$( error_class ).css( 'display', 'block' );
255							$( error_class_span ).html( validation_msg );
256							_this.scrollToError();
257						} else if ( 'resource_not_found' === data.error ) {
258							if ( 'string' === typeof cbm_validation_msg.not_exist_product ) {
259								validation_msg = err_msg + cbm_validation_msg.not_exist_product;
260							}
261							$( error_class ).css( 'display', 'block' );
262							$( error_class_span ).html( validation_msg );
263							_this.scrollToError();
264						} else if ( 'payment_processing_failed' === data.error ) {
265							if ( 'string' === typeof cbm_validation_msg.payment_failed ) {
266								validation_msg = err_msg + cbm_validation_msg.payment_failed;
267							}
268							$( error_class ).css( 'display', 'block' );
269							$( error_class_span ).html( validation_msg );
270							_this.scrollToError();
271						} else if ( 'not_logged_in' === data.error ) {
272							window.location.href = data.url;
273						} else if ( '' !== data.error ) {
274							$( error_class ).css( 'display', 'block' );
275							$( error_class_span ).html( err_msg + data.error );
276							_this.scrollToError();
277						}
278					}
279				});
280			});
281		},
282
283		// Validation of registration form.
284		validate_registration_form : function() {
285			var _this = this;
286			$('#cbm_registration_form').on('submit', function( event ) {
287				event.preventDefault();
288				var error_class = $( '.cbm_errors' );
289				var error_class_span = $( '.cbm_errors span.error' );
290				$( error_class ).css( 'display', 'none' );
291
292				// Get values of fields into variables
293				var username = $( '#cbm_user_Login' ).val();
294				var email = $( '#cbm_user_email' ).val();
295				var fname = $( '#cbm_user_first' ).val();
296				var lname = $( '#cbm_user_last' ).val();
297				var pass1 = $( '#password' ).val();
298				var pass2 = $( '#password_again' ).val();
299				var err_msg = '';
300				var validation_msg = '';
301				if ( 'string' === typeof cbm_validation_msg.error_label ) {
302					err_msg += cbm_validation_msg.error_label + ' ';
303				}
304
305				if ( '' === username ) { // Empty error check for user name
306					if ( 'string' === typeof cbm_validation_msg.empty_username ) {
307						validation_msg = err_msg + cbm_validation_msg.empty_username;
308					}
309				} else if ( '' === email ) { // Empty check for email.
310					if ( 'string' === typeof cbm_validation_msg.empty_email ) {
311						validation_msg = err_msg + cbm_validation_msg.empty_email;
312					}
313				} else if ( '' === pass1 ) { // Empty check for password.
314					if ( 'string' === typeof cbm_validation_msg.empty_password ) {
315						validation_msg = err_msg + cbm_validation_msg.empty_password;
316					}
317				} else if ( '' === pass2 ) { // Empty check for repeat password.
318					if ( 'string' === typeof cbm_validation_msg.empty_confirm_password ) {
319						validation_msg = err_msg + cbm_validation_msg.empty_confirm_password;
320					}
321				} else if ( pass1 !== pass2 ) { // Compare both passwords.
322					if ( 'string' === typeof cbm_validation_msg.password_not_match ) {
323						validation_msg = err_msg + cbm_validation_msg.password_not_match;
324					}
325				}
326
327				if ( '' !== validation_msg ) {
328					$( error_class ).css( 'display', 'block' );
329					$( error_class_span ).html( validation_msg );
330					_this.scrollToError();
331					return false;
332				} else {
333					$( error_class ).css( 'display', 'none' );
334				}
335
336				// Parameters for ajax validation and registration of account
337				var params = {
338					cbm_user_Login: 		username,
339					cbm_register_nonce: 	$( '#cbm_registration_nonce' ).val(),
340					cbm_user_email: 		email,
341					cbm_user_first: 		fname,
342					cbm_user_last: 			lname,
343					cbm_user_pass: 			pass1,
344					cbm_user_pass_confirm: 	pass2
345				};
346
347				// Ajax request for errors and create account if no errors
348				var request = wp.ajax.post( 'cbm_validate_registration_data', params );
349
350				request.done( function( data ) {
351					// Redirect to url if account is created
352					window.location.href = data.url;
353
354				}, 'json' );
355
356				request.fail( function( data ) {
357					// Display errors from php validation
358					var html_error = '';
359
360					$.each( data.errors, function( key, value ) {
361						if ( '' != html_error ) {
362							html_error = html_error + '<br />';
363						}
364						html_error = html_error + '<strong>Error : </strong>' + value;
365					});
366
367					// Display all errors into block
368					if ( '' != html_error ) {
369						$( error_class ).css( 'display', 'block' );
370						$( error_class_span ).html( html_error );
371					}
372
373				} );
374
375				return false;
376			});
377		},
378
379		// Close notification dialog.
380		user_nofication_dialog : function () {
381			$( '.cbm-close-dialog' ).on( 'click', function () {
382				var _this = this;
383				var params = {
384					notifiy_id: $( _this ).data( 'notifiy-id' )
385				};
386
387				var delete_notification = wp.ajax.post( 'cbm_delete_notification', params );
388				delete_notification.done( function ( data ) {
389					var dialog = $( _this ).parent();
390					dialog.slideUp( 'slow', function () {
391						$( this ).remove();
392					} );
393				});
394			} );
395		}
396	};
397
398	$( document ).ready( function() {
399		Chargebee_Membership.init();
400	} );
401
402	$( window ).load( function() {
403		Chargebee_Membership.initLoad();
404	} );
405
406})( jQuery, window.wp );

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.