Index: trunk/extensions/TreeAndMenu/TreeAndMenu.php |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | |
16 | 16 | if (!defined('MEDIAWIKI')) die('Not an entry point.'); |
17 | 17 | |
18 | | -define('TREEANDMENU_VERSION','1.0.6, 2008-06-25'); |
| 18 | +define('TREEANDMENU_VERSION','1.0.7, 2008-07-31'); |
19 | 19 | |
20 | 20 | # Set any unset images to default titles |
21 | 21 | if (!isset($wgTreeViewImages) || !is_array($wgTreeViewImages)) $wgTreeViewImages = array(); |
— | — | @@ -178,6 +178,7 @@ |
179 | 179 | $node = 0; |
180 | 180 | $last = -1; |
181 | 181 | $nodes = ''; |
| 182 | + $opennodes = array(); |
182 | 183 | foreach ($rows as $i => $info) { |
183 | 184 | $node++; |
184 | 185 | list($id, $depth, $icon, $item, $start) = $info; |
— | — | @@ -186,12 +187,16 @@ |
187 | 188 | $type = $args['type']; |
188 | 189 | $end = $i == count($rows)-1 || $rows[$i+1][4]; |
189 | 190 | if (!isset($args['root'])) $args['root'] = ''; # tmp - need to handle rootless trees |
| 191 | + $openlevels = isset($args['openlevels']) ? $args['openlevels']+1 : 0; |
190 | 192 | if ($start) $node = 1; |
191 | 193 | |
192 | 194 | # Append node script for this row |
193 | 195 | if ($depth > $last) $parents[$depth] = $node-1; |
194 | 196 | $parent = $parents[$depth]; |
195 | | - if ($type == 'tree') $nodes .= "$objid.add($node, $parent, '$item');\n"; |
| 197 | + if ($type == 'tree') { |
| 198 | + $nodes .= "$objid.add($node, $parent, '$item');\n"; |
| 199 | + if ($depth > 0 && $openlevels > $depth) $opennodes[$parent] = true; |
| 200 | + } |
196 | 201 | else { |
197 | 202 | if (!$start) { |
198 | 203 | if ($depth < $last) $nodes .= str_repeat('</ul></li>', $last-$depth); |
— | — | @@ -211,7 +216,8 @@ |
212 | 217 | |
213 | 218 | # Finalise a tree |
214 | 219 | $add = isset($args['root']) ? "tree.add(0,-1,'".$args['root']."');" : ''; |
215 | | - $top = $bottom = $root = ''; |
| 220 | + $top = $bottom = $root = $opennodesjs = ''; |
| 221 | + foreach (array_keys($opennodes) as $i) $opennodesjs .= "$objid.o($i);"; |
216 | 222 | foreach ($args as $arg => $pos) |
217 | 223 | if (($pos == 'top' || $pos == 'bottom' || $pos == 'root') && ($arg == 'open' || $arg == 'close')) |
218 | 224 | $$pos .= "<a href=\"javascript: $objid.{$arg}All();\"> {$arg} all</a> "; |
— | — | @@ -227,6 +233,7 @@ |
228 | 234 | $objid = tree; |
229 | 235 | $nodes |
230 | 236 | document.getElementById('$id').innerHTML = $objid.toString(); |
| 237 | + $opennodesjs |
231 | 238 | /*]]>*/</script> |
232 | 239 | </div>$bottom"; |
233 | 240 | } |