1/** 2 * Define global variables so that the core plugin and 3rd party plugins can use them 3 * 4 */ 5 6// Paid Member Subscription submit buttons 7var pms_payment_buttons; 8 9// Field wrappers 10var $pms_auto_renew_field; 11 12// Checked Subscription 13var $pms_checked_subscription; 14var $pms_checked_paygate; 15 16// Unavailable gateways message 17var $pms_gateways_not_available; 18 19// Text placeholder for the payment buttons while processing 20var pms_payment_button_loading_placeholder_text; 21 22/** 23 * Core plugin 24 * 25 */ 26jQuery( function($) { 27 28 if( window.history.replaceState ) { 29 30 currentURL = window.location.href; 31 32 currentURL = pms_remove_query_arg( 'pmsscscd', currentURL ); 33 currentURL = pms_remove_query_arg( 'pmsscsmsg', currentURL ); 34 currentURL = pms_remove_query_arg( 'pms_gateway_payment_action', currentURL ); 35 currentURL = pms_remove_query_arg( 'pms_gateway_payment_id', currentURL ); 36 37 window.history.replaceState( null, null, currentURL ); 38 } 39 40 41 /* 42 * Strips one query argument from a given URL string 43 * 44 */ 45 function pms_remove_query_arg( key, sourceURL ) { 46 47 var rtn = sourceURL.split("?")[0], 48 param, 49 params_arr = [], 50 queryString = (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : ""; 51 52 if (queryString !== "") { 53 params_arr = queryString.split("&"); 54 for (var i = params_arr.length - 1; i >= 0; i -= 1) { 55 param = params_arr[i].split("=")[0]; 56 if (param === key) { 57 params_arr.splice(i, 1); 58 } 59 } 60 61 rtn = rtn + "?" + params_arr.join("&"); 62 63 } 64 65 if(rtn.split("?")[1] == "") { 66 rtn = rtn.split("?")[0]; 67 } 68 69 return rtn; 70 } 71 72 // Paid Member Subscriptions submit buttons 73 pms_payment_buttons = 'input[name=pms_register], '; 74 pms_payment_buttons += 'input[name=pms_new_subscription], '; 75 pms_payment_buttons += 'input[name=pms_upgrade_subscription], '; 76 pms_payment_buttons += 'input[name=pms_renew_subscription], '; 77 pms_payment_buttons += 'input[name=pms_confirm_retry_payment_subscription], '; 78 79 // Profile Builder submit buttons 80 pms_payment_buttons += '.wppb-register-user input[name=register]'; 81 82 // Subscription pland ans payment gateway selectors 83 var subscription_plan_selector = 'input[name=subscription_plans]'; 84 var paygate_selector = 'input[name=pay_gate]'; 85 86 var settings_recurring = $('input[name="pms_default_recurring"]').val(); 87 88 // Field wrappers 89 $pms_auto_renew_field = jQuery( '.pms-subscription-plan-auto-renew' ); 90 91 // Checked Subscription 92 $pms_checked_subscription = jQuery( subscription_plan_selector + '[type=radio]' ).length > 0 ? jQuery( subscription_plan_selector + '[type=radio]:checked' ) : jQuery( subscription_plan_selector + '[type=hidden]' ); 93 $pms_checked_paygate = jQuery( paygate_selector + '[type=radio]' ).length > 0 ? jQuery( paygate_selector + '[type=radio]:checked' ) : jQuery( paygate_selector + '[type=hidden]' ); 94 95 // Unavailable gateways message 96 $pms_gateways_not_available = jQuery( '#pms-gateways-not-available' ); 97 98 pms_payment_button_loading_placeholder_text = $('#pms-submit-button-loading-placeholder-text').text(); 99 100 /* 101 * Hide "automatically renew subscription" checkbox for manual payment gateway 102 * 103 */ 104 jQuery(document).ready( function() { 105 106 /** 107 * Handle the auto renew checkbox field display in the page 108 * 109 */ 110 function handle_auto_renew_field_display() { 111 112 if( $pms_checked_subscription.data('recurring') == 1 && $pms_checked_paygate.data('recurring') != 'undefined' ) 113 $pms_auto_renew_field.show(); 114 else 115 $pms_auto_renew_field.hide(); 116 117 118 if( $pms_checked_subscription.data('recurring') == 0 ) { 119 120 if( settings_recurring == 1 ) 121 $pms_auto_renew_field.show(); 122 123 } 124 125 126 if( $pms_checked_subscription.data('recurring') == 2 || $pms_checked_subscription.data('recurring') == 3 ) { 127 $pms_auto_renew_field.hide(); 128 } 129 130 if ( $pms_checked_subscription.data('duration') == 0 || $pms_checked_subscription.data('price') == 0 ) { 131 $pms_auto_renew_field.hide(); 132 } 133 134 } 135 136 137 /** 138 * Handle the payment gateways radio buttons field display in the page 139 * 140 */ 141 function handle_payment_gateways_display() { 142 143 // Before anything we display all gateways 144 $('#pms-paygates-wrapper').show(); 145 $( paygate_selector ).removeAttr( 'disabled' ); 146 $( paygate_selector ).closest( 'label' ).show(); 147 148
149 // Support for "trial" 150 if( $pms_checked_subscription.data('trial') && $pms_checked_subscription.data('trial') != 0 ) { 151 152 $( paygate_selector + ':not([data-trial])' ).attr( 'disabled', true ); 153 $( paygate_selector + ':not([data-trial])' ).closest('label').hide(); 154 155 } 156 157 158 // Support for "sign_up_fee" 159 if( $pms_checked_subscription.data('sign_up_fee') && $pms_checked_subscription.data('sign_up_fee') != 0 ) { 160 161 $( paygate_selector + ':not([data-sign_up_fee])' ).attr( 'disabled', true ); 162 $( paygate_selector + ':not([data-sign_up_fee])' ).closest('label').hide(); 163 164 } 165 166 167 // Support for "recurring" 168 if( $pms_checked_subscription.data('recurring') == 2 ) { 169 170 $( paygate_selector + ':not([data-recurring])' ).attr( 'disabled', true ); 171 $( paygate_selector + ':not([data-recurring])' ).closest('label').hide(); 172 173 174 } else if( $pms_checked_subscription.data('recurring') == 1 ) { 175 176 if( $pms_auto_renew_field.find('input[type=checkbox]').is(':checked') ) { 177 $( paygate_selector + ':not([data-recurring])' ).attr( 'disabled', true ); 178 $( paygate_selector + ':not([data-recurring])' ).closest('label').hide(); 179 } 180 181 } else if( ! $pms_checked_subscription.data('recurring') ) { 182 183 if( settings_recurring == 1 ) { 184 if( $pms_auto_renew_field.find('input[type=checkbox]').is(':checked') ) { 185 $( paygate_selector + ':not([data-recurring])' ).attr( 'disabled', true ); 186 $( paygate_selector + ':not([data-recurring])' ).closest('label').hide(); 187 } 188 } else if( settings_recurring == 2 ) { 189 190 $( paygate_selector + ':not([data-recurring])' ).attr( 'disabled', true ); 191 $( paygate_selector + ':not([data-recurring])' ).closest('label').hide(); 192 193 } 194 195 } 196 197 198 // Select the first first available payment gateway by default after hiding the gateways 199 if( $( paygate_selector + ':not([disabled]):checked' ).length == 0 ) 200 $( paygate_selector + ':not([disabled])' ).first().trigger('click'); 201 202 203 204 if( $( paygate_selector ).length > 0 ) { 205 206 /** 207 * Handle case where no payment gateways are available 208 * 209 */ 210 if( $( paygate_selector + ':not([disabled])' ).length == 0 ) { 211 212 // Display the "no payment gateways are available" message 213 $pms_gateways_not_available.show(); 214 215 // Hide credit card fields 216 $('.pms-credit-card-information').hide(); 217 $('.pms-billing-details').hide(); 218 219 // Disable submit button 220 if( $pms_checked_subscription.data( 'price' ) != 0 ) { 221 222 if( $pms_checked_subscription.length != 0 ) 223 $( pms_payment_buttons ).attr( 'disabled', true ).addClass( 'pms-submit-disabled' ); 224 225 } 226 227 /** 228 * Handle case where payment gateways are available for selection 229 * 230 */ 231 } else { 232 233 // Hide the "no payment gateways are available" message 234 $pms_gateways_not_available.hide(); 235 236 // Show credit card fields if the selected payment gateway supports credit cards 237 if( $( paygate_selector + ':not([disabled]):checked[data-type="credit_card"]' ).length > 0 ) { 238 $('.pms-credit-card-information').show(); 239 $('.pms-billing-details').show(); 240 } 241 242 // Enable submit button 243 if( $pms_checked_subscription.length != 0 ) 244 $( pms_payment_buttons ).attr( 'disabled', false ).removeClass( 'pms-submit-disabled' ); 245 246 } 247 248 } 249 250 251 // Hide credit card fields if it's a free plan 252 if( $pms_checked_subscription.data( 'price' ) == 0 && ( typeof $pms_checked_subscription.data('sign_up_fee') == 'undefined' || $pms_checked_subscription.data('sign_up_fee') == 0 ) ) { 253 254 $('#pms-paygates-wrapper').hide(); 255 $( paygate_selector ).attr( 'disabled', true ); 256 $( paygate_selector ).closest( 'label' ).hide(); 257 258 $('.pms-credit-card-information').hide(); 259 $('.pms-billing-details').hide(); 260 261 } 262 263 } 264 265 266 /** 267 * Set checked payment gateway when clicking on a payment gateway radio 268 * 269 */ 270 jQuery( document ).on( 'click', paygate_selector, function() { 271 272 if( jQuery(this).is(':checked') ) 273 $pms_checked_paygate = jQuery(this); 274 275 // Show / hide the credit card details 276 if( $pms_checked_paygate.data('type') == 'credit_card' ) { 277 278 $('.pms-credit-card-information').show(); 279 $('.pms-billing-details').show(); 280 281 } else { 282 283 $('.pms-credit-card-information').hide(); 284 $('.pms-billing-details').hide(); 285 286 } 287 288 }); 289 290 291 /** 292 * Handle auto-renew checkbox and payment gateways display when clicking on a subscription plan 293 * 294 */ 295 jQuery( document ).on( 'click', subscription_plan_selector + '[type=radio]', function() { 296 297 if( jQuery(this).is(':checked') ) 298 $pms_checked_subscription = jQuery(this); 299 300 handle_auto_renew_field_display(); 301 handle_payment_gateways_display(); 302 303 }); 304 305 306 /** 307 * Disable the payment button when clicking on it so that only one request 308 * is sent to the server 309 * 310 */ 311 jQuery( document ).on( 'click', pms_payment_buttons, function(e) { 312 313 if( $(this).hasClass('pms-submit-disabled') ) 314 return false;
315 316 $(this).data( 'original-value', $(this).val() ); 317 318 // Replace the button text with the placeholder 319 if( pms_payment_button_loading_placeholder_text.length > 0 ) 320 $(this).addClass( 'pms-submit-disabled' ).val( pms_payment_button_loading_placeholder_text ); 321 322 }); 323 324 325 /** 326 * Trigger a click on the checked subscription plan when checking / unchecking the 327 * auto-renew checkbox as this also takes into account whether the auto-renew field 328 * is checked, thus hiding the unneeded payment gateways 329 * 330 */ 331 $pms_auto_renew_field.click( function() { 332 333 handle_auto_renew_field_display(); 334 handle_payment_gateways_display(); 335 336 }); 337 338 339 /** 340 * Trigger a click on the selected subscription plan so that 341 * the rest of the checkout interfacte changes 342 * 343 */ 344 handle_auto_renew_field_display(); 345 handle_payment_gateways_display(); 346 347 /** 348 * Show the paygates inner wrapper 349 * 350 */ 351 $( '#pms-paygates-inner' ).css( 'visibility', 'visible' ); 352 353 }); 354 355 356 /* 357 * Add field error for a given element name 358 * 359 */ 360 $.pms_add_field_error = function( error, field_name ) { 361 362 if( error == '' || error == 'undefined' || field_name == '' || field_name == 'undefined' ) 363 return false; 364 365 $field = $('[name=' + field_name + ']'); 366 $field_wrapper = $field.closest('.pms-field'); 367 368 error = '<p>' + error + '</p>'; 369 370 if( $field_wrapper.find('.pms_field-errors-wrapper').length > 0 ) 371 $field_wrapper.find('.pms_field-errors-wrapper').html( error ); 372 else 373 $field_wrapper.append('<div class="pms_field-errors-wrapper pms-is-js">' + error + '</div>'); 374 375 }; 376 377 /* 378 * Clear all field errors added with js 379 * 380 */ 381 $.pms_clean_field_errors = function() { 382 383 $('.pms_field-errors-wrapper.pms-is-js').remove(); 384 385 }; 386 387}); 388 389 390/* 391 * Profile Builder Compatibility 392 * 393 */ 394jQuery( function($) { 395 396 $(document).ready( function() { 397 398 // Handle on document ready 399 if ( $('.pms-subscription-plan input[type=radio][data-price="0"]').is(':checked') || $('.pms-subscription-plan input[type=hidden]').attr( 'data-price' ) == '0' ) { 400 $('.pms-email-confirmation-payment-message').hide(); 401 } 402 403 if( $('.pms-subscription-plan input[type=radio]').length > 0 ) { 404 405 var has_paid_subscription = false; 406 407 $('.pms-subscription-plan input[type=radio]').each( function() { 408 if( $(this).data('price') != 0 ) 409 has_paid_subscription = true; 410 }); 411 412 if( !has_paid_subscription ) 413 $('.pms-email-confirmation-payment-message').hide(); 414 415 } 416 417 // Handle clicking on the subscription plans 418 $('.pms-subscription-plan input[type=radio]').click(function(){ 419 420 if ($('.pms-subscription-plan input[type=radio][data-price="0"]').is(':checked')) { 421 $('.pms-email-confirmation-payment-message').hide(); 422 } 423 else { 424 $('.pms-email-confirmation-payment-message').show(); 425 } 426 }); 427 428 }); 429 430});
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.