Using CGI-Toggle

From WormBaseWiki
Revision as of 18:34, 17 August 2010 by Cgrove (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search


CGI::Toggle -- Utility methods for collapsible sections


use CGI ':standard'; use CGI::Toggle

print header(), start_html('Toggle Test'), h1("Toggle Test"), toggle_section({on=>1},p('This section is on by default'), toggle_section({on=>0},p('This section is off by default'), toggle_section({plus_img=>'/icons/open.png', minus_img=>'/icons/close.png'}, p('This section has custom open and close icons.')), hr, end_html;


This package adds JavaScript-based support for collapsible sections by adding a single new function toggle_section().

It overrides the CGI start_html() method, so CGI must be imported before bringing this module in.


($control,$content) = toggle_section([\%options],$section_title=>@section_content)

This method takes an optional \%options hashref, a section title and one or more strings containing the section content and returns a list of HTML fragments corresponding to the control link and the content. In a scalar context the control and content will be concatenated together. The option keys are as follows:

 ;; on

If true, the section will be on (visible) by default. The default is false (collapsed).

 ;; plus_img

URL of the icon to display next to the section title when the section is collapsed. The default is /gbrowse/images/plus.png.

 ;; minus_img

URL of the icon to display next to the section title when the section is expanded.. The default is /gbrowse/images/minus.png.

 ;; override

If false (default), the state of the section will be remembered in a cookie. If true, the initial state will be taken from the on option, ignoring the cookie (which will, however, still be generated).




Lincoln Stein <>.

Copyright (c) 2005 Cold Spring Harbor Laboratory

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See DISCLAIMER.txt for disclaimers of warranty.

The xGetCookie() and xSetCookie() JavaScript functions were derived from, and are copyright (c) 2004 Michael Foster, and licensed under the LGPL (