Outlining implementation

Tessellated Circuits: Home => Old Home => Outlining => How its done  

There are several possibilities if one wants to be able to hide/show content under control of the user. One could use JavaScript exclusively, but that relies on the browser implementing it (not too much of a concern these days), and the user enabling it (somewhat more of a concern due to security worries). So, if the content is to be controlled without a local script, then server-side code has to be used. Once that is said, there are still some options.

The method chosen here was to use the CSS display:none property/value pair to hide content. This means that all the content is sent each time the page is re-loaded (and it is reloaded every time a change is requested, not so good for dial-up users!), but the styles attached to the content change. An alternative would have been to send content only when it is to be shown, however some trickier, easier to mess up, PHP would be required to do it this way: in other words, “{” / “}” pairs, or, if:/endif; statements would have to be managed carefully.

The code also shows how <form> controls can be nicely styled to look much less clunky. (Look at the CSS for the “.RScontrols input” style.)

The PHP functions:

// Produce code that hides/shows a section of "content". Provides a heading
//   box, which stays the same, and which has built-in controls to:
//    0 show no sections            = display this section
//    < display previous section    > display next section
// Args: $title: string to use in heading box
//       $sect: section number for the present section,
//       $disp: the chosen display number.
function Outline($title,$sect,$disp){
  $prev=$sect-1; if ($prev <1) $prev=99;
  $next=$sect+1;
  $self = basename($_SERVER['SCRIPT_NAME']);
  echo "<a name=\"0_$sect\"></a>
  <table width='100%' class='hdg'>
    <tr><td>
      <div>
        <h3><span class='blue'>$sect</span> $title</h3>
      </div>
    </td>
    <td width='23%'>
      <div class='RScontrols'>";
      if (!($disp==0)) echo 
         /* conditionaly produce form that is the "none" button */ 
       "<form action='$self#0_0' method='post'> 
        <input type='submit' value='0'>
        <input type='hidden' name='disp' value='0'>
        </form>";
    echo /* produce form that is the "<" button */
       "<form action='$self#0"."_$prev' method='post'>
          <input type='submit' value='<'>
          <input type='hidden' name='disp' value='$prev'>
        </form>";
    echo /* produce form that is the "=" button */
       "<form action='$self#0"."_$sect' method='post'> 
          <input type='submit' value='='>
          <input type='hidden' name='disp' value='$sect'>
        </form>";
    echo /* produce form that is the ">" button */
       "<form action='$self#0"."_$next' method='post'> 
          <input type='submit' value='>'>
          <input type='hidden' name='disp' value='$next'>
        </form>
      </div>
    </td></tr>
  </table>";
}

function ShowContent($disp,$sect){
  if(!(($disp==$sect) | ($disp==99)))echo 'class=\"off\"';
}

Some details:

How to use the functions:

<div class='outline'>
<?php $sect = 1; Outline("A demonstration of outlining. Click on...",
                            $sect);?>
<ul <?php ShowContent($disp,$sect)?>>
  <li>This is a list</li>
  <li>that has been hidden.</li>
</ul>
<?php $sect++; Outline("the buttons at the right to see what happens.",
                          $sect);?>
<p <?php ShowContent($disp,$sect)?>>
This is a paragraph that was hidden 'till you clicked to see it.
</p> 
• • •
</div>

Notes: