Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.0
Component:
page displays
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
9 Nov 2009 at 22:22 UTC
Updated:
21 Dec 2009 at 02:06 UTC
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
Comment #1
dawehnerYou could use preprocess_page to get every activ js-files and if ajax_view.js is there you add your own.
Comment #2
30equals commentedmmm.. 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.
Comment #3
30equals commentedallright, found it!
with the following function in my .js, i can execute functions on each ajax load:
Comment #4
merlinofchaos commentedAhh, that's just your .js not using the API correctly then.
Comment #5
30equals commentedhow 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.
Comment #6
merlinofchaos commentedSorry, I meant the original problem. Using behaviors is the correct way. =)
Comment #7
30equals commentedallrighty then ;)
Comment #9
KerriO commentedSorry 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!
Comment #10
KerriO commentedComment #11
merlinofchaos commentedNote 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.
Comment #12
KerriO commentedWill do… sorry for the off-topicness :)