mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
✨ Listeners for custom “refresh button” event
This commit is contained in:
parent
25c5ef2e9e
commit
5ed2f37bd4
2 changed files with 16 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
||||||
import {loadCustomScript} from "@paypal/paypal-js";
|
import {loadCustomScript} from "@paypal/paypal-js";
|
||||||
import {loadPaypalScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading";
|
import {loadPaypalScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading";
|
||||||
import ApplepayManager from "./ApplepayManager";
|
import ApplepayManager from "./ApplepayManager";
|
||||||
|
import { debounce } from '../../../ppcp-blocks/resources/js/Helper/debounce';
|
||||||
|
|
||||||
(function ({
|
(function ({
|
||||||
buttonConfig,
|
buttonConfig,
|
||||||
|
@ -15,19 +16,19 @@ import ApplepayManager from "./ApplepayManager";
|
||||||
manager.init();
|
manager.init();
|
||||||
};
|
};
|
||||||
|
|
||||||
jQuery(document.body).on('updated_cart_totals updated_checkout', () => {
|
const refresh = debounce(function() {
|
||||||
if (manager) {
|
if (manager) {
|
||||||
manager.reinit();
|
manager.reinit();
|
||||||
}
|
}
|
||||||
});
|
}, 50);
|
||||||
|
|
||||||
|
jQuery(document).on('ppcp_refresh_payment_buttons', refresh);
|
||||||
|
|
||||||
|
jQuery(document.body).on('updated_cart_totals updated_checkout', refresh);
|
||||||
|
|
||||||
// Use set timeout as it's unnecessary to refresh upon Minicart initial render.
|
// Use set timeout as it's unnecessary to refresh upon Minicart initial render.
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', () => {
|
jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', refresh);
|
||||||
if (manager) {
|
|
||||||
manager.reinit();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {loadCustomScript} from "@paypal/paypal-js";
|
import {loadCustomScript} from "@paypal/paypal-js";
|
||||||
import {loadPaypalScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading";
|
import {loadPaypalScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading";
|
||||||
import GooglepayManager from "./GooglepayManager";
|
import GooglepayManager from "./GooglepayManager";
|
||||||
|
import { debounce } from '../../../ppcp-blocks/resources/js/Helper/debounce';
|
||||||
|
|
||||||
(function ({
|
(function ({
|
||||||
buttonConfig,
|
buttonConfig,
|
||||||
|
@ -15,19 +16,19 @@ import GooglepayManager from "./GooglepayManager";
|
||||||
manager.init();
|
manager.init();
|
||||||
};
|
};
|
||||||
|
|
||||||
jQuery(document.body).on('updated_cart_totals updated_checkout', () => {
|
const refresh = debounce(function() {
|
||||||
if (manager) {
|
if (manager) {
|
||||||
manager.reinit();
|
manager.reinit();
|
||||||
}
|
}
|
||||||
});
|
}, 50);
|
||||||
|
|
||||||
|
jQuery(document).on('ppcp_refresh_payment_buttons', refresh);
|
||||||
|
|
||||||
|
jQuery(document.body).on('updated_cart_totals updated_checkout', refresh);
|
||||||
|
|
||||||
// Use set timeout as it's unnecessary to refresh upon Minicart initial render.
|
// Use set timeout as it's unnecessary to refresh upon Minicart initial render.
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', () => {
|
jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', refresh);
|
||||||
if (manager) {
|
|
||||||
manager.reinit();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue