text: /*!
    JS group for layout Home or Post
    Chirpy v2.3
    https://github.com/cotes2020/jekyll-theme-chirpy
    © 2020 Cotes Chung
    MIT License
  */
  
  /*!
    Aggregation of common JS.
    Chirpy@2.3
    https://github.com/cotes2020/jekyll-theme-chirpy
    © 2020 Cotes Chung
    MIT License
  */
  
  /*
  Reference: https://bootsnipp.com/snippets/featured/link-to-top-page
  */
  $(function() {
    $(window).scroll(() => {
      if ($(this).scrollTop() > 50 &&
        $("#sidebar-trigger").css("display") === "none") {
        $("#back-to-top").fadeIn();
      } else {
        $("#back-to-top").fadeOut();
      }
    });
  
    $("#back-to-top").click(() => {
      $("body,html").animate({
        scrollTop: 0
      }, 800);
      return false;
    });
  });
  
  
  /*
  * This script make #search-result-wrapper switch to unloaded or shown automatically.
  * v2.0
  * https://github.com/cotes2020/jekyll-theme-chirpy
  * © 2018-2019 Cotes Chung
  * MIT License
  */
  
  $(function() {
  
    var btnSbTrigger = $("#sidebar-trigger");
    var btnSearchTrigger = $("#search-trigger");
    var btnCancel = $("#search-cancel");
    var btnClear = $("#search-cleaner");
  
    var main = $("#main");
    var topbarTitle = $("#topbar-title");
    var searchWrapper = $("#search-wrapper");
    var resultWrapper = $("#search-result-wrapper");
    var results = $("#search-results");
    var input = $("#search-input");
    var hints = $("#search-hints");
  
  
    /*--- Actions in small screens (Sidebar unloaded) ---*/
  
    var scrollBlocker = (function() {
      var offset = 0;
      return {
        block() {
          offset = $(window).scrollTop();
        },
        release() {
          $("html,body").scrollTop(offset);
        },
        getOffset() {
          return offset;
        }
      };
    }());
  
    var mobileSearchBar = (function() {
      return {
        on() {
          btnSbTrigger.addClass("unloaded");
          topbarTitle.addClass("unloaded");
          btnSearchTrigger.addClass("unloaded");
          searchWrapper.addClass("d-flex");
          btnCancel.addClass("loaded");
        },
        off() {
          btnCancel.removeClass("loaded");
          searchWrapper.removeClass("d-flex");
          btnSbTrigger.removeClass("unloaded");
          topbarTitle.removeClass("unloaded");
          btnSearchTrigger.removeClass("unloaded");
        }
      };
    }());
  
    var resultSwitch = (function() {
      var visable = false;
  
      return {
        on() {
          if (!visable) {
            resultWrapper.removeClass("unloaded");
            main.addClass("hidden");
  
            visable = true;
            scrollBlocker.block();
          }
        },
        off() {
          if (visable) {
            results.empty();
            if (hints.hasClass("unloaded")) {
              hints.removeClass("unloaded");
            }
            resultWrapper.addClass("unloaded");
            btnClear.removeClass("visable");
            main.removeClass("hidden");
  
            input.val("");
            visable = false;
  
            scrollBlocker.release();
          }
        },
        isVisable() {
          return visable;
        }
      };
  
    }());
  
  
    function isMobileView() {
      return btnCancel.hasClass("loaded");
    }
  
    btnSearchTrigger.click(function() {
      mobileSearchBar.on();
      resultSwitch.on();
      input.focus();
    });
  
    btnCancel.click(function() {
      mobileSearchBar.off();
      resultSwitch.off();
    });
  
    input.focus(function() {
      searchWrapper.addClass("input-focus");
    });
  
    input.focusout(function() {
      searchWrapper.removeClass("input-focus");
    });
  
    input.on("keyup", function(e) {
      if (e.keyCode === 8 && input.val() === "") {
        if (!isMobileView()) {
          resultSwitch.off();
        } else {
          hints.removeClass("unloaded");
        }
      } else {
        if (input.val() !== "") {
          resultSwitch.on();
  
          if (!btnClear.hasClass("visible")) {
            btnClear.addClass("visable");
          }
  
          if (isMobileView()) {
            hints.addClass("unloaded");
          }
        }
      }
    });
  
    btnClear.on("click", function() {
      input.val("");
      if (isMobileView()) {
        hints.removeClass("unloaded");
        results.empty();
      } else {
        resultSwitch.off();
      }
      input.focus();
      btnClear.removeClass("visable");
    });
  
  });
  
  
  /**
   * Expand or close the sidebar in mobile screens.
   * v2.0
   * https://github.com/cotes2020/jekyll-theme-chirpy
   * © 2018-2019 Cotes Chung
   * MIT License
   */
  
  $(function() {
  
    var sidebarUtil = (function() {
      const ATTR_DISPLAY = "sidebar-display";
      var isExpanded = false;
      var body = $("body");
  
      return {
        toggle() {
          if (isExpanded === false) {
            body.attr(ATTR_DISPLAY, "");
          } else {
            body.removeAttr(ATTR_DISPLAY);
          }
  
          isExpanded = !isExpanded;
        }
      };
  
    }());
  
    $("#sidebar-trigger").click(sidebarUtil.toggle);
  
    $("#mask").click(sidebarUtil.toggle);
  
  });
  
  
  /*
   * Hide Header on scroll down
   * v2.0
   * https://github.com/cotes2020/jekyll-theme-chirpy
   * © 2018-2019 Cotes Chung
   * MIT License
   */
  
  $(function() {
  
    var didScroll;
    var lastScrollTop = 0;
    var delta = 5;
    var topbarHeight = $("#topbar-wrapper").outerHeight();
  
    function hasScrolled() {
      var st = $(this).scrollTop();
  
      /* Make sure they scroll more than delta */
      if (Math.abs(lastScrollTop - st) <= delta) {
        return;
      }
  
      if (st > lastScrollTop && st > topbarHeight) {
        /* Scroll Down */
        $("#topbar-wrapper").removeClass("topbar-down").addClass("topbar-up");
  
        if ($("#toc-wrapper").length > 0) {
          $("#toc-wrapper").removeClass("topbar-down");
        }
  
        if ($(".access").length > 0) {
          $(".access").removeClass("topbar-down");
        }
  
        if ($("#search-input").is(":focus")) {
          $("#search-input").blur(); /* remove focus */
        }
  
      } else {
        /* Scroll Up */
        if (st + $(window).height() < $(document).height()) {
          $("#topbar-wrapper").removeClass("topbar-up").addClass("topbar-down");
          if ($("#toc-wrapper").length > 0) {
            $("#toc-wrapper").addClass("topbar-down");
          }
          if ($(".access").length > 0) {
            $(".access").addClass("topbar-down");
          }
        }
      }
  
      lastScrollTop = st;
    }
  
    $(window).scroll(function(event) {
      if ($("#topbar-title").is(":hidden")) { /* Not in small screens */
        didScroll = true;
      }
    });
  
    setInterval(function() {
      if (didScroll) {
        hasScrolled();
        didScroll = false;
      }
    }, 250);
  
  });
  
  /*
   * Topbar title auto change while scrolling in mobile screens.
   * v2.0
   * https://github.com/cotes2020/jekyll-theme-chirpy
   * © 2018-2019 Cotes Chung
   * MIT License
  */
  
  $(function() {
  
    var DEFAULT = $("#topbar-title").text().trim();
    var title = ($("div.post>h1").length > 0) ?
            $("div.post>h1").text().trim() : $("h1").text().trim();
  
    if ($("#page-category").length || $("#page-tag").length) {
      /* The title in Category or Tag page will be "<title> <count_of_posts>" */
      if (/\s/.test(title)) {
        title = title.replace(/[0-9]/g, "").trim();
      }
    }
  
    /* Replace topbar title while scroll screens. */
    $(window).scroll(function () {
      if ($("#post-list").length /* in Home page */
        || $("div.post>h1").is(":hidden") /* is tab pages */
        || $("#topbar-title").is(":hidden") /* not mobile screens */
        || $("#sidebar.sidebar-expand").length) { /* when the sidebar trigger is clicked */
        return false;
      }
  
      if ($(this).scrollTop() >= 95) {
        if ($("#topbar-title").text() !== title) {
          $("#topbar-title").text(title);
        }
      } else {
        if ($("#topbar-title").text() !== DEFAULT) {
          $("#topbar-title").text(DEFAULT);
        }
      }
    });
  
    /* Click title remove hover effect. */
    $("#topbar-title").click(function() {
      $("body,html").animate({scrollTop: 0}, 800);
    });
  
  });
  
  /*
   * Copy current page url to clipboard.
   * v2.1
   * https://github.com/cotes2020/jekyll-theme-chirpy
   * © 2020 Cotes Chung
   * MIT License
   */
  
  function copyLink(url) {
    if (!url || 0 === url.length) {
      url = window.location.href;
    }
    
    var $temp = $("<input>");
    $("body").append($temp);
    $temp.val(url).select();
    document.execCommand("copy");
    $temp.remove();
  
    alert("Link copied successfully!");
  
  }
  
  
  /*
   * Create a more beautiful checkbox
   */
  
  $(function() {
    /* hide browser default checkbox */
    $("input[type=checkbox]").addClass("unloaded");
    /* create checked checkbox */
    $("input[type=checkbox][checked]").before("<i class=\"fas fa-check-circle checked\"></i>");
    /* create normal checkbox */
    $("input[type=checkbox]:not([checked])").before("<i class=\"far fa-circle\"></i>");
  });
  
  
  /**
   * Initial Bootstrap Tooltip.
   * v2.0
   * https://github.com/cotes2020/jekyll-theme-chirpy
   * © 2019 Cotes Chung
   * MIT License
  */
  $(function () {
    $("[data-toggle=\"tooltip\"]").tooltip();
  });
  
  
  
  /*
   * Caculate the Timeago
   * v2.0
   * https://github.com/cotes2020/jekyll-theme-chirpy
   * © 2019 Cotes Chung
   * MIT Licensed
   */
  
  $(function() {
  
    var toRefresh = $(".timeago").length;
  
    var intervalId = void 0;
  
    function timeago(iso, isLastmod) {
      let now = new Date();
      let past = new Date(iso);
  
      if (past.getFullYear() !== now.getFullYear()) {
        toRefresh -= 1;
        return past.toLocaleString("en-US", {
          year: "numeric",
          month: "short",
          day: "numeric"
        });
      }
  
      if (past.getMonth() !== now.getMonth()) {
        toRefresh -= 1;
        return past.toLocaleString("en-US", {
          month: "short",
          day: "numeric"
        });
      }
  
      let seconds = Math.floor((now - past) / 1000);
  
      let day = Math.floor(seconds / 86400);
      if (day >= 1) {
        toRefresh -= 1;
        return day + " day" + (day > 1 ? "s" : "") + " ago";
      }
  
      let hour = Math.floor(seconds / 3600);
      if (hour >= 1) {
        return hour + " hour" + (hour > 1 ? "s" : "") + " ago";
      }
  
      let minute = Math.floor(seconds / 60);
      if (minute >= 1) {
        return minute + " minute" + (minute > 1 ? "s" : "") + " ago";
      }
  
      return (isLastmod ? "just" : "Just") + " now";
    }
  
    function updateTimeago() {
      $(".timeago").each(function() {
        if ($(this).children("i").length > 0) {
          var basic = $(this).text();
          var isLastmod = $(this).hasClass("lastmod");
          var node = $(this).children("i");
          var date = node.text(); /* ISO Date: "YYYY-MM-DDTHH:MM:SSZ" */
          $(this).text(timeago(date, isLastmod));
          $(this).append(node);
        }
      });
  
      if (toRefresh === 0 && typeof intervalId !== "undefined") {
        clearInterval(intervalId); /* stop interval */
      }
      return toRefresh;
    }
  
    if (toRefresh === 0) {
      return;
    }
  
    if (updateTimeago() > 0) { /* run immediately */
      intervalId = setInterval(updateTimeago, 60000); /* run every minute */
    }
  
  });
  
  
  
  
  
  
  