After the most recent update ( July 1, 2010), I am getting this javascript error:

da2a is not defined

in this function:

da2a.init = function(){ da2a.ready = true; } da2a.html_ready = true; if(da2a.script_ready && !da2a.ready)da2a.init();

I found the code that writes this into the footer in the addtoany.module file on line 132.

Any help?

CommentFileSizeAuthor
#13 addtoany.module.patch735 bytesmicropat
#12 addtoany.module.patch679 bytesmicropat

Comments

talee23’s picture

I would like to add that this is on a page that I have told the addtoany button block not to appear. I don't get this error where the button appears.

da2a is not defined unless there is a button on that page... thus getting the javascript error.

micropat’s picture

Interesting. The da2a object should be defined right after the first AddToAny button, for example:

<a class="da2a_button" href="http://www.addtoany.com/share_save" id="da2a_1"><img src="/sites/all/modules/addtoany/images/share_save_171_16.png" width="171" height="16" alt="Share/Save"/></a> 
<script type="text/javascript"> 
var a2a_config = a2a_config || {}, da2a = {ready: false, html_ready: false, script_ready: false, script_onready: function() { da2a.script_ready = true; if(da2a.html_ready)da2a.init(); }}; a2a_config.tracking_callback = ['ready', da2a.script_onready];
...

Do you see a block of code like the above in your source? Specifically looking for da2a =

talee23’s picture

I do see it.. but like i said above, only if i have told the button to appear on that page.

In my configuration of the addtoany block I have told it NOT to appear on my homepage ('') and so I am getting this error only on my homepage.

micropat’s picture

Status: Active » Needs work

We posted at the same time. :) So that makes sense. Will be fixed in the next release.

If anyone wants to provide a patch in the meantime, that would be great.

talee23’s picture

Great thanks!

talee23’s picture

To fix this I changed the code on line 135 in the addtoany.module file to the following:

$javascript = "<script type=\"text/javascript\">\n"
		. "if(typeof(da2a) != 'undefined'){\n"
		. "da2a.init = function(){\n"
		. $_addtoany_script
		. "da2a.ready = true;\n"
		. "}\n"
		. "da2a.html_ready = true;\n"
		. "if(da2a.script_ready && !da2a.ready)da2a.init();}\n" // Call a2a.init() if external script is ready, and if a2a.init() hasn't been called already
		. "</script>\n";
skizzo’s picture

Status: Needs work » Needs review

fix by talee23 works for me

tadeusz jurek’s picture

fix by talee23 works for me too :)

Rainman’s picture

Another working fix here. Thanks talee23

c4antonio’s picture

now it's work fine, thanks talee33

gillesbailleux’s picture

Many thanks to talee33 for this working fix!

micropat’s picture

Status: Needs review » Patch (to be ported)
StatusFileSize
new679 bytes

The attached patch ensures that no extraneous JavaScript is outputted in the first place. Cheers to talee23. ;)

Patch will be applied in version 6.x-3.3.

micropat’s picture

StatusFileSize
new735 bytes

My last patch had a bug; use this one.

micropat’s picture

Status: Patch (to be ported) » Fixed

Fixed in 6.x-3.3!

Ela’s picture

Status: Fixed » Active

I'm using version 6.x-3.3 , but still have this error
Update: However when applied the fix by talee33, it fixes the problem

zet’s picture

same problem with 6.x-3.3
and i don't find the code from talee33 http://drupal.org/node/843068#comment-3155884

micropat’s picture

Title: da2a is not defined » Premature JavaScript function call, should only output the JavaScript when needed
Status: Active » Closed (fixed)

FYI the code from talee33 is not recommended (it only stifles the error message), and the original issue was indeed fixed in 6.x-3.3. So I'm changing the issue title to be much more specific. :)

The "da2a is not defined" issue might be related to #884404: dropdown doesn't appear after editing properties (due to ckeditor) or something else. If it's something else, please post a new issue.

whitedroplet’s picture

I'm getting this da2a javascript error when I enable the addtoany block with no wysiwyg html editor installed.

mattsmith3’s picture

I have this error too- and I the dropdown isn't working for me. Version 3.3

aaron’s picture

Version: 6.x-3.2 » 6.x-3.3
Status: Closed (fixed) » Active

having the same issue, w/o wysiwyg

aaron’s picture

Status: Active » Fixed

seems to be slightly different than this issue though, i'll close and open a new one.

Ela’s picture

Status: Fixed » Active

... wrong post, sorry

Ela’s picture

sorry, wrong post

Status: Active » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

3gteen’s picture

Thanks you

RumpledElf’s picture

Issue summary: View changes

I have the same issue. Trying to put the share buttons on a blog, da2a_1 is the ID but da2a is what the jQuery is looking for so it fails. Been at this for hours, had numerous jQuery things failing to load for various reasons and was hoping cleaning up the jQuery on the site would help a bit since I had some other jQuery based modules failing but no ...

I'm working with the Barg theme from Drupalet which doesn't do a lot of standard Drupal things (including its own jQuery on top of Drupal's was one of the more minor things it does) and the blog TPL file is very long, complex and full of conditionals so I think my only option here is to just not use add to any and try and shoehorn yet another 3rd party non-Drupal library into this website to get share buttons. The same issue happens with the block so I have no idea what is going on.

I'm guessing my problem is the content being rendered so strangely is somehow incrementing the add to any button, although why it happens with both the block and the node versions is beyond me.

RumpledElf’s picture

Fixed my issue in the end by adding https://www.addtoany.com/buttons/for/website these buttons directly into the TPL. Worked first go, no problems.