6
6
/**
7
7
* jshint browser:true
8
8
*/
9
- /*eslint no-unused-vars: 0*/
10
9
define ( [
11
10
'jquery' ,
12
11
'Magento_Customer/js/zxcvbn' ,
13
- 'mage/translate' ,
14
- 'mage/validation'
15
- ] , function ( $ , zxcvbn , $t , validation ) {
12
+ 'mage/translate'
13
+ ] , function ( $ , zxcvbn , $t ) {
16
14
'use strict' ;
17
15
18
16
$ . widget ( 'mage.passwordStrengthIndicator' , {
19
17
options : {
18
+ cache : { } ,
20
19
defaultClassName : 'password-strength-meter-' ,
21
- passwordStrengthMeterId : 'password-strength-meter-container' ,
22
- passwordStrengthMeterLabelId : 'password-strength-meter-label'
20
+ passwordSelector : '[type=password]' ,
21
+ passwordStrengthMeterSelector : '[data-role=password-strength-meter]' ,
22
+ passwordStrengthMeterLabelSelector : '[data-role=password-strength-meter-label]'
23
23
} ,
24
24
25
25
/**
26
26
* Widget initialization
27
27
* @private
28
28
*/
29
29
_create : function ( ) {
30
+ this . options . cache . input = $ ( this . options . passwordSelector , this . element ) ;
31
+ this . options . cache . meter = $ ( this . options . passwordStrengthMeterSelector , this . element ) ;
32
+ this . options . cache . label = $ ( this . options . passwordStrengthMeterLabelSelector , this . element ) ;
30
33
this . _bind ( ) ;
31
34
} ,
32
35
@@ -35,10 +38,10 @@ define([
35
38
* @private
36
39
*/
37
40
_bind : function ( ) {
38
- this . _on ( {
39
- 'change input[type="password"] ' : this . _calculateStrength ,
40
- 'keyup input[type="password"] ' : this . _calculateStrength ,
41
- 'paste input[type="password"] ' : this . _calculateStrength
41
+ this . _on ( this . options . cache . input , {
42
+ 'change' : this . _calculateStrength ,
43
+ 'keyup' : this . _calculateStrength ,
44
+ 'paste' : this . _calculateStrength
42
45
} ) ;
43
46
} ,
44
47
@@ -54,7 +57,7 @@ define([
54
57
55
58
this . _displayStrength ( className , score , isEmpty ) ;
56
59
//update error messages
57
- $ . validator . validateSingleElement ( this . element . find ( ' input[type="password"]' ) ) ;
60
+ $ . validator . validateSingleElement ( this . options . cache . input ) ;
58
61
} ,
59
62
60
63
/**
@@ -65,11 +68,7 @@ define([
65
68
* @private
66
69
*/
67
70
_displayStrength : function ( className , score , isEmpty ) {
68
- var strengthContainer = this . element . find ( '#' + this . options . passwordStrengthMeterId ) ,
69
- strengthLabel = '' ;
70
-
71
- strengthContainer . removeClass ( ) ;
72
- strengthContainer . addClass ( className ) ;
71
+ var strengthLabel = '' ;
73
72
74
73
if ( isEmpty ) {
75
74
strengthLabel = $t ( 'No Password' ) ;
@@ -94,7 +93,10 @@ define([
94
93
}
95
94
}
96
95
97
- this . element . find ( '#' + this . options . passwordStrengthMeterLabelId ) . text ( strengthLabel ) ;
96
+ this . options . cache . meter
97
+ . removeClass ( )
98
+ . addClass ( className ) ;
99
+ this . options . cache . label . text ( strengthLabel ) ;
98
100
} ,
99
101
100
102
/**
@@ -103,7 +105,7 @@ define([
103
105
* @private
104
106
*/
105
107
_getPassword : function ( ) {
106
- return this . element . find ( ' input[type="password"]' ) . val ( ) ;
108
+ return this . options . cache . input . val ( ) ;
107
109
} ,
108
110
109
111
/**
@@ -114,8 +116,7 @@ define([
114
116
* @private
115
117
*/
116
118
_getClassName : function ( score , isEmpty ) {
117
- var suffix = isEmpty ? 'no-pwd' : score ;
118
- return this . options . defaultClassName + suffix ;
119
+ return this . options . defaultClassName + ( isEmpty ? 'no-pwd' : score ) ;
119
120
}
120
121
} ) ;
121
122
0 commit comments