mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge branch 'task/shared-apple-google' into feat/PCP-154-apple-pay-payment
This commit is contained in:
commit
a64bd0b762
5 changed files with 76 additions and 24 deletions
|
@ -9,6 +9,24 @@ const getElement = (selectorOrElement) => {
|
|||
return selectorOrElement;
|
||||
}
|
||||
|
||||
const triggerEnabled = (selectorOrElement, element) => {
|
||||
jQuery(document).trigger('ppcp-enabled', {
|
||||
'handler': 'ButtonsDisabler.setEnabled',
|
||||
'action': 'enable',
|
||||
'selector': selectorOrElement,
|
||||
'element': element
|
||||
});
|
||||
}
|
||||
|
||||
const triggerDisabled = (selectorOrElement, element) => {
|
||||
jQuery(document).trigger('ppcp-disabled', {
|
||||
'handler': 'ButtonsDisabler.setEnabled',
|
||||
'action': 'disable',
|
||||
'selector': selectorOrElement,
|
||||
'element': element
|
||||
});
|
||||
}
|
||||
|
||||
export const setEnabled = (selectorOrElement, enable, form = null) => {
|
||||
const element = getElement(selectorOrElement);
|
||||
|
||||
|
@ -17,7 +35,8 @@ export const setEnabled = (selectorOrElement, enable, form = null) => {
|
|||
}
|
||||
|
||||
if (enable) {
|
||||
jQuery(element).css({
|
||||
jQuery(element).removeClass('ppcp-disabled')
|
||||
.css({
|
||||
'cursor': '',
|
||||
'-webkit-filter': '',
|
||||
'filter': '',
|
||||
|
@ -25,8 +44,12 @@ export const setEnabled = (selectorOrElement, enable, form = null) => {
|
|||
.off('mouseup')
|
||||
.find('> *')
|
||||
.css('pointer-events', '');
|
||||
|
||||
triggerEnabled(selectorOrElement, element);
|
||||
|
||||
} else {
|
||||
jQuery(element).css({
|
||||
jQuery(element).addClass('ppcp-disabled')
|
||||
.css({
|
||||
'cursor': 'not-allowed',
|
||||
'-webkit-filter': 'grayscale(100%)',
|
||||
'filter': 'grayscale(100%)',
|
||||
|
@ -44,6 +67,8 @@ export const setEnabled = (selectorOrElement, enable, form = null) => {
|
|||
})
|
||||
.find('> *')
|
||||
.css('pointer-events', 'none');
|
||||
|
||||
triggerDisabled(selectorOrElement, element);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -9,6 +9,24 @@ const getElement = (selectorOrElement) => {
|
|||
return selectorOrElement;
|
||||
}
|
||||
|
||||
const triggerHidden = (handler, selectorOrElement, element) => {
|
||||
jQuery(document).trigger('ppcp-hidden', {
|
||||
'handler': handler,
|
||||
'action': 'hide',
|
||||
'selector': selectorOrElement,
|
||||
'element': element
|
||||
});
|
||||
}
|
||||
|
||||
const triggerShown = (handler, selectorOrElement, element) => {
|
||||
jQuery(document).trigger('ppcp-shown', {
|
||||
'handler': handler,
|
||||
'action': 'show',
|
||||
'selector': selectorOrElement,
|
||||
'element': element
|
||||
});
|
||||
}
|
||||
|
||||
export const isVisible = (element) => {
|
||||
return !!(element.offsetWidth || element.offsetHeight || element.getClientRects().length);
|
||||
}
|
||||
|
@ -27,14 +45,18 @@ export const setVisible = (selectorOrElement, show, important = false) => {
|
|||
}
|
||||
|
||||
element.style.setProperty('display', 'none', important ? 'important' : '');
|
||||
triggerHidden('Hiding.setVisible', selectorOrElement, element);
|
||||
|
||||
} else {
|
||||
if (currentValue === 'none') {
|
||||
element.style.removeProperty('display');
|
||||
triggerShown('Hiding.setVisible', selectorOrElement, element);
|
||||
}
|
||||
|
||||
// still not visible (if something else added display: none in CSS)
|
||||
if (!isVisible(element)) {
|
||||
element.style.setProperty('display', 'block');
|
||||
triggerShown('Hiding.setVisible', selectorOrElement, element);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -47,8 +69,10 @@ export const setVisibleByClass = (selectorOrElement, show, hiddenClass) => {
|
|||
|
||||
if (show) {
|
||||
element.classList.remove(hiddenClass);
|
||||
triggerShown('Hiding.setVisibleByClass', selectorOrElement, element);
|
||||
} else {
|
||||
element.classList.add(hiddenClass);
|
||||
triggerHidden('Hiding.setVisibleByClass', selectorOrElement, element);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -7,8 +7,7 @@ import {keysToCamelCase} from "./Utils";
|
|||
// This component may be used by multiple modules. This assures that options are shared between all instances.
|
||||
let options = window.ppcpWidgetBuilder = window.ppcpWidgetBuilder || {
|
||||
isLoading: false,
|
||||
onLoadedCallbacks: [],
|
||||
loadingWaitTime: 5000 // 5 seconds
|
||||
onLoadedCallbacks: []
|
||||
};
|
||||
|
||||
export const loadPaypalScript = (config, onLoaded) => {
|
||||
|
@ -27,13 +26,6 @@ export const loadPaypalScript = (config, onLoaded) => {
|
|||
}
|
||||
options.isLoading = true;
|
||||
|
||||
// Arm a timeout so the module isn't locked on isLoading state on failure.
|
||||
let loadingTimeout = setTimeout(() => {
|
||||
console.error('Failed to load PayPal script.');
|
||||
options.isLoading = false;
|
||||
options.onLoadedCallbacks = [];
|
||||
}, options.loadingWaitTime);
|
||||
|
||||
// Callback to be called once the PayPal script is loaded.
|
||||
const callback = (paypal) => {
|
||||
widgetBuilder.setPaypal(paypal);
|
||||
|
@ -44,7 +36,6 @@ export const loadPaypalScript = (config, onLoaded) => {
|
|||
|
||||
options.isLoading = false;
|
||||
options.onLoadedCallbacks = [];
|
||||
clearTimeout(loadingTimeout);
|
||||
}
|
||||
|
||||
// Build the PayPal script options.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue