123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- let BeautifulJekyllJS = {
- bigImgEl : null,
- numImgs : null,
- init : function() {
- setTimeout(BeautifulJekyllJS.initNavbar, 10);
-
- $(window).scroll(function() {
- if ($(".navbar").offset().top > 50) {
- $(".navbar").addClass("top-nav-short");
- } else {
- $(".navbar").removeClass("top-nav-short");
- }
- });
-
- $('#main-navbar').on('show.bs.collapse', function () {
- $(".navbar").addClass("top-nav-expanded");
- });
- $('#main-navbar').on('hidden.bs.collapse', function () {
- $(".navbar").removeClass("top-nav-expanded");
- });
-
- BeautifulJekyllJS.initImgs();
- BeautifulJekyllJS.initSearch();
- },
- initNavbar : function() {
-
- const rgb = $('.navbar').css("background-color").replace(/[^\d,]/g,'').split(",");
- const brightness = Math.round((
- parseInt(rgb[0]) * 299 +
- parseInt(rgb[1]) * 587 +
- parseInt(rgb[2]) * 114
- ) / 1000);
- if (brightness <= 125) {
- $(".navbar").removeClass("navbar-light").addClass("navbar-dark");
- } else {
- $(".navbar").removeClass("navbar-dark").addClass("navbar-light");
- }
- },
- initImgs : function() {
-
- if ($("#header-big-imgs").length > 0) {
- BeautifulJekyllJS.bigImgEl = $("#header-big-imgs");
- BeautifulJekyllJS.numImgs = BeautifulJekyllJS.bigImgEl.attr("data-num-img");
-
-
- const imgInfo = BeautifulJekyllJS.getImgInfo();
- const src = imgInfo.src;
- const desc = imgInfo.desc;
- BeautifulJekyllJS.setImg(src, desc);
-
- const getNextImg = function() {
- const imgInfo = BeautifulJekyllJS.getImgInfo();
- const src = imgInfo.src;
- const desc = imgInfo.desc;
- const prefetchImg = new Image();
- prefetchImg.src = src;
-
- setTimeout(function(){
- const img = $("<div></div>").addClass("big-img-transition").css("background-image", 'url(' + src + ')');
- $(".intro-header.big-img").prepend(img);
- setTimeout(function(){ img.css("opacity", "1"); }, 50);
-
-
- setTimeout(function() {
- BeautifulJekyllJS.setImg(src, desc);
- img.remove();
- getNextImg();
- }, 1000);
-
- }, 6000);
- };
-
- if (BeautifulJekyllJS.numImgs > 1) {
- getNextImg();
- }
- }
- },
- getImgInfo : function() {
- const randNum = Math.floor((Math.random() * BeautifulJekyllJS.numImgs) + 1);
- const src = BeautifulJekyllJS.bigImgEl.attr("data-img-src-" + randNum);
- const desc = BeautifulJekyllJS.bigImgEl.attr("data-img-desc-" + randNum);
- return {
- src : src,
- desc : desc
- }
- },
- setImg : function(src, desc) {
- $(".intro-header.big-img").css("background-image", 'url(' + src + ')');
- if (typeof desc !== typeof undefined && desc !== false) {
- $(".img-desc").text(desc).show();
- } else {
- $(".img-desc").hide();
- }
- },
- initSearch : function() {
- if (!document.getElementById("beautifuljekyll-search-overlay")) {
- return;
- }
- $("#nav-search-link").click(function(e) {
- e.preventDefault();
- $("#beautifuljekyll-search-overlay").show();
- $("#nav-search-input").focus().select();
- $("body").addClass("overflow-hidden");
- });
- $("#nav-search-exit").click(function(e) {
- e.preventDefault();
- $("#beautifuljekyll-search-overlay").hide();
- $("body").removeClass("overflow-hidden");
- });
- $(document).on('keyup', function(e) {
- if (e.key == "Escape") {
- $("#beautifuljekyll-search-overlay").hide();
- $("body").removeClass("overflow-hidden");
- }
- });
- }
- };
- document.addEventListener('DOMContentLoaded', BeautifulJekyllJS.init);
|