5 require_once 'prototype.php';
8 <script type="text/javascript" src="/planetlab/js/plc_toggles.js"></script>
9 <link href="/planetlab/css/plc_toggles.css" rel="stylesheet" type="text/css" />
12 // This is for creating an area that users can hide and show
13 // It is logically made of 3 parts:
14 // (*) area is what gets hidden and shown
15 // (*) switch is the area that can be clicked for toggling
16 // (*) image contains a visual indication of the current status
19 // (*) id: an 'id', used for naming the three parts
20 // (*) switch: the html text for the switch
21 // (*) options: a hash that can define
22 // - switch-tagname : to be used instead of <span> for wrapping the switch
23 // - switch-bubble : might not work if switch-tagname is redefined
24 // - init-hidden : start hidden rather than visible
26 // methods are as follows
27 // (*) switch_html (): return the html code for the switch
28 // (*) image_html (): returns the html code for the image
29 // (*) area_start (): because we have too many places where php 'prints' code instead
30 // (*) area_end(): of returning it, we do not expect the code for the area to be passed
31 // so these methods can be used to delimit the area in question
37 function PlcToggle ($id,$switch,$options=NULL) {
39 $this->switch=$switch;
40 if ( ! $options ) $options = array();
41 $this->options = $options;
44 function id_name ($zonename) { return "toggle-$zonename-$this->id"; }
46 // create two images that get shown/hidden - could not find a better way to do it
47 function image_html () {
49 if ( ! $this->options['start-hidden']) { $x1=""; $x2=" style='display:none'"; }
50 else { $x2=""; $x1=" style='display:none'"; }
51 $image_id=$this->id_name('image-visible');
52 $html .= "<img id=$image_id class='plc-toggle-visible' src='/planetlab/icons/toggle-visible.png'$x1>";
53 $image_id=$this->id_name('image-hidden');
54 $html .= "<img id=$image_id class='plc-toggle-hidden' src='/planetlab/icons/toggle-hidden.png'$x2>";
58 // don't define switch as it's a php keyword
59 function switch_html () {
60 $switch_id=$this->id_name('switch');
62 if (array_key_exists ('switch-tagname',$this->options)) $tagname=$this->options['switch-tagname'];
63 if (array_key_exists ('switch-bubble',$this->options)) $bubble=$this->options['switch-bubble'];
66 $html .= " id=$switch_id";
67 $html .= " class=plc-toggle-switch";
68 if ($bubble) $html .= " title='$bubble'";
69 $html .= " onclick=\"plc_toggle('$this->id')\"";
71 $html .= $this->image_html();
72 $html .= $this->switch;
73 $html .= "</$tagname>";
77 function area_start () { print $this->area_start_html(); }
78 function area_start_html () {
79 $area_id=$this->id_name('area');
82 $html .= " class=plc-toggle-area";
83 $html .= " id=$area_id";
84 if ($this->options['start-hidden']) $html .= " style='display:none'";
89 function area_end () { print $this->area_end_html(); }
90 function area_end_html () {