Skip to:
Content

BuddyPress.org

Opened 7 years ago

Closed 4 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)

#1 @swissspidy
7 years ago

  • Cc hello@… added

This ticket was mentioned in Slack in #buddypress by modemlooper. View the logs.


7 years ago

#3 @modemlooper
7 years ago

i'll submit a patch needed triggers more than once.

#4 @rogercoathup
7 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.

#5 @rogercoathup
7 years ago

  • Cc roger@… added

#6 @sbrajesh
7 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

https://api.jquery.com/ajaxComplete/

#7 @sbrajesh
7 years ago

  • Cc brajesh@… added

#8 @modemlooper
7 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

Last edited 7 years ago by modemlooper (previous) (diff)

#9 @sbrajesh
7 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.

#10 @modemlooper
7 years ago

oh, Bowe needs triggers for activity/groups/members filters

#11 @sbrajesh
7 years ago

In that case, we can add the following cases to the switch case(These are the ajax actions)

  1. activity_widget_filter for activity filter
  2. groups_filter
  3. 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 @modemlooper
7 years ago

yup, weird its working now. Had tried the exact thing earlier.

Version 0, edited 7 years ago by modemlooper (next)

#13 @DJPaul
7 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 @rogercoathup
7 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.

#15 @swissspidy
7 years ago

  • Cc hello@… removed

#16 @modemlooper
7 years ago

add

jq(document).trigger('bp_activity_request', [ scope, filter ] );

to response function of bp_ajax_request = jq.post( ajaxurl, {

#17 @DJPaul
7 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 @rogercoathup
6 years ago

Note: this project might provide useful foundation -- supports actions and filters on WP / JS

https://github.com/carldanley/WP-JS-Hooks

#19 @DJPaul
5 years ago

  • Component changed from Component - Any/All to Core

#20 @DJPaul
4 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/

#21 @DJPaul
4 years ago

  • Milestone Awaiting Contributions deleted
  • Resolution set to maybelater
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.