Opened 10 years ago
Closed 7 years ago
#6302 closed enhancement (maybelater)
Add callbacks/events when ajax functions have finished
Reported by: | Bowromir | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Core | Keywords: | needs-patch, trac-tidy-2018 |
Cc: | roger@…, brajesh@… |
Description
It would be handy to provide a callback when AJAX actions have finished. This would allow developers to easily (re)load javascript functions in places like the activity stream and component directories.
Change History (21)
This ticket was mentioned in Slack in #buddypress by modemlooper. View the logs.
10 years ago
#4
@
10 years ago
Note -- jQuery provides a generic ajaxStop event handler that you can use: https://api.jquery.com/ajaxStop/
This works well in conjunction with the activity stream.
#6
@
10 years ago
As rogercoathup suggested, It can be accomplished via javascript.
I have been using ajaxComplete to register the handler and It works great fro the activity. You can evn sniff action etc
#8
@
10 years ago
tried that and it didn't work or I should say it keeps running during any ajax. Post code or your you lie ;P
#9
@
10 years ago
Hi modemlooper,
Here is the code example
jQuery( document ).ajaxComplete( function( evt, xhr, options ) { var action = get_var_in_query( 'action', options.data ) ; //switch switch( action ){ case 'post_update': console.log('Activity was posted'); break; } }); function get_var_in_query( item, str ){ var items; if( !str ) return false; var data_fields = str.split('&'); for( var i=0; i< data_fields.length; i++ ){ items = data_fields[i].split('='); if( items[0] == item ) return items[1]; } return false; }
I am using a helper function 'get_var_in_query' to find an item in the query string.
The above example should log into the console when the the activity is posted and a response is returned.
#11
@
10 years ago
In that case, we can add the following cases to the switch case(These are the ajax actions)
- activity_widget_filter for activity filter
- groups_filter
- members_filter
Also, It can be further customized by checking for 'filter' value to see which drop down item was selected.
Hope that helps :)
#12
@
10 years ago
yup, weird its working now. Had tried the exact thing earlier. doing this could be an issue if you placed and ajax method inside.
#13
@
10 years ago
- Keywords reporter-feedback added
- Milestone changed from Awaiting Review to Under Consideration
@Bowromir could you provide a basic example of the sort of change you'd like to see made to the core scripts? If it's a trivial non-breaking change, we could consider it for BP-Legacy, otherwise it will likely wait until we build a new template pack later this year (with brand new, non-crappy JS).
#14
@
10 years ago
@DJPaul -- when the rewrite of the JS is done, I guess you'll be using Backbone. In that case, liberal use of trigger callbacks would seem the best solution. Firing the triggers when filters etc. start / finish their work -- allowing 3rd party JS to hook in.
#16
@
10 years ago
add
jq(document).trigger('bp_activity_request', [ scope, filter ] );
to response function of bp_ajax_request = jq.post( ajaxurl, {
#17
@
10 years ago
- Keywords needs-patch added; reporter-feedback removed
- Milestone changed from Under Consideration to Future Release
Happy to have a look at a patch if someone wants to propose something minimal and non-invasive.
#18
@
9 years ago
Note: this project might provide useful foundation -- supports actions and filters on WP / JS
#20
@
7 years ago
- Keywords trac-tidy-2018 added
We're closing this ticket because it has not received any contribution or comments for at least two years. We have decided that it is better to close tickets that are good ideas, which have not gotten (or are unlikely to get) contributions, rather than keep things open indefinitely. This will help us share a more realistic roadmap for BuddyPress with you.
Everyone very much appreciates the time and effort that you spent sharing your idea with us. On behalf of the entire BuddyPress team, thank you.
If you feel strongly that this enhancement should still be added to BuddyPress, and you are able to contribute effort towards it, we encourage you to re-open the ticket, or start a discussion about it in our Slack channel. Please consider that time has proven that good ideas without contributions do not get built.
For more information, see https://bpdevel.wordpress.com/2018/01/21/our-awaiting-contributions-milestone-contains/
or find us on Slack, in the #buddypress channel: https://make.wordpress.org/chat/
i'll submit a patch needed triggers more than once.