Skip to:
Content

BuddyPress.org

Changeset 2473


Ignore:
Timestamp:
01/29/2010 10:43:01 AM (16 years ago)
Author:
apeatling
Message:

Moving request functions into the global scope. Fixes #1628

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-themes/bp-default/_inc/global.js

    r2467 r2473  
    11// AJAX Functions
    2 
    3 jQuery(document).ready( function() {
    4         var j = jQuery;
    5 
     2var j = jQuery;
     3
     4j(document).ready( function() {
    65        /**** Page Load Actions *******************************************************/
    76
     
    250249                }
    251250        });
    252 
    253         /* Activity Loop Requesting */
    254         function bp_activity_request(scope, filter) {
    255                 if ( null == scope )
    256                         var scope = 'all';
    257 
    258                 if ( null == filter )
    259                         var filter = '-1';
    260 
    261                 /* Save the type and filter to a session cookie */
    262                 j.cookie( 'bp-activity-scope', scope, null );
    263                 j.cookie( 'bp-activity-filter', filter, null );
    264                 j.cookie( 'bp-activity-oldestpage', 1 );
    265 
    266                 /* Set the correct selected nav and filter */
    267                 j('div.item-list-tabs li').each( function() {
    268                         j(this).removeClass('selected');
    269                 });
    270                 j('li#activity-' + scope + ', div.item-list-tabs li.current').addClass('selected');
    271                 j('div.item-list-tabs li.selected').addClass('loading');
    272                 j('#activity-filter-select select option[value=' + filter + ']').attr( 'selected', 'selected' );
    273 
    274                 /* Reload the activity stream based on the selection */
    275                 j('.widget_bp_activity_widget h2 span.ajax-loader').show();
    276 
    277                 j.post( ajaxurl, {
    278                         action: 'activity_widget_filter',
    279                         'cookie': encodeURIComponent(document.cookie),
    280                         '_wpnonce_activity_filter': j("input#_wpnonce_activity_filter").val(),
    281                         'scope': scope,
    282                         'filter': filter
    283                 },
    284                 function(response)
    285                 {
    286                         j('.widget_bp_activity_widget h2 span.ajax-loader').hide();
    287                         j.cookie( 'bp-activity-querystring', response.query_string );
    288 
    289                         j('div.activity').fadeOut( 100, function() {
    290                                 j(this).html(response.contents);
    291                                 j(this).fadeIn(100);
    292                         });
    293 
    294                         /* Update the feed link */
    295                         if ( null != response.feed_url )
    296                                 j('.directory div#subnav li.feed a, .home-page div#subnav li.feed a').attr('href', response.feed_url);
    297 
    298                         j('div.item-list-tabs li.selected').removeClass('loading');
    299 
    300                         /* Selectively hide comments */
    301                         bp_dtheme_hide_comments();
    302 
    303                 }, 'json' );
    304         }
    305251
    306252        /**** Activity Comments *******************************************************/
     
    500446        });
    501447
    502         /* Hide long lists of activity comments, only show the latest five root comments. */
    503         function bp_dtheme_hide_comments() {
    504                 var comments_divs = j('div.activity-comments');
    505 
    506                 if ( !comments_divs.length )
    507                         return false;
    508 
    509                 comments_divs.each( function() {
    510                         if ( j(this).children('ul').children('li').length < 5 ) return;
    511 
    512                         var comments_div = j(this);
    513                         var parent_li = comments_div.parents('ul#activity-stream > li');
    514                         var comment_lis = j(this).children('ul').children('li');
    515                         var comment_count = ' ';
    516 
    517                         if ( j('li#' + parent_li.attr('id') + ' a.acomment-reply span').length )
    518                                 var comment_count = j('li#' + parent_li.attr('id') + ' a.acomment-reply span').html();
    519 
    520                         comment_lis.each( function(i) {
    521                                 /* Show the latest 5 root comments */
    522                                 if ( i < comment_lis.length - 5 ) {
    523                                         j(this).addClass('hidden');
    524                                         j(this).toggle();
    525 
    526                                         if ( !i )
    527                                                 j(this).before( '<li class="show-all"><a href="#' + parent_li.attr('id') + '/show-all/" title="' + bp_terms_show_all_comments + '">' + bp_terms_show_all + ' ' + comment_count + ' ' + bp_terms_comments + '</a></li>' );
    528                                 }
    529                         });
    530 
    531                 });
    532         }
    533 
    534448        /**** Directory Search ****************************************************/
    535449
     
    597511                return false;
    598512        });
    599 
    600         /* Filter the current content list (groups/members/blogs/topics) */
    601         function bp_filter_request( object, filter, scope, target, search_terms, page, extras ) {
    602                 if ( 'activity' == object )
    603                         return false;
    604 
    605                 if ( null == scope )
    606                         var scope = 'all';
    607 
    608                 if ( null == filter )
    609                         var filter = 'active';
    610 
    611                 if ( null == page )
    612                         var page = 1;
    613 
    614                 if ( null == search_terms )
    615                         var search_terms = false;
    616 
    617                 if ( null == extras )
    618                         var extras = false;
    619 
    620                 if ( j.query.get('s') )
    621                         search_terms = j.query.get('s');
    622 
    623                 /* Save the type and filter to a session cookie */
    624                 j.cookie( 'bp-' + object + '-scope', scope, null );
    625                 j.cookie( 'bp-' + object + '-filter', filter, null );
    626                 j.cookie( 'bp-' + object + '-page', page, null );
    627                 j.cookie( 'bp-' + object + '-search-terms', search_terms, null );
    628 
    629                 /* Set the correct selected nav and filter */
    630                 j('div.item-list-tabs li').each( function() {
    631                         j(this).removeClass('selected');
    632                 });
    633                 j('div.item-list-tabs li#' + object + '-' + scope + ', div.item-list-tabs#object-nav li.current').addClass('selected');
    634                 j('div.item-list-tabs li.selected').addClass('loading');
    635                 j('div.item-list-tabs select option[value=' + filter + ']').attr( 'selected', 'selected' );
    636 
    637                 if ( 'friends' == object )
    638                         object = 'members';
    639 
    640                 j.post( ajaxurl, {
    641                         action: object + '_filter',
    642                         'cookie': encodeURIComponent(document.cookie),
    643                         'object': object,
    644                         'filter': filter,
    645                         'search_terms': search_terms,
    646                         'scope': scope,
    647                         'page': page,
    648                         'extras': extras
    649                 },
    650                 function(response)
    651                 {
    652                         j(target).fadeOut( 100, function() {
    653                                 j(this).html(response);
    654                                 j(this).fadeIn(100);
    655                         });
    656                         j('div.item-list-tabs li.selected').removeClass('loading');
    657                 });
    658         }
    659513
    660514        /* All pagination links run through this function */
     
    1101955});
    1102956
    1103 // Helper JS Functions
     957/* Filter the current content list (groups/members/blogs/topics) */
     958function bp_filter_request( object, filter, scope, target, search_terms, page, extras ) {
     959        if ( 'activity' == object )
     960                return false;
     961
     962        if ( null == scope )
     963                var scope = 'all';
     964
     965        if ( null == filter )
     966                var filter = 'active';
     967
     968        if ( null == page )
     969                var page = 1;
     970
     971        if ( null == search_terms )
     972                var search_terms = false;
     973
     974        if ( null == extras )
     975                var extras = false;
     976
     977        if ( j.query.get('s') )
     978                search_terms = j.query.get('s');
     979
     980        /* Save the type and filter to a session cookie */
     981        j.cookie( 'bp-' + object + '-scope', scope, null );
     982        j.cookie( 'bp-' + object + '-filter', filter, null );
     983        j.cookie( 'bp-' + object + '-page', page, null );
     984        j.cookie( 'bp-' + object + '-search-terms', search_terms, null );
     985
     986        /* Set the correct selected nav and filter */
     987        j('div.item-list-tabs li').each( function() {
     988                j(this).removeClass('selected');
     989        });
     990        j('div.item-list-tabs li#' + object + '-' + scope + ', div.item-list-tabs#object-nav li.current').addClass('selected');
     991        j('div.item-list-tabs li.selected').addClass('loading');
     992        j('div.item-list-tabs select option[value=' + filter + ']').attr( 'selected', 'selected' );
     993
     994        if ( 'friends' == object )
     995                object = 'members';
     996
     997        j.post( ajaxurl, {
     998                action: object + '_filter',
     999                'cookie': encodeURIComponent(document.cookie),
     1000                'object': object,
     1001                'filter': filter,
     1002                'search_terms': search_terms,
     1003                'scope': scope,
     1004                'page': page,
     1005                'extras': extras
     1006        },
     1007        function(response)
     1008        {
     1009                j(target).fadeOut( 100, function() {
     1010                        j(this).html(response);
     1011                        j(this).fadeIn(100);
     1012                });
     1013                j('div.item-list-tabs li.selected').removeClass('loading');
     1014        });
     1015}
     1016
     1017/* Activity Loop Requesting */
     1018function bp_activity_request(scope, filter) {
     1019        if ( null == scope )
     1020                var scope = 'all';
     1021
     1022        if ( null == filter )
     1023                var filter = '-1';
     1024
     1025        /* Save the type and filter to a session cookie */
     1026        j.cookie( 'bp-activity-scope', scope, null );
     1027        j.cookie( 'bp-activity-filter', filter, null );
     1028        j.cookie( 'bp-activity-oldestpage', 1 );
     1029
     1030        /* Set the correct selected nav and filter */
     1031        j('div.item-list-tabs li').each( function() {
     1032                j(this).removeClass('selected');
     1033        });
     1034        j('li#activity-' + scope + ', div.item-list-tabs li.current').addClass('selected');
     1035        j('div.item-list-tabs li.selected').addClass('loading');
     1036        j('#activity-filter-select select option[value=' + filter + ']').attr( 'selected', 'selected' );
     1037
     1038        /* Reload the activity stream based on the selection */
     1039        j('.widget_bp_activity_widget h2 span.ajax-loader').show();
     1040
     1041        j.post( ajaxurl, {
     1042                action: 'activity_widget_filter',
     1043                'cookie': encodeURIComponent(document.cookie),
     1044                '_wpnonce_activity_filter': j("input#_wpnonce_activity_filter").val(),
     1045                'scope': scope,
     1046                'filter': filter
     1047        },
     1048        function(response)
     1049        {
     1050                j('.widget_bp_activity_widget h2 span.ajax-loader').hide();
     1051                j.cookie( 'bp-activity-querystring', response.query_string );
     1052
     1053                j('div.activity').fadeOut( 100, function() {
     1054                        j(this).html(response.contents);
     1055                        j(this).fadeIn(100);
     1056                });
     1057
     1058                /* Update the feed link */
     1059                if ( null != response.feed_url )
     1060                        j('.directory div#subnav li.feed a, .home-page div#subnav li.feed a').attr('href', response.feed_url);
     1061
     1062                j('div.item-list-tabs li.selected').removeClass('loading');
     1063
     1064                /* Selectively hide comments */
     1065                bp_dtheme_hide_comments();
     1066
     1067        }, 'json' );
     1068}
     1069
     1070/* Hide long lists of activity comments, only show the latest five root comments. */
     1071function bp_dtheme_hide_comments() {
     1072        var comments_divs = j('div.activity-comments');
     1073
     1074        if ( !comments_divs.length )
     1075                return false;
     1076
     1077        comments_divs.each( function() {
     1078                if ( j(this).children('ul').children('li').length < 5 ) return;
     1079
     1080                var comments_div = j(this);
     1081                var parent_li = comments_div.parents('ul#activity-stream > li');
     1082                var comment_lis = j(this).children('ul').children('li');
     1083                var comment_count = ' ';
     1084
     1085                if ( j('li#' + parent_li.attr('id') + ' a.acomment-reply span').length )
     1086                        var comment_count = j('li#' + parent_li.attr('id') + ' a.acomment-reply span').html();
     1087
     1088                comment_lis.each( function(i) {
     1089                        /* Show the latest 5 root comments */
     1090                        if ( i < comment_lis.length - 5 ) {
     1091                                j(this).addClass('hidden');
     1092                                j(this).toggle();
     1093
     1094                                if ( !i )
     1095                                        j(this).before( '<li class="show-all"><a href="#' + parent_li.attr('id') + '/show-all/" title="' + bp_terms_show_all_comments + '">' + bp_terms_show_all + ' ' + comment_count + ' ' + bp_terms_comments + '</a></li>' );
     1096                        }
     1097                });
     1098
     1099        });
     1100}
     1101
     1102/* Helper Functions */
    11041103
    11051104function checkAll() {
Note: See TracChangeset for help on using the changeset viewer.