Translations of this page?:

DokuWiki Fold Support

deprecated

Current versions (2005-09-22 and later) should use the plugin, folded.


This patch allows section of text to be 'folded', shown or hidden but user interaction. There are two sets of tags that I have choosen to use for this purpose, -+ text +-, for defaultly hidden sections, and +- text -+ for defaultly visible sections. This works by creating two DHTML blocks for each section, one to place the section of text within, and another with the expander-marker, that accepts clicks from the mouse to toggle the visibility of the section. When clicked, the expander-contractor (called folder in the code), calls the javascript function fold with the name of the DHTML block to toggle the visibility of. The names of the DHTML blocks are generated randomly using PHP's rand() function.

Please also checkout Chris Stoll's excellent rewrite for Folding Section Support.

Prerequisites

DokuWiki Changes

  • In style.css, add the following lines:
span.folder {
  float: left;
}
span.folder:hover {
  background-color: #bbbbff;
}
  • In script.js, add the following function:
function fold( folder, divname ) {
  var divstyle = document.getElementById( divname ).style;
  var showhide = (divstyle.display == 'none')?'':'none';
  divstyle.display = showhide;
  folder.innerHTML = (showhide=='none')?'<img src="images/closed.gif">':'<img src="images/open.gif">';
}
  • In inc/parser.php, carefully add the following lines below the line containing $text = customs($text);:
  // Add folding support (needs work)
  while ( preg_match( '/\+-.+?-\+/s', $text ) ) {
    $rand = rand();
    $text = preg_replace('/\+-(.+?)-\+/s','<span class="folder" onclick="fold(this, \''.$rand.'\');"><img src="images/open.gif"></span><div id="'.$rand.'">\1</div>',$text,1);
  }
  while ( preg_match( '/\-\+.+?\+\-/s', $text ) ) {
    $rand = rand();  
    $text = preg_replace('/-\+(.+?)\+-/s','<span class="folder" onclick="fold(this, \''.$rand.'\');"><img src="images/closed.gif"></span><div id="'.$rand.'" style="display:none;">\1</div>',$text,1);
  }

Comment

From what I can tell, I like this one better than the rewrite although I would like to see it in action if I could.

In the last release (available on 2006/05/03) the file /inc/paser.php does not exist, and i didn't found '$text = ….' anywhere .
 
wiki/tips/fold_support.txt · Last modified: 2006/11/13 14:31 by andi
 
Imprint Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsTranslate