diff --git a/CHANGES.md b/CHANGES.md index 21b85fb..b6b1e54 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,6 @@ +#### 1.2.4 (10/31/17) +* Fixed: Allow #hash in form redirect. + #### 1.2.3 (10/12/17) * Fixed: Align labels to the left, so Mai Pro sections with centered content won't center labels. diff --git a/includes/class-forms.php b/includes/class-forms.php index 73ba2ce..1df681c 100644 --- a/includes/class-forms.php +++ b/includes/class-forms.php @@ -84,7 +84,7 @@ function enqueue_scripts() { wp_enqueue_script( 'wampum-zxcvbn', WAMPUM_FORMS_PLUGIN_URL . 'js/zxcvbn.js', array('jquery'), '4.4.2', true ); } // All Forms - wp_enqueue_script( 'wampum-forms', WAMPUM_FORMS_PLUGIN_URL . 'js/wampum-forms.min.js', array('jquery'), WAMPUM_FORMS_VERSION, true ); + wp_enqueue_script( 'wampum-forms', WAMPUM_FORMS_PLUGIN_URL . 'js/wampum-forms.js', array('jquery'), WAMPUM_FORMS_VERSION, true ); wp_localize_script( 'wampum-forms', 'wampumFormVars', array( 'root' => esc_url_raw( rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ), diff --git a/js/wampum-forms.js b/js/wampum-forms.js index ed72857..94c16e4 100644 --- a/js/wampum-forms.js +++ b/js/wampum-forms.js @@ -1,669 +1,686 @@ ( function ( document, $, undefined ) { - 'use strict'; + 'use strict'; + + var $forms = $('.wampum-form'), + $strength = $('.password-strength-meter'); + + // Password match + $.each( $forms, function() { + + var $pwField = $(this).find('input[name="password"]'), + $pwConfirm = $(this).find('input[name="password_confirm"]'); + + // If we have password and password confirm fields + if ( ( $pwField.length && $pwConfirm.length ) > 0 ) { + // When typing in confirm field + $forms.on( 'keyup', $pwConfirm, function(e) { + + // Password fields values + var pw = $pwField.val(), + pwc = $pwConfirm.val(); + + // If both fields have a value + if ( '' != ( pw && pwc ) ) { + // If passwords match + if ( $pwField.val() == $pwConfirm.val() ) { + // Add green border to both fields if passwords match + $pwField.add($pwConfirm).css({'border-color':'#25f500'}); + } + // No match + else { + // Remove border + $pwField.add($pwConfirm).css({'border-color':''}); + } + } + }); + } + }); + + // If we have a strength meter + if ( $strength.length > 0 ) { + + // Show password strength meter when focusing on password field + $forms.on( 'focus', 'input[name="password"]', function(e) { + $(this).closest('form').find('.password-strength').slideDown('fast'); + }); + + // Password strength meter + $forms.on( 'keyup', 'input[name="password"]', function(e) { + + var $form = $(this).closest('form'); + + var strength = { + 0: "Weak", + 1: "Weak", + 2: "Okay", + 3: "Good", + 4: "Great", + } + + var $meter = $form.find('.password-strength-meter'); + var $text = $form.find('.password-strength-text'); + + var val = $(this).val(); + var result = zxcvbn(val); + + // Update the password strength meter + $meter.attr('data-strength', result.score); + + // Update the text indicator + if ( val !== "" ) { + $text.html(strength[result.score]); + } else { + $text.html(""); + } + + }); + + } + + // Login form submit + $forms.on( 'submit', 'form[data-form="login"]', function(e) { + + console.log('Login form submitted'); + + e.preventDefault(); + + // Set the form as a variable + var $loginForm = $(this), + $button = $loginForm.find( 'button[name="submit"]' ); + + // Get the button text/value so we can add it back later + var buttonHTML = $button.html(); + + // Show the form as processing + $loginForm.addClass('processing'); + + // Disable the $button + $button.prop( 'disabled', true ); + + // Set the $button text/value to loading icons + $button.html( getLoadingHTML() ); + + // Hide any notices + hideNotices( $loginForm ); + + // Setup our form data array + var data = { + user_login: $loginForm.find( 'input[name="username"]' ).val(), + user_password: $loginForm.find( 'input[name="password"]' ).val(), + remember: $loginForm.find( 'input[name="rememberme"]' ).val(), + notifications: $loginForm.find( 'input[name="notifications"]' ).val(), + say_what: $loginForm.find( 'input[name ="say_what"]' ).val(), // honeypot + }; + + $.ajax({ + method: 'POST', + url: wampumFormVars.root + 'wampum/v1/login/', + data: data, + beforeSend: function ( xhr ) { + xhr.setRequestHeader( 'X-WP-Nonce', wampumFormVars.nonce ); + }, + success: function( response ) { + if ( true == response.success ) { + // Display success message + displayNotice( $loginForm, 'success', 'Success!' ); + + // Get redirect URL + var redirect = $loginForm.find( 'input[name="redirect"]' ).val(); + if ( '' != redirect ) { + // If login form is part of a membership flow + if ( 'membership_form' == redirect ) { + // Refresh the page + window.location.reload(); + } else { + doRedirect( redirect ); + } + } + } else { + // Display error message + displayNotice( $loginForm, 'error', response.message ); + } + }, + fail: function( response ) { + // Not sure when this would happen, but fallbacks! + displayNotice( $loginForm, 'error', response.failure ); + } + }).done( function( response ) { + // Remove form processing CSS + $loginForm.removeClass('processing'); + // Re-enable the button + $button.html(buttonHTML).prop( 'disabled', false ); + }); - var $forms = $('.wampum-form'), - $strength = $('.password-strength-meter'); + }); + + // Password form submit + $forms.on( 'submit', 'form[data-form="password"]', function(e) { - // Password match - $.each( $forms, function() { + console.log('Password form submitted'); + + e.preventDefault(); - var $pwField = $(this).find('input[name="password"]'), - $pwConfirm = $(this).find('input[name="password_confirm"]'); + // Set the form as a variable + var $passwordForm = $(this), + $button = $passwordForm.find( 'button[name="submit"]' ); + + // Get the button text/value so we can add it back later + var buttonHTML = $button.html(); + + // Show the form as processing + $passwordForm.addClass('processing'); + + // Disable the $button + $button.prop( 'disabled', true ); + + // Set the $button text/value to loading icons + $button.html( getLoadingHTML() ); + + // Hide any notices + hideNotices( $passwordForm ); + + // Setup our form data array + var data = { + password: $passwordForm.find( 'input[name="password"]' ).val(), + password_confirm: $passwordForm.find( 'input[name="password_confirm"]' ).val(), + notifications: $passwordForm.find( 'input[name="notifications"]' ).val(), + say_what: $passwordForm.find( 'input[name="say_what"]' ).val(), // honeypot + }; + + $.ajax({ + method: 'POST', + url: wampumFormVars.root + 'wampum/v1/password/', + data: data, + beforeSend: function ( xhr ) { + xhr.setRequestHeader( 'X-WP-Nonce', wampumFormVars.nonce ); + }, + success: function( response ) { + + if ( true == response.success ) { + + // Display success notice. + displayNotice( $passwordForm, 'success', 'Success!' ); + + // Get redirect URL. + var redirect = $passwordForm.find( 'input[name="redirect"]' ).val(); + + /** + * Force refresh/redirect. + * Trying to submit password form again was giving 403 forbidden, not worth dealing with. + */ + doRedirect( redirect ); + } else { + // Clear the password strength value + $passwordForm.find('.password-strength-meter').attr('data-strength', ''); + // Clear the password strength text + $passwordForm.find('.password-strength-text').html(''); + // Display error message + displayNotice( $passwordForm, 'error', response.message ); + } + + }, + fail: function( response ) { + // Not sure when this would happen, but fallbacks! + displayNotice( $passwordForm, 'error', wampumFormVars.failure ); + } + }).done( function( response ) { + // Remove form processing CSS + $passwordForm.removeClass('processing'); + // Re-enable the button + $button.html(buttonHTML).prop( 'disabled', false ); + }); + + }); - // If we have password and password confirm fields - if ( ( $pwField.length && $pwConfirm.length ) > 0 ) { - // When typing in confirm field - $forms.on( 'keyup', $pwConfirm, function(e) { - - // Password fields values - var pw = $pwField.val(), - pwc = $pwConfirm.val(); - - // If both fields have a value - if ( '' != ( pw && pwc ) ) { - // If passwords match - if ( $pwField.val() == $pwConfirm.val() ) { - // Add green border to both fields if passwords match - $pwField.add($pwConfirm).css({'border-color':'#25f500'}); - } - // No match - else { - // Remove border - $pwField.add($pwConfirm).css({'border-color':''}); - } - } - }); - } - }); - - // If we have a strength meter - if ( $strength.length > 0 ) { - - // Show password strength meter when focusing on password field - $forms.on( 'focus', 'input[name="password"]', function(e) { - $(this).closest('form').find('.password-strength').slideDown('fast'); - }); - - // Password strength meter - $forms.on( 'keyup', 'input[name="password"]', function(e) { - - var $form = $(this).closest('form'); - - var strength = { - 0: "Weak", - 1: "Weak", - 2: "Okay", - 3: "Good", - 4: "Great", - } - - var $meter = $form.find('.password-strength-meter'); - var $text = $form.find('.password-strength-text'); - - var val = $(this).val(); - var result = zxcvbn(val); - - // Update the password strength meter - $meter.attr('data-strength', result.score); - - // Update the text indicator - if ( val !== "" ) { - $text.html(strength[result.score]); - } else { - $text.html(""); - } - - }); - - } - - // Login form submit - $forms.on( 'submit', 'form[data-form="login"]', function(e) { - - console.log('Login form submitted'); - - e.preventDefault(); - - // Set the form as a variable - var $loginForm = $(this), - $button = $loginForm.find( 'button[name="submit"]' ); - - // Get the button text/value so we can add it back later - var buttonHTML = $button.html(); - - // Show the form as processing - $loginForm.addClass('processing'); - - // Disable the $button - $button.prop( 'disabled', true ); - - // Set the $button text/value to loading icons - $button.html( getLoadingHTML() ); - - // Hide any notices - hideNotices( $loginForm ); - - // Setup our form data array - var data = { - user_login: $loginForm.find( 'input[name="username"]' ).val(), - user_password: $loginForm.find( 'input[name="password"]' ).val(), - remember: $loginForm.find( 'input[name="rememberme"]' ).val(), - notifications: $loginForm.find( 'input[name="notifications"]' ).val(), - say_what: $loginForm.find( 'input[name="say_what"]' ).val(), // honeypot - }; - - $.ajax({ - method: 'POST', - url: wampumFormVars.root + 'wampum/v1/login/', - data: data, - beforeSend: function ( xhr ) { - xhr.setRequestHeader( 'X-WP-Nonce', wampumFormVars.nonce ); - }, - success: function( response ) { - if ( true == response.success ) { - // Display success message - displayNotice( $loginForm, 'success', 'Success!' ); - - // Get redirect URL - var redirect = $loginForm.find( 'input[name="redirect"]' ).val(); - if ( '' != redirect ) { - // If login form is part of a membership flow - if ( 'membership_form' == redirect ) { - // Refresh the page - window.location.reload(); - } else { - // Redirect - window.location.replace( redirect ); - } - } - } else { - // Display error message - displayNotice( $loginForm, 'error', response.message ); - } - }, - fail: function( response ) { - // Not sure when this would happen, but fallbacks! - displayNotice( $loginForm, 'error', response.failure ); - } - }).done( function( response ) { - // Remove form processing CSS - $loginForm.removeClass('processing'); - // Re-enable the button - $button.html(buttonHTML).prop( 'disabled', false ); - }); - - }); - - // Password form submit - $forms.on( 'submit', 'form[data-form="password"]', function(e) { - - console.log('Password form submitted'); - - e.preventDefault(); - - // Set the form as a variable - var $passwordForm = $(this), - $button = $passwordForm.find( 'button[name="submit"]' ); - - // Get the button text/value so we can add it back later - var buttonHTML = $button.html(); - - // Show the form as processing - $passwordForm.addClass('processing'); - - // Disable the $button - $button.prop( 'disabled', true ); - - // Set the $button text/value to loading icons - $button.html( getLoadingHTML() ); - - // Hide any notices - hideNotices( $passwordForm ); - - // Setup our form data array - var data = { - password: $passwordForm.find( 'input[name="password"]' ).val(), - password_confirm: $passwordForm.find( 'input[name="password_confirm"]' ).val(), - notifications: $passwordForm.find( 'input[name="notifications"]' ).val(), - say_what: $passwordForm.find( 'input[name="say_what"]' ).val(), // honeypot - }; - - $.ajax({ - method: 'POST', - url: wampumFormVars.root + 'wampum/v1/password/', - data: data, - beforeSend: function ( xhr ) { - xhr.setRequestHeader( 'X-WP-Nonce', wampumFormVars.nonce ); - }, - success: function( response ) { - - if ( true == response.success ) { - - // Display success notice - displayNotice( $passwordForm, 'success', 'Success!' ); - - // Get redirect URL - var redirect = $passwordForm.find( 'input[name="redirect"]' ).val(); - - // Force refresh/redirect - // trying to submit password form again was giving 403 forbidden, not worth dealing with) - window.location.replace( redirect ); - } else { - // Clear the password strength value - $passwordForm.find('.password-strength-meter').attr('data-strength', ''); - // Clear the password strength text - $passwordForm.find('.password-strength-text').html(''); - // Display error message - displayNotice( $passwordForm, 'error', response.message ); - } - - }, - fail: function( response ) { - // Not sure when this would happen, but fallbacks! - displayNotice( $passwordForm, 'error', wampumFormVars.failure ); - } - }).done( function( response ) { - // Remove form processing CSS - $passwordForm.removeClass('processing'); - // Re-enable the button - $button.html(buttonHTML).prop( 'disabled', false ); - }); - - }); - - // Register form submit - $forms.on( 'submit', 'form[data-form="register"]', function(e) { - - console.log('Register form submitted'); - - e.preventDefault(); - - // Set the form as a variable - var $registerForm = $(this), - $button = $registerForm.find( 'button[name="submit"]' ); - - // Get the button text/value so we can add it back later - var buttonHTML = $button.html(); - - // Disable the $button - $button.prop( 'disabled', true ); - - // Set the $button text/value to loading icons - $button.html( getLoadingHTML() ); - - // Hide any notices - hideNotices( $registerForm ); - - // Setup our form data array - var data = { - email: $registerForm.find( 'input[name="email"]' ).val(), - username: $registerForm.find( 'input[name="username"]' ).val(), - first_name: $registerForm.find( 'input[name="first_name"]' ).val(), - last_name: $registerForm.find( 'input[name="last_name"]' ).val(), - password: $registerForm.find( 'input[name="password"]' ).val(), - password_confirm: $registerForm.find( 'input[name="password_confirm"]' ).val(), - log_in: $registerForm.find( 'input[name="log_in"]' ).val(), - ac_list_ids: $registerForm.find( 'input[name="ac_list_ids"]' ).val(), - ac_tags: $registerForm.find( 'input[name="ac_tags"]' ).val(), - notifications: $registerForm.find( 'input[name="notifications"]' ).val(), - say_what: $registerForm.find( 'input[name="say_what"]' ).val(), // honeypot - }; - - $.ajax({ - method: 'POST', - url: wampumFormVars.root + 'wampum/v1/register/', - data: data, - beforeSend: function ( xhr ) { - xhr.setRequestHeader( 'X-WP-Nonce', wampumFormVars.nonce ); - }, - success: function( response ) { - if ( true == response.success ) { - // Display success message - displayNotice( $registerForm, 'success', 'Success!' ); - - // Only redirect if we have a value - var redirect = $registerForm.find( 'input[name="redirect"]' ).val(); - // if ( '' != redirect ) { - // Force refresh/redirect because we may be logged in - window.location.replace( redirect ); - // } - } else { - // Display error message - displayNotice( $registerForm, 'error', response.message ); - } - }, - fail: function( response ) { - // Not sure when this would happen, but fallbacks! - displayNotice( $registerForm, 'error', response.failure ); - } - }).done( function( response ) { - // Remove form processing CSS - $registerForm.removeClass('processing'); - // Re-enable the button - $button.html(buttonHTML).prop( 'disabled', false ); - }); - - }); - - // Subscribe form submit - $forms.on( 'submit', 'form[data-form="subscribe"]', function(e) { - - console.log('Subscribe form submitted'); - - e.preventDefault(); - - // Set the form as a variable - var $subscribeForm = $(this), - $button = $subscribeForm.find( 'button[name="submit"]' ); - - // Get the button text/value so we can add it back later - var buttonHTML = $button.html(); - - // Disable the $button - $button.prop( 'disabled', true ); - - // Set the $button text/value to loading icons - $button.html( getLoadingHTML() ); - - // Hide any notices - hideNotices( $subscribeForm ); - - // Setup our form data array - var data = { - email: $subscribeForm.find( 'input[name="email"]' ).val(), - first_name: $subscribeForm.find( 'input[name="first_name"]' ).val(), - last_name: $subscribeForm.find( 'input[name="last_name"]' ).val(), - ac_list_ids: $subscribeForm.find( 'input[name="ac_list_ids"]' ).val(), - ac_tags: $subscribeForm.find( 'input[name="ac_tags"]' ).val(), - notifications: $subscribeForm.find( 'input[name="notifications"]' ).val(), - say_what: $subscribeForm.find( 'input[name="say_what"]' ).val(), // honeypot - }; - - $.ajax({ - method: 'POST', - url: wampumFormVars.root + 'wampum/v1/subscribe/', - data: data, - beforeSend: function ( xhr ) { - xhr.setRequestHeader( 'X-WP-Nonce', wampumFormVars.nonce ); - }, - success: function( response ) { - if ( true == response.success ) { - // Display success message - displayNotice( $subscribeForm, 'success', 'Success!' ); - - // Only redirect if we have a value - var redirect = $subscribeForm.find( 'input[name="redirect"]' ).val(); - // if ( '' != redirect ) { - // Force refresh/redirect because we may be logged in - window.location.replace( redirect ); - // } - } else { - // Display error message - displayNotice( $subscribeForm, 'error', response.message ); - } - }, - fail: function( response ) { - // Not sure when this would happen, but fallbacks! - displayNotice( $subscribeForm, 'error', response.failure ); - } - }).done( function( response ) { - // Remove form processing CSS - $subscribeForm.removeClass('processing'); - // Re-enable the button - $button.html(buttonHTML).prop( 'disabled', false ); - }); - - }); + // Register form submit + $forms.on( 'submit', 'form[data-form="register"]', function(e) { + + console.log('Register form submitted'); + + e.preventDefault(); + + // Set the form as a variable + var $registerForm = $(this), + $button = $registerForm.find( 'button[name="submit"]' ); + + // Get the button text/value so we can add it back later + var buttonHTML = $button.html(); + + // Disable the $button + $button.prop( 'disabled', true ); + + // Set the $button text/value to loading icons + $button.html( getLoadingHTML() ); + + // Hide any notices + hideNotices( $registerForm ); + + // Setup our form data array + var data = { + email: $registerForm.find( 'input[name="email"]' ).val(), + username: $registerForm.find( 'input[name="username"]' ).val(), + first_name: $registerForm.find( 'input[name="first_name"]' ).val(), + last_name: $registerForm.find( 'input[name="last_name"]' ).val(), + password: $registerForm.find( 'input[name="password"]' ).val(), + password_confirm: $registerForm.find( 'input[name="password_confirm"]' ).val(), + log_in: $registerForm.find( 'input[name="log_in"]' ).val(), + ac_list_ids: $registerForm.find( 'input[name="ac_list_ids"]' ).val(), + ac_tags: $registerForm.find( 'input[name="ac_tags"]' ).val(), + notifications: $registerForm.find( 'input[name="notifications"]' ).val(), + say_what: $registerForm.find( 'input[name="say_what"]' ).val(), // honeypot + }; + + $.ajax({ + method: 'POST', + url: wampumFormVars.root + 'wampum/v1/register/', + data: data, + beforeSend: function ( xhr ) { + xhr.setRequestHeader( 'X-WP-Nonce', wampumFormVars.nonce ); + }, + success: function( response ) { + if ( true == response.success ) { + // Display success message + displayNotice( $registerForm, 'success', 'Success!' ); + + // Only redirect if we have a value + var redirect = $registerForm.find( 'input[name="redirect"]' ).val(); + // Force refresh/redirect because we may be logged in + doRedirect( redirect ); + } else { + // Display error message + displayNotice( $registerForm, 'error', response.message ); + } + }, + fail: function( response ) { + // Not sure when this would happen, but fallbacks! + displayNotice( $registerForm, 'error', response.failure ); + } + }).done( function( response ) { + // Remove form processing CSS + $registerForm.removeClass('processing'); + // Re-enable the button + $button.html(buttonHTML).prop( 'disabled', false ); + }); + + }); + + // Subscribe form submit + $forms.on( 'submit', 'form[data-form="subscribe"]', function(e) { + + console.log('Subscribe form submitted'); + + e.preventDefault(); + + // Set the form as a variable + var $subscribeForm = $(this), + $button = $subscribeForm.find( 'button[name="submit"]' ); + + // Get the button text/value so we can add it back later + var buttonHTML = $button.html(); + + // Disable the $button + $button.prop( 'disabled', true ); + + // Set the $button text/value to loading icons + $button.html( getLoadingHTML() ); + + // Hide any notices + hideNotices( $subscribeForm ); + + // Setup our form data array + var data = { + email: $subscribeForm.find( 'input[name="email"]' ).val(), + first_name: $subscribeForm.find( 'input[name="first_name"]' ).val(), + last_name: $subscribeForm.find( 'input[name="last_name"]' ).val(), + ac_list_ids: $subscribeForm.find( 'input[name="ac_list_ids"]' ).val(), + ac_tags: $subscribeForm.find( 'input[name="ac_tags"]' ).val(), + notifications: $subscribeForm.find( 'input[name="notifications"]' ).val(), + say_what: $subscribeForm.find( 'input[name="say_what"]' ).val(), // honeypot + }; + + $.ajax({ + method: 'POST', + url: wampumFormVars.root + 'wampum/v1/subscribe/', + data: data, + beforeSend: function ( xhr ) { + xhr.setRequestHeader( 'X-WP-Nonce', wampumFormVars.nonce ); + }, + success: function( response ) { + if ( true == response.success ) { + // Display success message + displayNotice( $subscribeForm, 'success', 'Success!' ); + + // Only redirect if we have a value + var redirect = $subscribeForm.find( 'input[name="redirect"]' ).val(); + // Force refresh/redirect because we may be logged in + doRedirect( redirect ); + } else { + // Display error message + displayNotice( $subscribeForm, 'error', response.message ); + } + }, + fail: function( response ) { + // Not sure when this would happen, but fallbacks! + displayNotice( $subscribeForm, 'error', response.failure ); + } + }).done( function( response ) { + // Remove form processing CSS + $subscribeForm.removeClass('processing'); + // Re-enable the button + $button.html(buttonHTML).prop( 'disabled', false ); + }); + + }); // Membership verify submit - $forms.on( 'submit', 'form[data-form="user-available"]', function(e) { + $forms.on( 'submit', 'form[data-form="user-available"]', function(e) { - console.log( 'User available form submitted' ); + console.log( 'User available form submitted' ); e.preventDefault(); - // Set the form as a variable - var $userAvailableForm = $(this), - $button = $userAvailableForm.find( 'button[name="submit"]' ); + // Set the form as a variable + var $userAvailableForm = $(this), + $button = $userAvailableForm.find( 'button[name="submit"]' ); - // Show the form as processing - $userAvailableForm.addClass('processing'); + // Show the form as processing + $userAvailableForm.addClass('processing'); - // Get the button text/value so we can add it back later on text/value so we can add it back later - var buttonHTML = $button.html(); + // Get the button text/value so we can add it back later on text/value so we can add it back later + var buttonHTML = $button.html(); - // Disable the button - $button.prop( 'disabled', true ); + // Disable the button + $button.prop( 'disabled', true ); - // Set the button text/value to loading icons - $button.html( getLoadingHTML() ); + // Set the button text/value to loading icons + $button.html( getLoadingHTML() ); - // Hide any notices + // Hide any notices hideNotices($userAvailableForm); - // Setup our form data array - var data = { - email: $userAvailableForm.find( 'input[name="email"]' ).val(), - username: $userAvailableForm.find( 'input[name="username"]' ).val(), - say_what: $userAvailableForm.find( 'input[name="say_what"]' ).val(), - current_url: wampumFormVars.current_url, - }; - - // SharpSpring data, incase we need it later - // var SharpSpringBaseURI = $userAvailableForm.find( '.wampum_ss_baseuri' ).val(); - // var SharpSpringEndpoint = $userAvailableForm.find( '.wampum_ss_endpoint' ).val(); - // var urlParams = $userAvailableForm.serialize(); - - // If we have SharpSpring data, add the main __ss_noform code right after the form - // if ( SharpSpringBaseURI && SharpSpringEndpoint ) { - // // This fixes the error missing __ss_noform push - // $userAvailableForm.after( '' ); - // } - - $.ajax({ - method: 'POST', - url: wampumFormVars.root + 'wampum/v1/user-available/', - data: data, - beforeSend: function ( xhr ) { - xhr.setRequestHeader( 'X-WP-Nonce', wampumFormVars.nonce ); - }, - success: function( response ) { - - if ( true == response.success ) { - - // If this is a SharpSpring form, send that data! - // if ( SharpSpringBaseURI && SharpSpringEndpoint ) { - // // https://demodia.com/discovering-demand/how-to-create-multiple-forms-in-sharpspring - // $.ajax({ - // url: SharpSpringBaseURI + SharpSpringEndpoint + '/jsonp/?' + urlParams, - // contentType: "application/json", - // dataType: 'jsonp', - // success: function( response ) { - // console.log('Data successfully sent to SharpSpring.'); - // } - // }); - // } - - var $membershipForm = $userAvailableForm.siblings( 'form[data-form="join-membership"]' ); - - // Pass values and make fields read only - $membershipForm.find( 'input[name="first_name"]' ).val( $userAvailableForm.find( 'input[name="first_name"]' ).val() ).prop( 'readonly', true ); - $membershipForm.find( 'input[name="last_name"]' ).val( $userAvailableForm.find( 'input[name="last_name"]' ).val() ).prop( 'readonly', true ); - $membershipForm.find( 'input[name="email"]' ).val( $userAvailableForm.find( 'input[name="email"]' ).val() ).prop( 'readonly', true ); - $membershipForm.find( 'input[name="username"]' ).val( $userAvailableForm.find( 'input[name="username"]' ).val() ).prop( 'readonly', true ); - - // Hide already filled out fields - $membershipForm.find( '.first-name' ).hide(); - $membershipForm.find( '.last-name' ).hide(); - $membershipForm.find( '.email' ).hide(); - $membershipForm.find( '.username' ).hide(); - - // Add description to next form - displayNotice( $membershipForm, 'success', 'Almost there! This is the last step.' ); - - // Swap forms - $userAvailableForm.fadeOut( 300, function() { - $membershipForm.fadeIn( 600 ); - // Focus on password field (should be the only one left?) - $membershipForm.find( 'input[name="password"]' ).focus(); - }); - - } else { - - // Display error message - displayNotice( $userAvailableForm, 'error', response.message ); + // Setup our form data array + var data = { + email: $userAvailableForm.find( 'input[name="email"]' ).val(), + username: $userAvailableForm.find( 'input[name="username"]' ).val(), + say_what: $userAvailableForm.find( 'input[name="say_what"]' ).val(), + current_url: wampumFormVars.current_url, + }; + + // SharpSpring data, incase we need it later + // var SharpSpringBaseURI = $userAvailableForm.find( '.wampum_ss_baseuri' ).val(); + // var SharpSpringEndpoint = $userAvailableForm.find( '.wampum_ss_endpoint' ).val(); + // var urlParams = $userAvailableForm.serialize(); + + // If we have SharpSpring data, add the main __ss_noform code right after the form + // if ( SharpSpringBaseURI && SharpSpringEndpoint ) { + // // This fixes the error missing __ss_noform push + // $userAvailableForm.after( '' ); + // } + + $.ajax({ + method: 'POST', + url: wampumFormVars.root + 'wampum/v1/user-available/', + data: data, + beforeSend: function ( xhr ) { + xhr.setRequestHeader( 'X-WP-Nonce', wampumFormVars.nonce ); + }, + success: function( response ) { + + if ( true == response.success ) { + + // // If this is a SharpSpring form, send that data! + // if ( SharpSpringBaseURI && SharpSpringEndpoint ) { + // // https://demodia.com/discovering-demand/how-to-create-multiple-forms-in-sharpspring + // $.ajax({ + // url: SharpSpringBaseURI + SharpSpringEndpoint + '/jsonp/?' + urlParams, + // contentType: "application/json", + // dataType: 'jsonp', + // success: function( response ) { + // console.log('Data successfully sent to SharpSpring.'); + // } + // }); + // } + + var $membershipForm = $userAvailableForm.siblings( 'form[data-form="join-membership"]' ); + + // Pass values and make fields read only + $membershipForm.find( 'input[name="first_name"]' ).val( $userAvailableForm.find( 'input[name="first_name"]' ).val() ).prop( 'readonly', true ); + $membershipForm.find( 'input[name="last_name"]' ).val( $userAvailableForm.find( 'input[name="last_name"]' ).val() ).prop( 'readonly', true ); + $membershipForm.find( 'input[name="email"]' ).val( $userAvailableForm.find( 'input[name="email"]' ).val() ).prop( 'readonly', true ); + $membershipForm.find( 'input[name="username"]' ).val( $userAvailableForm.find( 'input[name="username"]' ).val() ).prop( 'readonly', true ); + + // Hide already filled out fields + $membershipForm.find( '.first-name' ).hide(); + $membershipForm.find( '.last-name' ).hide(); + $membershipForm.find( '.email' ).hide(); + $membershipForm.find( '.username' ).hide(); + + // Add description to next form + displayNotice( $membershipForm, 'success', 'Almost there! This is the last step.' ); + + // Swap forms + $userAvailableForm.fadeOut( 300, function() { + $membershipForm.fadeIn( 600 ); + // Focus on password field (should be the only one left?) + $membershipForm.find( 'input[name="password"]' ).focus(); + }); + + } else { + + // Display error message + displayNotice( $userAvailableForm, 'error', response.message ); // Show login form if clicking the "Log in?" link - $userAvailableForm.on( 'click', '.login-link', function(e) { - e.preventDefault(); - // Do the login stuff + $userAvailableForm.on( 'click', '.login-link', function(e) { + e.preventDefault(); + // Do the login stuff setTimeout(function() { - swapLoginForm( $userAvailableForm ); + swapLoginForm( $userAvailableForm ); }, 300 ); - }); - - } - - }, - fail: function( response ) { - // Not sure when this would happen, but fallbacks! - displayNotice( $userAvailableForm, 'error', wampumFormVars.failure ); - } - }).done( function( response ) { - // Remove form processing CSS - $userAvailableForm.removeClass('processing'); - // Re-enable the butto + }); + + } + + }, + fail: function( response ) { + // Not sure when this would happen, but fallbacks! + displayNotice( $userAvailableForm, 'error', wampumFormVars.failure ); + } + }).done( function( response ) { + // Remove form processing CSS + $userAvailableForm.removeClass('processing'); + // Re-enable the butto $button.html( buttonHTML ).attr( 'disabled', false ); - }); + }); }); // Membership add submit - $forms.on( 'submit', 'form[data-form="join-membership"]', function(e) { + $forms.on( 'submit', 'form[data-form="join-membership"]', function(e) { - console.log('Membership form submitted'); + console.log('Membership form submitted'); - e.preventDefault(); + e.preventDefault(); - // Set the form as a variable - var $membershipForm = $(this), - $button = $membershipForm.find( 'button[name="submit"]' ); + // Set the form as a variable + var $membershipForm = $(this), + $button = $membershipForm.find( 'button[name="submit"]' ); - // Show the form as processing - $membershipForm.addClass('processing'); + // Show the form as processing + $membershipForm.addClass('processing'); - // Get the button text/value so we can add it back later on text/value so we can add it back later - var buttonHTML = $button.html(); + // Get the button text/value so we can add it back later on text/value so we can add it back later + var buttonHTML = $button.html(); - // Disable the button - $button.prop( 'disabled', true ); + // Disable the button + $button.prop( 'disabled', true ); - // Set the button text/value to loading icons - $button.html( getLoadingHTML() ); + // Set the button text/value to loading icons + $button.html( getLoadingHTML() ); - // Hide any notices + // Hide any notices hideNotices( $membershipForm ); - // Setup our form data array - var data = { - plan_id: $membershipForm.find( 'input[name="plan_id"]' ).val(), - email: $membershipForm.find( 'input[name="email"]' ).val(), - first_name: $membershipForm.find( 'input[name="first_name"]' ).val(), - last_name: $membershipForm.find( 'input[name="last_name"]' ).val(), - username: $membershipForm.find( 'input[name="username"]' ).val(), - password: $membershipForm.find( 'input[name="password"]' ).val(), - log_in: $membershipForm.find( 'input[name="log_in"]' ).val(), - notifications: $membershipForm.find( 'input[name="notifications"]').val(), - ac_list_ids: $membershipForm.find( 'input[name="ac_list_ids"]' ).val(), - ac_tags: $membershipForm.find( 'input[name="ac_tags"]' ).val(), - notifications: $membershipForm.find( 'input[name="notifications"]' ).val(), - say_what: $membershipForm.find( 'input[name="say_what"]' ).val(), // honeypot - current_url: wampumFormVars.current_url, - }; - - // SharpSpring data, incase we need it later - // var SharpSpringBaseURI = $membershipForm.find( '.wampum_ss_baseuri' ).val(); - // var SharpSpringEndpoint = $membershipForm.find( '.wampum_ss_endpoint' ).val(); - // // var urlParams = $membershipForm.serialize(); - // var urlParams = $('input[type!=password]', $membershipForm).serialize(); - - // // If we have SharpSpring data, add the main __ss_noform code right after the form - // if ( SharpSpringBaseURI && SharpSpringEndpoint ) { - // // This fixes the error missing __ss_noform push - // $membershipForm.after( '' ); - // } - - $.ajax({ - method: 'POST', - url: wampumFormVars.root + 'wampum/v1/membership-add/', - data: data, - beforeSend: function ( xhr ) { - xhr.setRequestHeader( 'X-WP-Nonce', wampumFormVars.nonce ); - }, - success: function( response ) { - - if ( true == response.success ) { - - // If this is a SharpSpring form, send that data! - // if ( SharpSpringBaseURI && SharpSpringEndpoint ) { - // // https://demodia.com/discovering-demand/how-to-create-multiple-forms-in-sharpspring - // $.ajax({ - // url: SharpSpringBaseURI + SharpSpringEndpoint + '/jsonp/?' + urlParams, - // contentType: "application/json", - // dataType: 'jsonp', - // success: function( response ) { - // console.log('Data successfully sent to SharpSpring.'); - // } - // }); - // } - - // Display success message - displayNotice( $membershipForm, 'success', 'Success!' ); - - // Get the redirect value - var redirect = $membershipForm.find( 'input[name="redirect"]' ).val(); - - // Only redirect if we have a value - if ( '' != redirect ) { + // Setup our form data array + var data = { + plan_id: $membershipForm.find( 'input[name="plan_id"]' ).val(), + email: $membershipForm.find( 'input[name="email"]' ).val(), + first_name: $membershipForm.find( 'input[name="first_name"]' ).val(), + last_name: $membershipForm.find( 'input[name="last_name"]' ).val(), + username: $membershipForm.find( 'input[name="username"]' ).val(), + password: $membershipForm.find( 'input[name="password"]' ).val(), + log_in: $membershipForm.find( 'input[name="log_in"]' ).val(), + notifications: $membershipForm.find( 'input[name="notifications"]').val(), + ac_list_ids: $membershipForm.find( 'input[name="ac_list_ids"]' ).val(), + ac_tags: $membershipForm.find( 'input[name="ac_tags"]' ).val(), + notifications: $membershipForm.find( 'input[name="notifications"]' ).val(), + say_what: $membershipForm.find( 'input[name="say_what"]' ).val(), // honeypot + current_url: wampumFormVars.current_url, + }; + + // SharpSpring data, incase we need it later + // var SharpSpringBaseURI = $membershipForm.find( '.wampum_ss_baseuri' ).val(); + // var SharpSpringEndpoint = $membershipForm.find( '.wampum_ss_endpoint' ).val(); + // // var urlParams = $membershipForm.serialize(); + // var urlParams = $('input[type!=password]', $membershipForm).serialize(); + + // // If we have SharpSpring data, add the main __ss_noform code right after the form + // if ( SharpSpringBaseURI && SharpSpringEndpoint ) { + // // This fixes the error missing __ss_noform push + // $membershipForm.after( '' ); + // } + + $.ajax({ + method: 'POST', + url: wampumFormVars.root + 'wampum/v1/membership-add/', + data: data, + beforeSend: function ( xhr ) { + xhr.setRequestHeader( 'X-WP-Nonce', wampumFormVars.nonce ); + }, + success: function( response ) { + + if ( true == response.success ) { + + // If this is a SharpSpring form, send that data! + // if ( SharpSpringBaseURI && SharpSpringEndpoint ) { + // // https://demodia.com/discovering-demand/how-to-create-multiple-forms-in-sharpspring + // $.ajax({ + // url: SharpSpringBaseURI + SharpSpringEndpoint + '/jsonp/?' + urlParams, + // contentType: "application/json", + // dataType: 'jsonp', + // success: function( response ) { + // console.log('Data successfully sent to SharpSpring.'); + // } + // }); + // } + + // Display success message + displayNotice( $membershipForm, 'success', 'Success!' ); + + // Get the redirect value + var redirect = $membershipForm.find( 'input[name="redirect"]' ).val(); + + // Only redirect if we have a value + if ( '' != redirect ) { setTimeout(function() { - // Refresh/redirect - window.location.replace( redirect ); + // Refresh/redirect + doRedirect( redirect ); }, 300 ); - } else { + } else { setTimeout(function() { // Fade the form out - $membershipForm.fadeOut('fast'); + $membershipForm.fadeOut('fast'); }, 300 ); - } + } - } else { + } else { - // Display error message + // Display error message displayNotice( $membershipForm, 'error', response.message ); // Show login form if clicking the "Log in?" link - $membershipForm.on( 'click', '.login-link', function(e) { - e.preventDefault(); - // Do the login stuff + $membershipForm.on( 'click', '.login-link', function(e) { + e.preventDefault(); + // Do the login stuff setTimeout(function() { - swapLoginForm($userAvailableForm); + swapLoginForm($userAvailableForm); }, 300 ); - }); - - } - }, - fail: function( response ) { - // Not sure when this would happen, but fallbacks! - displayNotice( $membershipForm, 'error', wampumFormVars.failure ); - } - }).done( function( response ) { - // Remove form processing CSS - $membershipForm.removeClass('processing'); - // Re-enable the button - $button.html(buttonHTML).prop( 'disabled', false ); - }); - - }); - - // Swap a form for it's neighboring login form + }); + + } + }, + fail: function( response ) { + // Not sure when this would happen, but fallbacks! + displayNotice( $membershipForm, 'error', wampumFormVars.failure ); + } + }).done( function( response ) { + // Remove form processing CSS + $membershipForm.removeClass('processing'); + // Re-enable the button + $button.html(buttonHTML).prop( 'disabled', false ); + }); + + }); + + // Swap a form for it's neighboring login form function swapLoginForm( $form ) { - hideNotices($form); + hideNotices($form); - var $loginForm = $form.siblings('form[data-form="login"]'); + var $loginForm = $form.siblings('form[data-form="login"]'); - /** - * Swap forms - */ - $form.fadeOut( 300, function() { - $loginForm.fadeIn( 600 ); - }); + /** + * Swap forms + */ + $form.fadeOut( 300, function() { + $loginForm.fadeIn( 600 ); + }); - // Set submitted email value as the login field - $loginForm.find('input[name="username"]').val( $form.find('input[name="email"]').val() ); - $loginForm.find('input[name="password"]').focus(); + // Set submitted email value as the login field + $loginForm.find('input[name="username"]').val( $form.find('input[name="email"]').val() ); + $loginForm.find('input[name="password"]').focus(); - // If user goes to login, back to membership, then to login, we'd have duplicate back buttons - $loginForm.find('.wampum-back').remove(); + // If user goes to login, back to membership, then to login, we'd have duplicate back buttons + $loginForm.find('.wampum-back').remove(); - // Add back button - $loginForm.find('button[name="submit"]').after('  Go back'); + // Add back button + $loginForm.find('button[name="submit"]').after('  Go back'); // On click of the back button $loginForm.on( 'click', '.wampum-back', function(e) { e.preventDefault(); - // Swap forms - $loginForm.fadeOut( 300, function() { - $form.fadeIn( 600 ); - }); + // Swap forms + $loginForm.fadeOut( 300, function() { + $form.fadeIn( 600 ); + }); - // Clear the password field - $loginForm.find('input[name="password"]').val(''); + // Clear the password field + $loginForm.find('input[name="password"]').val(''); }); } + function doRedirect( redirect ) { + // If the redirct has a hash. + var hash = redirect.substring( redirect.indexOf('#') ); + if ( hash ) { + // Get the current URL without has/params. + var current_url = [location.protocol, '//', location.host, location.pathname].join(''); + // Make sure we're not redirecting to the same URL. + if ( current_url == getPathFromUrl( redirect ) ) { + window.location.href += "#" + hash; + location.reload(); + } + } + // Redirect + window.location.replace( redirect ); + } + + function getPathFromUrl( url ) { + return url.split(/[?#]/)[0]; + } + /** * Display a notice in the form * @@ -679,8 +696,8 @@ function hideNotices( form ) { form.find('.wampum-notice').slideUp('fast' , function(){ - $(this).removeClass('success error'); - }); + $(this).removeClass('success error'); + }); } function getLoadingHTML() { diff --git a/js/wampum-forms.min.js b/js/wampum-forms.min.js index 9b5f45d..7008e43 100644 --- a/js/wampum-forms.min.js +++ b/js/wampum-forms.min.js @@ -1 +1 @@ -!function(a,n,e){"use strict";function i(a){t(a);var n=a.siblings('form[data-form="login"]');a.fadeOut(300,function(){n.fadeIn(600)}),n.find('input[name="username"]').val(a.find('input[name="email"]').val()),n.find('input[name="password"]').focus(),n.find(".wampum-back").remove(),n.find('button[name="submit"]').after('  Go back'),n.on("click",".wampum-back",function(e){e.preventDefault(),n.fadeOut(300,function(){a.fadeIn(600)}),n.find('input[name="password"]').val("")})}function s(a,n,e){a.find(".wampum-notice").removeClass("success error").addClass(n).html(e).fadeIn("fast")}function t(a){a.find(".wampum-notice").slideUp("fast",function(){n(this).removeClass("success error")})}function o(){return''}var r=n(".wampum-form"),m=n(".password-strength-meter");n.each(r,function(){var a=n(this).find('input[name="password"]'),e=n(this).find('input[name="password_confirm"]');(a.length&&e.length)>0&&r.on("keyup",e,function(n){var i=a.val(),s=e.val();""!=(i&&s)&&(a.val()==e.val()?a.add(e).css({"border-color":"#25f500"}):a.add(e).css({"border-color":""}))})}),m.length>0&&(r.on("focus",'input[name="password"]',function(a){n(this).closest("form").find(".password-strength").slideDown("fast")}),r.on("keyup",'input[name="password"]',function(a){var e=n(this).closest("form"),i={0:"Weak",1:"Weak",2:"Okay",3:"Good",4:"Great"},s=e.find(".password-strength-meter"),t=e.find(".password-strength-text"),o=n(this).val(),r=zxcvbn(o);s.attr("data-strength",r.score),""!==o?t.html(i[r.score]):t.html("")})),r.on("submit",'form[data-form="login"]',function(a){console.log("Login form submitted"),a.preventDefault();var e=n(this),i=e.find('button[name="submit"]'),r=i.html();e.addClass("processing"),i.prop("disabled",!0),i.html(o()),t(e);var m={user_login:e.find('input[name="username"]').val(),user_password:e.find('input[name="password"]').val(),remember:e.find('input[name="rememberme"]').val(),notifications:e.find('input[name="notifications"]').val(),say_what:e.find('input[name="say_what"]').val()};n.ajax({method:"POST",url:wampumFormVars.root+"wampum/v1/login/",data:m,beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",wampumFormVars.nonce)},success:function(a){if(1==a.success){s(e,"success","Success!");var n=e.find('input[name="redirect"]').val();""!=n&&("membership_form"==n?window.location.reload():window.location.replace(n))}else s(e,"error",a.message)},fail:function(a){s(e,"error",a.failure)}}).done(function(a){e.removeClass("processing"),i.html(r).prop("disabled",!1)})}),r.on("submit",'form[data-form="password"]',function(a){console.log("Password form submitted"),a.preventDefault();var e=n(this),i=e.find('button[name="submit"]'),r=i.html();e.addClass("processing"),i.prop("disabled",!0),i.html(o()),t(e);var m={password:e.find('input[name="password"]').val(),password_confirm:e.find('input[name="password_confirm"]').val(),notifications:e.find('input[name="notifications"]').val(),say_what:e.find('input[name="say_what"]').val()};n.ajax({method:"POST",url:wampumFormVars.root+"wampum/v1/password/",data:m,beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",wampumFormVars.nonce)},success:function(a){if(1==a.success){s(e,"success","Success!");var n=e.find('input[name="redirect"]').val();window.location.replace(n)}else e.find(".password-strength-meter").attr("data-strength",""),e.find(".password-strength-text").html(""),s(e,"error",a.message)},fail:function(a){s(e,"error",wampumFormVars.failure)}}).done(function(a){e.removeClass("processing"),i.html(r).prop("disabled",!1)})}),r.on("submit",'form[data-form="register"]',function(a){console.log("Register form submitted"),a.preventDefault();var e=n(this),i=e.find('button[name="submit"]'),r=i.html();i.prop("disabled",!0),i.html(o()),t(e);var m={email:e.find('input[name="email"]').val(),username:e.find('input[name="username"]').val(),first_name:e.find('input[name="first_name"]').val(),last_name:e.find('input[name="last_name"]').val(),password:e.find('input[name="password"]').val(),password_confirm:e.find('input[name="password_confirm"]').val(),log_in:e.find('input[name="log_in"]').val(),ac_list_ids:e.find('input[name="ac_list_ids"]').val(),ac_tags:e.find('input[name="ac_tags"]').val(),notifications:e.find('input[name="notifications"]').val(),say_what:e.find('input[name="say_what"]').val()};n.ajax({method:"POST",url:wampumFormVars.root+"wampum/v1/register/",data:m,beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",wampumFormVars.nonce)},success:function(a){if(1==a.success){s(e,"success","Success!");var n=e.find('input[name="redirect"]').val();window.location.replace(n)}else s(e,"error",a.message)},fail:function(a){s(e,"error",a.failure)}}).done(function(a){e.removeClass("processing"),i.html(r).prop("disabled",!1)})}),r.on("submit",'form[data-form="subscribe"]',function(a){console.log("Subscribe form submitted"),a.preventDefault();var e=n(this),i=e.find('button[name="submit"]'),r=i.html();i.prop("disabled",!0),i.html(o()),t(e);var m={email:e.find('input[name="email"]').val(),first_name:e.find('input[name="first_name"]').val(),last_name:e.find('input[name="last_name"]').val(),ac_list_ids:e.find('input[name="ac_list_ids"]').val(),ac_tags:e.find('input[name="ac_tags"]').val(),notifications:e.find('input[name="notifications"]').val(),say_what:e.find('input[name="say_what"]').val()};n.ajax({method:"POST",url:wampumFormVars.root+"wampum/v1/subscribe/",data:m,beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",wampumFormVars.nonce)},success:function(a){if(1==a.success){s(e,"success","Success!");var n=e.find('input[name="redirect"]').val();window.location.replace(n)}else s(e,"error",a.message)},fail:function(a){s(e,"error",a.failure)}}).done(function(a){e.removeClass("processing"),i.html(r).prop("disabled",!1)})}),r.on("submit",'form[data-form="user-available"]',function(a){console.log("User available form submitted"),a.preventDefault();var e=n(this),r=e.find('button[name="submit"]');e.addClass("processing");var m=r.html();r.prop("disabled",!0),r.html(o()),t(e);var u={email:e.find('input[name="email"]').val(),username:e.find('input[name="username"]').val(),say_what:e.find('input[name="say_what"]').val(),current_url:wampumFormVars.current_url};n.ajax({method:"POST",url:wampumFormVars.root+"wampum/v1/user-available/",data:u,beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",wampumFormVars.nonce)},success:function(a){if(1==a.success){var n=e.siblings('form[data-form="join-membership"]');n.find('input[name="first_name"]').val(e.find('input[name="first_name"]').val()).prop("readonly",!0),n.find('input[name="last_name"]').val(e.find('input[name="last_name"]').val()).prop("readonly",!0),n.find('input[name="email"]').val(e.find('input[name="email"]').val()).prop("readonly",!0),n.find('input[name="username"]').val(e.find('input[name="username"]').val()).prop("readonly",!0),n.find(".first-name").hide(),n.find(".last-name").hide(),n.find(".email").hide(),n.find(".username").hide(),s(n,"success","Almost there! This is the last step."),e.fadeOut(300,function(){n.fadeIn(600),n.find('input[name="password"]').focus()})}else s(e,"error",a.message),e.on("click",".login-link",function(a){a.preventDefault(),setTimeout(function(){i(e)},300)})},fail:function(a){s(e,"error",wampumFormVars.failure)}}).done(function(a){e.removeClass("processing"),r.html(m).attr("disabled",!1)})}),r.on("submit",'form[data-form="join-membership"]',function(a){console.log("Membership form submitted"),a.preventDefault();var e=n(this),r=e.find('button[name="submit"]');e.addClass("processing");var m=r.html();r.prop("disabled",!0),r.html(o()),t(e);var u={plan_id:e.find('input[name="plan_id"]').val(),email:e.find('input[name="email"]').val(),first_name:e.find('input[name="first_name"]').val(),last_name:e.find('input[name="last_name"]').val(),username:e.find('input[name="username"]').val(),password:e.find('input[name="password"]').val(),log_in:e.find('input[name="log_in"]').val(),notifications:e.find('input[name="notifications"]').val(),ac_list_ids:e.find('input[name="ac_list_ids"]').val(),ac_tags:e.find('input[name="ac_tags"]').val(),notifications:e.find('input[name="notifications"]').val(),say_what:e.find('input[name="say_what"]').val(),current_url:wampumFormVars.current_url};n.ajax({method:"POST",url:wampumFormVars.root+"wampum/v1/membership-add/",data:u,beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",wampumFormVars.nonce)},success:function(a){if(1==a.success){s(e,"success","Success!");var n=e.find('input[name="redirect"]').val();""!=n?setTimeout(function(){window.location.replace(n)},300):setTimeout(function(){e.fadeOut("fast")},300)}else s(e,"error",a.message),e.on("click",".login-link",function(a){a.preventDefault(),setTimeout(function(){i($userAvailableForm)},300)})},fail:function(a){s(e,"error",wampumFormVars.failure)}}).done(function(a){e.removeClass("processing"),r.html(m).prop("disabled",!1)})})}(document,jQuery); \ No newline at end of file +!function(a,n,s){"use strict";function e(a){o(a);var n=a.siblings('form[data-form="login"]');a.fadeOut(300,function(){n.fadeIn(600)}),n.find('input[name="username"]').val(a.find('input[name="email"]').val()),n.find('input[name="password"]').focus(),n.find(".wampum-back").remove(),n.find('button[name="submit"]').after('  Go back'),n.on("click",".wampum-back",function(s){s.preventDefault(),n.fadeOut(300,function(){a.fadeIn(600)}),n.find('input[name="password"]').val("")})}function i(a){var n=a.substring(a.indexOf("#"));n&&[location.protocol,"//",location.host,location.pathname].join("")==t(a)&&(window.location.href+="#"+n,location.reload()),window.location.replace(a)}function t(a){return a.split(/[?#]/)[0]}function m(a,n,s){a.find(".wampum-notice").removeClass("success error").addClass(n).html(s).fadeIn("fast")}function o(a){a.find(".wampum-notice").slideUp("fast",function(){n(this).removeClass("success error")})}var r=n(".wampum-form"),l=n(".password-strength-meter");n.each(r,function(){var a=n(this).find('input[name="password"]'),s=n(this).find('input[name="password_confirm"]');(a.length&&s.length)>0&&r.on("keyup",s,function(n){var e=a.val(),i=s.val();""!=(e&&i)&&(a.val()==s.val()?a.add(s).css({"border-color":"#25f500"}):a.add(s).css({"border-color":""}))})}),l.length>0&&(r.on("focus",'input[name="password"]',function(a){n(this).closest("form").find(".password-strength").slideDown("fast")}),r.on("keyup",'input[name="password"]',function(a){var s=n(this).closest("form"),e={0:"Weak",1:"Weak",2:"Okay",3:"Good",4:"Great"},i=s.find(".password-strength-meter"),t=s.find(".password-strength-text"),m=n(this).val(),o=zxcvbn(m);i.attr("data-strength",o.score),""!==m?t.html(e[o.score]):t.html("")})),r.on("submit",'form[data-form="login"]',function(a){console.log("Login form submitted"),a.preventDefault();var s=n(this),e=s.find('button[name="submit"]'),t=e.html();s.addClass("processing"),e.prop("disabled",!0),e.html(''),o(s);var r={user_login:s.find('input[name="username"]').val(),user_password:s.find('input[name="password"]').val(),remember:s.find('input[name="rememberme"]').val(),notifications:s.find('input[name="notifications"]').val(),say_what:s.find('input[name ="say_what"]').val()};n.ajax({method:"POST",url:wampumFormVars.root+"wampum/v1/login/",data:r,beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",wampumFormVars.nonce)},success:function(a){if(1==a.success){m(s,"success","Success!");var n=s.find('input[name="redirect"]').val();""!=n&&("membership_form"==n?window.location.reload():i(n))}else m(s,"error",a.message)},fail:function(a){m(s,"error",a.failure)}}).done(function(a){s.removeClass("processing"),e.html(t).prop("disabled",!1)})}),r.on("submit",'form[data-form="password"]',function(a){console.log("Password form submitted"),a.preventDefault();var s=n(this),e=s.find('button[name="submit"]'),t=e.html();s.addClass("processing"),e.prop("disabled",!0),e.html(''),o(s);var r={password:s.find('input[name="password"]').val(),password_confirm:s.find('input[name="password_confirm"]').val(),notifications:s.find('input[name="notifications"]').val(),say_what:s.find('input[name="say_what"]').val()};n.ajax({method:"POST",url:wampumFormVars.root+"wampum/v1/password/",data:r,beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",wampumFormVars.nonce)},success:function(a){1==a.success?(m(s,"success","Success!"),i(s.find('input[name="redirect"]').val())):(s.find(".password-strength-meter").attr("data-strength",""),s.find(".password-strength-text").html(""),m(s,"error",a.message))},fail:function(a){m(s,"error",wampumFormVars.failure)}}).done(function(a){s.removeClass("processing"),e.html(t).prop("disabled",!1)})}),r.on("submit",'form[data-form="register"]',function(a){console.log("Register form submitted"),a.preventDefault();var s=n(this),e=s.find('button[name="submit"]'),t=e.html();e.prop("disabled",!0),e.html(''),o(s);var r={email:s.find('input[name="email"]').val(),username:s.find('input[name="username"]').val(),first_name:s.find('input[name="first_name"]').val(),last_name:s.find('input[name="last_name"]').val(),password:s.find('input[name="password"]').val(),password_confirm:s.find('input[name="password_confirm"]').val(),log_in:s.find('input[name="log_in"]').val(),ac_list_ids:s.find('input[name="ac_list_ids"]').val(),ac_tags:s.find('input[name="ac_tags"]').val(),notifications:s.find('input[name="notifications"]').val(),say_what:s.find('input[name="say_what"]').val()};n.ajax({method:"POST",url:wampumFormVars.root+"wampum/v1/register/",data:r,beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",wampumFormVars.nonce)},success:function(a){1==a.success?(m(s,"success","Success!"),i(s.find('input[name="redirect"]').val())):m(s,"error",a.message)},fail:function(a){m(s,"error",a.failure)}}).done(function(a){s.removeClass("processing"),e.html(t).prop("disabled",!1)})}),r.on("submit",'form[data-form="subscribe"]',function(a){console.log("Subscribe form submitted"),a.preventDefault();var s=n(this),e=s.find('button[name="submit"]'),t=e.html();e.prop("disabled",!0),e.html(''),o(s);var r={email:s.find('input[name="email"]').val(),first_name:s.find('input[name="first_name"]').val(),last_name:s.find('input[name="last_name"]').val(),ac_list_ids:s.find('input[name="ac_list_ids"]').val(),ac_tags:s.find('input[name="ac_tags"]').val(),notifications:s.find('input[name="notifications"]').val(),say_what:s.find('input[name="say_what"]').val()};n.ajax({method:"POST",url:wampumFormVars.root+"wampum/v1/subscribe/",data:r,beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",wampumFormVars.nonce)},success:function(a){1==a.success?(m(s,"success","Success!"),i(s.find('input[name="redirect"]').val())):m(s,"error",a.message)},fail:function(a){m(s,"error",a.failure)}}).done(function(a){s.removeClass("processing"),e.html(t).prop("disabled",!1)})}),r.on("submit",'form[data-form="user-available"]',function(a){console.log("User available form submitted"),a.preventDefault();var s=n(this),i=s.find('button[name="submit"]');s.addClass("processing");var t=i.html();i.prop("disabled",!0),i.html(''),o(s);var r={email:s.find('input[name="email"]').val(),username:s.find('input[name="username"]').val(),say_what:s.find('input[name="say_what"]').val(),current_url:wampumFormVars.current_url};n.ajax({method:"POST",url:wampumFormVars.root+"wampum/v1/user-available/",data:r,beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",wampumFormVars.nonce)},success:function(a){if(1==a.success){var n=s.siblings('form[data-form="join-membership"]');n.find('input[name="first_name"]').val(s.find('input[name="first_name"]').val()).prop("readonly",!0),n.find('input[name="last_name"]').val(s.find('input[name="last_name"]').val()).prop("readonly",!0),n.find('input[name="email"]').val(s.find('input[name="email"]').val()).prop("readonly",!0),n.find('input[name="username"]').val(s.find('input[name="username"]').val()).prop("readonly",!0),n.find(".first-name").hide(),n.find(".last-name").hide(),n.find(".email").hide(),n.find(".username").hide(),m(n,"success","Almost there! This is the last step."),s.fadeOut(300,function(){n.fadeIn(600),n.find('input[name="password"]').focus()})}else m(s,"error",a.message),s.on("click",".login-link",function(a){a.preventDefault(),setTimeout(function(){e(s)},300)})},fail:function(a){m(s,"error",wampumFormVars.failure)}}).done(function(a){s.removeClass("processing"),i.html(t).attr("disabled",!1)})}),r.on("submit",'form[data-form="join-membership"]',function(a){console.log("Membership form submitted"),a.preventDefault();var s=n(this),t=s.find('button[name="submit"]');s.addClass("processing");var r=t.html();t.prop("disabled",!0),t.html(''),o(s);var l={plan_id:s.find('input[name="plan_id"]').val(),email:s.find('input[name="email"]').val(),first_name:s.find('input[name="first_name"]').val(),last_name:s.find('input[name="last_name"]').val(),username:s.find('input[name="username"]').val(),password:s.find('input[name="password"]').val(),log_in:s.find('input[name="log_in"]').val(),notifications:s.find('input[name="notifications"]').val(),ac_list_ids:s.find('input[name="ac_list_ids"]').val(),ac_tags:s.find('input[name="ac_tags"]').val(),notifications:s.find('input[name="notifications"]').val(),say_what:s.find('input[name="say_what"]').val(),current_url:wampumFormVars.current_url};n.ajax({method:"POST",url:wampumFormVars.root+"wampum/v1/membership-add/",data:l,beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",wampumFormVars.nonce)},success:function(a){if(1==a.success){m(s,"success","Success!");var n=s.find('input[name="redirect"]').val();""!=n?setTimeout(function(){i(n)},300):setTimeout(function(){s.fadeOut("fast")},300)}else m(s,"error",a.message),s.on("click",".login-link",function(a){a.preventDefault(),setTimeout(function(){e($userAvailableForm)},300)})},fail:function(a){m(s,"error",wampumFormVars.failure)}}).done(function(a){s.removeClass("processing"),t.html(r).prop("disabled",!1)})})}(document,jQuery); \ No newline at end of file diff --git a/wampum-forms.php b/wampum-forms.php index 46f9f40..df29b40 100755 --- a/wampum-forms.php +++ b/wampum-forms.php @@ -16,7 +16,7 @@ * License: GPL-2.0+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt * - * Version: 1.2.3 + * Version: 1.2.4 * * GitHub Plugin URI: https://github.com/bizbudding/wampum-forms * GitHub Branch: master @@ -121,7 +121,7 @@ public function __wakeup() { private function setup_constants() { // Plugin version. if ( ! defined( 'WAMPUM_FORMS_VERSION' ) ) { - define( 'WAMPUM_FORMS_VERSION', '1.2.3' ); + define( 'WAMPUM_FORMS_VERSION', '1.2.4' ); } // Plugin Folder Path. if ( ! defined( 'WAMPUM_FORMS_PLUGIN_DIR' ) ) {