[Phphtmllib-devel] I patched widgets/TextCSSNav.inc for clarity
Status: Beta
Brought to you by:
hemna
From: Erich E. <twi...@fa...> - 2004-02-17 20:09:39
|
I was reading the code, and was having a hard time understanding exactly what was going on in this bit of code, so I rearranged some stuff (still equivalent function), and now IMHO it's a bit more readable. In particular: * I fixed broken indentation * I made an is_first variable to explicitly say what we're doing the first time around (and that it is the first time that we are actually concerned with) * I collected some of the repeated conditions into an assignment into a well-named variable * I collected only what really changed in those different conditions, namely the arguments to the function set_class, therefore making us able to call set_class only once. See what you think; here's the patch: --- TextCSSNav.inc.orig 2004-02-17 12:14:45.000000000 -0700 +++ TextCSSNav.inc 2004-02-17 12:39:57.000000000 -0700 @@ -165,7 +165,7 @@ $container = container(); $container->set_collapse(); - $class = "first"; + $is_first = TRUE; $cnt = 1; foreach( $this->data as $nav ) { switch ($nav["type"]) { @@ -178,19 +178,16 @@ $url .= "&".$this->_query_prefix."textcssnavselected=".$cnt; } $obj = html_a(htmlentities($url), $nav["text"], "normal", $nav["target"], $nav["title"]); - if ($class != NULL) { - if ($this->_highlight_selected && ($this->_selected == $cnt || - $nav["selected"])) { - $class = "selected".$class; - } + + $is_selected = $this->_highlight_selected && ($this->_selected == $cnt || $nav["selected"]); + $class = $is_selected ? "selected" : ""; + if ($is_first) { + $class .= "first"; + } + if ($is_selected || $is_first) { $obj->set_class( $class ); - $class = NULL; - } else { - if ($this->_highlight_selected && ($this->_selected == $cnt || - $nav["selected"])) { - $obj->set_class( "selected" ); - } } + $is_first = FALSE; $cnt++; break; case "blank": /// End patch /// Hope that helps someone, -- epte -- http://www.fastmail.fm - Accessible with your email software or over the web |