3c35841cbd7e3256e48f504058661a3860433477
[roojs1] / Roo / bootstrap / form / Password.js
1 /**
2  * @class Roo.bootstrap.form.Password
3  * @extends Roo.bootstrap.form.Input
4  * Bootstrap Password class
5  * 
6  * 
7  * 
8  * 
9  * @constructor
10  * Create a new Password
11  * @param {Object} config The config object
12  */
13
14 Roo.bootstrap.form.Password = function(config){
15     Roo.bootstrap.form.Password.superclass.constructor.call(this, config);
16
17     this.inputType = 'password';
18 };
19
20 Roo.extend(Roo.bootstrap.form.Password, Roo.bootstrap.form.Input, {
21
22     getAutoCreate : function()
23     {
24         this.after = {
25             xns : Roo.bootstrap,
26             xtype : 'Button',
27             cls : 'password-toggle'
28         };
29
30         return Roo.bootstrap.form.Password.superclass.getAutoCreate.call(this);
31     },
32
33     onRender : function(ct, position)
34     {
35         Roo.bootstrap.form.SecurePass.superclass.onRender.call(this, ct, position);
36
37         this.inputEl().wrap({
38             cls : 'password-wrap'
39         });
40     },
41
42     initEvents : function()
43     {   
44         Roo.bootstrap.form.Password.superclass.initEvents.call(this);
45
46         this.el.addClass('form-password');
47
48         this.toggleEl().addClass('password-hidden');
49
50         this.toggleEl().on('click', this.onToggleClick, this);;
51     },
52
53     toggleEl: function()
54     {
55         return this.el.select('button.password-toggle',true).first();
56     },
57
58     onToggleClick : function(e) 
59     {
60         var input = this.inputEl();
61         var toggle = this.toggleEl();
62
63         toggle.removeClass(['password-visible', 'password-hidden']);
64
65         if(input.attr('type') == 'password') {
66             input.attr('type', 'text');
67             toggle.addClass('password-visible');
68         }
69         else {
70             input.attr('type', 'password');
71             toggle.addClass('password-hidden');
72         }
73     }
74 });