1 |
|
2 | var InputPassword = function InputPassword(container, params) {
|
3 | |
4 |
|
5 |
|
6 | var defaults = {
|
7 | revealClass: 'input-icon-reveal',
|
8 | inputClass: 'input-text'
|
9 | };
|
10 | params = params || {};
|
11 | for (var def in defaults) {
|
12 | if (params[def] === undefined) {
|
13 | params[def] = defaults[def];
|
14 | }
|
15 | }
|
16 | var s = this;
|
17 | s.params = params;
|
18 |
|
19 |
|
20 | s.container = typeof container === 'string' ? document.querySelector(container) : container;
|
21 | if (!s.container) {
|
22 | console.log('SeedsUI Error:未找到InputPre的DOM对象,请检查传入参数是否正确');
|
23 | return;
|
24 | }
|
25 |
|
26 |
|
27 | s.reveal = s.container.querySelector('.' + s.params.revealClass);
|
28 | if (!s.container) {
|
29 | console.log('SeedsUI Error:未找到InputPre的pre,请检查传入参数是否正确');
|
30 | return;
|
31 | }
|
32 |
|
33 |
|
34 | s.input = s.container.querySelector('.' + s.params.inputClass);
|
35 | if (!s.input) {
|
36 | console.log('SeedsUI Error:未找到InputPre的input,请检查传入参数是否正确');
|
37 | return;
|
38 | }
|
39 |
|
40 | |
41 |
|
42 |
|
43 | s.events = function (detach) {
|
44 | var touchTarget = s.reveal;
|
45 | var action = detach ? 'removeEventListener' : 'addEventListener';
|
46 | touchTarget[action]('click', s.revealAutoSize, false);
|
47 | };
|
48 |
|
49 | s.attach = function () {
|
50 | s.events();
|
51 | };
|
52 | s.detach = function () {
|
53 | s.events(true);
|
54 | };
|
55 | s.attach();
|
56 | |
57 |
|
58 |
|
59 | s.onReveal = function () {
|
60 | if (s.reveal.classList.contains('active')) {
|
61 | s.reveal.classList.remove('active');
|
62 | s.input.type = 'password';
|
63 | } else {
|
64 | s.reveal.classList.add('active');
|
65 | s.input.type = 'text';
|
66 | }
|
67 | s.input.focus();
|
68 | };
|
69 | };
|
70 |
|
71 | export default InputPassword; |
\ | No newline at end of file |