science-ation/htabs.inc.php

80 lines
2.1 KiB
PHP
Raw Permalink Normal View History

<script type="text/javascript">
var htabs_current = new Array();
function htabs_open(tab)
{
var cur = htabs_current[tab];
$("#htabs_"+tab+"_"+cur).click();
}
</script>
<?
$htabs_current = "";
$htabs_tabs = array();
function htabs_begin($name, $tabs, $selected)
{
global $htabs_current, $htabs_tabs;
echo "<ul id=\"htabs_$name\" class=\"htabs\">";
foreach($tabs as $t=>$d) {
$sel = ($t == $selected) ? 'class=\"htabs_sel\"' : '';
echo "<li id=\"htabs_{$name}_$t\" $sel>".i18n($d['label']).'</li>';
$tabs[$t]['selected'] = false;
}
echo '</ul>';
/* Force the upcoming divs below this UL */
echo '<span style="clear: both; height: 0; visibility: hidden; display: block;"></span>';
$tabs[$selected]['selected'] = true;
$htabs_current = $name;
$htabs_tabs = $tabs;
}
function htabs_tab_begin($tab)
{
global $htabs_current, $htabs_tabs;
echo "<div id=\"htabs_tab_{$htabs_current}_$tab\" class=\"htabs\"
style=\"display:none;\">";
echo '<h1>'.i18n($htabs_tabs[$tab]['title']).'</h1>';
echo "<div id=\"htabs_tab_{$htabs_current}_{$tab}_body\">";
}
function htabs_tab_end()
{
echo '</div></div>';
}
function htabs_end()
{
global $htabs_current, $htabs_tabs;
$default = '';
$first = '';
echo '<script type="text/javascript">';
foreach($htabs_tabs as $t=>$d) {
echo "\$(\"#htabs_{$htabs_current}_$t\").click(function() {
\$(\"#htabs_{$htabs_current}_$t\").addClass(\"htabs_sel\");
\$(\"#htabs_tab_{$htabs_current}_$t\").css(\"display\", \"block\");\n";
foreach($htabs_tabs as $tt=>$dd) {
if($tt == $t) continue;
echo "\$(\"#htabs_{$htabs_current}_$tt\").removeClass(\"htabs_sel\");\n";
echo "\$(\"#htabs_tab_{$htabs_current}_$tt\").css(\"display\", \"none\");\n";
}
if(trim($d['callback']) != '') {
echo "{$d['callback']}();\n";
}
echo "htabs_current['$htabs_current'] = \"{$t}\";";
echo "});\n";
if($d['selected'] == true) $default = $t;
if($first == '') $first = $t;
}
if($default == '') $default = $first;
echo "htabs_current['$htabs_current'] = \"{$default}\";";
echo '</script>';
$htabs_current = "";
$htabs_tabs = array();
}
?>