From 31354451ce2c236c9c963064652c39fe54be4afd Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 15 Mar 2014 14:58:59 -0300 Subject: Squashed 'mod/elgg-favorites/' content from commit d96e69b git-subtree-dir: mod/elgg-favorites git-subtree-split: d96e69bd1365c3e3c4d998e72d9941ea1ea2278b --- views/default/js/favorites.php | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 views/default/js/favorites.php (limited to 'views/default/js/favorites.php') diff --git a/views/default/js/favorites.php b/views/default/js/favorites.php new file mode 100644 index 000000000..cc364f2ed --- /dev/null +++ b/views/default/js/favorites.php @@ -0,0 +1,55 @@ + + +elgg.provide('elgg.favorites'); + +elgg.favorites.init = function() { + $('.elgg-menu-item-favorite .favorites-add').live('click', elgg.favorites.add); + $('.elgg-menu-item-favorite .favorites-remove').live('click', elgg.favorites.remove); +}; + +elgg.favorites.add = function(event) { + event.preventDefault(); + var $link = $(this); + var $actionParam = $link.attr("href").split("/").pop(); + var $postGuid = $link.attr("href").match(/guid=([^&]+)/)[1]; + + elgg.action('favorites/add', { + data: { + guid: $postGuid + }, + success: function(json) { + $link.attr('href', elgg.config.wwwroot + 'action/favorites/remove/' + $actionParam); + $link.attr('class', '.elgg-menu-item-favorite .favorites-remove'); + $link.children('span').attr('class','elgg-icon elgg-icon-star'); + $link.unbind('click'); + $link.click(elgg.favorites.remove); + } + }); +}; + +elgg.favorites.remove = function(event) { + event.preventDefault(); + var $link = $(this); + var $actionParam = $link.attr("href").split("/").pop(); + var $postGuid = $link.attr("href").match(/guid=([^&]+)/)[1]; + + elgg.action('favorites/remove', { + data: { + guid: $postGuid + }, + success: function(json) { + $link.attr("href", elgg.config.wwwroot + 'action/favorites/add/' + $actionParam); + $link.attr('class', '.elgg-menu-item-favorite .favorites-add'); + $link.children('span').attr('class','elgg-icon elgg-icon-star-empty'); + $link.unbind('click'); + $link.click(elgg.favorites.add); + } + }); +}; + +elgg.register_hook_handler('init', 'system', elgg.favorites.init); + -- cgit v1.2.3