background image
HomeRecent PostsDrupalSearchTagsRSSContactAboutAccount
Eric.London's picture

You've probably seen the accordion effect in use at Apple's website. I recently implemented this plugin in a Drupal module to get a similar effect.

First, download the plugin from Bassistance. I stuck the jquery.accordion.js in my module directory and then included it using the following code:

<?php
drupal_add_js
(drupal_get_path('module','MYMODULENAME') . '/jquery.accordion.js');
?>

I created a dataset to use with the theme_item_list function. For this example, I'll query the node table.

<?php
$sql
= "select title from {node} where status='1' order by title asc";
$resource = db_query($sql);
$results = array();
while (
$row = db_fetch_array($resource)) $results[] = $row;
?>

I looped through the dataset and created an item list array consisting of an A tag and a DIV.

<?php
$items
= array();
foreach (
$results as $k => $v) {
 
// NOTE: you should use the l() function here, excuse my example
 
$items[] = "<a>{$v['title']}</a><div>MYTEXTHERE</div>";
}
?>

I used the theme function to generate the html for a UL with a unique identifier.

<?php
$title
= MYTITLE;
$type = 'ul';
$attributes = array(
 
'id' => 'MYITEMLISTID',
);
$page_contents .= theme('item_list', $items, $title, $type, $attributes);
?>

Last, I added the jQuery to apply the accordion effect to my UL.

<?php
$(document).ready(function(){
  $(
'#MYITEMLISTID').accordion();
});
?>

Eric.London's picture

For PHP development, I use Eclipse and the PDT Plugin. I always use the "update manager" functionality of Eclipse to install my plugins. PDT has some dependency issues, so here's how to get it installed...

First, add the following update sites...

- EMF - http://download.eclipse.org/modeling/emf/updates/releases/
- GEF - http://download.eclipse.org/tools/gef/update-site/releases/site.xml
- PDT - http://download.eclipse.org/tools/pdt/updates/site.xml
- WTP - http://download.eclipse.org/webtools/updates/

The dependency chain goes as follows:
PDT -> WTP -> GEF -> EMF

Start by installing the EMF plugins required by GEF...

EMF -> EMF SDK 2.3.2(EMF + SDO + XSD)
- Eclipse Modeling Framework (EMF) - org.eclipse.emf.common
- Eclipse Modeling Framework (EMF) - org.eclipse.emf.ecore
- Eclipse Modeling Framework (EMF) - org.eclipse.emf.edit
- Eclipse Modeling Framework (EMF) - org.eclipse.emf.ecore.edit
- Eclipse Modeling Framework (EMF) - org.eclipse.xsd.edit
- Eclipse Modeling Framework (EMF) - org.eclipse.xsd
- Eclipse Modeling Framework (EMF) - org.eclipse.emf.edit.ui
- Eclipse Modeling Framework (EMF) - org.eclipse.emf.common.ui

Second, install GEF...

GEF -> Eclipse DSK R3.3.2 -> Graphical Editing Framework

Third, install WST...

WTP -> Web Tools Platform (WTP) -> Web Standards Tools (WST) Project

Finally, you can install PDT...

PDT -> PDT Features -> PDT Feature

Syndicate content