| 41 |
|
|
| 42 |
/** |
/** |
| 43 |
* The default selected tab |
* The default selected tab |
| 44 |
|
* this is a tab name |
| 45 |
|
* |
| 46 |
|
* ActiveTab::name("Title of Tab"); |
| 47 |
*/ |
*/ |
| 48 |
var $_selected_tab = 0; |
var $_selected_tab = null; |
| 49 |
|
|
| 50 |
|
|
| 51 |
/** |
/** |
| 54 |
* |
* |
| 55 |
* @param string - the width table |
* @param string - the width table |
| 56 |
* @param string - the height of the tab's contents |
* @param string - the height of the tab's contents |
| 57 |
* @param int - the selected tab. |
* @param string - the selected tab name. |
| 58 |
|
* NOTE: this is set with |
| 59 |
|
* ActiveTab::name("Title of Tab"); |
| 60 |
|
* add_tab() can override this. |
| 61 |
*/ |
*/ |
| 62 |
function ActiveTab($width="100%", $height="300px", $selected_tab=0) { |
function ActiveTab($width="100%", $height="300px", $selected_tab=null) { |
| 63 |
$this->set_width( $width ); |
$this->set_width( $width ); |
| 64 |
$this->_height = $height; |
$this->_height = $height; |
| 65 |
$this->_selected_tab = $selected_tab; |
$this->_selected_tab = $selected_tab; |
| 90 |
$function .= " var tabs = new Array();\n"; |
$function .= " var tabs = new Array();\n"; |
| 91 |
|
|
| 92 |
foreach( $this->_data as $tab ) { |
foreach( $this->_data as $tab ) { |
| 93 |
$function .= " tabs['".$this->_tab_name($tab["title"])."'] = 1;\n"; |
$function .= " tabs['".$this->name($tab["title"])."'] = 1;\n"; |
| 94 |
} |
} |
| 95 |
|
|
| 96 |
$function .= " for (title in tabs ) {\n"; |
$function .= " for (title in tabs ) {\n"; |
| 110 |
|
|
| 111 |
$function .= " // save the last viewed div in a hidden variable (if it's there)\n"; |
$function .= " // save the last viewed div in a hidden variable (if it's there)\n"; |
| 112 |
$function .= " obj = document.getElementsByName('div_selected');\n"; |
$function .= " obj = document.getElementsByName('div_selected');\n"; |
| 113 |
$function .= " if (obj[0].value) obj[0].value = tab;\n"; |
$function .= " if (obj[0] != null && obj[0].value) obj[0].value = tab;\n"; |
| 114 |
$function .= "}\n"; |
$function .= "}\n"; |
| 115 |
return $function; |
return $function; |
| 116 |
} |
} |
| 123 |
* @param mixed - the conetnts for the tab |
* @param mixed - the conetnts for the tab |
| 124 |
* @param boolean - should this tab be |
* @param boolean - should this tab be |
| 125 |
* the default selected tab? |
* the default selected tab? |
| 126 |
|
* |
| 127 |
|
* Note: This will override the |
| 128 |
|
* selected tab parameter |
| 129 |
|
* in the constructor. |
| 130 |
|
* |
| 131 |
* @param int - the width of the tab in pixels |
* @param int - the width of the tab in pixels |
| 132 |
* defaults to 60 |
* defaults to 60 |
| 133 |
* |
* |
| 138 |
"width" => $width, |
"width" => $width, |
| 139 |
"content" => $content |
"content" => $content |
| 140 |
); |
); |
| 141 |
|
if ($selected) { |
| 142 |
|
$this->_selected_tab = $this->name($title); |
| 143 |
|
} |
| 144 |
} |
} |
| 145 |
|
|
| 146 |
|
|
| 152 |
|
|
| 153 |
//make sure that we have at least the |
//make sure that we have at least the |
| 154 |
//first tab selected if there is non selected |
//first tab selected if there is non selected |
| 155 |
if ($this->_selected_tab === 0 || strcasecmp($this->_selected_tab, "0") == 0) { |
if ($this->_selected_tab === null || strcasecmp($this->_selected_tab, "0") == 0) { |
| 156 |
$this->_selected_tab = $this->_tab_name($this->_data[0]["title"]); |
$this->_selected_tab = $this->name($this->_data[0]["title"]); |
| 157 |
} |
} |
| 158 |
|
|
| 159 |
$tr->add( $this->_spacer_td() ); |
$tr->add( $this->_spacer_td() ); |
| 160 |
foreach( $this->_data as $tab) { |
foreach( $this->_data as $tab) { |
| 161 |
$selected = FALSE; |
$selected = FALSE; |
| 162 |
if (strcasecmp($this->_tab_name($tab["title"]),$this->_selected_tab) == 0 || |
if (strcasecmp($this->name($tab["title"]),$this->_selected_tab) == 0 || |
| 163 |
$tab["selected"] == TRUE) { |
$tab["selected"] == TRUE) { |
| 164 |
$selected = TRUE; |
$selected = TRUE; |
| 165 |
} |
} |
| 220 |
} else { |
} else { |
| 221 |
$td_class .= "hidden"; |
$td_class .= "hidden"; |
| 222 |
} |
} |
| 223 |
$func = "show_activetab('".$this->_tab_name($title)."');"; |
$func = "show_activetab('".$this->name($title)."');"; |
| 224 |
$link = html_a("javascript: ".$func, $title, "link"); |
$link = html_a("javascript: ".$func, $title, "link"); |
| 225 |
|
|
| 226 |
$td = html_td($td_class, "", $link); |
$td = html_td($td_class, "", $link); |
| 227 |
$td->set_id("tab_".$this->_tab_name($title)); |
$td->set_id("tab_".$this->name($title)); |
| 228 |
$td->set_tag_attribute("onclick", "javascript: ".$func); |
$td->set_tag_attribute("onclick", "javascript: ".$func); |
| 229 |
if ( $selected ) { |
if ( $selected ) { |
| 230 |
$style = "font-weight: bold;background-color: ".$this->_selected_background.";"; |
$style = "font-weight: bold;background-color: ".$this->_selected_background.";"; |
| 251 |
$this->_hidden_background = $color; |
$this->_hidden_background = $color; |
| 252 |
} |
} |
| 253 |
|
|
| 254 |
|
/** |
| 255 |
|
* Build the 'name' of the tab. This can be |
| 256 |
|
* called in a static way to set the default |
| 257 |
|
* selected tab. |
| 258 |
|
* |
| 259 |
|
* {@source } |
| 260 |
|
* @param string |
| 261 |
|
* @return strint |
| 262 |
|
*/ |
| 263 |
|
function name($title) { |
| 264 |
|
return str_replace(" ", "_", strtolower($title)); |
| 265 |
|
} |
| 266 |
|
|
| 267 |
function _tab_name( $title ) { |
function _tab_name( $title ) { |
| 268 |
return str_replace(" ", "", strtolower($title)); |
return $this->name($title); |
| 269 |
} |
} |
| 270 |
|
|
| 271 |
} |
} |
| 272 |
|
|
| 273 |
/** |
/** |