aboutsummaryrefslogtreecommitdiff
path: root/views/default/js/favorites.php
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2014-03-15 14:58:59 -0300
committerSilvio Rhatto <rhatto@riseup.net>2014-03-15 14:58:59 -0300
commit31354451ce2c236c9c963064652c39fe54be4afd (patch)
tree6203d2ba3f7e29518291e2e3999d9fa89892b417 /views/default/js/favorites.php
downloadelgg-31354451ce2c236c9c963064652c39fe54be4afd.tar.gz
elgg-31354451ce2c236c9c963064652c39fe54be4afd.tar.bz2
Squashed 'mod/elgg-favorites/' content from commit d96e69b
git-subtree-dir: mod/elgg-favorites git-subtree-split: d96e69bd1365c3e3c4d998e72d9941ea1ea2278b
Diffstat (limited to 'views/default/js/favorites.php')
-rw-r--r--views/default/js/favorites.php55
1 files changed, 55 insertions, 0 deletions
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 @@
+<?php
+/**
+ * Favorites JS.
+ */
+?>
+
+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);
+