Anagio
Anagio

Reputation: 3075

AddThis in AJAX

I'm trying to get Addthis to work in a div tag that's being loaded with AJAX I read on their site I had to render the toolbox with javascript http://support.addthis.com/customer/portal/articles/381263-addthis-client-api

I'm using the code below but it doesn't seem to be working, any help with the function is appreciated. Thanks.

<div id="toolbox"></div>
<script type="text/javascript">
    addthis.method('#toolbox', [configurationObject], [sharingObject]);
</script>

Upvotes: 2

Views: 5274

Answers (4)

Ryan Ore
Ryan Ore

Reputation: 1345

Since I don't know that much about your particular problem, I'd start start by looking into addthis.toolbox('.yourClass');

If you have a typical toolbox like this...

<div id="myToolbox" class="toolbox addthis_toolbox addthis_default_style ">
    <a class="addthis_button_facebook" style="cursor:pointer"></a> 
    <a class="addthis_button_twitter" style="cursor:pointer"></a> 
    <a class="addthis_button_email" style="cursor:pointer"></a>
</div>

Once your ajax content has finished loading into the dom you could do the following...

addthis.toolbox('#myToolbox');

However, watch out for this!

Don't put your like button inside your toolbox because when you call the addthis.toolbox method it will create a duplicate like button iframe for some reason. It must be a bug but it took a couple years off my life. Instead you should put it in its own toolbox containing div and call the method on it as well.

In the case of multiple toolboxes

you should probably use a class instead. See the following code for the final example.

html

 <div class="toolbox">
    <a class="addthis_button_facebook_like" fb:like:layout="button_count" addthis:userid="myCompany"></a> 
 </div>
 <div class="toolbox addthis_toolbox addthis_default_style ">
    <a class="addthis_button_facebook" style="cursor:pointer"></a> 
    <a class="addthis_button_twitter" style="cursor:pointer"></a> 
    <a class="addthis_button_email" style="cursor:pointer"></a>
 </div>

javascript:

//on complete of ajax load
addthis.toolbox('.toolbox');

Upvotes: 4

Anushka
Anushka

Reputation: 2434

var addthis_config =
{
ui_hover_direction: -1
, ui_offset_left: offsetLeft
, ui_offset_top: -45
, ui_delay: 300
, ui_click: false

};


var addthis_share =
{
url: 'http://www.example.com',
title: 'example title'
}

addthis.method("#Button2", addthis_config, addthis_share);

Visit http://www.addthis.com/forum/viewtopic.php?f=5&t=14137 this may help you.

Upvotes: 1

databyss
databyss

Reputation: 6488

method is not a valid function of the addthis object. It's a placeholder in the example for you to use a real method name.

Upvotes: 0

naspinski
naspinski

Reputation: 34697

You are never really calling anything as you aren't waiting for the DOM to ready:

<script type="text/javascript"> 
    $().ready(function () {
        addthis.method('#toolbox', [configurationObject], [sharingObject]);
    });
</script>

Upvotes: -1

Related Questions