testimonials 0.1.3 → 0.1.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: ca7fa3a534c13036edc28e6206c06b5e4ef82949cafaeee614a2d196509c2176
4
- data.tar.gz: 140a7b0783d3284076def56a598a0c70bb72f1208b2a6158b62c09d634eeaeb2
3
+ metadata.gz: f22788e95288902bcd21a32e81a39841fcc71fb844b10c96ae768726e51026a1
4
+ data.tar.gz: 3cd300be21ce03785c3f10ac081299278ceeb434bdcd250496a80a67115f2e63
5
5
  SHA512:
6
- metadata.gz: 6eebe2d3c06afff74b999f4a8a29120a97d3a2e78eeb0ff1429df26bf14a9303c66861665489fdb10104c9f7557bca3ad140f466ddb4a4b2a2116d465c3bc302
7
- data.tar.gz: 343195af39cd476f4a74728ab5e11997efa834806c7213aa3ab3b61bba933a6f2d89ccb6d255a9463b9089f9a4ebba5af078ff968db4b2adfff1fe1c6ad97cb3
6
+ metadata.gz: 1fc585035952eedaac590b367271939f8c825ba44a8bc010f6e45223372c68aaab3ea773dc0f320420fc8b0cda3ccfa26ba7fc70a8800a6a03567eb77e9b8acd
7
+ data.tar.gz: 650ea64d54721adbe117e821e1f1873fbc84bc5d2320c1486c4cce866a788c12d05c19509d72c6bb390ea9bf5bff944a7f0b9354681d26e3914c295eef5f2653
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.5
4
+
5
+ - Docs: show how to wire `current_user` with Rails 8's built-in authentication
6
+ (`bin/rails generate authentication`), alongside the existing Devise/Warden
7
+ example — in the README and the generated initializer.
8
+
9
+ ## 0.1.4
10
+
11
+ - Validation and submit errors are announced to screen readers: every
12
+ `.tml-error` container is a `role="alert"` region from creation, and text
13
+ is inserted only after the region is exposed.
14
+ - Page scroll is locked behind the open widget dialog and restored on close;
15
+ a Turbo body swap that removes the overlay releases the lock too. The
16
+ inline collection-page form is unaffected.
17
+
3
18
  ## 0.1.3
4
19
 
5
20
  - Video playback no longer pauses itself moments after play in Firefox: the
data/README.md CHANGED
@@ -115,6 +115,20 @@ Testimonials.configure do |config|
115
115
  end
116
116
  ```
117
117
 
118
+ `current_user` (and any admin gate) receives the raw request, so it works
119
+ with whatever auth you have:
120
+
121
+ ```ruby
122
+ # Devise / Warden:
123
+ config.current_user = ->(request) { request.env["warden"]&.user }
124
+
125
+ # Rails 8 built-in auth (bin/rails generate authentication):
126
+ config.current_user = lambda do |request|
127
+ token = request.cookies["session_token"]
128
+ Session.find_signed(token)&.user if token
129
+ end
130
+ ```
131
+
118
132
  ### Guiding questions, localized
119
133
 
120
134
  The questions shown above the form ("How has %{app} helped you?") fight
@@ -15,7 +15,14 @@ Testimonials.configure do |config|
15
15
 
16
16
  # Attribute submissions to a user (optional). Return an object responding
17
17
  # to #id, or nil. Receives the request.
18
+ # Devise / Warden:
18
19
  # config.current_user = ->(request) { request.env["warden"]&.user }
20
+ #
21
+ # Rails 8 built-in auth (bin/rails generate authentication):
22
+ # config.current_user = lambda do |request|
23
+ # token = request.cookies["session_token"]
24
+ # Session.find_signed(token)&.user if token
25
+ # end
19
26
 
20
27
  # Attribution stored with a signed-in user's submission.
21
28
  # config.user_display = ->(user) { { name: user.name, email: user.email } }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Testimonials
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.5'
5
5
  end
@@ -29,6 +29,7 @@
29
29
  var Z = 2147482000;
30
30
  var overlay = null;
31
31
  var lastFocused = null;
32
+ var savedOverflow = null; // documentElement overflow to restore when the modal closes
32
33
  var state = null; // one open session: { kind, auto, stage, rating, videoBlob, ... }
33
34
  var media = { stream: null, recorder: null, chunks: [], timer: null };
34
35
 
@@ -67,6 +68,10 @@
67
68
  config = readConfig() || config;
68
69
  injectStyles();
69
70
 
71
+ // A Turbo body swap can remove the overlay without close() running; the
72
+ // lock lives on documentElement, which survives the swap, so release it.
73
+ if (!document.getElementById("tml-overlay")) unlockScroll();
74
+
70
75
  if (config.mode === "page") {
71
76
  renderInline();
72
77
  return;
@@ -147,6 +152,7 @@
147
152
 
148
153
  overlay.appendChild(dialog);
149
154
  document.body.appendChild(overlay);
155
+ lockScroll();
150
156
  overlay.addEventListener("keydown", trapFocus);
151
157
 
152
158
  if (auto) postEvent(kind, "shown");
@@ -161,9 +167,21 @@
161
167
  overlay.remove();
162
168
  overlay = null;
163
169
  state = null;
170
+ unlockScroll();
164
171
  if (lastFocused && lastFocused.focus) lastFocused.focus();
165
172
  }
166
173
 
174
+ function lockScroll() {
175
+ if (savedOverflow === null) savedOverflow = document.documentElement.style.overflow;
176
+ document.documentElement.style.overflow = "hidden";
177
+ }
178
+
179
+ function unlockScroll() {
180
+ if (savedOverflow === null) return;
181
+ document.documentElement.style.overflow = savedOverflow;
182
+ savedOverflow = null;
183
+ }
184
+
167
185
  function dialogEl() {
168
186
  return overlay ? overlay.querySelector("#tml-dialog") : document.querySelector("[data-testimonials-inline] .tml-inline");
169
187
  }
@@ -301,6 +319,7 @@
301
319
  form.appendChild(consentField());
302
320
 
303
321
  var error = el("p", "tml-error");
322
+ error.setAttribute("role", "alert");
304
323
  error.hidden = true;
305
324
  form.appendChild(error);
306
325
 
@@ -470,6 +489,7 @@
470
489
  stage.appendChild(hint);
471
490
 
472
491
  var error = el("p", "tml-error");
492
+ error.setAttribute("role", "alert");
473
493
  error.hidden = true;
474
494
  stage.appendChild(error);
475
495
 
@@ -640,6 +660,7 @@
640
660
  stage.appendChild(playback);
641
661
 
642
662
  var error = el("p", "tml-error");
663
+ error.setAttribute("role", "alert");
643
664
  error.hidden = true;
644
665
  stage.appendChild(error);
645
666
 
@@ -747,6 +768,7 @@
747
768
  }
748
769
 
749
770
  var error = el("p", "tml-error");
771
+ error.setAttribute("role", "alert");
750
772
  error.hidden = true;
751
773
  form.appendChild(error);
752
774
 
@@ -952,8 +974,10 @@
952
974
  function showError(form, text) {
953
975
  var error = form.querySelector(".tml-error");
954
976
  if (!error) return;
955
- error.textContent = text;
977
+ // Unhide first: text landing in an already-exposed alert region is
978
+ // reliably announced; revealing role+text together sometimes isn't.
956
979
  error.hidden = false;
980
+ error.textContent = text;
957
981
  }
958
982
 
959
983
  // --- styles -------------------------------------------------------------------
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testimonials
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Shmarov