-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
1,105 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,64 @@ | ||
import jQuery from 'jquery'; | ||
/** | ||
* WordPress dependencies. | ||
*/ | ||
import apiFetch from '@wordpress/api-fetch'; | ||
import domReady from '@wordpress/dom-ready'; | ||
|
||
/** | ||
* Window dependencies. | ||
*/ | ||
const { epAdmin, ajaxurl } = window; | ||
|
||
jQuery('.notice').on('click', '.notice-dismiss', (event) => { | ||
const notice = event.delegateTarget.getAttribute('data-ep-notice'); | ||
/** | ||
* Initialize. | ||
* | ||
* @returns {void} | ||
*/ | ||
const init = () => { | ||
const notices = document.querySelectorAll('.notice[data-ep-notice]'); | ||
|
||
if (!notice) { | ||
return; | ||
/** | ||
* Handle clicking in an ElasticPress notice. | ||
* | ||
* If the click target is the dismiss button send an AJAX request to remember | ||
* the dismissal. | ||
* | ||
* @param {Event} event Click event. | ||
* @returns {void} | ||
*/ | ||
const onClick = (event) => { | ||
/** | ||
* Only proceed if we're clicking dismiss. | ||
*/ | ||
if (!event.target.classList.contains('notice-dismiss')) { | ||
return; | ||
} | ||
|
||
/** | ||
* Handler is admin-ajax.php, so the body needs to be form data. | ||
*/ | ||
const formData = new FormData(); | ||
|
||
formData.append('action', 'ep_notice_dismiss'); | ||
formData.append('notice', event.currentTarget.dataset.epNotice); | ||
formData.append('nonce', epAdmin.nonce); | ||
|
||
apiFetch({ | ||
method: 'POST', | ||
url: ajaxurl, | ||
body: formData, | ||
}); | ||
}; | ||
|
||
/** | ||
* Bind click events to notices. | ||
*/ | ||
for (const notice of notices) { | ||
notice.addEventListener('click', onClick); | ||
} | ||
}; | ||
|
||
jQuery.ajax({ | ||
method: 'post', | ||
data: { | ||
nonce: epAdmin.nonce, | ||
action: 'ep_notice_dismiss', | ||
notice, | ||
}, | ||
url: ajaxurl, | ||
}); | ||
}); | ||
/** | ||
* Initialize. | ||
*/ | ||
domReady(init); |
Oops, something went wrong.