2 of 2
2
Using Favorites with JS libraries and AJAX
Posted: 19 January 2008 11:34 PM   [ Ignore ]   [ # 16 ]
Newbie
Rank
Total Posts:  8
Joined  2005-08-29

Can someone tell me why this isn’t working with the modal?

http://sogospelnews.com/index/features/test-comments/8476/

Also, how can I get it to work if I include a delete from favorites link?

Thanks so much!

Profile
 
 
Posted: 24 February 2008 01:47 PM   [ Ignore ]   [ # 17 ]
Newbie
Rank
Total Posts:  9
Joined  2008-02-22

It would be good to see some working examples of this as the one Malieka posted is a 404.

When it comes to ‘add to favourites’ scripts there’s few better than the solution used by Uncrate

Once you’ve signed up it works a treat, very elegant. I also like the URL structure, making it easy to remember and
send to your friends. They also enable you to output some code so you can post your list on your blog.

I think it’s very cool and the question is: can the Favorites module do something along these lines?

If not, then perhaps it should wink

Profile
 
 
Posted: 17 March 2008 04:11 AM   [ Ignore ]   [ # 18 ]
Newbie
Rank
Total Posts:  5
Joined  2006-04-25

The Favorites module rocks. grin
... 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>&nbsp;<class="Favorites_Trigger" href="{path='forms/favorite-add/'}{embed:myentryid}/delete">Remove from favorites list?</a></li>
{/if}
{if not_saved}
<li><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.

Profile
 
 
Posted: 17 March 2008 05:46 AM   [ Ignore ]   [ # 19 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  701
Joined  2004-03-30

I think what Bill is saying is that he doesn’t want to write the code block you see above into every single one of his templates. Instead, he wants to have one EE template that serves that block and then embed that template into all the pages where he needs it. Hence the {embed=… code. He reminds us to pass across the entry id so that the embedded code can send the correct entry id over to the AJAX template.

mk

 Signature 

Mitchell Kimbrough

Profile
 
 
Posted: 17 March 2008 06:39 AM   [ Ignore ]   [ # 20 ]
Newbie
Rank
Total Posts:  5
Joined  2006-04-25

Thanks a lot Mitchell for your quick reaction.
So you mean that the javascript code block should be put in the template named “ajax_inline_favorites”, right?

Profile
 
 
Posted: 17 March 2008 07:00 AM   [ Ignore ]   [ # 21 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  701
Joined  2004-03-30

Right.

 Signature 

Mitchell Kimbrough

Profile
 
 
Posted: 17 March 2008 07:52 AM   [ Ignore ]   [ # 22 ]
Newbie
Rank
Total Posts:  5
Joined  2006-04-25

Good! Getting nearer. grin
But there is still {embed:myentryid} showing up in the link instead of the real entry_id value.
There must be some code missing.
Bill said: “Here is the basic code for the template that was embedded just above post body?
Does it mean that there should be some other code under his basic code? If so, which one?
Is there any post function needed? Or which other code should figure under his given basic code?

Profile
 
 
Posted: 17 March 2008 08:01 AM   [ Ignore ]   [ # 23 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  701
Joined  2004-03-30

{embed:myentryid} is the code that you use to display the variable that you passed across as you embedded the other template.

So this appears in your main template, and is of course inside a weblog:entries tag somewhere…

{embed="template_group/template_name" myentryid="{entry_id}"}

Then in the template that’s getting embedded, you can call the variable you passed across using this construct:

{embed:myentryid}

Check the EE docs on embedding templates. It’s helpful.

mk

 Signature 

Mitchell Kimbrough

Profile
 
 
Posted: 17 March 2008 12:44 PM   [ Ignore ]   [ # 24 ]
Newbie
Rank
Total Posts:  5
Joined  2006-04-25

Rechecked it. Got it roughly working. Thanks a lot for your help and patience Mitchell.
grin

Profile
 
 
Posted: 17 March 2008 12:51 PM   [ Ignore ]   [ # 25 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  701
Joined  2004-03-30

Brilliant,

Your next step may be to have loading icons and events that execute once the data comes back from the server.

Good on ye!

mk

 Signature 

Mitchell Kimbrough

Profile
 
 
Posted: 17 March 2008 01:01 PM   [ Ignore ]   [ # 26 ]
Newbie
Rank
Total Posts:  5
Joined  2006-04-25

Right.
Don’t need to click away the exp:favorites:save-template any more and the links show up nicely.
Entry_id passes nicely and favorite_add and favorite_delete work well.

Only have to reload once my main page after clicking on the favorite_add link in order to see the changes.
I guess that I can trigger the page reload otherwise (automatically).
I guess that’s what you meant with “events that execute once the data comes back from the server”.
Still have to figure this out. Any further hint or code on this would be greatly appreciated.
grin

Profile
 
 
Posted: 13 October 2008 11:55 PM   [ Ignore ]   [ # 27 ]
Newbie
Rank
Total Posts:  28
Joined  2008-10-07

*solved*

Profile
 
 
   
2 of 2
2