mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +08:00
Remove the "Error:" prefix front he front-end facing error message The notice has already the error state and it's implied
31 lines
709 B
JavaScript
31 lines
709 B
JavaScript
class ErrorHandler {
|
|
|
|
constructor()
|
|
{
|
|
this.wrapper = document.querySelector('.woocommerce-notices-wrapper');
|
|
}
|
|
|
|
message(text)
|
|
{
|
|
this.wrapper.classList.add('woocommerce-error');
|
|
this.wrapper.innerText = this.sanitize(text);
|
|
}
|
|
|
|
sanitize(text)
|
|
{
|
|
const textarea = document.createElement('textarea');
|
|
textarea.innerHTML = text;
|
|
return textarea.value.replace('Error: ', '');
|
|
}
|
|
|
|
clear()
|
|
{
|
|
if (! this.wrapper.classList.contains('woocommerce-error')) {
|
|
return;
|
|
}
|
|
this.wrapper.classList.remove('woocommerce-error');
|
|
this.wrapper.innerText = '';
|
|
}
|
|
}
|
|
|
|
export default ErrorHandler;
|