turbo_modal 0.3.3 → 0.3.4

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: e8e72cdd25686a64f8cca7d141062e27cec69ae52e607a60a437ca1aad450cee
4
- data.tar.gz: 29555235b607fc5f343e3f11643143c0233329cf1d210402999896afdb4cecc2
3
+ metadata.gz: 109ad54770b4ca4dbf21878bc8c71b8cf26ab1419b94428c9b5e2f6f3039d6f6
4
+ data.tar.gz: 53074315c672b7872ddf00f7eb450ea1f211258ec846afd885e43867e80cd6fd
5
5
  SHA512:
6
- metadata.gz: 9380653ea1ff7ce20473b1b6e34b2324c3e4665f10abf4ff4f6e840bc7ae659c79d54bc9722c0714b8c9c2eaa469ee2f02a379148b1f1c2376f390df6d67cf0e
7
- data.tar.gz: 7220766f0abdd58b4eb5c89ec44a63db814ef6acd7e299af5e354d680896cbd6e66307405386f4820c0e696378dfe7999fd8db755848193ae811491a0ac87135
6
+ metadata.gz: c8b80f44d4a426e6b22e781c3b602c8a93b4e713e83ad5d19f2811fbdda5fb51534cc7e01a8fb708dece3dc8e1884f3c79b6bd56528f46a86875c48ef5bdd28b
7
+ data.tar.gz: b70024cf95327a99d3efe987c1f446031fb2b35e233f993a5cb7e8c35be851b7607fd47c9e2633d01d0f85f27bbde6dae6456ff7bf427f61368fefb53f57b9d9
@@ -14,37 +14,36 @@ class ScrimController extends Controller {
14
14
  static targets = ["scrim"];
15
15
 
16
16
  show(event) {
17
+ clipScreen(this);
17
18
  delete this.scrimTarget.dataset.hidden;
18
- document.body.style.height = "100vh";
19
- document.body.style.overflow = "hidden";
20
-
21
- if (!event.detail.dismiss) {
22
- this.scrimTarget.style.pointerEvents = "none";
19
+ if (event.detail.dismissable) {
20
+ this.scrimTarget.dataset.dismissable = "";
23
21
  }
24
22
  }
25
23
 
26
- hide(event) {
24
+ hide(event = null) {
25
+ delete this.scrimTarget.dataset.dismissable;
27
26
  this.scrimTarget.dataset.hidden = "";
28
- unclipScreen();
27
+ unclipScreen(this);
29
28
  }
30
29
 
31
30
  onClick(event) {
32
- window.dispatchEvent(new Event("scrim:hide"));
31
+ if (this.scrimTarget.dataset.dismissable) {
32
+ window.dispatchEvent(new Event("scrim:hide"));
33
+ }
33
34
  }
34
35
 
35
36
  disconnect() {
36
- this.scrimTarget.dataset.hidden = "";
37
- unclipScreen();
37
+ this.hide();
38
38
  super.disconnect();
39
39
  }
40
-
41
40
  }
42
41
 
43
42
  /**
44
43
  * Show the scrim element
45
44
  */
46
45
  function showScrim(dismiss = true) {
47
- window.dispatchEvent(new CustomEvent("scrim:show", { detail: { dismiss: dismiss }}));
46
+ window.dispatchEvent(new CustomEvent("scrim:show", { detail: { dismissable: dismiss } }));
48
47
  }
49
48
 
50
49
  /**
@@ -54,12 +53,22 @@ function hideScrim() {
54
53
  window.dispatchEvent(new Event("scrim:hide"));
55
54
  }
56
55
 
56
+ /**
57
+ * Clips body to viewport size
58
+ */
59
+ function clipScreen(controller) {
60
+ controller.previousHeight = document.body.style.height || "unset";
61
+ controller.previousOverflow = document.body.style.overflow || "unset";
62
+ document.body.style.height = "100vh";
63
+ document.body.style.overflow = "hidden";
64
+ }
65
+
57
66
  /**
58
67
  * Unclips body to viewport size
59
68
  */
60
- function unclipScreen() {
61
- document.body.style.height = "unset";
62
- document.body.style.overflow = "unset";
69
+ function unclipScreen(controller) {
70
+ document.body.style.height = controller.previousHeight;
71
+ document.body.style.overflow = controller.previousOverflow;
63
72
  }
64
73
 
65
74
  export { ScrimController as default, showScrim, hideScrim }
@@ -1,3 +1,3 @@
1
1
  module TurboModal
2
- VERSION = "0.3.3".freeze
2
+ VERSION = "0.3.4".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo_modal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Cornthwaite
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-05-11 00:00:00.000000000 Z
12
+ date: 2022-05-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails