1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2025-12-19 06:06:54 +00:00

Process JS files with gulp

This commit is contained in:
Cotes Chung
2021-01-23 15:07:18 +08:00
parent 0e9104a58f
commit da9f7b8218
37 changed files with 380 additions and 326 deletions

View File

@@ -10,8 +10,8 @@ function copyLink(url) {
if (!url || 0 === url.length) {
url = window.location.href;
}
var $temp = $("<input>");
const $temp = $("<input>");
$("body").append($temp);
$temp.val(url).select();
document.execCommand("copy");

View File

@@ -8,24 +8,24 @@
$(function() {
var btnSbTrigger = $("#sidebar-trigger");
var btnSearchTrigger = $("#search-trigger");
var btnCancel = $("#search-cancel");
var btnClear = $("#search-cleaner");
const btnSbTrigger = $("#sidebar-trigger");
const btnSearchTrigger = $("#search-trigger");
const btnCancel = $("#search-cancel");
const 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");
const main = $("#main");
const topbarTitle = $("#topbar-title");
const searchWrapper = $("#search-wrapper");
const resultWrapper = $("#search-result-wrapper");
const results = $("#search-results");
const input = $("#search-input");
const hints = $("#search-hints");
/*--- Actions in small screens (Sidebar unloaded) ---*/
var scrollBlocker = (function() {
var offset = 0;
const scrollBlocker = (function () {
let offset = 0;
return {
block() {
offset = $(window).scrollTop();
@@ -39,7 +39,7 @@ $(function() {
};
}());
var mobileSearchBar = (function() {
const mobileSearchBar = (function () {
return {
on() {
btnSbTrigger.addClass("unloaded");
@@ -58,21 +58,21 @@ $(function() {
};
}());
var resultSwitch = (function() {
var visable = false;
const resultSwitch = (function () {
let visible = false;
return {
on() {
if (!visable) {
if (!visible) {
resultWrapper.removeClass("unloaded");
main.addClass("hidden");
visable = true;
visible = true;
scrollBlocker.block();
}
},
off() {
if (visable) {
if (visible) {
results.empty();
if (hints.hasClass("unloaded")) {
hints.removeClass("unloaded");
@@ -82,13 +82,13 @@ $(function() {
main.removeClass("hidden");
input.val("");
visable = false;
visible = false;
scrollBlocker.release();
}
},
isVisable() {
return visable;
isVisible() {
return visible;
}
};

View File

@@ -8,10 +8,10 @@
$(function() {
var sidebarUtil = (function() {
const sidebarUtil = (function () {
const ATTR_DISPLAY = "sidebar-display";
var isExpanded = false;
var body = $("body");
let isExpanded = false;
const body = $("body");
return {
toggle() {

View File

@@ -0,0 +1,10 @@
/**
* Initial Bootstrap Tooltip.
* v2.0
* https://github.com/cotes2020/jekyll-theme-chirpy
* © 2019 Cotes Chung
* MIT License
*/
$(function () {
$("[data-toggle=\"tooltip\"]").tooltip();
});

View File

@@ -8,10 +8,16 @@
$(function() {
var didScroll;
var lastScrollTop = 0;
var delta = 5;
var topbarHeight = $("#topbar-wrapper").outerHeight();
const topbarWrapper = $("#topbar-wrapper");
const toc = $("#toc-wrapper");
const access = $(".access");
const searchInput = $("#search-input");
let didScroll;
let lastScrollTop = 0;
const delta = 5;
const topbarHeight = topbarWrapper.outerHeight();
function hasScrolled() {
var st = $(this).scrollTop();
@@ -23,30 +29,28 @@ $(function() {
if (st > lastScrollTop && st > topbarHeight) {
/* Scroll Down */
$("#topbar-wrapper").removeClass("topbar-down").addClass("topbar-up");
topbarWrapper.removeClass("topbar-down").addClass("topbar-up");
if ($("#toc-wrapper").length > 0) {
$("#toc-wrapper").removeClass("topbar-down");
if (toc.length > 0) {
toc.removeClass("topbar-down");
}
if ($(".access").length > 0) {
$(".access").removeClass("topbar-down");
if (access.length > 0) {
access.removeClass("topbar-down");
}
if ($("#search-input").is(":focus")) {
$("#search-input").blur(); /* remove focus */
if (searchInput.is(":focus")) {
searchInput.blur(); /* remove focus */
}
} else {
} else if (st + $(window).height() < $(document).height()) {
/* 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");
}
topbarWrapper.removeClass("topbar-up").addClass("topbar-down");
if (toc.length > 0) {
toc.addClass("topbar-down");
}
if (access.length > 0) {
access.addClass("topbar-down");
}
}
@@ -66,4 +70,4 @@ $(function() {
}
}, 250);
});
});

View File

@@ -1,5 +1,5 @@
/*
* Topbar title auto change while scrolling in mobile screens.
* Top bar title auto change while scrolling in mobile screens.
* v2.0
* https://github.com/cotes2020/jekyll-theme-chirpy
* © 2018-2019 Cotes Chung
@@ -8,9 +8,13 @@
$(function() {
var DEFAULT = $("#topbar-title").text().trim();
var title = ($("div.post>h1").length > 0) ?
$("div.post>h1").text().trim() : $("h1").text().trim();
const topbarTitle = $("#topbar-title");
const postTitle = $("div.post>h1");
const DEFAULT = topbarTitle.text().trim();
let title = (postTitle.length > 0) ?
postTitle.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>" */
@@ -22,26 +26,26 @@ $(function() {
/* 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 */
|| postTitle.is(":hidden") /* is tab pages */
|| topbarTitle.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);
if (topbarTitle.text() !== title) {
topbarTitle.text(title);
}
} else {
if ($("#topbar-title").text() !== DEFAULT) {
$("#topbar-title").text(DEFAULT);
if (topbarTitle.text() !== DEFAULT) {
topbarTitle.text(DEFAULT);
}
}
});
/* Click title remove hover effect. */
$("#topbar-title").click(function() {
topbarTitle.click(function() {
$("body,html").animate({scrollTop: 0}, 800);
});
});
});