Posted by 30equals on November 9, 2009 at 10:22pm
Jump to:
| Project: | Views |
| Version: | 6.x-2.0 |
| Component: | page displays |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
hey
in my drupal site i have some custom jquery functions which run on a page load. the .js is been added through a drupal_add_js in my template.php
now, with ajax enabled, the .js doesn't get loaded anymore on each page of my view.
is there a views hook i should use or something, so on every ajax load, the .js gets called ?
thanx!
Comments
#1
You could use preprocess_page to get every activ js-files and if ajax_view.js is there you add your own.
#2
mmm.. i put my drupal_add_js functions in the preprocess_page now, but it's still the same.
it's not that the jquery isn't there, but my dom manipulation only works on the first page load. when applying filters or paging to my ajax enabled view, the functions don't get applied to my elements in the page.
#3
allright, found it!
with the following function in my .js, i can execute functions on each ajax load:
Drupal.behaviors.myBehavior = function (context) {
....
};
#4
Ahh, that's just your .js not using the API correctly then.
#5
how so ?
my jquery is manipulating some view rows, and i added the .js in my template.php.
if there's a better way please do share it.
#6
Sorry, I meant the original problem. Using behaviors is the correct way. =)
#7
allrighty then ;)
#8
Automatically closed -- issue fixed for 2 weeks with no activity.
#9
Sorry for such a newb question, but I'm having this exact same problem, and have known that this is the answer for *days*, but I can't figure out how exactly to apply it. If anyone can help me out that'd be wonderful.
This is what I've *been* doing, that works on the first load, and not thereafter, and I know it's not right, but I can't find enough details in regard to what exactly I should be changing.
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 I should be using Drupal behaviors to get it to fire up correctly with ajax in views, 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)? 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 swear, I've looked up and down for the answer, but I'm no Drupal developer, and it seems I have to understand Drupal development from the ground up to get most of the documentation about this, and I'm just trying to build a relatively basic site and get js to work!
#10
#11
Note that this is the issue queue for Views, so asking generic javascript questions here isn't very valuable. You should try on the general forums, perhaps. One downside is that there aren't that many javascript experts within the community.
#12
Will do… sorry for the off-topicness :)