5 <script type="text/javascript" src="/planetlab/minitabs/minitabs.js"></script>
6 <link href="/planetlab/minitabs/minitabs.css" rel="stylesheet" type="text/css" />
10 // the expected argument is an (ordered) associative array
11 // ( label => todo , ...)
12 // label is expected to be the string to display in the menu
14 // (*) a string : it is then taken to be a URL to move to
15 // (*) or an associative array with the following keys
16 // (*) 'label' : if set, this overrides the string key just above
17 // this is used for functions that return a tab, more convenient to write&use
18 // (*) 'method': 'POST' or 'GET' -- default is 'GET'
19 // (*) 'url': where to go
20 // (*) 'values': an associative array of (key,value) pairs to send to the URL; values are strings
21 // (*) 'confirm': a question to display before actually triggering
22 // (*) 'bubble': a longer message displayed when the mouse stays quite for a while on the label
23 // (*) 'image' : the url of an image used instead of the label
24 // (*) 'height' : used for the image
25 // (*) 'id' : assign given id to the <li> element
28 // values can also be set in the URL, e.g. ?var=value&foo=bar, even for POST'ing
31 // function my_tab () { return array('label'=>'Go to google','url'=>'http://google.com'); }
33 // $tabs[] = my_tab();
34 // $tabs['Simple Tab']="http://planet-lab.org";
35 // $tabs['Complex Tab']=array('url'=>'http://planet-lab.org/',
36 // 'bubble'=>'This text gets displayed when the mouse remains over for a while');
39 ////////// Notes: limited support for images
40 // (*) for some reason, confirmation does not work with image tabs
41 // (the form gets submitted whatever the confirmation....)
42 // (*) you need to tune the image size, which is wrong, as the image should rather be bottom-aligned
44 function plc_tabs ($array) {
45 print '<div id="minitabs-container">';
46 print '<ul id="minitabs-list">';
48 foreach ($array as $label=>$todo) {
49 // in case we have a simple string, rewrite it as an array
50 if (is_string ($todo)) $todo=array('method'=>'GET','url'=>$todo);
51 // the 'label' key, if set in the hash, supersedes key
52 if ($todo['label']) $label=$todo['label'];
53 $tracer="class=minitabs";
55 $tracer .= " id=".$todo['id'];
56 printf ("<li %s>\n",$tracer);
58 if ( ! $todo['method'] ) $todo['method']='GET';
59 // extract var=value settings from url if any
60 $full_url=$todo['url'];
61 $split=split_url($full_url);
63 $url_values=$split['values'];
66 $method=$todo['method'];
67 print "<form name='$label' action='$url' method='$method'>";
69 $values=$todo['values'];
70 if ( ! $values) $values = array();
71 if ($url_values) $values = array_merge($values,$url_values);
72 if ( $values ) foreach ($values as $key=>$value) {
73 printf('<input class="minitabs-hidden" type=hidden name="%s" value="%s" />',$key,$value);
75 $tracer="class=minitabs-submit";
76 // image and its companions 'height'
78 $type='type=image src="' . $todo['image'] . '"';
79 if ($todo['height']) $type.= ' height=' . $todo['height'];
81 $type='type=button value="' . $label . '"';
83 printf('<span title="%s">',$todo['bubble']);
85 if ($todo['confirm']) $message=$todo['confirm'] . " ?";
86 printf('<input %s %s onclick=\'miniTab.submit("%s");\' />',$tracer,$type,$message);
87 printf('</span>',$todo['bubble']);
88 printf("</form></li>\n");
92 print "<p class='plc-minittabs'></p>\n";