BuddyDev

Search

[Resolved] "Laod more" and "Refresh" in buddypress activity stream

  • Participant
    Level: Enlightened
    Posts: 33
    Nestor Djintelbé on #29717

    Hello,

    I am getting problem with “Load more” in my Buddypress activity stream.
    When I click the “Load More” on the buddypress activity it loads more but it does not refresh it. I want to make it “loads more” and refreshes at the same time after the load more is clicked.
    The raison I want that is I am using MathJax-Latex to render mathematical symbols and equations and it needs the page to be refreshed before redering them.

    Please help me. I need really that and I tried solving it myself several days but nothing.

    Best Regards

    Wordpress version: 5.4.1
    Buddypress version : 5.2.0

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #29718

    Hi
    Welcome to BuddyDev.

    Even though it is not feasible to reload and refresh at the same time(It is by using pagination but not recommended), There is a solution.
    I had a look at MathJAX api. The MathJAX provides a way to apply it on dynamically loaded content. So, that will resolve your issue.

    To help you with that, I will need the following

    1. Which version of MathJAX are you using(1.x or 2.x )
    2. Are you using any custom theme? If yes, which one?
    3. Which template pack(Nouveau or Legacy) are you using.

    Please let me know and I will assist.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 33
    Nestor Djintelbé on #29719

    Hello Brajesh,

    Thank you very much for your quick reply.

    I am using
    1. MathJax 3.x
    2. Theme: OceanWP
    3. Buddypress template: Legacy

    Thank you for assistance

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #29787

    Hi,
    My apologies for the delayed reply. I had to install OcenWp to see if the include custom js for BuddyPress or not.

    Please copy the plugins/buddypress/bp-templates/bp-legacy/buddypress/js/buddypress.js to your theme/buddyoress/js/buddypress.js and look for the code which looks like this

    
    
    		/* Load more updates at the end of the page */
    		if ( target.parent().hasClass('load-more') ) {
    			if ( bp_ajax_request ) {
    				bp_ajax_request.abort();
    			}
    
    			jq('#buddypress li.load-more').addClass('loading');
    
    			oldest_page = activity_oldestpage + 1;
    			just_posted = [];
    
    			jq('.activity-list li.just-posted').each( function(){
    				just_posted.push( jq(this).attr('id').replace( 'activity-','' ) );
    			});
    
    			load_more_args = {
    				action: 'activity_get_older_updates',
    				'cookie': bp_get_cookies(),
    				'page': oldest_page,
    				'exclude_just_posted': just_posted.join(',')
    			};
    
    			load_more_search = bp_get_querystring('s');
    
    			if ( load_more_search ) {
    				load_more_args.search_terms = load_more_search;
    			}
    
    			bp_ajax_request = jq.post( ajaxurl, load_more_args,
    			function(response)
    			{
    				jq('#buddypress li.load-more').removeClass('loading');
    				activity_oldestpage = oldest_page;
    				jq('#buddypress ul.activity-list').append(response.contents);
    
    				target.parent().hide();
    			}, 'json' );
    
    			return false;
    		}
    
    

    It is around line 431, we need to add 1 line

    
    MathJax.typeset();
    

    as shown below.

    
    		/* Load more updates at the end of the page */
    		if ( target.parent().hasClass('load-more') ) {
    			if ( bp_ajax_request ) {
    				bp_ajax_request.abort();
    			}
    
    			jq('#buddypress li.load-more').addClass('loading');
    
    			oldest_page = activity_oldestpage + 1;
    			just_posted = [];
    
    			jq('.activity-list li.just-posted').each( function(){
    				just_posted.push( jq(this).attr('id').replace( 'activity-','' ) );
    			});
    
    			load_more_args = {
    				action: 'activity_get_older_updates',
    				'cookie': bp_get_cookies(),
    				'page': oldest_page,
    				'exclude_just_posted': just_posted.join(',')
    			};
    
    			load_more_search = bp_get_querystring('s');
    
    			if ( load_more_search ) {
    				load_more_args.search_terms = load_more_search;
    			}
    
    			bp_ajax_request = jq.post( ajaxurl, load_more_args,
    			function(response)
    			{
    				jq('#buddypress li.load-more').removeClass('loading');
    				activity_oldestpage = oldest_page;
    				jq('#buddypress ul.activity-list').append(response.contents);
    
    				target.parent().hide();
                                   // New line added. 
                                   MathJax.typeset();
    			}, 'json' );
    
    			return false;
    		}
    
    

    You will need to rename the file to buddypress.min.js (or you can minify and name the new file as this) and BuddyPress will load it.

    All we are doing is folllowing the re-initialization for MatchJAX as specified here
    https://docs.mathjax.org/en/latest/web/typeset.html#resetting-automatic-equation-numbering

    That should take care of it.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 33
    Nestor Djintelbé on #29839

    Hello Brajesh,

    Thank you for your reply.
    Your proposition worked perfectly. Now I can “load more” and it render me beautiful latex equations. I have also tried to apply the solution to others parts of activity stream like “Load newest” post and “Posting new” post; all worked very fine. I don’t know how to thank you; I am very grateful to you.

    I am doing to ask you again, excuse for that. As I said, I can load dynamically mathjax in some part of activity stream but I were not able to do it for “Comments”, “Edit” and “Select activities”; I tried to paste the code everywhere in the buddypress.js since yesterday but it did not work. When the reply for comments is sent, edit of existing post is saved and activity categorie is selected, MathaJax-Latex equations are not rendered. So, I am asking for the places I can paste the code MathJax.typeset() to solve these problems. I don’t know if it is possible to paste the magic code in one place so that it can work for entire activies.
    Maybe it is important to precise that “Edit” comes from Buddypress Edit Activity plugin.

    Best Regards

    Nestor

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #29841

    Hi Nestor,
    You are welcome.

    I am not sure what “Select activities” is. Also, I do not use BP Edit Activity, so I regret my inability to assit with these 2.

    I will help with the comments though.

    Please look for a section

    
    			jq.post( ajaxurl, ajaxdata, function(response) {
    				target.removeClass('loading');
    				content.removeClass('loading');
    
    				/* Check for errors and append if found. */
    				if ( response[0] + response[1] === '-1' ) {
    					form.append( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
    				} else {
    					var activity_comments = form.parent();
    					form.fadeOut( 200, function() {
    						if ( 0 === activity_comments.children('ul').length ) {
    							if ( activity_comments.hasClass('activity-comments') ) {
    								activity_comments.prepend('<ul></ul>');
    							} else {
    								activity_comments.append('<ul></ul>');
    							}
    						}
    
    						/* Preceding whitespace breaks output with jQuery 1.9.0 */
    						var the_comment = jq.trim( response );
    
    						activity_comments.children('ul').append( jq( the_comment ).hide().fadeIn( 200 ) );
    						form.children('textarea').val('');
    						activity_comments.parent().addClass('has-comments');
    					} );
    					jq( '#' + form.attr('id') + ' textarea').val('');
    
    					/* Increase the "Reply (X)" button count */
    					new_count = Number( jq('#activity-' + form_id[2] + ' a.acomment-reply span').html() ) + 1;
    					jq('#activity-' + form_id[2] + ' a.acomment-reply span').html( new_count );
    
    					// Increment the 'Show all x comments' string, if present
    					show_all_a = activity_comments.parents('.activity-comments').find('.show-all a');
    					if ( show_all_a ) {
    						show_all_a.html( BP_DTheme.show_x_comments.replace( '%d', new_count ) );
    					}
    				}
    
    				jq(target).prop('disabled', false);
    				jq(content).prop('disabled', false);
    			});
    

    It starts around line 625

    and you can add that line just below “jq(content).prop(‘disabled’, false);” like

    
    
    jq(content).prop('disabled', false);
    MathJax.typeset();
    

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 33
    Nestor Djintelbé on #29852

    Hello Brajesh,

    Thank you very much.

    I tried the code for comments but it is not working well. It doesn’t render the current comment but if I put a second comment, it renders very well the latex equation of the comment above but not that second comment and so on…

    By “Select activities”, I am talking about “show activiies” at the top of activity page. By default, it display “All” activities and one can select to display by “new members”, “contacts”, ect. I am using the French version of plugin because of that I have difficulties to retranslate with the right words (I am not good in English).

    For BP Edit activity, can I copy the buddypress-edit-activity.js to the directory of my theme as you show me for buddypress.js and try to pass the code MathJax.typeset() somewhere?

    Best Regards,

    Nestor

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #29882

    Hi Nestor,
    In that case, add atime delay before applying the MathJax.typeset();

    That should most probably fix it.

    something like this

    
    
    setTimeout(function() {
     MathJax.typeset();
    }, 300);
    
    

    I believe the dom insertion might be the case, so delaying the running of MathJax.typeset() might fix it.

    For activity tabs, you should look for this function ‘bp_activity_request’

    As of BP Edit activity, It is a 3rd party plugin that works with BuddyPress. We offer limited support for BuddyPress here. We do not offer support for other 3rd party plugins.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 33
    Nestor Djintelbé on #29898

    Hello Brajesh,

    Yes, it works! You are the best; I have never seen that! Thank you so much; thank you for helping people. I am very grateful to you.

    For the BP Edit Activity plugin, as you said, I understand well. I will uninstall it and leave the posts without editing.

    Thank you very much!

    Best Regards

    Nestor

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #29905

    Hi Nestor,
    You are welcome.

    I am glad I was able to assist.

    Best Regards
    Brajesh

The topic ‘ [Resolved] "Laod more" and "Refresh" in buddypress activity stream’ is closed to new replies.

This topic is: resolved