global.js
931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import '../scss/common.scss';
/* global ajaxurl */
document.addEventListener('DOMContentLoaded', function () {
const dismissNoticeButton = document.querySelectorAll(
'.smush-dismissible-notice .smush-dismiss-notice-button'
);
dismissNoticeButton.forEach((button) => {
button.addEventListener('click', dismissNotice);
});
function dismissNotice(event) {
event.preventDefault();
const button = event.target;
const notice = button.closest('.smush-dismissible-notice');
const key = notice.getAttribute('data-key');
const xhr = new XMLHttpRequest();
xhr.open(
'POST',
ajaxurl + '?action=smush_dismiss_notice&key=' + key + '&_ajax_nonce=' + smush_global.nonce,
true
);
xhr.onload = () => {
if (notice) {
notice.querySelector('button.notice-dismiss').dispatchEvent(new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true
}));
}
};
xhr.send();
}
});