The Favorites module rocks.
... though I haven’t figured out yet how to implement it with AJAX. As I am a javascript newbie even Maleika’s and Bill’s great efforts didn’t bring the working solution. But I’m close.
I would appreciate if anyone could have a second look at Bill’s approach.
Bill Warters - 13 August 2007 04:01 PM
I took a different approach, having decided not to use a modal window. Thus, you only need jQuery and not the plugin code as well. Here’s the basics of my approach. It needs more sprucing up, such as an indicator of what has changed on the page (yellow background fade perhaps?), but it works.
Here is the basic code for the template that was embedded just above post body -
Don’t forget to pass the entryid along to your embedded template ie - {embed="includes/ajax_inline_favorites" myentryid="{entry_id}"}
{if logged_in}
{exp:favorites:saved entry_id="{embed:myentryid}"}
<ul class="favoritesul">
{if saved}
<li><em>Saved as a favorite.</em> <a class="Favorites_Trigger" href="{path='forms/favorite-add/'}{embed:myentryid}/delete">Remove from favorites list?</a></li>
{/if}
{if not_saved}
<li><a class="Favorites_Trigger" href="{path='forms/favorite-add/'}{embed:myentryid}">Add this item to your favorites?</a></li>
{/if}
</ul>
{/exp:favorites:saved}
{/if }
embedded javascript in head of page
</script>
$().ready(function() {
$('a.Favorites_Trigger') .click (function() {
$.get(this.href, function(data) {
$('ul.favoritesul > li')
.html(data);
});
return false;
});
});
</script>
The page the add and remove links point to is a very basic template that activates the favorites module:
{exp:favorites:save}
To get it work, I need to understand two things:
1. As Bill said, we have to pass the entryid along to another template. But what is the “includes/ajax_inline_favorites” template? As I understood it is neither the simple “exp:favorites:save” template, nor the main template coded above. So what is it than? What am I missing?
2. Bill says that “It needs more sprucing up, such as an indicator of what has changed on the page (yellow background fade perhaps?)” How would we link this to this specific case? On which template will we do that and how?
Sorry for my maybe stupid questions. Your help guys is much appreciated.