Posted by perignon on September 27, 2012 at 1:07pm
I got a topic to talk about. We could even start the discussion here as well as at the next meetup.
I been fairly successful writing my own modules except for ONE thing. Loading an existing javascript using the API, drupal_add_js(). So far I have not got it to work and I've had to revert to putting the JS into a template file and loading it which is wrong, but works...
Each time I have tried this it causes all kinds of havoc on the site, admin menu stops working and all my flexsliders.

Comments
Have you tried a different JS
Have you tried a different JS file that you know is syntactically correct? Like just an "alert('w00t')". I am wondering if it is the JS code, not the method of adding it.
Michelle Lauer
michellelauer.com
Oh ya.. Scripts work fine
Oh ya.. Scripts work fine crammed in a tpl file. Cause havoc if I use drupal_add_js().
Brady
@fastglassllc
@derailedonline
From which function/hook are
From which function/hook are you adding the JS? What is the drupal_add_js() line you are adding?
Michelle Lauer
michellelauer.com
I'm doing this in a custom
I'm doing this in a custom module.
drupal_add_js('path-to-js-file')
I've also added options per the api documentation to drupal_add_js to change the location, weight, blabla of the JS I'm adding but always the same results.
The one I ran up on is adding the twitter JS to run the twitter feed. Most recently - last night - I was adding the JS for Facebook like buttons, G+ like buttons, and Twitter buttons (all the counting widgets) and none of those work either. They do work when crammed in a template file though.
Brady
@fastglassllc
@derailedonline
Here is the JS for the
Here is the JS for the Twitter feed:
https://gist.github.com/3794890
Brady
@fastglassllc
@derailedonline
Try this.... Change your JS
Try this....
Place the following two lines in whatever function/hook you are using. Replace 'MY_MODULE' & 'MY_JS' with what is appropriate.
drupal_add_js('https://widgets.twimg.com/j/2/widget.js', array('type' => 'external', 'scope' => 'footer'));
drupal_add_js(drupal_get_path('module', 'MY_MODULE').'/MY_JS.js', array('type' => 'file', 'scope' => 'footer'));
Michelle Lauer
michellelauer.com
Hrm... didn't think about
Hrm... didn't think about tearing it apart. I'll try that now.
Brady
@fastglassllc
@derailedonline
You know what I been
You know what I been missing.... 'type' => 'file'
And it loaded without messing anything else up!
Although I quickly found out the second part of the JS for that twitter thing is a rendering JS so it has to be in the block TPL file so that it will render the content to allow it to be displayed in a block.
Brady
@fastglassllc
@derailedonline
All it took was bouncing this
All it took was bouncing this off some people. Just learned a lot in like a few minutes. Awesome!
Brady
@fastglassllc
@derailedonline