Background:
(*) I'm a JavaScript dilettante -- I just dabble when I need to.
(*) I have a piece of javascript that I've tested with a dummy page that I loaded by just calling it from a <body onload="..."/>
. It does what I want there. (See https://github.com/cwestin/bobt/blob/master/site/style/article.html , and the sibling file http://github.com/cwestin/bobt/blob/master/site/style/bobt.js).
(*) I want to add this onload behavior to my Drupal site.
I followed the instructions on how to create a Drupal 7 module from here: http://drupal.org/node/361112.
However, this seems to be aimed at PHP development of block modules that generate content. All I have is the JS file, which will act on some div classes I put in my content's unfiltered HTML markup.
I also found instructions on managing JavaScript here: http://drupal.org/node/756722.
And, a search on this site found these instructions for including JS: Best way for including javascript/jQuery OnLoad in EVERY page on my site . However, that didn't really seem to answer the question it posed -- that I could tell.
However, having created a module by following these incomplete instructions as best I can, it doesn't look like my JS is getting triggered. A View Source shows that my .js file is being included in the pages, but the transformation it does isn't happening (it did work in my dummy test page). It's possible I'm not translating into jQuery correctly; I've never used that before, and the syntax is clearly not just plain old JS.
Here's the module: https://github.com/cwestin/bobt/tree/master/site/style/sectiontoc . As you can see, in the spooky function($)
thingy, I add the required attach()
to try to add my behavior to $(document).ready
at the bottom. But as I said, it's not getting triggered.
Could anyone please tell me what I'm missing, or what I'm doing wrong here? Thanks in advance for any help.
drupal_add_js('myfile.js');
?