How to use AddThis within a jQuery Fancybox?

autocleaners Dec 15, 2011 04:39AM EST

Hi guys,

I've got a jQuery Fancybox (http://fancybox.net/) displaying some markup retrieved via an HTTP request. Now I'm fighting with adding an AddThis toolbox to this markup. My first step was to simply add a basic toolbox markup:

<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_button_google_plusone" g:plusone:size="medium"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4eb2f6a46482052a&domready=1"></script>

First problem: This markup is not changed by AddThis, i. e. it remains empty.

It may be the case, that the markup is not yet added to the document when the included script is run. So I tried to manually call addthis.toolbox('.addthis_toolbox') after the fancybox is displayed. This call is made, the Chrome debugger shows two steps within the AddThis script and then immediately returns. No changes are made, no errors are thrown.

When I use the exact same markup within a simple page instead the fancybox and call addthis.toolbox('.addthis_toolbox') on load, everything is set up as expected. So it somehow seems like AddThis cannot find the markup. But the fancybox is simply appended to the content of the body element, so I can't see any reason for this.

Do you have any idea how to get this working?

Regards

10 Community Answers

Paul Dec 16, 2011 03:19PM EST

Have you tried adding the AddThis JavaScript to the page, rather than in the FancyBox? Also, could you post a link to your implementation so I could see it running as well?

View in conversation


Up 0 Rated Down
Paul (AddThis Happiness Specialist) Best Answer Dec 16, 2011 03:19PM EST
Have you tried adding the AddThis JavaScript to the page, rather than in the FancyBox? Also, could you post a link to your implementation so I could see it running as well?
Up 0 Rated Down
autocleaners Dec 18, 2011 08:20AM EST
Adding the script tag to the page, it works. I wonder what's the difference, since the addthis.toolbox function is defined when the script is included within the fancybox, so it has to be already loaded when the call is made...
Up 0 Rated Down
Paul (AddThis Happiness Specialist) Dec 19, 2011 03:16PM EST
It's likely that the JavaScript code isn't parsed when you run include it dynamically. Putting the addthis_widget.js on the page makes sure everything's ready to go when the page is loaded.
Up 0 Rated Down
autocleaners Dec 21, 2011 11:07AM EST
One more problem with this:

If I fill and show the FancyBox a second time and then call addthis.toolbox() again, the toolbox gets nearly rendered as expected, but the tweet button - it becomes a simple link saying "Tweet".

Is there some known problem with rendering a tweet button multiple times?
Up 0 Rated Down
Paul (AddThis Happiness Specialist) Dec 21, 2011 04:15PM EST
I haven't heard of any issue with the Tweet button but it's not impossible. Could you post a sample page so I could take a closer look?
Up -1 Rated Down
autocleaners Dec 22, 2011 04:28AM EST
Here you are: http://pastie.org/3056444 What happens for me (testing in Chrome btw) is the toolbox gets rendered as expected at first time. When I close the fancybox, it gets reopened and the toolbox gets rendered a second time. Now the twitter button is a link and - as I just discovered - the AddThis pill is missing completely.
Up 0 Rated Down
Paul (AddThis Happiness Specialist) Jan 04, 2012 05:09PM EST
Just wanted to let you know we've got a fix for this that will be coming out soon.
Up 0 Rated Down
berthoud Jan 08, 2012 05:12PM EST
Hello,

I've got a similar issue with a jQueryUI dialog with html content loaded dynamically. The Addthis markup and scripts are in this html document. I think the problem is coming from the jQuery.load() function.

Paul, do you think the fix you are talking about could fix my issue and when it will be out roughly ? I mean, is it a matter of days, weeks, months ? Thanks for your help.
Up 0 Rated Down
Paul (AddThis Happiness Specialist) Jan 11, 2012 04:38PM EST
It should be fixed in a couple weeks, and might help with the JQuery.load() function.
Up 2 Rated Down
autocleaners Mar 04, 2012 05:08PM EST
Hey Paul,

the Twitter button works for me now. But the AddThis pill is still missing (on every call, not just starting with the second one). Are you working on this? Or couldn't you even reproduce it?

Regards!

Post Your Public Answer

Your name (required)
Your email address (required)
Answer (required)

Still need help?


General Topics

 

Developers