rails_modal_manager 1.0.53 → 1.0.54

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: f5ea3c9a0f748719fffb7a377e31eb8ffa82aa92a51fe5e57d0c9e766757f6bd
4
- data.tar.gz: 299fa546552e45abccac98ddd60d258b8b24d8a5ffe3b4e8c8e5647df5b63003
3
+ metadata.gz: 5a176f75787294b2e24e87ca52d21f8320ba48687479ad7e68433525d1dc9ca2
4
+ data.tar.gz: 13de8b01baca4cd5e78b50d0578730ccf01812056241cdf2017b1f88fd8e050d
5
5
  SHA512:
6
- metadata.gz: 577924acb8554d70314b4380100d2f6c72ffed2216fb43f78c6197007508e833b35c11f527644cf8ca3e2115cfd06328bb3fa74b7c4eb648336ba3a94587f779
7
- data.tar.gz: f56d2917b83eab179ec1a54e9cf3654e0c81e3e3fe778d0982279d13c18e859dd069f1d7bf73238c0771ddea72d1dbe0b6d189db039bfc0892ad7bfce414b877
6
+ metadata.gz: 6f444d0b166c4e32ef0af8c17a3b51a4402c34631ef55e39d2ad09a984abe7ecf07b34fc3212f96e73f82f50cd34116195e635e3d7caa9e8cb30728eb7e8bb1c
7
+ data.tar.gz: ebe7588251b75cdedc70d5fcd73fb32f42c1afacdf5594981ef06244af9e46c7f37437926e4fcf29acbd29b0172e7a3cb77a4c431c21d9631dc0a41eb1bc2710
@@ -72,12 +72,41 @@ export default class extends Controller {
72
72
  // Subscribe to store changes
73
73
  this.unsubscribe = modalStore.subscribe(() => this.handleStoreChange())
74
74
 
75
+ // v1.0.54+: Bind `data-rmm-onclick` on footer buttons rendered by the ERB partial.
76
+ // Matches the binding path in setModalFooter() so footer buttons declared via the
77
+ // footer_buttons: [{ onclick: "..." }] option work regardless of whether the footer
78
+ // was rendered by the server ERB or replaced dynamically by setModalFooter.
79
+ this._bindFooterOnclicks()
80
+
75
81
  // Check if should be open on connect
76
82
  if (this.openValue) {
77
83
  this.open()
78
84
  }
79
85
  }
80
86
 
87
+ /**
88
+ * Bind data-rmm-onclick attributes on footer buttons as real click listeners.
89
+ * Idempotent: each button bound only once (tracked via _rmmOnclickBound flag).
90
+ * Called on connect; setModalFooter() handles its own buttons when it replaces the footer.
91
+ */
92
+ _bindFooterOnclicks() {
93
+ const footer = this.element.querySelector(".rmm-footer")
94
+ if (!footer) return
95
+ footer.querySelectorAll("[data-rmm-onclick]").forEach((btn) => {
96
+ if (btn._rmmOnclickBound) return
97
+ btn._rmmOnclickBound = true
98
+ const code = btn.getAttribute("data-rmm-onclick")
99
+ btn.addEventListener("click", function() {
100
+ try {
101
+ // `this` inside onclick code refers to the clicked button element
102
+ new Function(code).call(this)
103
+ } catch (e) {
104
+ console.warn("[rmm-footer] onclick handler error:", e)
105
+ }
106
+ })
107
+ })
108
+ }
109
+
81
110
  // Getter for effective modal ID (fallback to element.id if modalIdValue is empty)
82
111
  get effectiveModalId() {
83
112
  return this.modalIdValue || this.element.id
@@ -4,8 +4,10 @@
4
4
  Locals:
5
5
  modal_id: String - The modal ID
6
6
  message: String - Footer message (optional)
7
- buttons: Array - Footer buttons [{id:, label:, variant:, disabled:, loading:, action:}]
7
+ buttons: Array - Footer buttons [{id:, label:, variant:, disabled:, loading:, action:, onclick:}]
8
8
  variant: primary, secondary, danger, success, warning
9
+ onclick: JavaScript code string. Bound as click listener on modal connect
10
+ (v1.0.54+) so it works even without setModalFooter JS path.
9
11
  %>
10
12
  <%
11
13
  modal_id ||= ""
@@ -30,6 +32,7 @@
30
32
  class="<%= btn_classes.join(' ') %>"
31
33
  <% if btn[:disabled] || btn[:loading] %>disabled<% end %>
32
34
  <% if btn[:action] %>data-action="<%= btn[:action] %>"<% end %>
35
+ <% if btn[:onclick] %>data-rmm-onclick="<%= btn[:onclick] %>"<% end %>
33
36
  data-button-id="<%= btn[:id] %>">
34
37
  <%= btn[:label] %>
35
38
  </button>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsModalManager
4
- VERSION = "1.0.53"
4
+ VERSION = "1.0.54"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_modal_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.53
4
+ version: 1.0.54
5
5
  platform: ruby
6
6
  authors:
7
7
  - reshacs