By webadpro on
Hello,
I'm not too sure how drupal.behaviors are working. Is there a good place where I could actually learn how its actually working and how can I get it working the right way in my custom modules.
Also, this might sound stupid but can I bind a behaviors to a button which has ahah on it?
And is it Drupal.behaviors.hook_name? Im very new to behaviors so any tutorials would be greatly appreciated.
Warm regards,
Pat
Comments
google is your friend
Search for "drupal.behaviours', there are 10.5 million matches, the first page looks to have some good info!
www.purpleoar.co.nz/scryptik - Javascript editor with syntax error checking
www.purpleoar.co.nz - Web development, Drupal consultancy
Drupal.behaviors is
Drupal.behaviors is essentially an onload function. You put any onload queries you have into it. If does checks to make sure the browser has the right capabilities, and if it does, it will execute your commands when the DOM has loaded.
It is usually namespaced by your module name. For example:
Contact me to contract me for D7 -> D10/11 migrations.
resource recommendation
There is a book for drupal 6 covering the subject.
Title : Drupal 6 JavaScript and JQuery
ISBN : 978-847196-16-3
I find a well written book is far better than several Google searched pages.
Thanks everyone. Its simply
Thanks everyone.
Its simply because I often see prototype in the js too, and Id like to understand that part.
Can I attach a js to be
Can I attach a js to be executed only on a certain page?
Lets say I have a form where I want to execute a certain js on that form only. How would I do this?
If anyone could help.
Thanks
There are various ways you
There are various ways you can do it, but the way I do it is to add a themeing function and put the JS in there.
So for example, if I have the following form definition:
Then I would register a theme in hook theme as follows:
And that will add your JS to your pages.
Contact me to contract me for D7 -> D10/11 migrations.
Hi, Thanks for the example
Hi,
Thanks for the example and that's what I've been doing all along, although I was wondering from my JS file is there a way to tell to check if some function are for a certain form!?
Exemple:
As you can see in Form2 I don't include any jquery.ui files so I get a JS error when viewing it. So I was wonderinf if in JS file if there was a built-in function to attach a form or some sort?
Any help is greatly appreciated.
Thanks
You can test if a function
You can test if a function exists like this:
Replace
yourFunctionNamewith the actual function name (no quotes).But really, I'd just create a separate javascript file for the other form. It will keep your code cleaner.
Contact me to contract me for D7 -> D10/11 migrations.
I was looking for the same
I was looking for the same information and found that this page (http://mydrupalblog.lhmdesign.com/drupal-theming-jquery-basics-inc-drupal-behaviors) was very enlightening.