I have a javascript—just a plain 'ol jQuery plugin as-is (not as a module), that I'm using in a ajax-enabled View with exposed filters. When a filter is applied, the javascript does not reload. I know, in theory, what I need to do to make sure that it loads upon each no ajax reload, which is to use "Drupal.behaviors.myBehavior = function (context) {…" instead of the standard "$(document).ready(function(){…" call.
I have the script located at "sites/all/scripts/myscript.js" . It's the jquery pluging as-is, completely unaltered.
I call it using
drupal_add_js('/sites/all/scripts/myscript.js');
I also add this to get it to load
drupal_add_js( '$("input[type=\'radio\']").myscript( { customvar: "var" });', 'inline');
(Which, even though I know is an improper method, it works—at least on the first load…)
So, I know what I should be doing, but I can't figure out what I should be replacing where:
does Drupal.behaviors.myBehavior = function (context) { } replace the function($) { … } in the actual .js file, or just the call for that file (the inline javascript in my example above)? I *think* it's the call, but if so, I don't know the exact syntax to use. I've been searching and searching and I can't find any explanations anywhere that are detailed enough to allow me to finally "get" this. Any help would be greatly appreciated. And example of the full syntax (or even a link that shows an example) would be even more appreciated. I've looked up and down for the answer, I haven't found anything specific enough to account for my very basic drupal and javascript development knowledge.
If anyone could, very specifically, explain to me what I need to replace where, I would greatly appreciate it.
Comments
any solution
Did you ever figure this out? I just ran into the exact same problem. Any tips would be greatly appreciated.
Thanks!
I found it!
HAHA. I had same issue and i found solution here http://drupal.org/node/1793334
If you look attentively you can notice the wrappers for drupal custom .js files
Do not do any changes to your js contents, just place th whole code between these footer/header.
Just wrap all your .js file contents as per above code example.
Gamepart, Krambol