add-payment-method.js
3 years ago
add-payment-method.min.js
3 years ago
add-to-cart-variation.js
3 years ago
add-to-cart-variation.min.js
3 years ago
add-to-cart.js
3 years ago
add-to-cart.min.js
3 years ago
address-i18n.js
5 years ago
address-i18n.min.js
3 years ago
cart-fragments.js
3 years ago
cart-fragments.min.js
3 years ago
cart.js
3 years ago
cart.min.js
3 years ago
checkout.js
3 years ago
checkout.min.js
3 years ago
country-select.js
5 years ago
country-select.min.js
3 years ago
credit-card-form.js
8 years ago
credit-card-form.min.js
8 years ago
geolocation.js
3 years ago
geolocation.min.js
3 years ago
lost-password.js
8 years ago
lost-password.min.js
8 years ago
password-strength-meter.js
4 years ago
password-strength-meter.min.js
3 years ago
price-slider.js
5 years ago
price-slider.min.js
3 years ago
single-product.js
4 years ago
single-product.min.js
3 years ago
tokenization-form.js
5 years ago
tokenization-form.min.js
5 years ago
woocommerce.js
5 years ago
woocommerce.min.js
5 years ago
password-strength-meter.js
133 lines
| 1 | /* global wp, pwsL10n, wc_password_strength_meter_params */ |
| 2 | ( function( $ ) { |
| 3 | 'use strict'; |
| 4 | /** |
| 5 | * Password Strength Meter class. |
| 6 | */ |
| 7 | var wc_password_strength_meter = { |
| 8 | |
| 9 | /** |
| 10 | * Initialize strength meter actions. |
| 11 | */ |
| 12 | init: function() { |
| 13 | $( document.body ) |
| 14 | .on( |
| 15 | 'keyup change', |
| 16 | 'form.register #reg_password, form.checkout #account_password, ' + |
| 17 | 'form.edit-account #password_1, form.lost_reset_password #password_1', |
| 18 | this.strengthMeter |
| 19 | ); |
| 20 | $( 'form.checkout #createaccount' ).trigger( 'change' ); |
| 21 | }, |
| 22 | |
| 23 | /** |
| 24 | * Strength Meter. |
| 25 | */ |
| 26 | strengthMeter: function() { |
| 27 | var wrapper = $( 'form.register, form.checkout, form.edit-account, form.lost_reset_password' ), |
| 28 | submit = $( 'button[type="submit"]', wrapper ), |
| 29 | field = $( '#reg_password, #account_password, #password_1', wrapper ), |
| 30 | strength = 1, |
| 31 | fieldValue = field.val(), |
| 32 | stop_checkout = ! wrapper.is( 'form.checkout' ); // By default is disabled on checkout. |
| 33 | |
| 34 | wc_password_strength_meter.includeMeter( wrapper, field ); |
| 35 | |
| 36 | strength = wc_password_strength_meter.checkPasswordStrength( wrapper, field ); |
| 37 | |
| 38 | // Allow password strength meter stop checkout. |
| 39 | if ( wc_password_strength_meter_params.stop_checkout ) { |
| 40 | stop_checkout = true; |
| 41 | } |
| 42 | |
| 43 | if ( |
| 44 | fieldValue.length > 0 && |
| 45 | strength < wc_password_strength_meter_params.min_password_strength && |
| 46 | -1 !== strength && |
| 47 | stop_checkout |
| 48 | ) { |
| 49 | submit.attr( 'disabled', 'disabled' ).addClass( 'disabled' ); |
| 50 | } else { |
| 51 | submit.prop( 'disabled', false ).removeClass( 'disabled' ); |
| 52 | } |
| 53 | }, |
| 54 | |
| 55 | /** |
| 56 | * Include meter HTML. |
| 57 | * |
| 58 | * @param {Object} wrapper |
| 59 | * @param {Object} field |
| 60 | */ |
| 61 | includeMeter: function( wrapper, field ) { |
| 62 | var meter = wrapper.find( '.woocommerce-password-strength' ); |
| 63 | |
| 64 | if ( '' === field.val() ) { |
| 65 | meter.hide(); |
| 66 | $( document.body ).trigger( 'wc-password-strength-hide' ); |
| 67 | } else if ( 0 === meter.length ) { |
| 68 | field.after( '<div class="woocommerce-password-strength" aria-live="polite"></div>' ); |
| 69 | $( document.body ).trigger( 'wc-password-strength-added' ); |
| 70 | } else { |
| 71 | meter.show(); |
| 72 | $( document.body ).trigger( 'wc-password-strength-show' ); |
| 73 | } |
| 74 | }, |
| 75 | |
| 76 | /** |
| 77 | * Check password strength. |
| 78 | * |
| 79 | * @param {Object} field |
| 80 | * |
| 81 | * @return {Int} |
| 82 | */ |
| 83 | checkPasswordStrength: function( wrapper, field ) { |
| 84 | var meter = wrapper.find( '.woocommerce-password-strength' ), |
| 85 | hint = wrapper.find( '.woocommerce-password-hint' ), |
| 86 | hint_html = '<small class="woocommerce-password-hint">' + wc_password_strength_meter_params.i18n_password_hint + '</small>', |
| 87 | strength = wp.passwordStrength.meter( field.val(), wp.passwordStrength.userInputDisallowedList() ), |
| 88 | error = ''; |
| 89 | |
| 90 | // Reset. |
| 91 | meter.removeClass( 'short bad good strong' ); |
| 92 | hint.remove(); |
| 93 | |
| 94 | if ( meter.is( ':hidden' ) ) { |
| 95 | return strength; |
| 96 | } |
| 97 | |
| 98 | // Error to append |
| 99 | if ( strength < wc_password_strength_meter_params.min_password_strength ) { |
| 100 | error = ' - ' + wc_password_strength_meter_params.i18n_password_error; |
| 101 | } |
| 102 | |
| 103 | switch ( strength ) { |
| 104 | case 0 : |
| 105 | meter.addClass( 'short' ).html( pwsL10n['short'] + error ); |
| 106 | meter.after( hint_html ); |
| 107 | break; |
| 108 | case 1 : |
| 109 | meter.addClass( 'bad' ).html( pwsL10n.bad + error ); |
| 110 | meter.after( hint_html ); |
| 111 | break; |
| 112 | case 2 : |
| 113 | meter.addClass( 'bad' ).html( pwsL10n.bad + error ); |
| 114 | meter.after( hint_html ); |
| 115 | break; |
| 116 | case 3 : |
| 117 | meter.addClass( 'good' ).html( pwsL10n.good + error ); |
| 118 | break; |
| 119 | case 4 : |
| 120 | meter.addClass( 'strong' ).html( pwsL10n.strong + error ); |
| 121 | break; |
| 122 | case 5 : |
| 123 | meter.addClass( 'short' ).html( pwsL10n.mismatch ); |
| 124 | break; |
| 125 | } |
| 126 | |
| 127 | return strength; |
| 128 | } |
| 129 | }; |
| 130 | |
| 131 | wc_password_strength_meter.init(); |
| 132 | })( jQuery ); |
| 133 |