JavaScript Hooks and Events
There are common JavaScript hooks for Comment Edit Lite.
Last updated
There are common JavaScript hooks for Comment Edit Lite.
Last updated
Here are the common JavaScript hooks available in Comment Edit Core.
sce.comment.timer.text
FilterThe sce.comment.timer.text
filter allows developers to modify the text displayed by a timer before it is returned to the user interface. This filter is particularly useful for customizing the display of countdowns or time-related information in comments.
Introduced in version 1.4.0.
This filter receives the following parameters:
commentText (string
): The original text of the comment.
minuteText (string
): Text representation of minutes.
secondText (string
): Text representation of seconds.
numMinutesLeft (int
): The number of minutes remaining.
numSecondsLeft (int
): The number of seconds remaining.
To modify the timer text, add a filter function using wp.hooks.addFilter
. Here's an example:
sce.comment.save.data
FilterThe sce.comment.save.data
filter allows developers to modify the parameters sent during an AJAX request to save a comment. This filter is useful for adding or modifying data before the comment is saved.
Introduced in version 1.4.0.
This filter receives the following parameter:
ajaxSaveParams (object
): An object containing the parameters for the AJAX request. The default properties include:
action
(string
): The action identifier for the AJAX request, typically 'sce_save_comment'
.
comment_content
(string
): The content of the comment to be saved.
comment_id
(int
): The ID of the comment being saved.
post_id
(int
): The ID of the post associated with the comment.
nonce
(string
): A nonce for security purposes.
To modify the AJAX save parameters, add a filter function using wp.hooks.addFilter
. Here's an example:
sceCommentSavePost
Custom EventThe sceCommentSavePost
event is a custom JavaScript event triggered after a comment save action is initiated. This event is dispatched to provide additional hooks for custom functionality or integrations when a comment is being saved.
The event carries a detail
object with the following properties:
button (Element
): The button element that initiated the save action.
textarea (Element
): The textarea element containing the comment content.
commentId (int
): The ID of the comment being saved.
postId (int
): The ID of the post associated with the comment.
ajaxData (object
): The data object returned from the AJAX save request.
To listen to the sceCommentSavePost
event, add an event listener to the document
object. Here's an example:
sceTimerLoaded
Custom EventThe sceTimerLoaded
event is a custom JavaScript event that is triggered when a timer associated with a comment is loaded. This event provides a hook for developers to add custom functionality or integrations at the moment a comment timer is initialized.
The event includes a detail
object containing the following properties:
button (Element
): The button element related to the comment timer.
commentId (int
): The ID of the comment for which the timer is loaded.
postId (int
): The ID of the post associated with the comment.
To handle the sceTimerLoaded
event, you need to add an event listener to the document
object. Here's an example of how to do this:
sceTimerCountdown
Custom EventThe sceTimerCountdown
event is a custom JavaScript event that is triggered during the countdown of a comment timer. This event is designed to provide developers with a hook for implementing custom functionality or integrations that respond to the progression of the timer.
The event carries a detail
object with the following properties:
button (Element
): The button element associated with the comment timer.
commentId (int
): The ID of the comment for which the timer is counting down.
postId (int
): The ID of the post associated with the comment.
timer_seconds (int
): The current number of seconds remaining in the timer.
timer_minutes (int
): The current number of minutes remaining in the timer.
To listen to the sceTimerCountdown
event, add an event listener to the document
object. Here's an example:
sceEditTextareaShow
Custom EventThe sceEditTextareaShow
event is a custom JavaScript event that is triggered when the text area for editing a comment is displayed. This event provides a hook for developers to add custom functionality or integrations at the moment the text area for editing a comment becomes visible.
The event includes a detail
object containing the following properties:
textarea (Element
): The textarea element that is used for editing the comment.
commentId (int
): The ID of the comment being edited.
postId (int
): The ID of the post associated with the comment.
To handle the sceEditTextareaShow
event, you need to add an event listener to the document
object. Here's an example of how to do this:
sceCommentSavePre
Custom EventThe sceCommentSavePre
event is a custom JavaScript event that is triggered just before a comment save action is initiated. This event provides developers with an opportunity to implement custom logic or integrations immediately before the comment saving process begins.
The event includes a detail
object containing the following properties:
button (Element
): The button element that initiates the save action.
textarea (Element
): The textarea element containing the comment content.
commentId (int
): The ID of the comment being saved.
postId (int
): The ID of the post associated with the comment.
To handle the sceCommentSavePre
event, add an event listener to the document
object. Here's an example: