support menus in navbar

This commit is contained in:
Dean Attali 2016-03-17 21:20:11 -07:00
parent 1d3b3e258c
commit 4fe69971e3
4 changed files with 117 additions and 27 deletions

View File

@ -1,4 +1,4 @@
# --- Serving options --- # # --- General options --- #
# url is the full website URL # url is the full website URL
# baseurl is the website's URL without the hostname # baseurl is the website's URL without the hostname
@ -21,16 +21,19 @@ description: A virtual proof that name is awesome!
# --- Navigation bar options --- # # --- Navigation bar options --- #
# List of links in the navigation bar
navbar-links:
About Me: "aboutme"
Resources:
- Beautiful Jekyll: "http://deanattali.com/beautiful-jekyll/"
- Learn markdown: "http://www.markdowntutorial.com/"
- GitHub Pages: "https://pages.github.com/"
Author's home: "http://deanattali.com"
# Image to show in the navigation bar - image must be a square (width = height) # Image to show in the navigation bar - image must be a square (width = height)
# Remove this parameter if you don't want an image in the navbar # Remove this parameter if you don't want an image in the navbar
avatar: "/img/avatar-icon.png" avatar: "/img/avatar-icon.png"
# List of links in the navigation bar
navbar-links:
Home: ""
About Me: "aboutme"
Author's home: "http://deanattali.com"
# --- Footer options --- # # --- Footer options --- #
# Change all these values or delete the ones you don't want. # Change all these values or delete the ones you don't want.

View File

@ -12,26 +12,54 @@
<div class="collapse navbar-collapse" id="main-navbar"> <div class="collapse navbar-collapse" id="main-navbar">
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
{% for link in site.navbar-links %} {% for link in site.navbar-links %}
{% capture before %}{{ link[1] | split: "://" | first }}{% endcapture %} {% if link[1].first %}
{% capture after %}{{ link[1] | split: "://" | last }}{% endcapture %} <li class="navlinks-container">
<li> <a class="navlinks-parent" href="javascript:void(0)">{{ link[0] }}</a>
{% assign internal = true %} <div class="navlinks-children">
{% if before != after %} {% for childlink in link[1] %}
{% if before == "http" or before == "https" %} {% for linkparts in childlink %}
{% assign internal = false %} {% capture before %}{{ linkparts[1] | split: "://" | first }}{% endcapture %}
{% endif %} {% capture after %}{{ linkparts[1] | split: "://" | last }}{% endcapture %}
{% endif %} {% assign internal = true %}
{% if before != after %}
{% if internal %} {% if before == "http" or before == "https" %}
{% capture linkurl %}{{ site.baseurl }}/{{ link[1] }}{% endcapture %} {% assign internal = false %}
{% endif %}
{% endif %}
{% if internal %}
{% capture linkurl %}{{ site.baseurl }}/{{ linkparts[1] }}{% endcapture %}
{% else %}
{% capture linkurl %}{{ linkparts[1] }}{% endcapture %}
{% endif %}
<a href="{{ linkurl }}">{{ linkparts[0] }}</a>
{% endfor %}
{% endfor %}
</div>
</li>
{% else %} {% else %}
{% capture linkurl %}{{ link[1] }}{% endcapture %} <li>
{% endif %} {% capture before %}{{ link[1] | split: "://" | first }}{% endcapture %}
{% capture after %}{{ link[1] | split: "://" | last }}{% endcapture %}
{% assign internal = true %}
{% if before != after %}
{% if before == "http" or before == "https" %}
{% assign internal = false %}
{% endif %}
{% endif %}
<a href="{{ linkurl }}">{{ link[0] }}</a> {% if internal %}
</li> {% capture linkurl %}{{ site.baseurl }}/{{ link[1] }}{% endcapture %}
{% endfor %} {% else %}
{% capture linkurl %}{{ link[1] }}{% endcapture %}
{% endif %}
<a href="{{ linkurl }}">{{ link[0] }}</a>
</li>
{% endif %}
{% endfor %}
</ul> </ul>
</div> </div>

View File

@ -182,6 +182,53 @@ img {
} }
} }
/* Multi-level navigation links */
.navbar-custom .nav .navlinks-container {
position: relative;
}
.navbar-custom .nav .navlinks-parent:after {
content: " \25BC";
}
.navbar-custom .nav .navlinks-children {
width: 100%;
display: none;
word-break: break-word;
}
.navbar-custom .nav .navlinks-container .navlinks-children a {
display: block;
padding: 10px;
padding-left: 30px;
background: #f5f5f5;
text-decoration: none !important;
border-width: 0 1px 1px 1px;
font-weight: normal;
}
@media only screen and (max-width: 767px) {
.navbar-custom .nav .navlinks-container.show-children {
background: #eee;
}
.navbar-custom .nav .navlinks-container.show-children .navlinks-children {
display: block;
}
}
@media only screen and (min-width: 768px) {
.navbar-custom .nav .navlinks-container:hover {
background: #eee;
}
.navbar-custom .nav .navlinks-container:hover .navlinks-children {
display: block;
}
.navbar-custom .nav .navlinks-children {
position: absolute;
text-align: center;
}
.navbar-custom .nav .navlinks-container .navlinks-children a {
padding-left: 10px;
border: 1px solid #eaeaea;
border-width: 0 1px 1px;
}
}
/* --- Footer --- */ /* --- Footer --- */
footer { footer {

View File

@ -12,9 +12,21 @@ $(window).scroll(function() {
// On mobile, hide the avatar when expanding the navbar menu // On mobile, hide the avatar when expanding the navbar menu
$('#main-navbar').on('show.bs.collapse', function () { $('#main-navbar').on('show.bs.collapse', function () {
$(".navbar").addClass("top-nav-expanded"); $(".navbar").addClass("top-nav-expanded");
}) });
$('#main-navbar').on('hidden.bs.collapse', function () { $('#main-navbar').on('hidden.bs.collapse', function () {
$(".navbar").removeClass("top-nav-expanded"); $(".navbar").removeClass("top-nav-expanded");
}) });
// On mobile, when clicking on a multi-level navbar menu, show the child links
$('#main-navbar').on("click", ".navlinks-parent", function(e) {
var target = e.target;
$.each($(".navlinks-parent"), function(key, value) {
if (value == target) {
$(value).parent().toggleClass("show-children");
} else {
$(value).parent().removeClass("show-children");
}
});
});
// 2fc73a3a967e97599c9763d05e564189 // 2fc73a3a967e97599c9763d05e564189