5

I have managed to add a jQuery accordion content page to my Drupal7 site by following the instructions/code given here: http://www.chrisherberte.com/blog/drupal-7-and-jquery-ui-accordion.

However, the height on the drop down fields is not being calculated correctly. Some are too long with lots of white space, others are too short meaning a scroll bar is added to view all the text. It appears to be taking all the heights of each field and using that to calculate an average height which it then applies.

I have tried the default Bartik theme, as well as my custom theme, functionality is the same on both so not a css issue, but a problem with the jquery itself.

On top of this, using HTML list elements stops it working all together, and messes up the formatting completely.

screenshot

I do not have any idea where or how to edit the Jquery to fix this problem and certainly don't really want to be hacking core.

3

First you should try to set autoHeight to false , this will fix the height problem.
You should aslo consider to use behaviors in Drupal.

<?php
drupal_add_library('system', 'ui.accordion');
drupal_add_js("
  (function ($) {
    Drupal.behaviors.accordionRoles = {
      attach: function (context, settings) {
        $('#accordion').accordion({
          autoHeight: false
         });
      }
    };
  }(jQuery));
", 'inline');
?>

Then I could find the problem regarding HTML lists, I grabbed your HTML, put it locally and used the demo source for jQuery UI accordion (the section 3 have some HTML list inside) and it seems to work fine.

HTML lists working fine

  • Many thanks indeed - will try this now and see how I go. Renaee. – Renaee Jun 10 '11 at 3:57
  • Could you tell me the exact code you put in the page to make this work, I am get an error currently. Does the behaviour code replace the previous code i had, or is in addition to. – Renaee Jun 10 '11 at 4:22
  • @Renaee replace your accordion JavaScript code by mine. – tostinni Jun 10 '11 at 4:48
  • Parse error: syntax error, unexpected T_FUNCTION in /home/ohsinchi/public_html/modules/php/php.module(74) : eval()'d code on line 2 – Renaee Jun 10 '11 at 4:52
  • this is what I get when use just yours? – Renaee Jun 10 '11 at 4:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.