| 1 |
jonen |
1.1 |
<?php |
| 2 |
|
|
|
| 3 |
|
|
|
| 4 |
|
|
class ActiveTab extends BaseWidget { |
| 5 |
|
|
|
| 6 |
|
|
|
| 7 |
|
|
/** |
| 8 |
|
|
* We have to code these here instead of |
| 9 |
|
|
* the css because JS is used to change |
| 10 |
|
|
* the colors. JS can't change a color |
| 11 |
|
|
* that is defined in a css class. It only |
| 12 |
|
|
* works on an inline style |
| 13 |
|
|
*/ |
| 14 |
|
|
|
| 15 |
|
|
/** |
| 16 |
|
|
* The active tab's background color |
| 17 |
|
|
* |
| 18 |
|
|
*/ |
| 19 |
|
|
var $_selected_background = "#eeeeee"; |
| 20 |
|
|
|
| 21 |
|
|
/** |
| 22 |
|
|
* The hidden tab's background color |
| 23 |
|
|
*/ |
| 24 |
|
|
var $_hidden_background = "#e0e0e0"; |
| 25 |
|
|
|
| 26 |
|
|
|
| 27 |
|
|
function ActiveTab($width="100%", $height="300px") { |
| 28 |
|
|
$this->set_width( $width ); |
| 29 |
|
|
$this->_height = $height; |
| 30 |
|
|
} |
| 31 |
|
|
|
| 32 |
|
|
|
| 33 |
|
|
function render($indent_level=1, $output_debug=0) { |
| 34 |
|
|
$tabs = $this->build_tabs(); |
| 35 |
|
|
|
| 36 |
|
|
$span = 2 + (count($this->_data) *2 ); |
| 37 |
|
|
|
| 38 |
|
|
$td = new TDtag(array("colspan" => $span), $this->build_content() ); |
| 39 |
|
|
$tabs->add_row( $td ); |
| 40 |
|
|
$div = html_div("activetab", $tabs); |
| 41 |
|
|
$div->set_style("width:".$this->get_width()); |
| 42 |
|
|
return $div->render($indent_level, $output_debug); |
| 43 |
|
|
} |
| 44 |
|
|
|
| 45 |
|
|
/** |
| 46 |
|
|
* This function MUST be called AFTER ALL content |
| 47 |
|
|
* has been added, in order for the js to work properly |
| 48 |
|
|
* |
| 49 |
|
|
* @return string |
| 50 |
|
|
*/ |
| 51 |
|
|
function get_javascript() { |
| 52 |
|
|
$function = "function show_activetab(tab) {\n"; |
| 53 |
|
|
|
| 54 |
|
|
$function .= " var tabs = new Array();\n"; |
| 55 |
|
|
|
| 56 |
|
|
foreach( $this->_data as $tab ) { |
| 57 |
|
|
$function .= " tabs['".$this->_tab_name($tab["title"])."'] = 1;\n"; |
| 58 |
|
|
} |
| 59 |
|
|
|
| 60 |
|
|
$function .= " for (title in tabs ) {\n"; |
| 61 |
|
|
$function .= " obj = document.getElementById('div_'+title).style.visibility = 'hidden';\n"; |
| 62 |
|
|
$function .= " obj = document.getElementById('tab_'+title).style.borderBottom = '1px solid #a1a1a1';\n"; |
| 63 |
|
|
$function .= " obj = document.getElementById('tab_'+title).style.fontWeight = '';\n"; |
| 64 |
|
|
$function .= " obj = document.getElementById('tab_'+title).style.backgroundColor = '".$this->_hidden_background."';\n"; |
| 65 |
|
|
$function .= " }\n"; |
| 66 |
|
|
|
| 67 |
|
|
$function .= " // show the content of ips\n"; |
| 68 |
|
|
$function .= " obj = document.getElementById('div_'+tab).style.visibility = 'visible';\n"; |
| 69 |
|
|
|
| 70 |
|
|
$function .= " // draw the tab separator line\n"; |
| 71 |
|
|
$function .= " obj = document.getElementById('tab_'+tab).style.borderBottom = 'none';\n"; |
| 72 |
|
|
$function .= " obj = document.getElementById('tab_'+tab).style.fontWeight = 'bold';\n"; |
| 73 |
|
|
$function .= " obj = document.getElementById('tab_'+tab).style.backgroundColor = '".$this->_selected_background."';\n"; |
| 74 |
|
|
|
| 75 |
|
|
$function .= " // hide the content of the other tabs\n"; |
| 76 |
|
|
$function .= "}\n"; |
| 77 |
|
|
return $function; |
| 78 |
|
|
} |
| 79 |
|
|
|
| 80 |
|
|
|
| 81 |
|
|
/** |
| 82 |
|
|
* Add a tab |
| 83 |
|
|
* |
| 84 |
|
|
* @param string - the title of the tab |
| 85 |
|
|
* @param mixed - the conetnts for the tab |
| 86 |
|
|
* @param boolean - should this tab be |
| 87 |
|
|
* the default selected tab? |
| 88 |
|
|
* @param int - the width of the tab in pixels |
| 89 |
|
|
* defaults to 60 |
| 90 |
|
|
* |
| 91 |
|
|
*/ |
| 92 |
|
|
function add_tab( $title, $content, $selected=FALSE, $width=NULL) { |
| 93 |
|
|
$this->_data[] = array("title" => $title, |
| 94 |
|
|
"content" => $content, |
| 95 |
|
|
"selected" => $selected, |
| 96 |
|
|
"width" => $width); |
| 97 |
|
|
} |
| 98 |
|
|
|
| 99 |
|
|
|
| 100 |
|
|
|
| 101 |
|
|
function build_tabs() { |
| 102 |
|
|
$table = html_table($this->get_width(), 0,0,0, "center"); |
| 103 |
|
|
|
| 104 |
|
|
$tr = new TRtag; |
| 105 |
|
|
|
| 106 |
|
|
$tr->add( $this->_spacer_td() ); |
| 107 |
|
|
|
| 108 |
|
|
|
| 109 |
|
|
foreach( $this->_data as $tab) { |
| 110 |
|
|
$tr->add( $this->_build_tab_td( $tab["title"], |
| 111 |
|
|
$tab["selected"], |
| 112 |
|
|
$tab["width"]) ); |
| 113 |
|
|
$tr->add( $this->_spacer_td() ); |
| 114 |
|
|
} |
| 115 |
|
|
$tr->add( $this->_end_td() ); |
| 116 |
|
|
|
| 117 |
|
|
$table->add( $tr ); |
| 118 |
|
|
return $table; |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
|
function build_content() { |
| 122 |
|
|
$div = html_div("content"); |
| 123 |
|
|
$div->set_class( "content" ); |
| 124 |
|
|
$div->set_style( "height:".$this->_height.";"); |
| 125 |
|
|
|
| 126 |
|
|
|
| 127 |
|
|
foreach ( $this->_data as $tab ) { |
| 128 |
|
|
if ($tab["selected"]) { |
| 129 |
|
|
$class = "content_visible"; |
| 130 |
|
|
} else { |
| 131 |
|
|
$class = "content_hidden"; |
| 132 |
|
|
} |
| 133 |
|
|
$tab_div = html_div($class, $tab["content"]); |
| 134 |
|
|
$tab_div->set_id( "div_".$this->_tab_name( $tab["title"] ) ); |
| 135 |
|
|
$div->add( $tab_div ); |
| 136 |
|
|
} |
| 137 |
|
|
|
| 138 |
|
|
return $div; |
| 139 |
|
|
} |
| 140 |
|
|
|
| 141 |
|
|
function _spacer_td() { |
| 142 |
|
|
return html_td("spacer", NULL, " "); |
| 143 |
|
|
} |
| 144 |
|
|
|
| 145 |
|
|
function _end_td() { |
| 146 |
|
|
return html_td("end", NULL, " "); |
| 147 |
|
|
} |
| 148 |
|
|
|
| 149 |
|
|
|
| 150 |
|
|
function _build_tab_td($title, $selected, $width) { |
| 151 |
|
|
$td_class = "tab"; |
| 152 |
|
|
$link_class = "link"; |
| 153 |
|
|
|
| 154 |
|
|
if ($width == NULL) { |
| 155 |
|
|
$width = "60px"; |
| 156 |
|
|
} |
| 157 |
|
|
|
| 158 |
|
|
if (!strstr($width, "px")) { |
| 159 |
|
|
$width .= "px"; |
| 160 |
|
|
} |
| 161 |
|
|
|
| 162 |
|
|
if ($selected) { |
| 163 |
|
|
$td_class .= "selected"; |
| 164 |
|
|
} else { |
| 165 |
|
|
$td_class .= "hidden"; |
| 166 |
|
|
} |
| 167 |
|
|
$func = "show_activetab('".$this->_tab_name($title)."');"; |
| 168 |
|
|
$link = html_a("javascript: ".$func, $title, "link"); |
| 169 |
|
|
|
| 170 |
|
|
$td = html_td($td_class, "", $link); |
| 171 |
|
|
$td->set_id("tab_".$this->_tab_name($title)); |
| 172 |
|
|
$td->set_tag_attribute("onclick", "javascript: ".$func); |
| 173 |
|
|
if ($selected) { |
| 174 |
|
|
$style = "font-weight: bold;background-color: ".$this->_selected_background.";"; |
| 175 |
|
|
} else { |
| 176 |
|
|
$style = "background-color: ".$this->_hidden_background.";"; |
| 177 |
|
|
} |
| 178 |
|
|
$td->set_style($style."width:".$width); |
| 179 |
|
|
return $td; |
| 180 |
|
|
} |
| 181 |
|
|
|
| 182 |
|
|
/** |
| 183 |
|
|
* Thie method is used to change the selected tab's |
| 184 |
|
|
* background color |
| 185 |
|
|
*/ |
| 186 |
|
|
function selected_background( $color ) { |
| 187 |
|
|
$this->_selected_background = $color; |
| 188 |
|
|
} |
| 189 |
|
|
|
| 190 |
|
|
/** |
| 191 |
|
|
* Thie method is used to change the hidden tab's |
| 192 |
|
|
* background color |
| 193 |
|
|
*/ |
| 194 |
|
|
function hidden_background( $color ) { |
| 195 |
|
|
$this->_hidden_background = $color; |
| 196 |
|
|
} |
| 197 |
|
|
|
| 198 |
|
|
|
| 199 |
|
|
function _tab_name( $title ) { |
| 200 |
|
|
return str_replace(" ", "", strtolower($title)); |
| 201 |
|
|
} |
| 202 |
|
|
} |
| 203 |
|
|
|
| 204 |
|
|
|
| 205 |
|
|
class ActiveTabCSS extends CSSBuilder { |
| 206 |
|
|
function user_setup() { |
| 207 |
|
|
$this->add_entry(".activetab", "", |
| 208 |
|
|
array("align" => "center") ); |
| 209 |
|
|
|
| 210 |
|
|
$this->add_entry(".activetab", ".spacer", |
| 211 |
|
|
array("width" => "5px", |
| 212 |
|
|
"border-bottom" => "1px solid #a1a1a1")); |
| 213 |
|
|
$this->add_entry(".activetab", ".end", |
| 214 |
|
|
array("border-bottom" => "1px solid #a1a1a1")); |
| 215 |
|
|
|
| 216 |
|
|
$this->add_entry(".activetab", ".link:active,.link:hover,.link:link,.link:visited", |
| 217 |
|
|
array("text-decoration" => "none", |
| 218 |
|
|
"color" => "#000000")); |
| 219 |
|
|
|
| 220 |
|
|
$this->add_entry(".activetab", ".tabhidden", |
| 221 |
|
|
array("border" => "1px solid #999999", |
| 222 |
|
|
"padding-left" => "5px", |
| 223 |
|
|
"padding-right" => "5px", |
| 224 |
|
|
"background-color" => "#eeeeee", |
| 225 |
|
|
"text-align" => "center", |
| 226 |
|
|
"white-space" => "nowrap", |
| 227 |
|
|
"font-family" => "arial", |
| 228 |
|
|
"font-size" => "10pt")); |
| 229 |
|
|
|
| 230 |
|
|
$this->add_entry(".activetab", ".tabselected", |
| 231 |
|
|
array("border-left" => "1px solid #999999", |
| 232 |
|
|
"border-top" => "1px solid #999999", |
| 233 |
|
|
"border-right" => "1px solid #999999", |
| 234 |
|
|
"padding-left" => "5px", |
| 235 |
|
|
"padding-right" => "5px", |
| 236 |
|
|
"text-align" => "center", |
| 237 |
|
|
"white-space" => "nowrap", |
| 238 |
|
|
"font-family" => "arial", |
| 239 |
|
|
"font-size" => "10pt")); |
| 240 |
|
|
|
| 241 |
|
|
$this->add_entry(".activetab", ".content", |
| 242 |
|
|
array("border-left" => "1px solid #a1a1a1", |
| 243 |
|
|
"border-right" => "1px solid #a1a1a1", |
| 244 |
|
|
"border-bottom" => "1px solid #a1a1a1", |
| 245 |
|
|
"position" => "relative", |
| 246 |
|
|
"z-index" => "100")); |
| 247 |
|
|
|
| 248 |
|
|
$this->add_entry(".activetab", ".content_visible", |
| 249 |
|
|
array("position" => "absolute", |
| 250 |
|
|
"left" => "0px", |
| 251 |
|
|
"top" => "0px", |
| 252 |
|
|
"visibility" => "visible", |
| 253 |
|
|
"z-index" => "50", |
| 254 |
|
|
"padding" => "5px 5px 5px 5px")); |
| 255 |
|
|
|
| 256 |
|
|
$this->add_entry(".activetab", ".content_hidden", |
| 257 |
|
|
array("position" => "absolute", |
| 258 |
|
|
"left" => "0px", |
| 259 |
|
|
"top" => "0px", |
| 260 |
|
|
"visibility" => "hidden", |
| 261 |
|
|
"z-index" => "50", |
| 262 |
|
|
"padding" => "5px 5px 5px 5px")); |
| 263 |
|
|
} |
| 264 |
|
|
|
| 265 |
|
|
} |
| 266 |
|
|
?> |