The info and module files

The accordion.info file will follow the same structure as our previous .info files: ; $Id$

name = Accordion description = Display the left-hand blocks as an accordion, core = 6.x php = 5.2

There should be nothing surprising here.

Next, we will create a very simple module file. The PHP code for our module will simply add the requisite JavaScript libraries. Like our previous module, it will implement only the hook_help() and hook_init() hooks:

* Attach an accordion effect to menus.

function accordion_help($path, $args) { if ($path == 'admin/help#accordion') {

return t('This module adds accordion effects to menus.');

function accordion_init() {

$path = drupal_get_path('module', 'accordion'); drupal_add_css($path . '/accordion.css'); drupal_add_js($path . '/accordion.js'); drupal_add_js($path . '/ui/ui.core.js'); drupal_add_js($path . '/ui/ui.accordion.js');

The accordion_init() function adds four files.

First, the accordion.css file (which we will create in a moment) contains styling information. It is a CSS file, not a JavaScript file. Therefore, we add it with the drupal_add_css() function.

Next, we have three JavaScript files that need to be added:

1. accordion.js: This holds our custom JavaScript code. We will take a close look at the contents of this file shortly.

2. ui/ui.core.js: This is the base library for jQuery UI. It contains functions used by the rest of the jQuery UI components. Any time you use jQuery UI you will need to include this library.

3. ui/ui.accordion.js: This contains the jQuery UI accordion widget code.

That is all there is to our module. Next, we will look at the JavaScript.

Was this article helpful?

0 0

Post a comment