From 375a3021d73e629883830c1c9aa6fd216d59e6d3 Mon Sep 17 00:00:00 2001 From: brettp Date: Tue, 8 Jun 2010 21:37:14 +0000 Subject: Ajaxified likes view on activity stream. git-svn-id: http://code.elgg.org/elgg/trunk@6409 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/riverdashboard/endpoint/get_likes.php | 22 ++++++++++++++++ .../views/default/river/item/wrapper.php | 7 +++--- .../views/default/riverdashboard/js.php | 29 ++++++++++++++++------ 3 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 mod/riverdashboard/endpoint/get_likes.php (limited to 'mod') diff --git a/mod/riverdashboard/endpoint/get_likes.php b/mod/riverdashboard/endpoint/get_likes.php new file mode 100644 index 000000000..cc9e83aaf --- /dev/null +++ b/mod/riverdashboard/endpoint/get_likes.php @@ -0,0 +1,22 @@ +getAnnotations('likes', $limit, $offset); + +if (is_array($annotations) && sizeof($annotations) > 0) { + foreach($annotations as $annotation) { + echo elgg_view_annotation($annotation, "", false); + } +} diff --git a/mod/riverdashboard/views/default/river/item/wrapper.php b/mod/riverdashboard/views/default/river/item/wrapper.php index a2bc10c54..e50a3fe3f 100644 --- a/mod/riverdashboard/views/default/river/item/wrapper.php +++ b/mod/riverdashboard/views/default/river/item/wrapper.php @@ -69,9 +69,8 @@ if ($comments){ if ($likes_count != 0) { //show the users who liked the object - echo ""; + // this is loaded via ajax to avoid pounding the server with avatar requests. + echo ""; } echo "
"; @@ -148,4 +147,4 @@ if ($comments){ } ?>
- \ No newline at end of file + diff --git a/mod/riverdashboard/views/default/riverdashboard/js.php b/mod/riverdashboard/views/default/riverdashboard/js.php index 37de3ad04..edb041e4f 100644 --- a/mod/riverdashboard/views/default/riverdashboard/js.php +++ b/mod/riverdashboard/views/default/riverdashboard/js.php @@ -6,14 +6,27 @@ $('.likes_user_list_button').click(function() { var myParent = $(this).closest('.river_item'); - if (myParent.find('.likes_list').css('display') == 'none') { - // hide comments - myParent.find('.comments_container').animate({"height": "toggle", "opacity": "toggle"}, { duration: 400 }); - // change selected tab - myParent.find('.show_comments_button').addClass('off'); - myParent.find('.likes_user_list_button').removeClass('off'); - // show users that liked object - elgg_slide_toggle(this, '.river_item', '.likes_list'); + var likesList = myParent.find('.likes_list'); + + if (likesList.css('display') == 'none') { + // pull in likes via ajax to save on loading many avatars + var riverItem = $(this).closest('.river_item'); + var guid = riverItem.attr('id').replace('river_entity_', ''); + + var params = { + 'entity_guid': guid + } + + $(likesList).load('mod/riverdashboard/endpoint/get_likes.php', params, function(data) { + console.log(data); + // hide comments + myParent.find('.comments_container').animate({"height": "toggle", "opacity": "toggle"}, { duration: 400 }); + // change selected tab + myParent.find('.show_comments_button').addClass('off'); + myParent.find('.likes_user_list_button').removeClass('off'); + // show users that liked object + elgg_slide_toggle(this, '.river_item', '.likes_list'); + }); } }); -- cgit v1.2.3