3 require_once 'prototype.php';
4 require_once 'nifty.php';
7 <script type="text/javascript" src="/plekit/toggle/toggle.js"></script>
8 <link href="/plekit/toggle/toggle.css" rel="stylesheet" type="text/css" />
11 // This is for creating an area that users can hide and show
12 // It is logically made of 3 parts:
13 // (*) area is what gets hidden and shown
14 // (*) trigger is the area that can be clicked for toggling
15 // (*) image contains a visual indication of the current status
18 // (*) id: an 'id', used for naming the three parts
19 // (*) trigger: the html text for the trigger
20 // (*) options: a hash that can define
21 // - trigger-tagname : to be used instead of <span> for wrapping the trigger
22 // - bubble : might not work if trigger-tagname is redefined
23 // - init-hidden : start hidden rather than visible
25 // methods are as follows
26 // (*) trigger_html (): return the html code for the trigger
27 // (*) image_html (): returns the html code for the image
28 // (*) area_start (): because we have too many places where php 'prints' code: instead
29 // (*) area_end(): of returning it, we do not expect the code for the area to be passed
30 // so these methods can be used to delimit the area in question
38 function PlekitToggle ($id,$trigger,$options=NULL) {
40 $this->trigger=$trigger;
41 if ( ! $options ) $options = array();
42 if (array_key_exists ('visible',$options)) {
43 $options['start-hidden'] = ! $options['visible'];
44 unset ($options['visible']);
47 if (array_key_exists ('info_div',$options)) {
48 $this->info_div = $options['info_div'];
51 if (!isset ($options['start-hidden'])) $options['start-hidden']=false;
52 $this->options = $options;
55 // the simple, usual way to use it :
56 // a container that contains the switch and the area in sequence
57 function start () { print $this->start_html(); }
58 function start_html () {
60 $html .= $this->container_start();
61 $html .= $this->trigger_html();
62 $html .= $this->area_start_html();
66 function end () { print $this->end_html(); }
67 function end_html () {
69 $html .= $this->area_end_html();
70 $html .= $this->container_end();
75 // create two images that get shown/hidden - could not find a better way to do it
76 function image_html () {
78 if ( ! $this->options['start-hidden']) { $x1=""; $x2=" style='display:none'"; }
79 else { $x2=""; $x1=" style='display:none'"; }
80 $image_id=$this->id_name('image-visible');
81 $html .= "<img id='$image_id' class='plc-toggle-visible' src='/plekit/icons/toggle-visible.png'$x1";
82 $html .= " alt='Hide this section' />";
83 $image_id=$this->id_name('image-hidden');
84 $html .= "<img id='$image_id' class='plc-toggle-hidden' src='/plekit/icons/toggle-hidden.png'$x2";
85 $html .= " alt='Show this section' />";
89 function trigger () { print $this->trigger_html(); }
90 function trigger_html () {
91 $trigger_id=$this->id_name('trigger');
92 if (array_key_exists ('trigger-tagname',$this->options)) $tagname=$this->options['trigger-tagname'];
93 if (empty($tagname)) $tagname="span";
95 if (array_key_exists ('bubble',$this->options)) $bubble=$this->options['bubble'];
98 $html .= " id='$trigger_id'";
99 $html .= " class='plc-toggle-trigger'";
100 if ($bubble) $html .= " title='$bubble'";
101 $html .= " onclick=\"plc_toggle('$this->id')\"";
103 $html .= $this->image_html();
104 $html .= $this->trigger;
105 $html .= "</$tagname>";
106 if ($this->info_div != "")
107 $html .= " (<a href=javascript:plc_show_toggle_info('$this->info_div','$this->id')>?</a>)";
111 function area_start () { print $this->area_start_html(); }
112 function area_start_html () {
113 $area_id=$this->id_name('area');
116 $html .= " class='plc-toggle-area'";
117 $html .= " id='$area_id'";
118 if ($this->options['start-hidden']) $html .= " style='display:none'";
123 function area_end () { print $this->area_end_html(); }
124 function area_end_html () {
128 /* if desired, you can embed the whole (trigger+area) in another div for visual effects */
129 function container_start () { print $this->container_start_html(); }
130 function container_start_html () {
131 $id=$this->id_name('container');
132 $this->nifty=new PlekitNifty ($id,'plc-toggle-container','medium');
133 return $this->nifty->start_html();
136 function container_end () { print $this->container_end_html(); }
137 function container_end_html () { return $this->nifty->end_html(); }
140 function id_name ($zonename) { return "toggle-$zonename-$this->id"; }