cosmetic
[plewww.git] / plekit / php / toggle.php
index 3474b41..acc9fe5 100644 (file)
@@ -3,6 +3,7 @@
   // $Id$
 
 require_once 'prototype.php';
+require_once 'nifty.php';
 
 drupal_set_html_head('
 <script type="text/javascript" src="/plekit/toggle/toggle.js"></script>
@@ -20,28 +21,30 @@ drupal_set_html_head('
 // (*) trigger:        the html text for the trigger
 // (*) options:        a hash that can define
 //     - trigger-tagname : to be used instead of <span> for wrapping the trigger
-//     - trigger-bubble : might not work if trigger-tagname is redefined
+//     - bubble : might not work if trigger-tagname is redefined
 //     - init-hidden : start hidden rather than visible
 // 
 // methods are as follows
 // (*) trigger_html ():        return the html code for the trigger
 // (*) image_html ():  returns the html code for the image
-// (*) area_start ():  because we have too many places where php 'prints' code instead 
+// (*) area_start ():  because we have too many places where php 'prints' code: instead 
 // (*) area_end():       of returning it, we do not expect the code for the area to be passed
 //                       so these methods can be used to delimit the area in question
 
 class PlekitToggle {
   // mandatory
   var $id;
+  var $nifty;
 
   function PlekitToggle ($id,$trigger,$options=NULL) {
     $this->id = $id;
     $this->trigger=$trigger;
     if ( ! $options ) $options = array();
-    if (array_key_exists ('start-visible',$options)) {
-      $options['start-hidden'] = ! $options['start-visible'];
-      unset ($options['start-visible']);
+    if (array_key_exists ('visible',$options)) {
+      $options['start-hidden'] = ! $options['visible'];
+      unset ($options['visible']);
     }
+    if (!isset ($options['start-hidden'])) $options['start-hidden']=false;
     $this->options = $options;
   }
 
@@ -71,9 +74,11 @@ class PlekitToggle {
     if ( ! $this->options['start-hidden'])     { $x1=""; $x2=" style='display:none'"; }
     else                                       { $x2=""; $x1=" style='display:none'"; }
     $image_id=$this->id_name('image-visible');
-    $html .= "<img id=$image_id class='plc-toggle-visible' src='/plekit/icons/toggle-visible.png'$x1>";
+    $html .= "<img id='$image_id' class='plc-toggle-visible' src='/plekit/icons/toggle-visible.png'$x1";
+    $html .= " alt='Hide this section' />";
     $image_id=$this->id_name('image-hidden');
-    $html .= "<img id=$image_id class='plc-toggle-hidden' src='/plekit/icons/toggle-hidden.png'$x2>";
+    $html .= "<img id='$image_id' class='plc-toggle-hidden' src='/plekit/icons/toggle-hidden.png'$x2";
+    $html .= " alt='Show this section' />";
     return $html;
   }
 
@@ -81,12 +86,13 @@ class PlekitToggle {
   function trigger_html () {
     $trigger_id=$this->id_name('trigger');
     if (array_key_exists ('trigger-tagname',$this->options)) $tagname=$this->options['trigger-tagname'];
-    if (array_key_exists ('trigger-bubble',$this->options)) $bubble=$this->options['trigger-bubble'];
     if (empty($tagname)) $tagname="span";
+    $bubble="";
+    if (array_key_exists ('bubble',$this->options)) $bubble=$this->options['bubble'];
     
     $html="<$tagname";
-    $html .= " id=$trigger_id";
-    $html .= " class=plc-toggle-trigger";
+    $html .= " id='$trigger_id'";
+    $html .= " class='plc-toggle-trigger'";
     if ($bubble) $html .= " title='$bubble'";
     $html .= " onclick=\"plc_toggle('$this->id')\"";
     $html .= ">";
@@ -101,8 +107,8 @@ class PlekitToggle {
     $area_id=$this->id_name('area');
     $html="";
     $html .= "<div";
-    $html .= " class=plc-toggle-area";
-    $html .= " id=$area_id";
+    $html .= " class='plc-toggle-area'";
+    $html .= " id='$area_id'";
     if ($this->options['start-hidden']) $html .= " style='display:none'";
     $html .= ">";
     return $html;
@@ -116,15 +122,13 @@ class PlekitToggle {
   /* if desired, you can embed the whole (trigger+area) in another div for visual effects */
   function container_start ()          { print $this->container_start_html(); }
   function container_start_html ()     { 
-    $html="<div class='plc-toggle-container'";
     $id=$this->id_name('container');
-    $html .= " id='$id'";
-    $html .= ">";
-    return $html;
+    $this->nifty=new PlekitNifty ($id,'plc-toggle-container','medium');
+    return $this->nifty->start_html();
   }
 
   function container_end ()            { print $this->container_end_html(); }
-  function container_end_html ()       { return "</div>"; }
+  function container_end_html ()       { return $this->nifty->end_html(); }
 
   // build id names
   function id_name ($zonename) { return "toggle-$zonename-$this->id"; }