2020-04-02 08:38:00 +03:00
|
|
|
class ErrorHandler {
|
|
|
|
|
2020-04-06 11:16:18 +03:00
|
|
|
constructor()
|
|
|
|
{
|
2020-04-02 08:38:00 +03:00
|
|
|
this.wrapper = document.querySelector('.woocommerce-notices-wrapper');
|
|
|
|
}
|
|
|
|
|
2020-04-06 11:16:18 +03:00
|
|
|
message(text)
|
|
|
|
{
|
2020-04-02 08:38:00 +03:00
|
|
|
this.wrapper.classList.add('woocommerce-error');
|
|
|
|
this.wrapper.innerText = this.sanitize(text);
|
|
|
|
}
|
|
|
|
|
2020-04-06 11:16:18 +03:00
|
|
|
sanitize(text)
|
|
|
|
{
|
2020-04-02 08:38:00 +03:00
|
|
|
const textarea = document.createElement('textarea');
|
|
|
|
textarea.innerHTML = text;
|
|
|
|
return textarea.value;
|
|
|
|
}
|
|
|
|
|
2020-04-06 11:16:18 +03:00
|
|
|
clear()
|
|
|
|
{
|
2020-04-02 08:38:00 +03:00
|
|
|
if (! this.wrapper.classList.contains('woocommerce-error')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.wrapper.classList.remove('woocommerce-error');
|
|
|
|
this.wrapper.innerText = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ErrorHandler;
|