/*
* Copyright 2018-2020 Tomas Zeman <tomas@functionals.cz>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sqwl.cms.layout
import scalatags.Text.TypedTag
import scalatags.Text.all._
import sqwl.cms._
object Navbar extends config {
def apply(cnt: iContent, st: ViewState): TypedTag[String] = {
def activeCls(c: iCategory): String = {
st match {
case ViewCategory(v) if v == c => "active"
case ViewArticle(v) if v.category contains c => "active"
case _ => ""
}
}
val navSections = ul(cls:="nav navbar-nav navbar-section", width:="100%",
cnt.categories map(c =>
li(cls:=s"text-center ${activeCls(c)}",
a(href:=s"/${http.prefix}/${c.pathSegment}", c.name))
)
)
header(cls:="navbar navbar-default navbar-fixed-top",
div(cls:="navbar-inner",
div(cls:="container",
div(cls:="navbar-header",
button(`type`:="button", cls:="navbar-toggle collapsed",
attr("data-toggle"):="collapse",
attr("data-target"):="#navbar1",
span(cls:="sr-only", "Navigation"),
span(cls:="icon-bar"),
span(cls:="icon-bar"),
span(cls:="icon-bar")
),
a(href:=s"/${http.prefix}", cls:="navbar-brand",
paddingTop:=4, paddingBottom:=4,
img(src:=s"/${http.prefix}/public/${cnt.icon._1}",
alt:=cnt.appTitleShort, width:=40, height:=40)),
a(href:=s"/${http.prefix}", cls:="navbar-brand visible-xs",
span(cnt.appTitleShort)),
a(href:=s"/${http.prefix}", cls:="navbar-brand hidden-xs",
span(cnt.appTitle))
)
//tag("nav")(cls:="hidden-xs", navMenu)
)
),
div(cls:="collapse navbar-collapse", id:="navbar1",
div(cls:="container", navSections))
)
}
}