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
24 // - info_div : the id of a 'div' element that contains a help text
25 // - info_text : the text for help on the tab
26 // - info_visible : whether info needs to be visible at startup
28 // methods are as follows
29 // (*) trigger_html (): return the html code for the trigger
30 // (*) image_html (): returns the html code for the image
31 // (*) area_start (): because we have too many places where php 'prints' code: instead
32 // (*) area_end(): of returning it, we do not expect the code for the area to be passed
33 // so these methods can be used to delimit the area in question
40 function PlekitToggle ($id,$trigger,$options=NULL) {
42 $this->trigger=$trigger;
43 if ( ! $options ) $options = array();
44 if (array_key_exists ('visible',$options)) {
45 $options['start-hidden'] = ! $options['visible'];
46 unset ($options['visible']);
49 if (!isset ($options['start-hidden'])) $options['start-hidden']=false;
50 $this->options = $options;
53 // the simple, usual way to use it :
54 // a container that contains the switch and the area in sequence
55 function start () { print $this->start_html(); }
56 function start_html () {
58 $html .= $this->container_start();
59 $html .= $this->trigger_html();
60 $html .= $this->area_start_html();
61 $html .= $this->info_html();
65 function end () { print $this->end_html(); }
66 function end_html () {
68 $html .= $this->area_end_html();
69 $html .= $this->container_end();
74 // create two images that get shown/hidden - could not find a better way to do it
75 function image_html () {
77 if ( ! $this->options['start-hidden']) { $x1=""; $x2=" style='display:none'"; }
78 else { $x2=""; $x1=" style='display:none'"; }
79 $image_id=$this->id_name('image-visible');
80 $html .= "<img id='$image_id' class='plc-toggle-visible' src='/plekit/icons/toggle-visible.png'$x1";
81 $html .= " alt='Hide this section' />";
82 $image_id=$this->id_name('image-hidden');
83 $html .= "<img id='$image_id' class='plc-toggle-hidden' src='/plekit/icons/toggle-hidden.png'$x2";
84 $html .= " alt='Show this section' />";
88 function trigger () { print $this->trigger_html(); }
89 function trigger_html () {
90 $trigger_id=$this->id_name('trigger');
91 if (array_key_exists ('trigger-tagname',$this->options)) $tagname=$this->options['trigger-tagname'];
92 if (empty($tagname)) $tagname="span";
94 if (array_key_exists ('bubble',$this->options)) $bubble=$this->options['bubble'];
97 $html .= " id='$trigger_id'";
98 $html .= " class='plc-toggle-trigger'";
99 if ($bubble) $html .= " title='$bubble'";
100 $html .= " onclick=\"plekit_toggle('$this->id')\"";
102 $html .= $this->image_html();
103 $html .= $this->trigger;
104 $html .= "</$tagname>";
105 if (array_key_exists ('info_text',$this->options)) {
107 $html .= "<span class='toggle-info-button' onClick='plekit_toggle_info(\"$id\");'><img height=20 src='/planetlab/icons/info.png' alt='close info'/></span>";
112 function info() { print $this->info_html();}
113 function info_html () {
114 if (! array_key_exists ('info_text',$this->options)) return "";
116 // compute if info should be visible at startup
117 // xxx in fact the default should be fetched in the browser storage xxx
119 // if info_visible is set, use this value
120 if (array_key_exists ('info_visible',$this->options))
121 $info_visible=$this->options['info_visible'];
124 $div_id=$this->id_name('info');
126 $html .= "<div class='toggle-info'";
127 $html .= " id='$div_id'";
128 if ($info_visible) $html .= " style='display:none'";
130 $html .= "<table class='center'><tr><td class='top'>";
131 $html .= $this->options['info_text'];
132 $html .= "</td><td class='top'><span onClick='plekit_toggle_info(\"$id\");'><img height=20 class='reset' src='/planetlab/icons/close.png' alt='toggle info' /></span>";
133 $html .= "</td></tr></table></div>";
138 function area_start () { print $this->area_start_html(); }
139 function area_start_html () {
140 $area_id=$this->id_name('area');
143 $html .= " class='plc-toggle-area'";
144 $html .= " id='$area_id'";
145 if ($this->options['start-hidden']) $html .= " style='display:none'";
150 function area_end () { print $this->area_end_html(); }
151 function area_end_html () {
155 /* if desired, you can embed the whole (trigger+area) in another div for visual effects */
156 function container_start () { print $this->container_start_html(); }
157 function container_start_html () {
158 $id=$this->id_name('container');
159 $this->nifty=new PlekitNifty ($id,'plc-toggle-container','medium');
160 return $this->nifty->start_html();
163 function container_end () { print $this->container_end_html(); }
164 function container_end_html () { return $this->nifty->end_html(); }
167 function id_name ($zonename) { return "toggle-$zonename-$this->id"; }