Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
166 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
$object = $params['entity']; | ||
|
||
if (elgg_is_logged_in() && !elgg_in_context('widgets') && elgg_is_active_plugin('likes')) { | ||
$menu = new EvanMenu($return); | ||
|
||
if ($object->canAnnotate(0, 'likes')) { | ||
$hasLiked = elgg_annotation_exists($object->guid, 'likes'); | ||
|
||
// Always register both. That makes it super easy to toggle with javascript | ||
$menu->registerItem('like', array( | ||
'href' => elgg_add_action_tokens_to_url("/action/likes/add?guid={$object->guid}"), | ||
'text' => elgg_view_icon('thumbs-up'), | ||
'title' => elgg_echo('likes:likethis'), | ||
'item_class' => $hasLiked ? 'hidden' : '', | ||
)); | ||
$menu->registerItem('unlike', array( | ||
'href' => elgg_add_action_tokens_to_url("/action/likes/delete?guid={$object->guid}"), | ||
'text' => elgg_view_icon('thumbs-up-alt'), | ||
'title' => elgg_echo('likes:remove'), | ||
'item_class' => $hasLiked ? '' : 'hidden', | ||
)); | ||
} | ||
|
||
$count = elgg_view('likes/count', array('entity' => $object)); | ||
|
||
if ($count) { | ||
$menu->registerItem('likes_count', array( | ||
'href' => false, | ||
'priority' => 1001, | ||
'text' => $count, | ||
'title' => elgg_echo('likes:see'), | ||
)); | ||
} | ||
|
||
return $menu->getItems(); | ||
} | ||
|
||
return NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
// The river item | ||
$item = $params['item']; | ||
|
||
// only like group creation #3958 | ||
if ($item->type == "group" && $item->view != "river/group/create") { | ||
return $return; | ||
} | ||
|
||
// don't like users #4116 | ||
if ($item->type == "user") { | ||
return $return; | ||
} | ||
|
||
$object = $item->getObjectEntity(); | ||
|
||
if (elgg_is_logged_in() && !elgg_in_context('widgets') && elgg_is_active_plugin('likes')) { | ||
$menu = new EvanMenu($return); | ||
|
||
if ($object->canAnnotate(0, 'likes')) { | ||
$hasLiked = elgg_annotation_exists($object->guid, 'likes'); | ||
|
||
// Always register both. That makes it super easy to toggle with javascript | ||
$menu->registerItem('like', array( | ||
'href' => elgg_add_action_tokens_to_url("/action/likes/add?guid={$object->guid}"), | ||
'text' => elgg_view_icon('thumbs-up'), | ||
'title' => elgg_echo('likes:likethis'), | ||
'item_class' => $hasLiked ? 'hidden' : '', | ||
)); | ||
$menu->registerItem('unlike', array( | ||
'href' => elgg_add_action_tokens_to_url("/action/likes/delete?guid={$object->guid}"), | ||
'text' => elgg_view_icon('thumbs-up-alt'), | ||
'title' => elgg_echo('likes:remove'), | ||
'item_class' => $hasLiked ? '' : 'hidden', | ||
)); | ||
} | ||
|
||
$count = elgg_view('likes/count', array('entity' => $object)); | ||
|
||
if ($count) { | ||
$menu->registerItem('likes_count', array( | ||
'href' => false, | ||
'priority' => 1001, | ||
'text' => $count, | ||
'title' => elgg_echo('likes:see'), | ||
)); | ||
} | ||
|
||
return $menu->getItems(); | ||
} | ||
|
||
|
||
return NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
(function($) { | ||
function showLikeHideUnlike($menu) { | ||
$menu.find('.elgg-menu-item-like').removeClass('hidden'); | ||
$menu.find('.elgg-menu-item-unlike').addClass('hidden'); | ||
} | ||
|
||
function showUnlikeHideLike($menu) { | ||
$menu.find('.elgg-menu-item-unlike').removeClass('hidden'); | ||
$menu.find('.elgg-menu-item-like').addClass('hidden'); | ||
} | ||
|
||
// Handles clicking the like button. | ||
$('.elgg-menu-item-like a').live('click', function() { | ||
var $menu = $(this).closest('.elgg-menu'); | ||
|
||
// Be optimistic about success | ||
showUnlikeHideLike($menu); | ||
|
||
// Send the ajax request | ||
elgg.action($(this).attr('href'), { | ||
error: function() { | ||
// Something went wrong, so undo the optimistic changes | ||
showLikeHideUnlike($menu); | ||
} | ||
}); | ||
|
||
// Don't want to actually click the link | ||
return false; | ||
}); | ||
|
||
// Handles clicking the unlike button | ||
$('.elgg-menu-item-unlike a').live('click', function() { | ||
var $menu = $(this).closest('.elgg-menu'); | ||
|
||
// Be optimistic about success | ||
showLikeHideUnlike($menu); | ||
|
||
// Send the ajax request | ||
console.log($menu); | ||
elgg.action($(this).attr('href'), { | ||
error: function() { | ||
// Something went wrong, so undo the optimistic changes | ||
showUnlikeHideLike($menu); | ||
} | ||
}); | ||
|
||
// Don't want to actually click the link | ||
return false; | ||
}); | ||
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters