From cb70c441a3bd183229b274110a093020fc6e9504 Mon Sep 17 00:00:00 2001
From: andi <andi@splitbrain.org>
Date: Sat, 15 Jan 2005 21:57:41 +0100
Subject: [PATCH] fancy index

darcs-hash:20050115205741-9977f-75c87471f0c801a8b623e2a0af53896331f80975.gz
---
 images/closed.gif | Bin 0 -> 54 bytes
 images/open.gif   | Bin 0 -> 54 bytes
 inc/html.php      |  38 ++++++++++++++++++++++++++++++++++----
 inc/search.php    |   5 ++++-
 style.css         |   8 ++++++++
 5 files changed, 46 insertions(+), 5 deletions(-)
 create mode 100644 images/closed.gif
 create mode 100644 images/open.gif

diff --git a/images/closed.gif b/images/closed.gif
new file mode 100644
index 0000000000000000000000000000000000000000..8414d4d69fa9cba7821efd06e5afba8134be2d10
GIT binary patch
literal 54
zcmZ?wbhEHbWM$xGXkcVW?wP~Dz@Ye(g^`PakwFK@W&p`BF!A>EujD9r%T%)YRN4nE
G25SHn$_y0%

literal 0
HcmV?d00001

diff --git a/images/open.gif b/images/open.gif
new file mode 100644
index 0000000000000000000000000000000000000000..f5d5c7e56f01c1933ab59785f73a12e6c004de60
GIT binary patch
literal 54
zcmZ?wbhEHbWM|-IXkcVW?wP~Dz@Ye(g^`PakwFK@W&p`BF!A>EuRPt$uy{)1ycrGJ
G4AuY|7Yq^r

literal 0
HcmV?d00001

diff --git a/inc/html.php b/inc/html.php
index 7624e238c..37fad428a 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -663,7 +663,7 @@ function html_index($ns){
 
   $data = array();
   search($data,$conf['datadir'],'search_index',array('ns' => $ns));
-  print html_buildlist($data,'idx','html_list_index');
+  print html_buildlist($data,'idx','html_list_index','html_li_index');
 }
 
 /**
@@ -687,17 +687,47 @@ function html_list_index($item){
   return $ret;
 }
 
+/**
+ * Index List item
+ *
+ * This user function is used in html_build_lidt to build the
+ * <li> tags for namespaces when displaying the page index
+ * it gives different classes to opened or closed "folders"
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function html_li_index($item){
+  if($item['type'] == "f"){
+    return '<li class="level'.$item['level'].'">';
+  }elseif($item['open']){
+    return '<li class="open">';
+  }else{
+    return '<li class="closed">';
+  }
+}
+
+/**
+ * Default List item
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function html_li_default($item){
+  return '<li class="level'.$item['level'].'">';
+}
+
 /**
  * Build an unordered list
  *
  * Build an unordered list from the given $data array
  * Each item in the array has to have a 'level' property
  * the item itself gets printed by the given $func user
- * function
+ * function. The second and optional function is used to
+ * print the <li> tag. Both user function need to accept
+ * a single item.
  *
  * @author Andreas Gohr <andi@splitbrain.org>
  */
-function html_buildlist($data,$class,$func){
+function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
   $level = 0;
   $opens = 0;
   $ret   = '';
@@ -723,7 +753,7 @@ function html_buildlist($data,$class,$func){
     $level = $item['level'];
 
     //print item
-    $ret .= '<li class="level'.$item['level'].'">';
+    $ret .= $lifunc($item); //user function
     $ret .= '<span class="li">';
     $ret .= $func($item); //user function
     $ret .= '</span>';
diff --git a/inc/search.php b/inc/search.php
index c620b7133..46b36f816 100644
--- a/inc/search.php
+++ b/inc/search.php
@@ -79,6 +79,8 @@ function search(&$data,$base,$func,$opts,$dir='',$lvl=1){
 function search_index(&$data,$base,$file,$type,$lvl,$opts){
   $return = true;
 
+  $item = array();
+
   if($type == 'd' && !preg_match('#^'.$file.'(/|$)#','/'.$opts['ns'])){
     //add but don't recurse
     $return = false;
@@ -95,7 +97,8 @@ function search_index(&$data,$base,$file,$type,$lvl,$opts){
 
   $data[]=array( 'id'    => $id,
                  'type'  => $type,
-                 'level' => $lvl );
+                 'level' => $lvl,
+                 'open'  => $return );
   return $return;
 }
 
diff --git a/style.css b/style.css
index 7bf145b06..79cd59468 100644
--- a/style.css
+++ b/style.css
@@ -368,6 +368,14 @@ span.li {
   font-weight: normal;
 }
 
+li.open {
+  list-style-image: url(images/open.gif);
+}
+
+li.closed {
+  list-style-image: url(images/closed.gif);
+}
+
 .quote {
   border-left: 2px solid #8cacbb;
   padding-left: 3px;
-- 
GitLab