Javascript can add features and functionality to your site. For best results, follow these suggestions (thanks to Chaz Chumley for his knowledge and help!):
- Configure the JS injector (Configuration > Development > JS injector):
- Default jQuery version: change to 1.7
- Alternate version for admin pages: Default jQuery version
- jQuery compression level: minified
- jQuery and jQuery UI CDN: Choose Google
- Save
- Install whatever javascript set you need (+ Add). Give the name of the script something that is meaningful to you.
- For those js sets requiring a function (initialization) script, follow this syntax:
- A function script usually appears in the header or in the body of a static page in which the behavior will be displayed, and typically takes the form:
$(function() {
$( "[id-or-class-of-your-div-containing-the-behavior]" ).[name-of-function-in-your-source-script]({
[variable: desired-result] (if any)
});
});
- This syntax will not work in Drupal Cloud 7. The following syntax will work. You do not need to use Drupal.behaviors (as mentioned in some MIT guides.
(function ($) {
$(document).ready(function() {
$( "[id-or-class-of-your-div-containing-the-behavior]" ).[name-of-function-in-your-source-script]({
[variable: desired-result] (if any)
});
});
})(jQuery);
- Example:
- This doesn’t work in Drupal Cloud 7:
$(function() {
$( "#accordion" ).accordion({
collapsible: true
});
});
- This does work:
(function ($) {
$(document).ready(function() {
$( "#accordion" ).accordion({
collapsible: true
});
});
})(jQuery);
- This doesn’t work in Drupal Cloud 7:
- A function script usually appears in the header or in the body of a static page in which the behavior will be displayed, and typically takes the form: