--- nfo/php/libs/com.newsblob.phphtmllib/widgets/ActiveTab.inc 2003/11/14 21:31:40 1.3
+++ nfo/php/libs/com.newsblob.phphtmllib/widgets/ActiveTab.inc 2004/05/06 16:27:40 1.4
@@ -2,7 +2,7 @@
/**
* This file contains the ActiveTab class
*
- * $Id: ActiveTab.inc,v 1.3 2003/11/14 21:31:40 jonen Exp $
+ * $Id: ActiveTab.inc,v 1.4 2004/05/06 16:27:40 jonen Exp $
*
* @author Walter A. Boring IV
* @package phpHtmlLib
@@ -41,8 +41,11 @@
/**
* The default selected tab
+ * this is a tab name
+ *
+ * ActiveTab::name("Title of Tab");
*/
- var $_selected_tab = 0;
+ var $_selected_tab = null;
/**
@@ -51,9 +54,12 @@
*
* @param string - the width table
* @param string - the height of the tab's contents
- * @param int - the selected tab.
+ * @param string - the selected tab name.
+ * NOTE: this is set with
+ * ActiveTab::name("Title of Tab");
+ * add_tab() can override this.
*/
- function ActiveTab($width="100%", $height="300px", $selected_tab=0) {
+ function ActiveTab($width="100%", $height="300px", $selected_tab=null) {
$this->set_width( $width );
$this->_height = $height;
$this->_selected_tab = $selected_tab;
@@ -84,7 +90,7 @@
$function .= " var tabs = new Array();\n";
foreach( $this->_data as $tab ) {
- $function .= " tabs['".$this->_tab_name($tab["title"])."'] = 1;\n";
+ $function .= " tabs['".$this->name($tab["title"])."'] = 1;\n";
}
$function .= " for (title in tabs ) {\n";
@@ -104,7 +110,7 @@
$function .= " // save the last viewed div in a hidden variable (if it's there)\n";
$function .= " obj = document.getElementsByName('div_selected');\n";
- $function .= " if (obj[0].value) obj[0].value = tab;\n";
+ $function .= " if (obj[0] != null && obj[0].value) obj[0].value = tab;\n";
$function .= "}\n";
return $function;
}
@@ -117,6 +123,11 @@
* @param mixed - the conetnts for the tab
* @param boolean - should this tab be
* the default selected tab?
+ *
+ * Note: This will override the
+ * selected tab parameter
+ * in the constructor.
+ *
* @param int - the width of the tab in pixels
* defaults to 60
*
@@ -127,6 +138,9 @@
"width" => $width,
"content" => $content
);
+ if ($selected) {
+ $this->_selected_tab = $this->name($title);
+ }
}
@@ -138,14 +152,14 @@
//make sure that we have at least the
//first tab selected if there is non selected
- if ($this->_selected_tab === 0 || strcasecmp($this->_selected_tab, "0") == 0) {
- $this->_selected_tab = $this->_tab_name($this->_data[0]["title"]);
+ if ($this->_selected_tab === null || strcasecmp($this->_selected_tab, "0") == 0) {
+ $this->_selected_tab = $this->name($this->_data[0]["title"]);
}
$tr->add( $this->_spacer_td() );
foreach( $this->_data as $tab) {
$selected = FALSE;
- if (strcasecmp($this->_tab_name($tab["title"]),$this->_selected_tab) == 0 ||
+ if (strcasecmp($this->name($tab["title"]),$this->_selected_tab) == 0 ||
$tab["selected"] == TRUE) {
$selected = TRUE;
}
@@ -206,11 +220,11 @@
} else {
$td_class .= "hidden";
}
- $func = "show_activetab('".$this->_tab_name($title)."');";
+ $func = "show_activetab('".$this->name($title)."');";
$link = html_a("javascript: ".$func, $title, "link");
$td = html_td($td_class, "", $link);
- $td->set_id("tab_".$this->_tab_name($title));
+ $td->set_id("tab_".$this->name($title));
$td->set_tag_attribute("onclick", "javascript: ".$func);
if ( $selected ) {
$style = "font-weight: bold;background-color: ".$this->_selected_background.";";
@@ -237,10 +251,23 @@
$this->_hidden_background = $color;
}
+ /**
+ * Build the 'name' of the tab. This can be
+ * called in a static way to set the default
+ * selected tab.
+ *
+ * {@source }
+ * @param string
+ * @return strint
+ */
+ function name($title) {
+ return str_replace(" ", "_", strtolower($title));
+ }
function _tab_name( $title ) {
- return str_replace(" ", "", strtolower($title));
+ return $this->name($title);
}
+
}
/**