|
Cookbook /
ToggleSummary: Adds links or buttons for toggling (hiding/showing) div sections and objects
Version: 2009-07-23
Prerequisites: PmWiki 2.2.0
Status: stable
Maintainer: HansB
Discussion: Toggle-Talk
Download: toggle.phpΔ
Toggle Popup BoxAn absolutely positioned div.
Questions answered by this recipeHow can I add toggle switches to show and hide sections of the page? DescriptionThe script adds markup for links, buttons or images for toggling (hiding/showing) div sections and objects Download toggle.phpΔ and copy to cookbook folder. Install by adding to config.php: include_once("$FarmD/cookbook/toggle.php");
Toggle button examples: Short syntax:
Long syntax:
Toggle link examples:
Necessary parameter:
Optional parameters:
Shortcut syntax:You can avoid some of the parameter keywords and use keyless arguments in the markup instead.
LabelsFor custom labels set labels with parameters show= or hide= (or label= for one 'show' and 'hide' label). Images as togglesYou can have images displayed instead of link text. Use the image file name with extension as label text, like show=myshow.gif hide=myhide.gif. Then clicking the image will toggle the div display, and if you use different images for show and hide these images will toggle as well. Images should be attached to the page (use action=upload to upload file to page or group). Syntax like label=Attach:myimage.ext Δ does not work. If your uploaded image file is attached to a different group, for instance it is uploaded to the 'Site' group, then use syntax like show=Site/myshow.gif. - The toggle markup recognises images with extensions png, gif, jpg, jpeg and ico. If there are problems with uploading such images, make sure you follow all the advice about uploading images and necessary permissions are set. config.php parameters
Backward compatibilityThe script is backwards compatible with the togglelink markup syntax. lshow= works same as show= parameter, lhide= works same as hide= parameter, div= works same as id= parameter, div2= works same as id2= parameter. Buttons are implemented with a button=1 parameter, and work that way like ShowHide Buttons. This recipe supersedes the ShowHide and ToggleLink scripts. NotesThe script requires a javascript enabled modern browser. It places a javascript function into the html body, which will achieve instant toggle effects without page reloads. A toggle button can act on any named division of the page, even a sidebar or other structural division outside the normal page content. But in such a case it may not make a too good job, because to hide such a div effectively may need more than applying display:none, for instance resetting of margins. A toggle button can also act on other objects with an id= set, for instance tables. It is not restricted to divs. A toggle button or link can toggle two divisions or objects, hiding one and showing the other, alternating. Name the first division or object id with id=... and the second with id2=... Two toggle buttons or two toggle links can act together as a pair on one div. For instance put one on top of the div, and the other inside at the bottom, to conveniently close it. But note that the label or link text of the second one will be displayed on the first one when clicked, so use the same labels for both. And if the div shall be initially hidden, place init=hide into the first markup and not the second. Release Notes
See Also
CommentsSee discussion at Toggle-Talk
User notes: If you use, used or reviewed this recipe, you can add your name. The following format is recognized:
* (+) Optional positive comment. Name, date * (-) Optional negative comment. Name, date These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |