I am trying to make use of the collapsible classes like this, in a node.

<script type="text/javascript" src="/misc/collapse.js"></script>
<fieldset class="collapsible collapsed"> <legend>Title of collapsible content</legend> Hidden text </fieldset>

The text within the fieldset is visible 'behind' the rest of the content while the fieldset is collapsed.

Why is the text still visible?

I've been able to get it to work by using

<?php
drupal_add_js('misc/collapse.js');
?>

but I don't want to use the PHP input filter. How can I make this script accessible to node content?

Interestingly enough, it works if I add the drupal_add_js() call to node.tpl.php but I still need to give PHP as input format to the node for the script to be executed properly.

Comments

nevets’s picture

Not sure, but try placing Hidden text in a div.

jmlavarenne’s picture

Thanks for the tip, I tried it, but even then the effect will only work if the node is posted with the PHP input filter on the body field, even if the js file is included in a script tag instead of the drupal_add_js() call.

jefkin’s picture

Essentially, that's by design.

If you are working on a "hand-crafted" node or page, then you can use the PHP input filter.

If you don't mind slowing down the rest of your site slightly, you could do this:

1) Modify your theme to place the following javascript includes.

<script type="text/javascript" src="/misc/jquery.js"></script>
<script type="text/javascript" src="/misc/drupal.js"></script>
<script type="text/javascript" src="/misc/collapse.js"></script>

Inside the standard "output" for the site, but just before or just after where the theme puts the Drupal generated script includes. That way, if your site does include these files in generating a page, it won't hurt you.

And that could work directly, but it might not. If it doesn't,

2) Then you can add this code:

<script type="text/javascript">
if  (Drupal.jsEnabled)
{
  $(document).ready(
    function()
    { 
      Drupal.attachBehaviors();
    });
}
</script>

to your node body, without using the php input type, but you will need full html.

Hope that helps.