r38266 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38265‎ | r38266 | r38267 >
Date:00:15, 31 July 2008
Author:nad
Status:old
Tags:
Comment:
implemenent openlevels parameter - thanks Andrea\!
Modified paths:
  • /trunk/extensions/TreeAndMenu/TreeAndMenu.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TreeAndMenu/TreeAndMenu.php
@@ -14,7 +14,7 @@
1515
1616 if (!defined('MEDIAWIKI')) die('Not an entry point.');
1717
18 -define('TREEANDMENU_VERSION','1.0.6, 2008-06-25');
 18+define('TREEANDMENU_VERSION','1.0.7, 2008-07-31');
1919
2020 # Set any unset images to default titles
2121 if (!isset($wgTreeViewImages) || !is_array($wgTreeViewImages)) $wgTreeViewImages = array();
@@ -178,6 +178,7 @@
179179 $node = 0;
180180 $last = -1;
181181 $nodes = '';
 182+ $opennodes = array();
182183 foreach ($rows as $i => $info) {
183184 $node++;
184185 list($id, $depth, $icon, $item, $start) = $info;
@@ -186,12 +187,16 @@
187188 $type = $args['type'];
188189 $end = $i == count($rows)-1 || $rows[$i+1][4];
189190 if (!isset($args['root'])) $args['root'] = ''; # tmp - need to handle rootless trees
 191+ $openlevels = isset($args['openlevels']) ? $args['openlevels']+1 : 0;
190192 if ($start) $node = 1;
191193
192194 # Append node script for this row
193195 if ($depth > $last) $parents[$depth] = $node-1;
194196 $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+ }
196201 else {
197202 if (!$start) {
198203 if ($depth < $last) $nodes .= str_repeat('</ul></li>', $last-$depth);
@@ -211,7 +216,8 @@
212217
213218 # Finalise a tree
214219 $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);";
216222 foreach ($args as $arg => $pos)
217223 if (($pos == 'top' || $pos == 'bottom' || $pos == 'root') && ($arg == 'open' || $arg == 'close'))
218224 $$pos .= "<a href=\"javascript: $objid.{$arg}All();\">&nbsp;{$arg} all</a>&nbsp;";
@@ -227,6 +233,7 @@
228234 $objid = tree;
229235 $nodes
230236 document.getElementById('$id').innerHTML = $objid.toString();
 237+ $opennodesjs
231238 /*]]>*/</script>
232239 </div>$bottom";
233240 }

Status & tagging log