DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:navi

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
plugin:navi [2015-02-11 14:05] – [navi plugin] 105.236.249.39plugin:navi [2024-01-25 09:05] (current) – old revision restored (2023-04-27 22:25) - submit a pull request for changes andi
Line 1: Line 1:
-====== navi plugin ======+====== navi Plugin ======
  
 ---- plugin ---- ---- plugin ----
 description: Build a navigation menu from a list description: Build a navigation menu from a list
 author     : Andreas Gohr author     : Andreas Gohr
-email      : wiki@cosmocode.de+email      : dokuwiki@cosmocode.de
 type       : syntax type       : syntax
-lastupdate : 2012-10-26 +lastupdate : 2023-02-15 
-compatible : 2009-12-25++compatible : Detritus, Hrun, Elenor Of Tsort, Greebo, Hogfather, Igor
 depends    :  depends    : 
 conflicts  conflicts 
Line 14: Line 14:
 alter      : true alter      : true
  
-sourcerepo : http://github.com/cosmocode/navi +sourcerepo : https://github.com/cosmocode/navi 
-downloadurl: http://github.com/cosmocode/navi/zipball/master +downloadurl: https://github.com/cosmocode/navi/zipball/master 
-bugtracker : http://github.com/cosmocode/navi/issues+bugtracker : https://github.com/cosmocode/navi/issues
 ---- ----
  
Line 22: Line 22:
  
 ===== Download and Install ===== ===== Download and Install =====
-[[http://www.cosmocode.de/en/open-source/dokuwiki-plugins/|{{ http://cosmocode.de/static/img/dokuwiki/dwplugins.png?recache|A CosmoCode Plugin}}]] 
  
-Use the download link above to either manually download the plugin or install it through the plugin manager.+[[https://www.cosmocode.de/en/open-source/dokuwiki-plugins/|{{ https://www.cosmocode.de/static/img/dokuwiki/dwplugins.png?recache|A CosmoCode Plugin}}]] 
 + 
 +Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually.
  
  
Line 45: Line 46:
   * The list items should only contain links, any other syntax will be ignored   * The list items should only contain links, any other syntax will be ignored
   * Each page linked in the list should occur only once   * Each page linked in the list should occur only once
 +  * Displayed links are dependent on user permissions. When the current user can not read a page it will not be shown (neither will any pages further down the hierarchy)
  
 ==== Control Page Example ==== ==== Control Page Example ====
Line 67: Line 69:
 Sometimes the navi plugin is used to create collapsible, editable navigation even though content is structured into nested namespaces. But since the plugin knows nothing about those namespaces by default it will collapse completely as soon as a page is opened that is not defined in the control page. Sometimes the navi plugin is used to create collapsible, editable navigation even though content is structured into nested namespaces. But since the plugin knows nothing about those namespaces by default it will collapse completely as soon as a page is opened that is not defined in the control page.
  
-By adding ''?ns'' to the navi plugin syntax you can make the plugin to be clever about namespaces: When it is called on a page that is not mentioned on the control page, it will have a look at the namespace of the page. It then checks if a startpage for the namespace is to be found in the control page. If it is, it will be used as the current open branch, if not it is checked if there is //any// other page in the same namespace on the controlpage. If found it's used. This is repeated for each higher namespace until the top is reached or a matching page.+By adding ''?ns'' to the navi plugin syntax, e.g. ''%%{{navi>navigationmenu?ns}}%%'', you can make the plugin to be clever about namespaces: When it is called on a page that is not mentioned on the control page, it will have a look at the namespace of the page. It then checks if a startpage for the namespace is to be found in the control page. If it is, it will be used as the current open branch, if not it is checked if there is //any// other page in the same namespace on the controlpage. If found it's used. This is repeated for each higher namespace until the top is reached or a matching page.
  
 +==== Displaying the Full Tree and dynamic JS ====
  
 +Sometimes you may want to display the full navigation hierarchy (but still leave out pages without permission). Especially template authors may want to use this feature for mobile menus and such. You can do this by adding the ''full'' parameter:
  
-===== Addon ===== +  {{navi>navigationmenu?ns&full}}
- +
-I modified the function render to use it a little bit like a dynamic version, +
-Menuitems will have ''list items'' now. If a child is defined and if it is open the Icon will change. +
-If no Child is defined there is no list item. +
-I add to the ''DIV li'' an open or closed class which can be read from the template css like following css-code example. +
- --- [[user>oh-mark|oh-mark]] //2011/06/20// +
- +
-<code css> +
-div.dokuwiki div.navigation li { +
-  list-style: none; +
-  margin-left: 5em; /** default if more than defined levels **/  +
-+
-div.dokuwiki div.navigation li.open   { list-style-image: url(images/open.gif);+
-div.dokuwiki div.navigation li.close  list-style-image: url(images/closed.gif);+
-div.dokuwiki div.navigation li.level1 { margin-left: 0em; } +
-div.dokuwiki div.navigation li.level2 { margin-left: 1em; } +
-div.dokuwiki div.navigation li.level3 { margin-left: 2em; } +
-div.dokuwiki div.navigation li.level4 { margin-left: 3em; } +
-div.dokuwiki div.navigation li.level5 { margin-left: 4em; } +
-</code> +
- +
-here is the mod +
- +
-<code php> +
- +
-    /** +
-     * Create output +
-     * +
-     * We handle all modes (except meta) because we pass all output creation back to the parent +
-     * mod by Mark Wolfgruber 20.06.2011 +
-          *            +
-     */ +
-    function render($format, &$R, $data) { +
-        global $INFO; +
-        global $ID; +
-        $fn   = $data[0]; +
-        $opt  = $data[2]; +
-        $data = $data[1]; +
- +
-        if($format == 'metadata'){ +
-            $R->meta['relation']['naviplugin'][] = $fn; +
-            return true; +
-        } +
- +
-        $R->info['cache'] = false; // no cache please +
- +
-        $parent = array(); +
-        if(isset($data[$INFO['id']])){ +
-            $parent = (array) $data[$INFO['id']]['parents']; // get the "path" of the page we're on currently +
-            array_push($parent,$INFO['id']); +
-            $current = $INFO['id']; +
-        }elseif($opt == 'ns'){ +
-            $ns   = $INFO['id']; +
- +
-            // traverse up for matching namespaces +
-            do { +
-                $ns = getNS($ns); +
-                $try = "$ns:"; +
-                resolve_pageid('',$try,$foo); +
-                if(isset($data[$try])){ +
-                    // got a start page +
-                    $parent = (array) $data[$try]['parents']; +
-                    array_push($parent,$try); +
-                    $current = $try; +
-                    break; +
-                }else{ +
-                    // search for the first page matching the namespace +
-                     foreach($data as $key => $junk){ +
-                        if(getNS($key) == $ns){ +
-                            $parent = (array) $data[$key]['parents']; +
-                            array_push($parent,$key); +
-                            $current = $key; +
-                            break 2; +
-                        }  +
-                    }  +
-                } +
- +
-            } while($ns); +
-        } +
- +
-        // we need the top ID for the renderer +
-        $oldid = $ID; +
-        $ID = $INFO['id']; +
- +
-        // create a correctly nested list (or so I hope) +
-//        $open = false; /** deacivated by mark **/ +
-        $lvl  = 1; +
-        $R->listu_open(); +
- +
-        // read if item has childs and if it is open or closed /** mod by mark **/ +
-        $upper=array(); +
-        foreach((array) $data as $pid => $info){ +
-            $state=(array_diff($info['parents'],$parent)) ? 'close':''; +
-            $countparents=count($info['parents']); +
-            if ( $countparents > '0') { +
-                for($i=0; $i < $countparents; $i++){ +
-                  $upperlevel=$countparents-1; +
-                  $upper[$info['parents'][$upperlevel]]=($state=='close')? 'close' : 'open'; +
-                } +
-            }         +
-        } /** mod by mark **/  +
-        unset($pid); // break the reference with the last element /** mod by mark **/ +
-         +
-            // read if item has childs if it is open or closed +
-            foreach((array) $data as $pid => $info){ +
-                // only show if we are in the "path" +
-                if(array_diff($info['parents'],$parent)) continue; +
-                 +
-                if ($upper[$pid]) { /** mod by mark **/ +
-                  $menuitem=($upper[$pid]=='open') ? 'open' : 'close'; +
-                 } else { +
-                  $menuitem=''; +
-                 } /** mod by mark **/ +
- +
-                // skip every non readable page +
-                if(auth_quickaclcheck(cleanID($info['page'])) < AUTH_READ) continue; +
-     +
-                if($info['lvl'] == $lvl){ +
-//                    if($open) $R->listitem_close(); /** deacivated by mark **/ +
-                    $R->listitem_open($lvl.' '.$menuitem); /** mod by mark **/ +
-//                    $open = true; /** deacivated by mark **/ +
-                }elseif($lvl > $info['lvl']){ +
-                    for($lvl; $lvl > $info['lvl']; $lvl--){ +
-//                      $R->listitem_close(); /** deacivated by mark **/ +
-//                      $R->listu_close();    /** deacivated by mark **/ +
-                    } +
-//                    $R->listitem_close();   /** deacivated by mark **/ +
-                    $R->listitem_open($lvl.' '.$menuitem); /** mod by mark **/ +
-                }elseif($lvl < $info['lvl']){ +
-                    // more than one run is bad nesting! +
-                    for($lvl; $lvl < $info['lvl']; $lvl++){ +
-//                    $R->listu_open(); /** deacivated by mark **/ +
-                      $R->listitem_open($info['lvl'].' '.$menuitem); /** mod by oh-mark **/ +
-//                    $open = true;  /** deacivated by mark **/ +
-                    } +
-                } +
-     +
-                $R->listcontent_open(); +
-                if(($format == 'xhtml'&& ($info['page'] == $current)) $R->doc .= '<span class="current">'; +
-                $R->internallink(':'.$info['page'],$info['title']); +
-                if(($format == 'xhtml') && ($info['page'] == $current)) $R->doc .= '</span>'; +
-                $R->listcontent_close(); +
-                $R->listitem_close();  /** mod by mark **/ +
-            } +
-/*        while($lvl > 0){  +
-            $R->listitem_close(); +
-            $R->listu_close(); +
-            $lvl--; +
-         /** deacivated by mark **/ +
-            $R->listu_close();  /** mod by mark **/ +
- +
-        $ID = $oldid; +
- +
-        return true; +
-    } +
- +
-</code> +
- +
-===== BUG ===== +
-====  first submenu item level1 instead level2 ==== +
- +
-i tried this plugin and have a problem with the first submenu item. it have to be in the div class level2 but it became level1 after the script did his work --- [[user>oh-mark|oh-mark]] //2011/06/19// +
- +
-> found the error: +
-> replace $lvl with $info['lvl'] in line ~173 --- [[user>oh-mark|oh-mark]] //2011/06/19 22:50// +
- +
-<code> +
-            }elseif($lvl < $info['lvl']){ +
-                // more than one run is bad nesting! +
-                for($lvl; $lvl < $info['lvl']; $lvl++){ +
-                    $R->listu_open(); +
-                    $R->listitem_open($info['lvl']); /** mod by oh-mark **/ +
-                    $open = true; +
-                } +
- +
-</code>+
  
-==== Rendering Bugs ==== +If you want to use the full hierarchy but be able to open without page reloads, you can use the ''js'' parameter:
-The closing of open menu entries does not work.  +
-The open menu child entries are on the same level like the main menu entries. +
-The user does not see any indicator for child menu items if the main menu is closed. +
  
-Tested with the code modifications on this page with Dokuwiki dokuwiki-rc2011-11-10.tgz “Angua”.  +  {{navi>navigationmenu?ns&js}}
-HH 29.12.2011+
  
  
plugin/navi.1423659957.txt.gz · Last modified: 2015-02-11 14:05 by 105.236.249.39

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki