view: nav
dependencies: css/nav.css,js/nav3.js missing dependencies: none downloads: nav.zip ccViewsSkel.zip ccViewsAll.zip show: descriptionsourceappearance
a general-purpose hierarchical navigator. hierarchy types: fixed, toggle, dynamic down, dynamic right <?php /* * Copyright 2008, Peter Rowntree. All Rights Reserved. * http://www.hdyn.com/mail/contact.php?addr=pr * horizontally fills parent element. * see editable section below. */ /* depends: css/nav.css, js/nav3.js */ /* description: a general-purpose hierarchical navigator. hierarchy types: fixed, toggle, dynamic down, dynamic right */ ?> <script type="text/javascript" src="js/nav3.js"></script> <?php //-----editing these values does not constitute a code change------------------- //the form of a nav item is: <link label>=><target url> //link label must be valid html; target url need not. //an array of submenus: $subs=array(); $subs["sub0_1"]=array( "sub1_0"=>"/", "introduction"=>"?d1=,nav,intro" ); $subs["sub0_0"]=array( "sub0_0"=>"/", "sub0_1"=>"/" ); $subs["category"]=array( "sub0_0"=>$subs["sub0_0"], "sub0_1"=>$subs["sub0_1"] ); //the final navigation array: $navArr=array( "introduction"=>"?d1=gh,nav,intro", "a test category"=>$subs["category"], "d1=b,nav,b,c<br/>d2=a;c"=>"?d1=b,nav,b,c&d2=a;c", "d1=a,nav,b,fred"=>"?d1=a,nav,b,fred", "d1=a,nav,aj"=>"?d1=a,nav,aj", "license"=>"http://www.apache.org/licenses/LICENSE-2.0", "download"=>"download/ccViewsSkel.zip" ); if(gotView("aj")) { $navArr["do aj call"]="javascript:ajCall('some post data','ajServerExample.php?param1=a%20get%20param')"; } $type=3; //hierarchy type: 0:fixed; 1:toggle; 2:dynamic down; 3:dynamic right $activeBGColor="#ffc"; //if this is set, labels of expanded categories will have this bg color //------------------------------------------------------------------------------ if(isset($activeBGColor) && $activeBGColor) echo "<script type='text/javascript'>var g_activeBGColor='$activeBGColor';</script>"; setGlobal("g_thisPage","?".$_SERVER["QUERY_STRING"]); setGlobal("g_type",$type); echo "<div class='nav' id='nav'", $type == 2 || $type == 3 ? " onmouseover='rc(event)' onmouseout='htStart()' onclick='hideAllSubs()'" : "", ">"; buildNav($navArr,0); echo "</div>"; //expects $k to be good HTML function buildNav($arr,$depth) { global $g_thisPage,$g_type; static $maxDepth=30; //even though infinite recursion currently can't happen. foreach($arr as $k=>$v) { if(is_array($v)) { if(++$depth > $maxDepth) continue; //elements with class names 'ceil' and 'block' must NOT have their class //names changed, because nav3.js relies on them. switch ($g_type) { case 0: echo "<div class='ceil'>",$k,"</div><div class='block'>"; break; case 1: echo "<a class='ceil' onclick='toggleSib(this)' style='cursor:pointer'>",$k,"</a><div class='block' style='display:none'>"; break; default: $cName = $g_type == 3 ? "block block2" : "block"; echo "<div class='ceil'>",$k,"</div><div class='$cName' style='display:none'>"; } buildNav($v,$depth); echo "</div>"; } else if($v == $g_thisPage) echo "<div class='thisPage' title='this page'>",$k,"</div>"; else echo "<a href=\"",htmlspecialchars($v),"\">",$k,"</a>"; } } //viewByName('gv'); ?> |