Created assets/js/frontend/password-strength-meter.js #9319
This commit is contained in:
parent
332a0d52ad
commit
eedff144e7
|
@ -490,50 +490,4 @@ jQuery( function( $ ) {
|
|||
wc_checkout_form.init();
|
||||
wc_checkout_coupons.init();
|
||||
wc_checkout_login_form.init();
|
||||
|
||||
// Password strength message container.
|
||||
$( ".woocommerce-billing-fields .create-account .clear" ).after( '<div id="pass-strength-result" aria-live="polite"></div>');
|
||||
|
||||
// Function for check password strength for checkout page
|
||||
function checkPasswordStrengthChekout( s, a, r ) {
|
||||
var t = jQuery( '#account_password' ).val();
|
||||
a.removeClass( 'short bad good strong' ),
|
||||
r = r.concat( wp.passwordStrength.userInputBlacklist() );
|
||||
var e = wp.passwordStrength.meter( t, r );
|
||||
|
||||
switch ( e ) {
|
||||
case 2:
|
||||
a.addClass( 'bad' ).html( pwsL10n.bad );
|
||||
break;
|
||||
case 3:
|
||||
a.addClass( 'good' ).html( pwsL10n.good );
|
||||
break;
|
||||
case 4:
|
||||
a.addClass( 'strong' ).html( pwsL10n.strong );
|
||||
break;
|
||||
case 5:
|
||||
a.addClass( 'short' ).html( pwsL10n.mismatch );
|
||||
break;
|
||||
default:
|
||||
a.addClass( 'short' ).html( pwsL10n.short );
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
$( '#account_password' ).keyup(function() {
|
||||
checkPasswordStrengthChekout(
|
||||
$( 'input[name=account_password]' ), // First password field
|
||||
$( '#pass-strength-result' ), // Strength meter
|
||||
[ 'black', 'listed', 'word' ] // Blacklisted words
|
||||
);
|
||||
|
||||
var passLength = jQuery( '#account_password' ).val().length;
|
||||
|
||||
if ( passLength<= 0 ) {
|
||||
$( '#pass-strength-result' ).css( 'display','none' );
|
||||
}else {
|
||||
$( '#pass-strength-result' ).css( 'display','block' );
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,89 @@
|
|||
/* global wp, pwsL10n */
|
||||
jQuery( function( $ ) {
|
||||
|
||||
/**
|
||||
* Password Strength Meter class
|
||||
*/
|
||||
var wc_password_strength_meter = {
|
||||
|
||||
/**
|
||||
* Initialize strength meter actions
|
||||
*/
|
||||
init: function() {
|
||||
$( document.body ).on( 'keyup', 'form.register #reg_password, form.checkout #account_password', this.strengthMeter );
|
||||
},
|
||||
|
||||
/**
|
||||
* Strength Meter
|
||||
*/
|
||||
strengthMeter: function() {
|
||||
var wrapper = $( 'form.register, form.checkout' ),
|
||||
submit = $( 'input[type="submit"]', wrapper ),
|
||||
field = $( '#reg_password, #account_password', wrapper ),
|
||||
strength = 1;
|
||||
|
||||
wc_password_strength_meter.includeMeter( wrapper, field );
|
||||
|
||||
strength = wc_password_strength_meter.checkPasswordStrength( field );
|
||||
|
||||
if ( 3 === strength || 4 === strength ) {
|
||||
submit.removeAttr( 'disabled' );
|
||||
} else {
|
||||
submit.attr( 'disabled', 'disabled' );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Include meter HTML
|
||||
*
|
||||
* @param {Object} wrapper
|
||||
* @param {Object} field
|
||||
*/
|
||||
includeMeter: function( wrapper, field ) {
|
||||
var meter = wrapper.find( '#pass-strength-result' );
|
||||
|
||||
if ( 0 === meter.length ) {
|
||||
field.after( '<div id="pass-strength-result" aria-live="polite">CARALHo!</div>' );
|
||||
} else if ( '' === field.val() ) {
|
||||
meter.remove();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Check password strength
|
||||
*
|
||||
* @param {Object} field
|
||||
*
|
||||
* @return {Int}
|
||||
*/
|
||||
checkPasswordStrength: function( field ) {
|
||||
var meter = $( '#pass-strength-result' );
|
||||
var strength = wp.passwordStrength.meter( field.val(), wp.passwordStrength.userInputBlacklist() );
|
||||
|
||||
// Reset classes
|
||||
meter.removeClass( 'short bad good strong' );
|
||||
|
||||
switch ( strength ) {
|
||||
case 2 :
|
||||
meter.addClass( 'bad' ).html( pwsL10n.bad );
|
||||
break;
|
||||
case 3 :
|
||||
meter.addClass( 'good' ).html( pwsL10n.good );
|
||||
break;
|
||||
case 4 :
|
||||
meter.addClass( 'strong' ).html( pwsL10n.strong );
|
||||
break;
|
||||
case 5 :
|
||||
meter.addClass( 'short' ).html( pwsL10n.mismatch );
|
||||
break;
|
||||
|
||||
default :
|
||||
meter.addClass( 'short' ).html( pwsL10n['short'] );
|
||||
}
|
||||
|
||||
return strength;
|
||||
}
|
||||
};
|
||||
|
||||
wc_password_strength_meter.init();
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
jQuery(function(a){var b={init:function(){a(document.body).on("keyup","form.register #reg_password, form.checkout #account_password",this.strengthMeter)},strengthMeter:function(){var c=a("form.register, form.checkout"),d=a('input[type="submit"]',c),e=a("#reg_password, #account_password",c),f=1;b.includeMeter(c,e),f=b.checkPasswordStrength(e),3===f||4===f?d.removeAttr("disabled"):d.attr("disabled","disabled")},includeMeter:function(a,b){var c=a.find("#pass-strength-result");0===c.length?b.after('<div id="pass-strength-result" aria-live="polite">CARALHo!</div>'):""===b.val()&&c.remove()},checkPasswordStrength:function(b){var c=a("#pass-strength-result"),d=wp.passwordStrength.meter(b.val(),wp.passwordStrength.userInputBlacklist());switch(c.removeClass("short bad good strong"),d){case 2:c.addClass("bad").html(pwsL10n.bad);break;case 3:c.addClass("good").html(pwsL10n.good);break;case 4:c.addClass("strong").html(pwsL10n.strong);break;case 5:c.addClass("short").html(pwsL10n.mismatch);break;default:c.addClass("short").html(pwsL10n["short"])}return d}};b.init()});
|
|
@ -12,50 +12,4 @@ jQuery( function( $ ) {
|
|||
$( this ).val( min );
|
||||
}
|
||||
});
|
||||
|
||||
// Password strength message container.
|
||||
$( '#password_1' ).after( '<div id="pass-strength-result" aria-live="polite"></div>' );
|
||||
|
||||
// Function for check password strength for Edit My Account
|
||||
function checkPasswordStrength( s, a, r ) {
|
||||
var t = jQuery( '#password_1' ).val();
|
||||
a.removeClass( 'short bad good strong' ),
|
||||
r = r.concat( wp.passwordStrength.userInputBlacklist() );
|
||||
var e = wp.passwordStrength.meter( t, r );
|
||||
|
||||
switch ( e ) {
|
||||
case 2:
|
||||
a.addClass( 'bad' ).html( pwsL10n.bad );
|
||||
break;
|
||||
case 3:
|
||||
a.addClass( 'good' ).html( pwsL10n.good );
|
||||
break;
|
||||
case 4:
|
||||
a.addClass( 'strong' ).html( pwsL10n.strong );
|
||||
break;
|
||||
case 5:
|
||||
a.addClass( 'short' ).html( pwsL10n.mismatch );
|
||||
break;
|
||||
default:
|
||||
a.addClass( 'short' ).html( pwsL10n.short );
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
$( '#password_1' ).keyup(function() {
|
||||
checkPasswordStrength(
|
||||
$( 'input[name=password_1]' ), // First password field
|
||||
$( '#pass-strength-result' ), // Strength meter
|
||||
[ 'black', 'listed', 'word' ] // Blacklisted words
|
||||
);
|
||||
|
||||
var passLength = jQuery( '#password_1' ).val().length;
|
||||
|
||||
if ( passLength<= 0 ) {
|
||||
$( '#pass-strength-result' ).css( 'display','none' );
|
||||
}else {
|
||||
$( '#pass-strength-result' ).css( 'display','block' );
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -1 +1 @@
|
|||
jQuery(function(a){a(".woocommerce-ordering").on("change","select.orderby",function(){a(this).closest("form").submit()}),a("input.qty:not(.product-quantity input.qty)").each(function(){var b=parseFloat(a(this).attr("min"));b>=0&&parseFloat(a(this).val())<b&&a(this).val(b)})});
|
||||
jQuery(function(a){a(".woocommerce-ordering").on("change","select.orderby",function(){a(this).closest("form").submit()}),a("input.qty:not(.product-quantity input.qty)").each(function(){var b=parseFloat(a(this).attr("min"));b>=0&&parseFloat(a(this).val())<b&&a(this).val(b)})});
|
File diff suppressed because one or more lines are too long
|
@ -170,6 +170,7 @@ class WC_Frontend_Scripts {
|
|||
self::register_script( 'wc-single-product', $frontend_script_path . 'single-product' . $suffix . '.js' );
|
||||
self::register_script( 'wc-country-select', $frontend_script_path . 'country-select' . $suffix . '.js' );
|
||||
self::register_script( 'wc-address-i18n', $frontend_script_path . 'address-i18n' . $suffix . '.js' );
|
||||
self::register_script( 'wc-password-strength-meter', $frontend_script_path . 'password-strength-meter' . $suffix . '.js', array( 'jquery', 'password-strength-meter' ) );
|
||||
|
||||
// Register frontend scripts conditionally
|
||||
if ( $ajax_cart_en ) {
|
||||
|
@ -183,8 +184,8 @@ class WC_Frontend_Scripts {
|
|||
self::enqueue_style( 'select2', $assets_path . 'css/select2.css' );
|
||||
|
||||
// Password strength meter js called for checkout page.
|
||||
if ( ! is_user_logged_in() ) {
|
||||
wp_enqueue_script( 'password-strength-meter' );
|
||||
if ( 'no' === get_option( 'woocommerce_registration_generate_password' ) && ! is_user_logged_in() ) {
|
||||
self::enqueue_script( 'wc-password-strength-meter' );
|
||||
}
|
||||
}
|
||||
if ( is_checkout() ) {
|
||||
|
|
Loading…
Reference in New Issue