simple_form_password_with_hints 0.0.2 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 411165d58276c0c20a5597ff5fdc7fb019952929d639770ea8d64bcd41ec6289
|
4
|
+
data.tar.gz: e4cd204922a412f181ba7bb598908a4c4daaa5902c86ebbf1707dc0a96cc906f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ff1c838a6d2a72d3232987fb7d6356b9e4122d15fc06321e0e089f951c6da79731ddc26052658c2f080f19d1ed73d5d169e2fe041f557a8aa6fb11b3332bf18
|
7
|
+
data.tar.gz: fecbacc41e06e575a289357e6e846fa993f41d2d5060e2504b6eaa64942d947acf1c1cda115450467354cac6301c30339c64056021d523b0efe29b45daca466d
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple_form_password_with_hints (0.0.
|
4
|
+
simple_form_password_with_hints (0.0.6)
|
5
5
|
rails
|
6
6
|
simple_form
|
7
7
|
|
@@ -106,12 +106,12 @@ GEM
|
|
106
106
|
mini_mime (>= 0.1.1)
|
107
107
|
marcel (1.0.2)
|
108
108
|
method_source (1.0.0)
|
109
|
-
mini_mime (1.1.
|
109
|
+
mini_mime (1.1.2)
|
110
110
|
mini_portile2 (2.6.1)
|
111
111
|
minitest (5.14.4)
|
112
112
|
msgpack (1.4.2)
|
113
113
|
nio4r (2.5.8)
|
114
|
-
nokogiri (1.12.
|
114
|
+
nokogiri (1.12.5)
|
115
115
|
mini_portile2 (~> 2.6.1)
|
116
116
|
racc (~> 1.4)
|
117
117
|
orm_adapter (0.5.0)
|
@@ -1,10 +1,130 @@
|
|
1
|
-
|
2
|
-
$(function () {
|
1
|
+
Element.prototype.parents = function (selector) {
|
3
2
|
'use strict';
|
4
|
-
|
3
|
+
|
4
|
+
var elements = [],
|
5
|
+
// eslint-disable-next-line consistent-this
|
6
|
+
elem = this,
|
7
|
+
ishaveselector = typeof selector !== 'undefined';
|
8
|
+
|
9
|
+
while ((elem = elem.parentElement) !== null) {
|
10
|
+
if (elem.nodeType !== Node.ELEMENT_NODE) {
|
11
|
+
continue;
|
12
|
+
}
|
13
|
+
|
14
|
+
if (!ishaveselector || elem.matches(selector)) {
|
15
|
+
elements.push(elem);
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
return elements;
|
20
|
+
};
|
21
|
+
|
22
|
+
Element.prototype.parent = function (selector) {
|
23
|
+
'use strict';
|
24
|
+
var elements = this.parents(selector);
|
25
|
+
|
26
|
+
if (elements.length > 0) {
|
27
|
+
return elements[0];
|
28
|
+
} else {
|
29
|
+
return null;
|
30
|
+
}
|
31
|
+
};
|
32
|
+
|
33
|
+
(function () {
|
34
|
+
'use strict';
|
35
|
+
var initialized = false,
|
36
|
+
simpleFormPasswordWithHints;
|
37
|
+
|
38
|
+
simpleFormPasswordWithHints = {
|
39
|
+
init: function () {
|
40
|
+
var inputs = document.querySelectorAll('.js-sfpwh-hints-input'),
|
41
|
+
togglers = document.querySelectorAll('.js-sfpwh-password-toggle'),
|
42
|
+
syncInputs = document.querySelectorAll('.js-sfpwh-sync-input'),
|
43
|
+
i = 0;
|
44
|
+
|
45
|
+
if (initialized) {
|
46
|
+
return false;
|
47
|
+
}
|
48
|
+
initialized = true;
|
49
|
+
|
50
|
+
this.listen(inputs, 'input', this.onInput.bind(this));
|
51
|
+
this.listen(togglers, 'click', this.onClickToggler);
|
52
|
+
|
53
|
+
for (i = 0; i < syncInputs.length; i +=1) {
|
54
|
+
this.bindEquality(syncInputs[i]);
|
55
|
+
}
|
56
|
+
},
|
57
|
+
|
58
|
+
listen: function (elements, action, callback) {
|
59
|
+
var i;
|
60
|
+
for (i = 0; i < elements.length; i +=1) {
|
61
|
+
elements[i].addEventListener(action, callback.bind(this, elements[i]));
|
62
|
+
}
|
63
|
+
},
|
64
|
+
|
65
|
+
onInput: function (element) {
|
66
|
+
var container = element.parent('.password_with_hints'),
|
67
|
+
checks = ['length', 'uppercase', 'lowercase', 'number', 'special'],
|
68
|
+
i;
|
69
|
+
for (i = 0; i < checks.length; i += 1) {
|
70
|
+
this.check(container, checks[i], element.value);
|
71
|
+
}
|
72
|
+
},
|
73
|
+
|
74
|
+
check: function (container, key, value) {
|
75
|
+
var check = container.querySelector('.js-sfpwh-hint-' + key),
|
76
|
+
regexKey,
|
77
|
+
regex;
|
78
|
+
|
79
|
+
if (check) {
|
80
|
+
regexKey = this.getRegex(key, check);
|
81
|
+
regex = new RegExp(regexKey);
|
82
|
+
if (value.match(regex)) {
|
83
|
+
check.classList.remove('sfpwh-hint--invalid');
|
84
|
+
} else {
|
85
|
+
check.classList.add('sfpwh-hint--invalid');
|
86
|
+
}
|
87
|
+
}
|
88
|
+
},
|
89
|
+
|
90
|
+
bindEquality: function (input) {
|
91
|
+
var form = input.parent('form'),
|
92
|
+
target = form.querySelector('input[name="' + input.getAttribute('data-link-to') + '"]');
|
93
|
+
input.addEventListener('input', this.compare.bind(this, input, target));
|
94
|
+
target.addEventListener('input', this.compare.bind(this, input, target));
|
95
|
+
},
|
96
|
+
|
97
|
+
compare: function (field, target) {
|
98
|
+
var container = field.parent('.password_with_sync'),
|
99
|
+
check;
|
100
|
+
|
101
|
+
if (container) {
|
102
|
+
check = container.querySelector('.js-sfpwh-hint-match');
|
103
|
+
}
|
104
|
+
|
105
|
+
if (field.value !== '' && field.value === target.value) {
|
106
|
+
check.classList.remove('sfpwh-hint--invalid');
|
107
|
+
} else {
|
108
|
+
check.classList.add('sfpwh-hint--invalid');
|
109
|
+
}
|
110
|
+
},
|
111
|
+
|
112
|
+
onClickToggler: function (element) {
|
113
|
+
var container = element.parent('.password_with_hints, .password_with_sync'),
|
114
|
+
input = container.querySelector('.js-sfpwh-input');
|
115
|
+
|
116
|
+
element.classList.toggle('sfpwh-password-toggle-revealed');
|
117
|
+
|
118
|
+
input.type = input.type === 'text' ? 'password' : 'text';
|
119
|
+
},
|
120
|
+
|
121
|
+
// HELPERS
|
122
|
+
|
123
|
+
getRegex: function (key, element) {
|
5
124
|
var regex,
|
6
125
|
min,
|
7
126
|
chars;
|
127
|
+
|
8
128
|
switch (key) {
|
9
129
|
case 'uppercase':
|
10
130
|
regex = '[A-Z]';
|
@@ -17,71 +137,25 @@ $(function () {
|
|
17
137
|
break;
|
18
138
|
case 'special':
|
19
139
|
// hyphen must be at the end
|
20
|
-
chars =
|
140
|
+
chars = element.getAttribute('data-chars');
|
21
141
|
regex = '[' + chars + ']';
|
22
142
|
break;
|
23
143
|
case 'length':
|
24
|
-
min =
|
144
|
+
min = element.getAttribute('data-length');
|
25
145
|
regex = '.{' + min + ',128}';
|
26
146
|
break;
|
27
147
|
default:
|
28
148
|
break;
|
29
149
|
}
|
30
150
|
return regex;
|
31
|
-
},
|
32
|
-
performCheck = function ($container, key, password) {
|
33
|
-
var $check = $('.js-sfpwh-hint-' + key, $container),
|
34
|
-
regexKey = getCheckRegex(key, $check),
|
35
|
-
regex = new RegExp(regexKey);
|
36
|
-
if ($check.length) {
|
37
|
-
if (password.match(regex)) {
|
38
|
-
$check.removeClass('sfpwh-hint--invalid');
|
39
|
-
} else {
|
40
|
-
$check.addClass('sfpwh-hint--invalid');
|
41
|
-
}
|
42
|
-
}
|
43
|
-
},
|
44
|
-
compareFields = function (e) {
|
45
|
-
var $field = $(e.data.$field),
|
46
|
-
$target = $(e.data.$target),
|
47
|
-
$container = $field.parents('.password_with_sync'),
|
48
|
-
$check = $('.js-sfpwh-hint-match', $container);
|
49
|
-
|
50
|
-
if ($field.val() !== '' && $field.val() === $target.val()) {
|
51
|
-
$check.removeClass('sfpwh-hint--invalid');
|
52
|
-
} else {
|
53
|
-
$check.addClass('sfpwh-hint--invalid');
|
54
|
-
}
|
55
|
-
};
|
56
|
-
|
57
|
-
$('.js-sfpwh-hints-input').on('input', function () {
|
58
|
-
var $container = $(this).parents('.password_with_hints'),
|
59
|
-
checks = ['length', 'uppercase', 'lowercase', 'number', 'special'],
|
60
|
-
password = $(this).val(),
|
61
|
-
i;
|
62
|
-
for (i = 0; i < checks.length; i += 1) {
|
63
|
-
performCheck($container, checks[i], password);
|
64
|
-
}
|
65
|
-
});
|
66
|
-
|
67
|
-
$('.js-sfpwh-password-toggle').on('click', function () {
|
68
|
-
var $container = $(this).parents('.password_with_hints, .password_with_sync'),
|
69
|
-
$input = $('.js-sfpwh-input', $container),
|
70
|
-
type = $input.attr('type');
|
71
|
-
$(this).toggleClass('sfpwh-password-toggle-revealed');
|
72
|
-
if (type === 'text') {
|
73
|
-
$input.attr('type', 'password');
|
74
|
-
} else {
|
75
|
-
$input.attr('type', 'text');
|
76
151
|
}
|
77
|
-
}
|
78
|
-
|
79
|
-
$('.js-sfpwh-sync-input').each(function (index, value) {
|
80
|
-
var $field = $(value),
|
81
|
-
$form = $field.parents('form'),
|
82
|
-
$target = $('input[name="' + $field.data('link-to') + '"]', $form);
|
152
|
+
};
|
83
153
|
|
84
|
-
|
85
|
-
|
86
|
-
}
|
87
|
-
|
154
|
+
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
155
|
+
simpleFormPasswordWithHints.init();
|
156
|
+
} else {
|
157
|
+
window.addEventListener('DOMContentLoaded', () => {
|
158
|
+
simpleFormPasswordWithHints.init();
|
159
|
+
});
|
160
|
+
}
|
161
|
+
}());
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form_password_with_hints
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre-andré Boissinot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|