woocommerce-paypal-payments/modules.local/ppcp-button/resources/js/modules/ErrorHandler.js

27 lines
669 B
JavaScript
Raw Normal View History

2020-04-02 08:38:00 +03:00
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;
}
clear() {
if (! this.wrapper.classList.contains('woocommerce-error')) {
return;
}
this.wrapper.classList.remove('woocommerce-error');
this.wrapper.innerText = '';
}
}
export default ErrorHandler;