drupal.behaviors
DESCRIPTION
LA Drupal Lightning TalkTRANSCRIPT
![Page 1: Drupal.Behaviors](https://reader038.vdocument.in/reader038/viewer/2022100600/555e3ec0d8b42a63048b5059/html5/thumbnails/1.jpg)
presentation by: Tom Friedhof
IntroducingDrupal.behaviors
![Page 2: Drupal.Behaviors](https://reader038.vdocument.in/reader038/viewer/2022100600/555e3ec0d8b42a63048b5059/html5/thumbnails/2.jpg)
Review jQuery Basics
![Page 3: Drupal.Behaviors](https://reader038.vdocument.in/reader038/viewer/2022100600/555e3ec0d8b42a63048b5059/html5/thumbnails/3.jpg)
Review jQuery Basics
$( [find something] ).doSomething();
![Page 4: Drupal.Behaviors](https://reader038.vdocument.in/reader038/viewer/2022100600/555e3ec0d8b42a63048b5059/html5/thumbnails/4.jpg)
Review jQuery Basics
$( [find something] ).doSomething();
$(“#tabs”).tabs();
CSS Selector jQuery UI Method
![Page 5: Drupal.Behaviors](https://reader038.vdocument.in/reader038/viewer/2022100600/555e3ec0d8b42a63048b5059/html5/thumbnails/5.jpg)
The DOM has to be ready
$(document).ready(function() {
// Code Goes Here
});
![Page 6: Drupal.Behaviors](https://reader038.vdocument.in/reader038/viewer/2022100600/555e3ec0d8b42a63048b5059/html5/thumbnails/6.jpg)
The DOM has to be ready
$(document).ready(function() {
$(“#tabs”).tabs();
});
![Page 7: Drupal.Behaviors](https://reader038.vdocument.in/reader038/viewer/2022100600/555e3ec0d8b42a63048b5059/html5/thumbnails/7.jpg)
The Drupal Way
Drupal.behaviors.loadTabs = function(context) {
// Code Goes Here
};
![Page 8: Drupal.Behaviors](https://reader038.vdocument.in/reader038/viewer/2022100600/555e3ec0d8b42a63048b5059/html5/thumbnails/8.jpg)
The Drupal Way
Drupal.behaviors.loadTabs = function(context) {
$(“#tabs”).tabs();
};
![Page 9: Drupal.Behaviors](https://reader038.vdocument.in/reader038/viewer/2022100600/555e3ec0d8b42a63048b5059/html5/thumbnails/9.jpg)
Why use Drupal.behaviors?
• Ability to override JS
• Behaviors are re-attachable
• Attach Behaviors to a specific context
• HTML loaded via AHAH
![Page 10: Drupal.Behaviors](https://reader038.vdocument.in/reader038/viewer/2022100600/555e3ec0d8b42a63048b5059/html5/thumbnails/10.jpg)
Why use Drupal.behaviors?
• Ability to override JS
• Behaviors are re-attachable
• Attach Behaviors to a specific context
• HTML loaded via AHAH
Drupal.attachBehaviors(elem);
![Page 11: Drupal.Behaviors](https://reader038.vdocument.in/reader038/viewer/2022100600/555e3ec0d8b42a63048b5059/html5/thumbnails/11.jpg)
DemoDrupal.behaviors
![Page 12: Drupal.Behaviors](https://reader038.vdocument.in/reader038/viewer/2022100600/555e3ec0d8b42a63048b5059/html5/thumbnails/12.jpg)
Resources
http://api.drupal.org/api/file/developer/topics/javascript_startup_guide.html/6
http://raincitystudios.com/blogs-and-pods/katherine-bailey/the-lowdown-jquery-drupal-part-two
http://www.chapterthree.com/blog/josh_koenig/handling_aysnchronous_data_drupal_session_materials
![Page 13: Drupal.Behaviors](https://reader038.vdocument.in/reader038/viewer/2022100600/555e3ec0d8b42a63048b5059/html5/thumbnails/13.jpg)
Questions?