simple_form_password_with_hints 0.0.1 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98458d88dfc28b816842f0dc56ad249d4b54496e05c266d386b80cb2b4f559e4
4
- data.tar.gz: 99191725c33b8633b7c2b56d9685201242b4a3e7a793419dea654588ed5d0e0b
3
+ metadata.gz: 891b21002820e82ef116a1b150acfee6fc0134ee7330f710e3804a2ce0fdcd7a
4
+ data.tar.gz: 6cb703cc5b166a077d450af16a3f05fc4d004c440cb9980ca5f60dccf645b6f0
5
5
  SHA512:
6
- metadata.gz: 25135c64eafba3a0b3a793c87098ac93fd0d98160effcad1f933c87f7b46745a67ce7b958b71b29d8e12f19e36745d0e9bdc81ec48ea76ce0dcd0b8789f7dc00
7
- data.tar.gz: 7128e1b3b8c2fc69e0d9bb64d261854203fdaddbce818f8876d4cfdc640f83fe6088b821e68d3bc74055f177760c296f384025ec81e05f0f29820bcb8f249d7e
6
+ metadata.gz: 58beba01eee82e29dd3497cf101b397de049465564865a2730b632b6d2f9b23d98cca51ab2c97b6bf2ffb03caf1edf50c56b6e512b7b20bcbfb5b4590087edd5
7
+ data.tar.gz: 22521ab12a5d39ec5c1b10066ab49f8640bb2a3d740f32ccccc472d0d15da5905f15b20e29475f2c3643642be59c61d2b7aedaf410a4fa0c79b4cc83e83b981e
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /test/dummy/tmp/
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.1)
4
+ simple_form_password_with_hints (0.0.5)
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.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.4)
114
+ nokogiri (1.12.5)
115
115
  mini_portile2 (~> 2.6.1)
116
116
  racc (~> 1.4)
117
117
  orm_adapter (0.5.0)
data/README.md CHANGED
@@ -20,6 +20,18 @@ Run the following command to install it:
20
20
  bundle install
21
21
  ```
22
22
 
23
+ Add it to your application.sass:
24
+
25
+ ```
26
+ @import 'simple_form_password_with_hints'
27
+ ```
28
+
29
+ Add it to your application.js:
30
+
31
+ ```
32
+ //= require simple_form_password_with_hints
33
+ ```
34
+
23
35
  ### Bootstrap
24
36
 
25
37
  **Simple Form Password With Hints** relies on the [Bootstrap](http://getbootstrap.com/) markup, so it presumes that you installed Simple Form with the Bootstrap option. To do that you have to use the `bootstrap` option in the Simple Form install generator, like this:
@@ -142,4 +154,4 @@ https://github.com/noesya/simple_form_password_with_hints/issues
142
154
 
143
155
  ## License
144
156
 
145
- MIT License.
157
+ MIT License.
@@ -1,10 +1,128 @@
1
- /*global $, RegExp */
2
- $(function () {
1
+ Element.prototype.parents = function (selector) {
3
2
  'use strict';
4
- var getCheckRegex = function (key, $check) {
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 = this.getRegex(key, check),
77
+ regex = new RegExp(regexKey);
78
+
79
+ if (check) {
80
+ if (value.match(regex)) {
81
+ check.classList.remove('sfpwh-hint--invalid');
82
+ } else {
83
+ check.classList.add('sfpwh-hint--invalid');
84
+ }
85
+ }
86
+ },
87
+
88
+ bindEquality: function (input) {
89
+ var form = input.parent('form'),
90
+ target = form.querySelector('input[name="' + input.getAttribute('data-link-to') + '"]');
91
+ input.addEventListener('input', this.compare.bind(this, input, target));
92
+ target.addEventListener('input', this.compare.bind(this, input, target));
93
+ },
94
+
95
+ compare: function (field, target) {
96
+ var container = field.parent('.password_with_sync'),
97
+ check;
98
+
99
+ if (container) {
100
+ check = container.querySelector('.js-sfpwh-hint-match');
101
+ }
102
+
103
+ if (field.value !== '' && field.value === target.value) {
104
+ check.classList.remove('sfpwh-hint--invalid');
105
+ } else {
106
+ check.classList.add('sfpwh-hint--invalid');
107
+ }
108
+ },
109
+
110
+ onClickToggler: function (element) {
111
+ var container = element.parent('.password_with_hints, .password_with_sync'),
112
+ input = container.querySelector('.js-sfpwh-input');
113
+
114
+ element.classList.toggle('sfpwh-password-toggle-revealed');
115
+
116
+ input.type = input.type === 'text' ? 'password' : 'text';
117
+ },
118
+
119
+ // HELPERS
120
+
121
+ getRegex: function (key, element) {
5
122
  var regex,
6
123
  min,
7
124
  chars;
125
+
8
126
  switch (key) {
9
127
  case 'uppercase':
10
128
  regex = '[A-Z]';
@@ -17,71 +135,25 @@ $(function () {
17
135
  break;
18
136
  case 'special':
19
137
  // hyphen must be at the end
20
- chars = $check.data('chars');
138
+ chars = element.getAttribute('data-chars');
21
139
  regex = '[' + chars + ']';
22
140
  break;
23
141
  case 'length':
24
- min = $check.data('length');
142
+ min = element.getAttribute('data-length');
25
143
  regex = '.{' + min + ',128}';
26
144
  break;
27
145
  default:
28
146
  break;
29
147
  }
30
148
  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
149
  }
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);
150
+ };
83
151
 
84
- $field.on('input', { $field: $field, $target: $target }, compareFields);
85
- $target.on('input', { $field: $field, $target: $target }, compareFields);
86
- });
87
- });
152
+ if (document.readyState === 'complete' || document.readyState === 'interactive') {
153
+ simpleFormPasswordWithHints.init();
154
+ } else {
155
+ window.addEventListener('DOMContentLoaded', () => {
156
+ simpleFormPasswordWithHints.init();
157
+ });
158
+ }
159
+ }());
@@ -10,6 +10,7 @@
10
10
  & ~.invalid-feedback
11
11
  margin-top: -1.275rem
12
12
  &-hint
13
+ display: inline-block
13
14
  font-size: 11px
14
15
  white-space: nowrap
15
16
  &:not(:first-child)
@@ -0,0 +1,8 @@
1
+ fr:
2
+ simple_form_password_with_hints:
3
+ test_chars: "%{min_length} caractères minimum"
4
+ test_uppercase: 'Majuscule'
5
+ test_lowercase: 'Minuscule'
6
+ test_numeric: 'Chiffre'
7
+ test_special_char: 'Caractère spécial'
8
+ test_fields_matching: 'Champs similaires'
@@ -1,3 +1,3 @@
1
1
  module SimpleFormPasswordWithHints
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.0.5".freeze
3
3
  end
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.1
4
+ version: 0.0.5
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-09-22 00:00:00.000000000 Z
11
+ date: 2021-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -88,6 +88,7 @@ files:
88
88
  - assets/javascripts/simple_form_password_with_hints.js
89
89
  - assets/stylesheets/simple_form_password_with_hints.sass
90
90
  - config/locales/en.yml
91
+ - config/locales/fr.yml
91
92
  - lib/simple_form_password_with_hints.rb
92
93
  - lib/simple_form_password_with_hints/password_with_hints_input.rb
93
94
  - lib/simple_form_password_with_hints/password_with_sync_input.rb