Commit 3d769073 authored by mrodzis's avatar mrodzis 🐸
Browse files

Enables up to three levels

parent a6b6a54f
......@@ -12,6 +12,7 @@ declare variable $nav:langTest := if($nav:langDefault = "")
then true()
else ($nav:lang = $nav:langDefault);
(:~ Returns all first level navitems incl. their children :)
declare
%templates:wrap
function nav:navitems($node as node(), $model as map(*)) as map(*) {
......@@ -21,52 +22,81 @@ function nav:navitems($node as node(), $model as map(*)) as map(*) {
map { "navitems" := $navitems }
};
(:~ Creates the visible first level entries in the navbar :)
declare function nav:head($node as node(), $model as map(*)) {
switch(local-name($model("item")))
case "submenu" return
element { node-name($node) } {
$node/@*,
if ($nav:langTest)
then (string($model("item")/@label))
else string($model("item")/@*[local-name( . ) = "label-" || $nav:lang]),
if ($nav:langTest) then
string($model("item")/@label)
else
string($model("item")/@*[local-name( . ) = "label-" || $nav:lang]),
$node/node()
}
case "item" return
element { node-name($node) } {
attribute href {$model("item")/@link},
if(contains(string($model("item")/@link), ":")
or string($model("item")/@link) = "info.html") then
()
else
attribute target {"_blank"},
(: if ($nav:langTest or not($model("subitem")/@*[local-name() ="label-" || $nav:lang])):)
if ($nav:langTest)
then string($model("item")/@label)
else string($model("item")/@*[local-name( . ) = "label-" || $nav:lang])
local:make-link-content($model("item"))
}
default return
<b>not defined: { node-name($model("item")) }</b>
};
(:~ Returns all non-first-level entries :)
declare
%templates:wrap
function nav:subitems($node as node(), $model as map(*)) as map(*) {
map{ "subitems" := $model("item")/*}
};
(:~ Creates the non-first-level entries :)
declare function nav:subitem($node as node(), $model as map(*)) {
if($model("subitem")/@class) then
<span class="{$model("subitem")/@class}">&#160;</span>
else if ($model("subitem")/name() != 'divider') then
element a {
if(string($model("subitem")/@link)) then attribute href { string($model("subitem")/@link)} else (),
if(contains(string($model("subitem")/@link), ":")) then
()
else
attribute target {"_blank"},
if ($nav:langTest or not($model("subitem")/@*[local-name() ="label-" || $nav:lang]))
then string($model("subitem")/@label)
else string($model("subitem")/@*[local-name( . ) = "label-" || $nav:lang])
}
else <span>&#160;</span>
else
if ($model("subitem")/name() != 'divider') then
switch($model("subitem")/name())
case "item" return
element a {
local:make-link-content($model("subitem"))
}
case "submenu" return
<li class="dropdown-submenu">
<a class="dropdown-toggle" data-toggle="dropdown">
{local:make-link-content($model("subitem"))}
</a>
<ul class="dropdown-menu">
{
for $level-3-item in $model("subitem")/* return
<li>
<a>{local:make-link-content($level-3-item)}</a>
</li>
}
</ul>
</li>
default return
<b>not defined: { node-name($model("subitem")) }</b>
else
<span>&#160;</span>
};
(: Returns the link content of a navbar item.
:
: @param $node either $model("item") or $model("subitem") depending on the level that calls the function :)
declare function local:make-link-content($node as node()) {
if(string($node/@link)) then
attribute href { string($node/@link)}
else
(),
if(contains(string($node/@link), ":")) then
()
else
attribute target {"_blank"},
if ($nav:langTest
or not($node/@*[local-name() ="label-" || $nav:lang])) then
string($node/@label)
else
string($node/@*[local-name( . ) = "label-" || $nav:lang])
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment