rails_modal_manager 1.0.52 → 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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5a176f75787294b2e24e87ca52d21f8320ba48687479ad7e68433525d1dc9ca2
|
|
4
|
+
data.tar.gz: 13de8b01baca4cd5e78b50d0578730ccf01812056241cdf2017b1f88fd8e050d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
@@ -26,9 +26,11 @@ function renderButtonHtml(btn) {
|
|
|
26
26
|
const attrs = [`class="${classes.join(" ")}"`]
|
|
27
27
|
if (btn.disabled || btn.loading) attrs.push("disabled")
|
|
28
28
|
if (btn.action) attrs.push(`data-action="${escapeHtml(btn.action)}"`)
|
|
29
|
-
// v1.0.
|
|
30
|
-
//
|
|
31
|
-
|
|
29
|
+
// v1.0.53+: onclick 을 `data-rmm-onclick` 속성에 저장하고 setModalFooter 가
|
|
30
|
+
// 렌더 직후 실제 click listener 로 바인딩. innerHTML 로 박힌 inline `onclick`
|
|
31
|
+
// 은 일부 환경(CSP, 특정 브라우저 파싱) 에서 핸들러로 등록되지 않는 경우가 있어
|
|
32
|
+
// 이 방식으로 확실히 동작시킴.
|
|
33
|
+
if (btn.onclick) attrs.push(`data-rmm-onclick="${escapeHtml(btn.onclick)}"`)
|
|
32
34
|
if (btn.id) attrs.push(`data-button-id="${escapeHtml(btn.id)}"`)
|
|
33
35
|
|
|
34
36
|
return `<button type="button" ${attrs.join(" ")}>${escapeHtml(btn.label || "")}</button>`
|
|
@@ -63,6 +65,20 @@ export function setModalFooter(modal, buttons = [], message = null) {
|
|
|
63
65
|
// 우측 버튼 영역
|
|
64
66
|
right.innerHTML = (buttons || []).map(renderButtonHtml).join("")
|
|
65
67
|
|
|
68
|
+
// v1.0.53+: data-rmm-onclick 속성을 실제 click 이벤트 리스너로 바인딩
|
|
69
|
+
right.querySelectorAll("[data-rmm-onclick]").forEach(function(btn) {
|
|
70
|
+
const code = btn.getAttribute("data-rmm-onclick")
|
|
71
|
+
btn.removeAttribute("data-rmm-onclick")
|
|
72
|
+
btn.addEventListener("click", function() {
|
|
73
|
+
try {
|
|
74
|
+
// 버튼 본인을 `this` 로 전달 (호출측에서 this.dataset 등 접근 가능)
|
|
75
|
+
new Function(code).call(btn)
|
|
76
|
+
} catch (e) {
|
|
77
|
+
console.warn("[rmm-footer] onclick handler error:", e)
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
66
82
|
// 교체 이벤트 dispatch (앱에서 후처리 원할 경우용)
|
|
67
83
|
footer.dispatchEvent(
|
|
68
84
|
new CustomEvent("rmm-footer:updated", {
|
|
@@ -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>
|