5
5
6
6
define ( [
7
7
'jquery' ,
8
- 'ko' ,
9
8
'uiComponent'
10
- ] , function ( $ , ko , Component ) {
9
+ ] , function ( $ , Component ) {
11
10
'use strict' ;
12
11
13
12
return Component . extend ( {
14
13
passwordSelector : '' ,
15
- showPasswordSelector : '[data-role=show-password]' ,
16
14
passwordInputType : 'password' ,
17
15
textInputType : 'text' ,
18
16
19
17
defaults : {
20
- template : 'Magento_Customer/show-password'
21
- } ,
22
-
23
- /** @inheritdoc */
24
- initialize : function ( ) {
25
- this . _super ( ) ;
18
+ template : 'Magento_Customer/show-password' ,
19
+ isPasswordVisible : false
26
20
} ,
27
21
28
22
/**
29
23
* @return {Object }
30
24
*/
31
25
initObservable : function ( ) {
32
- var self = this ;
33
-
34
26
this . _super ( )
35
- . observe ( {
36
- isChecked : ko . observable ( false )
37
- } ) ;
27
+ . observe ( [ 'isPasswordVisible' ] ) ;
38
28
39
- this . isChecked . subscribe ( function ( ) {
40
- self . _showPassword ( ) ;
41
- } ) ;
29
+ this . isPasswordVisible . subscribe ( function ( isChecked ) {
30
+ this . _showPassword ( isChecked ) ;
31
+ } . bind ( this ) ) ;
42
32
43
33
return this ;
44
34
} ,
@@ -47,12 +37,9 @@ define([
47
37
* Show/Hide password
48
38
* @private
49
39
*/
50
- _showPassword : function ( ) {
51
- var passwordField = this . passwordSelector ;
52
-
53
- $ ( passwordField ) . attr ( 'type' ,
54
- $ ( passwordField ) . attr ( 'type' ) === this . passwordInputType ?
55
- this . textInputType : this . passwordInputType
40
+ _showPassword : function ( isChecked ) {
41
+ $ ( this . passwordSelector ) . attr ( 'type' ,
42
+ isChecked ? this . textInputType : this . passwordInputType
56
43
) ;
57
44
}
58
45
} ) ;
0 commit comments