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 = "") ...@@ -12,6 +12,7 @@ declare variable $nav:langTest := if($nav:langDefault = "")
then true() then true()
else ($nav:lang = $nav:langDefault); else ($nav:lang = $nav:langDefault);
(:~ Returns all first level navitems incl. their children :)
declare declare
%templates:wrap %templates:wrap
function nav:navitems($node as node(), $model as map(*)) as map(*) { 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(*) { ...@@ -21,52 +22,81 @@ function nav:navitems($node as node(), $model as map(*)) as map(*) {
map { "navitems" := $navitems } map { "navitems" := $navitems }
}; };
(:~ Creates the visible first level entries in the navbar :)
declare function nav:head($node as node(), $model as map(*)) { declare function nav:head($node as node(), $model as map(*)) {
switch(local-name($model("item"))) switch(local-name($model("item")))
case "submenu" return case "submenu" return
element { node-name($node) } { element { node-name($node) } {
$node/@*, $node/@*,
if ($nav:langTest) if ($nav:langTest) then
then (string($model("item")/@label)) string($model("item")/@label)
else string($model("item")/@*[local-name( . ) = "label-" || $nav:lang]), else
string($model("item")/@*[local-name( . ) = "label-" || $nav:lang]),
$node/node() $node/node()
} }
case "item" return case "item" return
element { node-name($node) } { element { node-name($node) } {
attribute href {$model("item")/@link}, local:make-link-content($model("item"))
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])
} }
default return default return
<b>not defined: { node-name($model("item")) }</b> <b>not defined: { node-name($model("item")) }</b>
}; };
(:~ Returns all non-first-level entries :)
declare declare
%templates:wrap %templates:wrap
function nav:subitems($node as node(), $model as map(*)) as map(*) { function nav:subitems($node as node(), $model as map(*)) as map(*) {
map{ "subitems" := $model("item")/*} map{ "subitems" := $model("item")/*}
}; };
(:~ Creates the non-first-level entries :)
declare function nav:subitem($node as node(), $model as map(*)) { declare function nav:subitem($node as node(), $model as map(*)) {
if($model("subitem")/@class) then if($model("subitem")/@class) then
<span class="{$model("subitem")/@class}">&#160;</span> <span class="{$model("subitem")/@class}">&#160;</span>
else if ($model("subitem")/name() != 'divider') then else
element a { if ($model("subitem")/name() != 'divider') then
if(string($model("subitem")/@link)) then attribute href { string($model("subitem")/@link)} else (), switch($model("subitem")/name())
if(contains(string($model("subitem")/@link), ":")) then case "item" return
() element a {
else local:make-link-content($model("subitem"))
attribute target {"_blank"},
if ($nav:langTest or not($model("subitem")/@*[local-name() ="label-" || $nav:lang])) }
then string($model("subitem")/@label) case "submenu" return
else string($model("subitem")/@*[local-name( . ) = "label-" || $nav:lang]) <li class="dropdown-submenu">
} <a class="dropdown-toggle" data-toggle="dropdown">
else <span>&#160;</span> {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