hugo-theme-introduction/assets/js/index.js

53 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-07-19 13:37:06 +00:00
// Nav burger animation
2018-07-29 07:21:19 +00:00
document.addEventListener("DOMContentLoaded", function () {
2018-07-19 13:37:06 +00:00
// Get all "navbar-burger" elements
2018-07-29 07:21:19 +00:00
var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll(".navbar-burger"), 0);
2018-07-19 13:37:06 +00:00
// Check if there are any navbar burgers
if ($navbarBurgers.length > 0) {
// Add a click event on each of them
$navbarBurgers.forEach(function ($el) {
2018-07-29 07:21:19 +00:00
$el.addEventListener("click", function () {
2018-07-19 13:37:06 +00:00
// Get the target from the "data-target" attribute
var target = $el.dataset.target;
var $target = document.getElementById(target);
// Toggle the class on both the "navbar-burger" and the "navbar-menu"
2018-07-29 07:21:19 +00:00
$el.classList.toggle("is-active");
$target.classList.toggle("is-active");
2018-07-19 13:37:06 +00:00
});
});
}
});
2018-07-01 08:09:29 +00:00
// Bitty scrolling links script
2018-07-29 07:21:19 +00:00
$("a[href^=\"#\"]").click(function(e) {
2018-07-01 08:09:29 +00:00
e.preventDefault();
//BUG fix: https://github.com/victoriadrake/hugo-theme-introduction/issues/108
//
//let's get the right attribute `id` of the heading
v = e.target.href.replace(/http.*#/, '')
id = decodeURI(v)
2018-07-29 07:21:19 +00:00
$("html, body").animate({
//scrollTop: $(document.getElementById(this.hash.substr(1))).offset().top
scrollTop: $(document.getElementById(id)).offset().top
2018-07-01 08:09:29 +00:00
}, 500);
$("#nav-menu").removeClass("is-active");
return true;
})
// Modal closer
2018-07-29 07:21:19 +00:00
$(".card").click(function () {
$($(this).attr("data-target")).addClass("is-active");
$("html").addClass("modal-open");
2018-07-01 08:09:29 +00:00
});
2018-07-29 07:21:19 +00:00
$(".modal-close").click(function () {
$($(this).attr("data-target")).removeClass("is-active");
$("html").removeClass("modal-open");
2018-07-01 08:09:29 +00:00
});
$(document).keypress(function(e) {
if(e.which == 0) {
2018-07-29 07:21:19 +00:00
$(".modal.is-active").removeClass("is-active");
2018-07-19 13:15:30 +00:00
$("html").removeClass("modal-open");
2018-07-01 08:09:29 +00:00
}
});