<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[BuddyPress] [2152] trunk:
Replaced pagination on sitewide activity widget with a 'Load More'
link at the bottom</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>2152</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2009-11-28 16:54:24 +0000 (Sat, 28 Nov 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Replaced pagination on sitewide activity widget with a 'Load More' link at the bottom</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivitywidgetsphp">trunk/bp-activity/bp-activity-widgets.php</a></li>
<li><a href="#trunkbpactivityjswidgetactivityjs">trunk/bp-activity/js/widget-activity.js</a></li>
<li><a href="#trunkbpthemesbpdefault_inccssscreencss">trunk/bp-themes/bp-default/_inc/css/screen.css</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivitywidgetsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-widgets.php (2151 => 2152)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-widgets.php        2009-11-28 14:11:07 UTC (rev 2151)
+++ trunk/bp-activity/bp-activity-widgets.php        2009-11-28 16:54:24 UTC (rev 2152)
</span><span class="lines">@@ -53,6 +53,12 @@
</span><span class="cx">                 <?php // The loop will be loaded here via AJAX on page load to retain settings. ?>
</span><span class="cx">         </div>
</span><span class="cx">
</span><ins>+        <form action="" name="activity-widget-form" id="activity-widget-form" method="post">
+                <?php wp_nonce_field( 'activity_filter', '_wpnonce_activity_filter' ) ?>
+                <input type="hidden" id="aw-querystring" name="aw-querystring" value="" />
+                <input type="hidden" id="aw-oldestpage" name="aw-oldestpage" value="1" />
+        </div>
+
</ins><span class="cx">         <?php echo $after_widget; ?>
</span><span class="cx">         <?php
</span><span class="cx">         }
</span><span class="lines">@@ -77,37 +83,44 @@
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-function bp_activity_widget_loop( $type = 'all', $filter = false, $per_page = 20 ) {
</del><ins>+function bp_activity_widget_loop( $type = 'all', $filter = false, $query_string = false, $per_page = 20 ) {
</ins><span class="cx">         global $bp;
</span><span class="cx">
</span><del>-        /* Set a valid type */
-        if ( !$type || ( 'all' != $type && 'friends' != $type && 'groups' != $type ) )
-                $type = 'all';
</del><ins>+        if ( !$query_string ) {
+                /* Set a valid type */
+                if ( !$type || ( 'all' != $type && 'friends' != $type && 'groups' != $type ) )
+                        $type = 'all';
</ins><span class="cx">
</span><del>-        if ( ( 'friends' == $type || 'groups' == $type ) && !is_user_logged_in() )
-                $type = 'all';
</del><ins>+                if ( ( 'friends' == $type || 'groups' == $type ) && !is_user_logged_in() )
+                        $type = 'all';
</ins><span class="cx">
</span><del>-        switch( $type ) {
-                case 'friends':
-                        $friend_ids = implode( ',', friends_get_friend_user_ids( $bp->loggedin_user->id ) );
-                        $query_string = 'user_id=' . $friend_ids;
-                        break;
-                case 'groups':
-                        $groups = groups_get_user_groups( $bp->loggedin_user->id );
-                        $group_ids = implode( ',', $groups['groups'] );
-                        $query_string = 'object=groups&primary_id=' . $group_ids;
-                        break;
</del><ins>+                switch( $type ) {
+                        case 'friends':
+                                $friend_ids = implode( ',', friends_get_friend_user_ids( $bp->loggedin_user->id ) );
+                                $query_string = 'user_id=' . $friend_ids;
+                                break;
+                        case 'groups':
+                                $groups = groups_get_user_groups( $bp->loggedin_user->id );
+                                $group_ids = implode( ',', $groups['groups'] );
+                                $query_string = 'object=groups&primary_id=' . $group_ids;
+                                break;
+                }
+
+                /* Build the filter */
+                if ( $filter && $filter != '-1' )
+                        $query_string .= '&action=' . $filter;
+
+                /* Add the per_page param */
+                $query_string .= '&per_page=' . $per_page;
</ins><span class="cx">         }
</span><span class="cx">
</span><del>-        /* Build the filter */
-        if ( $filter && $filter != '-1' )
-                $query_string .= '&action=' . $filter;
</del><ins>+        if ( bp_has_activities( $query_string . '&display_comments=threaded' ) ) : ?>
+                <?php echo $query_string . '&display_comments=threaded||'; // Pass the qs back to the JS. ?>
</ins><span class="cx">
</span><del>-        /* Add the per_page param */
-        $query_string .= '&per_page=' . $per_page;
</del><ins>+                <?php if ( !$_POST['acpage'] || 1 == $_POST['acpage'] ) : ?>
+                        <ul id="site-wide-stream" class="activity-list">
+                <?php endif; ?>
</ins><span class="cx">
</span><del>-        if ( bp_has_activities( $query_string . '&display_comments=threaded' ) ) : ?>
-                <ul id="site-wide-stream" class="activity-list">
</del><span class="cx">                 <?php while ( bp_activities() ) : bp_the_activity(); ?>
</span><span class="cx">                         <li class="<?php bp_activity_css_class() ?>" id="activity-<?php bp_activity_id() ?>">
</span><span class="cx">                                 <div class="activity-avatar">
</span><span class="lines">@@ -141,8 +154,14 @@
</span><span class="cx">
</span><span class="cx">                         </li>
</span><span class="cx">                 <?php endwhile; ?>
</span><del>-                </ul>
</del><ins>+                        <li class="load-more">
+                                <a href="#more"><?php _e( 'Load More', 'buddypress' ) ?></a> &nbsp; <span class="ajax-loader"></span>
+                        </li>
</ins><span class="cx">
</span><ins>+                <?php if ( !$_POST['acpage'] || 1 == $_POST['acpage'] ) : ?>
+                        </ul>
+                <?php endif; ?>
+
</ins><span class="cx">         <?php else: ?>
</span><span class="cx"> <?php echo "-1<div id='message' class='info'><p>" . __( 'No activity found', 'buddypress' ) . '</p></div>'; ?>
</span><span class="cx">         <?php endif;
</span><span class="lines">@@ -154,6 +173,12 @@
</span><span class="cx"> }
</span><span class="cx"> add_action( 'wp_ajax_activity_widget_filter', 'bp_activity_ajax_widget_filter' );
</span><span class="cx">
</span><ins>+/* The ajax function to load older updates at the end of the list */
+function bp_activity_ajax_load_older_updates() {
+        bp_activity_widget_loop( false, false, $_POST['query_string'] );
+}
+add_action( 'wp_ajax_aw_get_older_updates', 'bp_activity_ajax_load_older_updates' );
</ins><span class="cx">
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> ?>
</span></span></pre></div>
<a id="trunkbpactivityjswidgetactivityjs"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/js/widget-activity.js (2151 => 2152)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/js/widget-activity.js        2009-11-28 14:11:07 UTC (rev 2151)
+++ trunk/bp-activity/js/widget-activity.js        2009-11-28 16:54:24 UTC (rev 2152)
</span><span class="lines">@@ -32,6 +32,42 @@
</span><span class="cx">                 return false;
</span><span class="cx">         });
</span><span class="cx">
</span><ins>+        /* Stream event delegation */
+        j('div.widget_bp_activity_widget').click( function(event) {
+                var target = j(event.target).parent();
+
+                /* Load more updates at the end of the page */
+                if ( target.attr('class') == 'load-more' ) {
+                        j("li.load-more span.ajax-loader").show();
+                        var oldest_page = ( j("input#aw-oldestpage").val() * 1 ) + 1;
+
+                        j.post( ajaxurl, {
+                                action: 'aw_get_older_updates',
+                                'cookie': encodeURIComponent(document.cookie),
+                                'query_string': j("input#aw-querystring").val(),
+                                'acpage': oldest_page
+                        },
+                        function(response)
+                        {
+                                j("li.load-more span.ajax-loader").hide();
+
+                                /* Check for errors and append if found. */
+                                if ( response[0] + response[1] != '-1' ) {
+                                        var response = response.split('||');
+                                        j("input#aw-querystring").val(response[0]);
+
+                                        j("ul.activity-list").append(response[1]);
+                                        j("input#aw-oldestpage").val( oldest_page );
+                                }
+
+                                target.hide();
+                        });
+
+                        return false;
+                }
+        });
+
+
</ins><span class="cx">         function bp_activity_widget_post(type, filter) {
</span><span class="cx">                 if ( null == type )
</span><span class="cx">                         var type = 'all';
</span><span class="lines">@@ -71,8 +107,11 @@
</span><span class="cx">                                         j(this).fadeIn(100);
</span><span class="cx">                                 });
</span><span class="cx">                         } else {
</span><ins>+                                var response = response.split('||');
+                                j("input#aw-querystring").val(response[0]);
+
</ins><span class="cx">                                 j('div.activity').fadeOut( 100, function() {
</span><del>-                                        j(this).html(response);
</del><ins>+                                        j(this).html(response[1]);
</ins><span class="cx">                                         j(this).fadeIn(100);
</span><span class="cx">                                 });
</span><span class="cx">                         }
</span></span></pre></div>
<a id="trunkbpthemesbpdefault_inccssscreencss"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/_inc/css/screen.css (2151 => 2152)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/_inc/css/screen.css        2009-11-28 14:11:07 UTC (rev 2151)
+++ trunk/bp-themes/bp-default/_inc/css/screen.css        2009-11-28 16:54:24 UTC (rev 2152)
</span><span class="lines">@@ -1366,6 +1366,19 @@
</span><span class="cx">                 margin: 0;
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+.activity-list li.load-more {
+        margin: 15px !important;
+        padding: 10px 15px !important;
+        background: #f0f0f0 !important;
+        text-align: center;
+        font-size: 1.2em;
+        border-right: 1px solid #ddd;
+        border-bottom: 1px solid #ddd;
+}
+        .activity-list li.load-more a {
+                color: #555;
+        }
+
</ins><span class="cx"> div.item-list-tabs ul {
</span><span class="cx">         margin: 0;
</span><span class="cx">         padding: 0;
</span></span></pre>
</div>
</div>
</body>
</html>