Skip to content

Commit 669f86a

Browse files
committed
fix dialog option
1 parent b446480 commit 669f86a

File tree

5 files changed

+69
-61
lines changed

5 files changed

+69
-61
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codebarista/buybuttonstatesynchronizer",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "Allows multiple plugins to control the buy button state.",
55
"type": "shopware-platform-plugin",
66
"license": "MIT",

src/Resources/app/storefront/dist/storefront/js/barista-buy-button-state-synchronizer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Resources/app/storefront/src/buybuttonstatesynchronizer/buybuttonstatesynchronizer.plugin.js

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default class BuyButtonStateSynchronizer extends Plugin {
117117
if (event.code == "Enter" || event.code == "NumpadEnter") {
118118
return this.onBuyButtonClicked(event);
119119
}
120-
})
120+
});
121121
}
122122

123123
buyButtonNodeChanged() {
@@ -155,46 +155,51 @@ export default class BuyButtonStateSynchronizer extends Plugin {
155155
return true;
156156
}
157157

158-
// Create a button for each registered action
159-
const actionButtons = [];
160-
for (const actionID in window.buyButtonStateSynchronizerActions) {
161-
const action = window.buyButtonStateSynchronizerActions[actionID];
162-
if (action.label != null) {
163-
const actionButton = document.createElement("button");
164-
actionButton.classList.add("btn", "btn-primary");
165-
actionButton.innerHTML = action.label;
166-
actionButton.onclick = (e) => {
167-
$("#buy-button-state-synchronizer-modal").modal("hide");
168-
action.callback(e);
169-
};
170-
actionButtons.push(actionButton);
158+
const dialog = document.querySelector(
159+
"#buy-button-state-synchronizer-modal"
160+
);
161+
162+
if (dialog) {
163+
// Create a button for each registered action
164+
const actionButtons = [];
165+
for (const actionID in window.buyButtonStateSynchronizerActions) {
166+
const action = window.buyButtonStateSynchronizerActions[actionID];
167+
if (action.label != null) {
168+
const actionButton = document.createElement("button");
169+
actionButton.classList.add("btn", "btn-primary");
170+
actionButton.innerHTML = action.label;
171+
actionButton.onclick = (e) => {
172+
dialog.close();
173+
action.callback(e);
174+
};
175+
actionButtons.push(actionButton);
176+
}
171177
}
172-
}
173-
if (actionButtons.length > 0) {
174-
// Preserve the cancel button
175-
actionButtons.push(
176-
document.getElementById(
177-
"buy-button-state-synchronizer-modal-cancel-btn"
178-
)
179-
);
178+
if (actionButtons.length === 0) {
179+
// If there is no labled action for which a button in the dialog
180+
// can be shown we search for an action that we can invoke
181+
for (const actionID in window.buyButtonStateSynchronizerActions) {
182+
const action = window.buyButtonStateSynchronizerActions[actionID];
183+
if (action.callback != null) {
184+
action.callback();
185+
e.preventDefault();
186+
return false;
187+
}
188+
}
189+
}
190+
// Add cancel button
191+
const actionButton = document.createElement("button");
192+
actionButton.classList.add("btn", "btn-secondary");
193+
actionButton.innerHTML = dialog.getAttribute("data-cancel-btn-label");
194+
actionButton.onclick = () => dialog.close();
195+
actionButtons.push(actionButton);
180196
// Replace all buttons
181197
document
182198
.getElementById("buy-button-state-synchronizer-modal-actions")
183199
.replaceChildren(...actionButtons);
184-
} else {
185-
// If there is no labled action for which a button in the dialog
186-
// can be shown we search for an action that we can invole
187-
for (const actionID in window.buyButtonStateSynchronizerActions) {
188-
const action = window.buyButtonStateSynchronizerActions[actionID];
189-
if (action.callback != null) {
190-
action.callback();
191-
e.preventDefault();
192-
return false;
193-
}
194-
}
195-
}
196200

197-
$("#buy-button-state-synchronizer-modal").modal("show");
201+
dialog.showModal();
202+
}
198203
e.preventDefault();
199204
return false;
200205
}
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
#buy-button-state-synchronizer-modal .modal-footer {
1+
#buy-button-state-synchronizer-modal {
2+
border: 0;
3+
padding: 1.75rem;
4+
box-shadow: 43px 43px -6px rgba(0, 0, 0, 0.2);
5+
.modal-footer {
26
border-top: 0;
37
gap: 10px;
48
flex-wrap: wrap;
59
justify-content: flex-start;
610

711
> button {
8-
flex: 1 auto;
9-
margin: 0;
12+
flex: 1 auto;
13+
margin: 0;
1014
}
15+
}
1116
}
1217

1318
#buy-button-state-synchronizer-modal-cancel-btn {
14-
flex: 1 auto;
15-
display: flex;
16-
justify-content: flex-end;
17-
}
19+
flex: 1 auto;
20+
display: flex;
21+
justify-content: flex-end;
22+
}

src/Resources/views/storefront/page/product-detail/buy-widget-form.html.twig

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@
22

33

44
{% block page_product_detail_buy_form_inner %}
5-
{% if config('BuyButtonStateSynchronizer').config.showDialogInsteadOfDisableButton %}
6-
<div id="buy-button-state-synchronizer-modal" class="modal" tabindex="-1" role="dialog" data-backdrop="static">
7-
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
8-
<div class="modal-content">
9-
<div class="modal-body">
10-
<p>{{ 'buybuttonstate.product-not-ready' | trans }}</p>
11-
</div>
12-
<div id="buy-button-state-synchronizer-modal-actions" class="modal-footer">
13-
<div id="buy-button-state-synchronizer-modal-cancel-btn">
14-
<button
15-
type="button"
16-
class="btn btn-secondary"
17-
data-dismiss="modal">
18-
{{ 'buybuttonstate.cancel' | trans }}
19-
</button>
20-
</div>
5+
{% if config('BaristaBuyButtonStateSynchronizer').config.showDialogInsteadOfDisableButton %}
6+
<dialog id="buy-button-state-synchronizer-modal" data-cancel-btn-label="{{ 'buybuttonstate.cancel' | trans }}">
7+
<div class="modal-content">
8+
<div class="modal-body">
9+
<p>{{ 'buybuttonstate.product-not-ready' | trans }}</p>
10+
</div>
11+
<div id="buy-button-state-synchronizer-modal-actions" class="modal-footer">
12+
<div id="buy-button-state-synchronizer-modal-cancel-btn">
13+
<button
14+
type="button"
15+
class="btn btn-secondary"
16+
data-dismiss="modal">
17+
{{ 'buybuttonstate.cancel' | trans }}
18+
</button>
2119
</div>
2220
</div>
2321
</div>
24-
</div>
22+
</dialog>
2523
{% endif %}
2624
{{ parent() }}
2725
{% endblock %}

0 commit comments

Comments
 (0)