Skip to:
Content

BuddyPress.org

Changeset 7470


Ignore:
Timestamp:
10/23/2013 07:11:32 PM (13 years ago)
Author:
r-a-y
Message:

Scroll to top when clicking on bottom pagination links in BP loops.

If a user clicks on a pagination link located at the bottom of any BP loop
(members, groups), the loop will refresh with AJAX, but will not scroll to
the top of the page. This isn't so great for UX.

This commit adds the ability to scroll to top when a bottom-paginated
link is clicked.

In order for this to work, an additional parameter ('caller') was added to
the bp_filter_request() JS function to determine where the link was called
from.

Fixes #5206.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-templates/bp-legacy/js/buddypress.js

    r7458 r7470  
    750750                        var object = css_id[0];
    751751                        var search_terms = false;
     752                        var pagination_id = jq(target).closest('.pagination-links').attr('id');
    752753
    753754                        if ( jq('div.dir-search input').length )
     
    760761                        else
    761762                                var page_number = Number( jq(target).html() );
    762 
    763                         bp_filter_request( object, jq.cookie('bp-' + object + '-filter'), jq.cookie('bp-' + object + '-scope'), 'div.' + object, search_terms, page_number, jq.cookie('bp-' + object + '-extras') );
     763                       
     764                        if ( pagination_id.indexOf( 'pag-bottom' ) !== -1 ) {
     765                                var caller = 'pag-bottom';
     766                        } else {
     767                                var caller = null;
     768                        }
     769
     770                        bp_filter_request( object, jq.cookie('bp-' + object + '-filter'), jq.cookie('bp-' + object + '-scope'), 'div.' + object, search_terms, page_number, jq.cookie('bp-' + object + '-extras'), caller );
    764771
    765772                        return false;
     
    13771384
    13781385/* Filter the current content list (groups/members/blogs/topics) */
    1379 function bp_filter_request( object, filter, scope, target, search_terms, page, extras ) {
     1386function bp_filter_request( object, filter, scope, target, search_terms, page, extras, caller ) {
    13801387        if ( 'activity' == object )
    13811388                return false;
     
    14241431        function(response)
    14251432        {
    1426                 jq(target).fadeOut( 100, function() {
    1427                         jq(this).html(response);
    1428                         jq(this).fadeIn(100);
    1429                 });
     1433                /* animate to top if called from bottom pagination */
     1434                if ( caller == 'pag-bottom' && jq('#subnav').length ) {
     1435                        var top = jq('#subnav').parent();
     1436                        jq('html,body').animate({scrollTop: top.offset().top}, 'slow', function() {
     1437                                jq(target).fadeOut( 100, function() {
     1438                                        jq(this).html(response);
     1439                                        jq(this).fadeIn(100);
     1440                                });
     1441                        });     
     1442
     1443                } else {
     1444                        jq(target).fadeOut( 100, function() {
     1445                                jq(this).html(response);
     1446                                jq(this).fadeIn(100);
     1447                        });
     1448                }
     1449
    14301450                jq('.item-list-tabs li.selected').removeClass('loading');
    14311451        });
  • trunk/bp-themes/bp-default/_inc/global.js

    r7443 r7470  
    736736                        var object = css_id[0];
    737737                        var search_terms = false;
     738                        var pagination_id = jq(target).closest('.pagination-links').attr('id');
    738739
    739740                        if ( jq('div.dir-search input').length )
     
    746747                        else
    747748                                var page_number = Number( jq(target).html() );
    748 
    749                         bp_filter_request( object, jq.cookie('bp-' + object + '-filter'), jq.cookie('bp-' + object + '-scope'), 'div.' + object, search_terms, page_number, jq.cookie('bp-' + object + '-extras') );
     749                       
     750                        if ( pagination_id.indexOf( 'pag-bottom' ) !== -1 ) {
     751                                var caller = 'pag-bottom';
     752                        } else {
     753                                var caller = null;
     754                        }
     755
     756                        bp_filter_request( object, jq.cookie('bp-' + object + '-filter'), jq.cookie('bp-' + object + '-scope'), 'div.' + object, search_terms, page_number, jq.cookie('bp-' + object + '-extras'), caller );
    750757
    751758                        return false;
     
    13431350
    13441351/* Filter the current content list (groups/members/blogs/topics) */
    1345 function bp_filter_request( object, filter, scope, target, search_terms, page, extras ) {
     1352function bp_filter_request( object, filter, scope, target, search_terms, page, extras, caller ) {
    13461353        if ( 'activity' == object )
    13471354                return false;
     
    13901397        function(response)
    13911398        {
    1392                 jq(target).fadeOut( 100, function() {
    1393                         jq(this).html(response);
    1394                         jq(this).fadeIn(100);
    1395                 });
     1399                /* animate to top if called from bottom pagination */
     1400                if ( caller == 'pag-bottom' && jq('#subnav').length ) {
     1401                        var top = jq('#subnav').parent();
     1402                        jq('html,body').animate({scrollTop: top.offset().top}, 'slow', function() {
     1403                                jq(target).fadeOut( 100, function() {
     1404                                        jq(this).html(response);
     1405                                        jq(this).fadeIn(100);
     1406                                });
     1407                        });     
     1408
     1409                } else {
     1410                        jq(target).fadeOut( 100, function() {
     1411                                jq(this).html(response);
     1412                                jq(this).fadeIn(100);
     1413                        });
     1414                }
     1415
    13961416                jq('.item-list-tabs li.selected').removeClass('loading');
    13971417        });
Note: See TracChangeset for help on using the changeset viewer.