Download & Extend

External JavaScript does not load if the first button does not output

Project:Share Buttons (AddToAny) by Lockerz
Version:6.x-3.4
Component:Code
Category:bug report
Priority:normal
Assigned:micropat
Status:active

Issue Summary

The Javascript on page fails due to error: "da2a is not defined". Originally thought this was related to #843068: Premature JavaScript function call, should only output the JavaScript when needed or #884404: dropdown doesn't appear after editing properties (due to ckeditor). However, WYSIWYG is not on the form for additional settings in my case, and there is nothing in that box anyway. And this is on pages with the button, which makes the thing even more bizarre.

Comments

#1

furthermore, after reading #905466: da2a not defined in IE (solution: reduce number of stylesheets), this is in firefox, as well as in internet explorer. it does seem to be specifically on pages that embed videos (from blip.tv and youtube).

#2

and css is being aggregated, so it's definitely not the 'too many stylesheets' problem.

#3

Title:Javascript on page fails due to error: "da2a is not defined".» Javascript on page fails due to error: "da2a is not defined", when embedding a video on the page

definitely seems to be when embedding a video object. marking that in the title.

#4

if i run da2a from firebug on those pages, i get "ReferenceError: da2a is not defined", whereas i get the expected object on other pages.

#5

even odder: tracing the html, on good pages, i see id="da2a_1" with the js defining the object later. on video pages, however, i see id="da2a_2" with no js. which makes sense -- somehow the button is being called twice, but only printed the second time...

makes me wonder if that code couldn't be added as a script and using Drupal.settings to get around some of these issues.

and no, i grepped first to make sure, we aren't actually calling any functions from addtoany manually on the site...

#6

it was because i had overridden the node template, which was not printing the first node addtoany button. instead, we were using the block. however, without the resultant js being printed from the first, the whole thing broke. turned off the addtoany for that node type, and it all started working again.

seems fragile to me. could the module print the initial declaration for da2a in the footer, rather than in the content? or even better, move all that code into a js file and make use of Drupal.settings to initialize the data?

#7

Title:Javascript on page fails due to error: "da2a is not defined", when embedding a video on the page» External JavaScript does not load if the first button does not output
Version:6.x-3.3» 7.x-3.0
Assigned to:Anonymous» micropat

Excellent troubleshooting, Aaron! You're right, the async loading has been fragile for some setups, and this issue has prompted me to give it a bit of a rewrite. Very soon I'll issue a hardening release, which will likely resolve other various related issues.

The next release, 7.x-3.1 and 6.x-3.4, will continue to call the JS after the first button output (to take advantage of concurrent downloading enabled by async), and it will additionally attempt to load the script from the footer if it hasn't already been loaded.

Using a JS file & Drupal.settings is a good suggestion and it'll probably be the method moving forward, Transitioning to that method will require more load order dependency, which varies slightly across D6/67 installations with a few issues here and there, so the inline JS is more robust for now but eventually we will cross over into more elegant territory. :)

#8

Status:active» fixed

Fixed in 6.x-3.4 and 7.x-3.1.

#9

Status:fixed» closed (fixed)

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

#10

Version:7.x-3.0» 6.x-3.4
Status:closed (fixed)» active

I have just installed 6.x-3.4 and this issue persists. Same situation for me. I am only displaying the block, not showing the button on any content.

#11

I am using the AddToAny block to show the share link/widget. In IE8 and Firefox (latest, 13.0) I am getting a "'da2a' is undefined" error on every page. No issues in Chrome so far. I'm not embedding in a template file, just using the stock block from the module and JavaScript is not aggregated. No videos embedded on my site, Drupal core and all modules up to date.