summaryrefslogtreecommitdiff
path: root/inc/html.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2011-11-27 10:50:03 +0100
committerAndreas Gohr <andi@splitbrain.org>2011-11-27 10:50:03 +0100
commit560f6ea3cdac2767863c3be3a9e7933b6e37e88f (patch)
tree6f51d4b3402458e4de1a596b93ec752c8ac747b2 /inc/html.php
parente0dd04a6493f1b7f7133f75c08f9ea55ee8bd50a (diff)
parentc66c7229a0dfc4f9f06dadda98408679fa7a18d6 (diff)
downloadrpg-560f6ea3cdac2767863c3be3a9e7933b6e37e88f.tar.gz
rpg-560f6ea3cdac2767863c3be3a9e7933b6e37e88f.tar.bz2
Merge branch 'master' into bcrypt
Diffstat (limited to 'inc/html.php')
-rw-r--r--inc/html.php39
1 files changed, 21 insertions, 18 deletions
diff --git a/inc/html.php b/inc/html.php
index 7f5a46b93..1a2d7daef 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -899,45 +899,41 @@ function html_li_default($item){
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
-function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
+function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
if (count($data) === 0) {
return '';
}
$start_level = $data[0]['level'];
- $ret = '';
-
- if ($start_level < 2) {
- // Trigger building a wrapper ul if the first level is
- // 0 (we have a root object) or 1 (just the root content)
- --$start_level;
- }
-
$level = $start_level;
+ $ret = '';
+ $open = 0;
foreach ($data as $item){
if( $item['level'] > $level ){
//open new list
for($i=0; $i<($item['level'] - $level); $i++){
- if ($i) $ret .= "<li class=\"clear\">\n";
+ if ($i) $ret .= "<li class=\"clear\">";
$ret .= "\n<ul class=\"$class\">\n";
+ $open++;
}
+ $level = $item['level'];
+
}elseif( $item['level'] < $level ){
//close last item
$ret .= "</li>\n";
- for ($i=0; $i<($level - $item['level']); $i++){
+ while( $level > $item['level'] && $open > 0 ){
//close higher lists
$ret .= "</ul>\n</li>\n";
+ $level--;
+ $open--;
}
} elseif ($ret !== '') {
- //close last item
+ //close previous item
$ret .= "</li>\n";
}
- //remember current level
- $level = $item['level'];
-
//print item
$ret .= call_user_func($lifunc,$item);
$ret .= '<div class="li">';
@@ -947,8 +943,15 @@ function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
}
//close remaining items and lists
- while(--$level >= $start_level) {
- $ret .= "</li></ul>\n";
+ $ret .= "</li>\n";
+ while($open-- > 0) {
+ $ret .= "</ul></li>\n";
+ }
+
+ if ($forcewrapper || $start_level < 2) {
+ // Trigger building a wrapper ul if the first level is
+ // 0 (we have a root object) or 1 (just the root content)
+ $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n";
}
return $ret;
@@ -1694,7 +1697,7 @@ function html_TOC($toc){
$out .= $lang['toc'];
$out .= '</div>'.DOKU_LF;
$out .= '<div id="toc__inside">'.DOKU_LF;
- $out .= html_buildlist($toc,'toc','html_list_toc');
+ $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true);
$out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
$out .= '<!-- TOC END -->'.DOKU_LF;
return $out;