2016-03-10 03:23:27 +01:00
|
|
|
/* ==========================================================================
|
|
|
|
jQuery plugin settings and other scripts
|
|
|
|
========================================================================== */
|
2014-02-13 20:20:28 +01:00
|
|
|
|
2017-12-07 14:56:14 +01:00
|
|
|
$(document).ready(function() {
|
2016-07-20 15:10:37 +02:00
|
|
|
// Sticky footer
|
|
|
|
var bumpIt = function() {
|
2017-12-07 14:56:14 +01:00
|
|
|
$("body").css("margin-bottom", $(".page__footer").outerHeight(true));
|
2019-01-04 18:53:36 +01:00
|
|
|
};
|
2016-07-20 15:10:37 +02:00
|
|
|
|
|
|
|
bumpIt();
|
2019-01-04 18:53:36 +01:00
|
|
|
$(window).resize(jQuery.throttle(250, function() {
|
|
|
|
bumpIt();
|
|
|
|
}));
|
2016-07-20 15:10:37 +02:00
|
|
|
|
2016-03-10 19:06:17 +01:00
|
|
|
// FitVids init
|
|
|
|
$("#main").fitVids();
|
2013-09-09 16:12:07 +02:00
|
|
|
|
2018-01-03 20:20:41 +01:00
|
|
|
// Sticky sidebar
|
|
|
|
var stickySideBar = function() {
|
|
|
|
var show =
|
|
|
|
$(".author__urls-wrapper button").length === 0
|
|
|
|
? $(window).width() > 1024 // width should match $large Sass variable
|
|
|
|
: !$(".author__urls-wrapper button").is(":visible");
|
|
|
|
if (show) {
|
|
|
|
// fix
|
|
|
|
$(".sidebar").addClass("sticky");
|
|
|
|
} else {
|
|
|
|
// unfix
|
|
|
|
$(".sidebar").removeClass("sticky");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
stickySideBar();
|
|
|
|
|
|
|
|
$(window).resize(function() {
|
|
|
|
stickySideBar();
|
|
|
|
});
|
|
|
|
|
2016-03-21 05:03:46 +01:00
|
|
|
// Follow menu drop down
|
2016-03-21 21:01:19 +01:00
|
|
|
$(".author__urls-wrapper button").on("click", function() {
|
2017-08-04 17:55:10 +02:00
|
|
|
$(".author__urls").toggleClass("is--visible");
|
2016-03-21 21:01:19 +01:00
|
|
|
$(".author__urls-wrapper button").toggleClass("open");
|
|
|
|
});
|
2016-03-17 20:38:07 +01:00
|
|
|
|
2019-02-11 22:00:14 +01:00
|
|
|
// Close search screen with Esc key
|
|
|
|
$(document).keyup(function(e) {
|
|
|
|
if (e.keyCode === 27) {
|
|
|
|
if ($(".initial-content").hasClass("is--hidden")) {
|
|
|
|
$(".search-content").toggleClass("is--visible");
|
|
|
|
$(".initial-content").toggleClass("is--hidden");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-12-07 14:56:14 +01:00
|
|
|
// Search toggle
|
|
|
|
$(".search__toggle").on("click", function() {
|
|
|
|
$(".search-content").toggleClass("is--visible");
|
|
|
|
$(".initial-content").toggleClass("is--hidden");
|
|
|
|
// set focus on input
|
|
|
|
setTimeout(function() {
|
2018-02-16 21:12:57 +01:00
|
|
|
$(".search-content input").focus();
|
2017-12-07 14:56:14 +01:00
|
|
|
}, 400);
|
|
|
|
});
|
|
|
|
|
2019-01-04 18:31:38 +01:00
|
|
|
// Smooth scrolling
|
|
|
|
|
|
|
|
// Bind popstate event listener to support back/forward buttons.
|
2019-01-04 18:29:13 +01:00
|
|
|
var smoothScrolling = false;
|
2019-01-04 18:31:38 +01:00
|
|
|
$(window).bind("popstate", function (event) {
|
|
|
|
$.smoothScroll({
|
2019-02-08 18:28:56 +01:00
|
|
|
scrollTarget: decodeURI(location.hash),
|
2019-01-04 18:29:13 +01:00
|
|
|
offset: -20,
|
|
|
|
beforeScroll: function() { smoothScrolling = true; },
|
|
|
|
afterScroll: function() { smoothScrolling = false; }
|
2019-01-04 18:31:38 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
// Override clicking on links to smooth scroll
|
|
|
|
$('a[href*="#"]').bind("click", function (event) {
|
|
|
|
if (this.pathname === location.pathname && this.hash) {
|
|
|
|
event.preventDefault();
|
|
|
|
history.pushState(null, null, this.hash);
|
|
|
|
$(window).trigger("popstate");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Smooth scroll on page load if there is a hash in the URL.
|
|
|
|
if (location.hash) {
|
|
|
|
$(window).trigger("popstate");
|
|
|
|
}
|
2016-03-10 03:23:27 +01:00
|
|
|
|
2019-01-04 18:29:13 +01:00
|
|
|
// Scrollspy equivalent: update hash fragment while scrolling.
|
2019-01-04 18:53:36 +01:00
|
|
|
$(window).scroll(jQuery.throttle(250, function() {
|
2019-01-04 18:29:13 +01:00
|
|
|
// Don't run while smooth scrolling (from clicking on a link).
|
|
|
|
if (smoothScrolling) return;
|
2019-01-15 14:08:41 +01:00
|
|
|
var scrollTop = $(window).scrollTop() + 20 + 1; // 20 = offset
|
2019-01-04 18:53:36 +01:00
|
|
|
var links = [];
|
|
|
|
$("nav.toc a").each(function() {
|
|
|
|
var link = $(this);
|
|
|
|
var href = link.attr("href");
|
|
|
|
if (href && href[0] == "#") {
|
|
|
|
var element = $(href);
|
|
|
|
links.push({
|
|
|
|
link: link,
|
|
|
|
href: href,
|
|
|
|
top: element.offset().top
|
|
|
|
});
|
|
|
|
link.removeClass('active');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
for (var i = 0; i < links.length; i++) {
|
|
|
|
var top = links[i].top;
|
|
|
|
var bottom = (i < links.length - 1 ? links[i+1].top : Infinity);
|
|
|
|
if (top <= scrollTop && scrollTop < bottom) {
|
|
|
|
// Mark all ancestors as active
|
|
|
|
links[i].link.parents("li").children("a").addClass('active');
|
2019-02-08 18:28:56 +01:00
|
|
|
if (links[i].href !== decodeURI(location.hash)) {
|
2019-01-04 18:53:36 +01:00
|
|
|
history.replaceState(null, null, links[i].href);
|
2019-01-04 18:29:13 +01:00
|
|
|
}
|
2019-01-15 14:08:41 +01:00
|
|
|
return;
|
2019-01-04 18:29:13 +01:00
|
|
|
}
|
2019-01-04 18:53:36 +01:00
|
|
|
}
|
2019-01-15 14:08:41 +01:00
|
|
|
if ('#' !== location.hash) {
|
|
|
|
history.replaceState(null, null, '#');
|
|
|
|
}
|
2019-01-04 18:53:36 +01:00
|
|
|
}));
|
2019-01-04 18:29:13 +01:00
|
|
|
|
2016-03-10 19:06:17 +01:00
|
|
|
// add lightbox class to all image links
|
2017-12-07 14:56:14 +01:00
|
|
|
$(
|
|
|
|
"a[href$='.jpg'],a[href$='.jpeg'],a[href$='.JPG'],a[href$='.png'],a[href$='.gif']"
|
|
|
|
).addClass("image-popup");
|
2016-03-10 03:23:27 +01:00
|
|
|
|
2016-03-10 19:06:17 +01:00
|
|
|
// Magnific-Popup options
|
2016-03-10 03:23:27 +01:00
|
|
|
$(".image-popup").magnificPopup({
|
2016-07-07 15:50:09 +02:00
|
|
|
// disableOn: function() {
|
|
|
|
// if( $(window).width() < 500 ) {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// return true;
|
|
|
|
// },
|
2017-12-07 14:56:14 +01:00
|
|
|
type: "image",
|
|
|
|
tLoading: "Loading image #%curr%...",
|
2013-09-09 16:12:07 +02:00
|
|
|
gallery: {
|
|
|
|
enabled: true,
|
|
|
|
navigateByImgClick: true,
|
2017-12-07 14:56:14 +01:00
|
|
|
preload: [0, 1] // Will preload 0 - before current, and 1 after the current image
|
2013-09-09 16:12:07 +02:00
|
|
|
},
|
|
|
|
image: {
|
2017-12-07 14:56:14 +01:00
|
|
|
tError: '<a href="%url%">Image #%curr%</a> could not be loaded.'
|
2013-09-09 16:12:07 +02:00
|
|
|
},
|
2016-03-10 19:06:17 +01:00
|
|
|
removalDelay: 500, // Delay in milliseconds before popup is removed
|
|
|
|
// Class that is added to body when popup is open.
|
|
|
|
// make it unique to apply your CSS animations just to this exact popup
|
2017-12-07 14:56:14 +01:00
|
|
|
mainClass: "mfp-zoom-in",
|
2016-03-10 19:06:17 +01:00
|
|
|
callbacks: {
|
|
|
|
beforeOpen: function() {
|
|
|
|
// just a hack that adds mfp-anim class to markup
|
2017-12-07 14:56:14 +01:00
|
|
|
this.st.image.markup = this.st.image.markup.replace(
|
|
|
|
"mfp-figure",
|
|
|
|
"mfp-figure mfp-with-anim"
|
|
|
|
);
|
2016-03-10 19:06:17 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
closeOnContentClick: true,
|
|
|
|
midClick: true // allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source.
|
2013-09-09 16:12:07 +02:00
|
|
|
});
|
2016-06-23 00:59:16 +02:00
|
|
|
});
|