1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2025-12-24 00:23:10 +00:00

Import the framework.

This commit is contained in:
Cotes Chung
2019-09-30 20:38:41 +08:00
parent 5d0e72d5da
commit b845c829f6
103 changed files with 4640 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
/*
Reference: https://bootsnipp.com/snippets/featured/link-to-top-page
*/
$(window).scroll(function() {
if ($(this).scrollTop() > 50
&& $('#sidebar-trigger').css('display') == 'none') {
$('#back-to-top').fadeIn();
} else {
$('#back-to-top').fadeOut();
}
});
$(function() {
$('#back-to-top').click(function() {
$('body,html').animate({scrollTop: 0}, 800);
return false;
});
});

View File

@@ -0,0 +1,88 @@
/*
* This script make #search-result-wrap switch to hidden or shown automatically.
* © 2018-2019 Cotes Chung
* MIT License
*/
$(function() {
var offset = 0;
var btnCancel = $('#search-wrap + a');
var btnSbTrigger = $('#sidebar-trigger');
var btnSearchTrigger = $('#search-trigger');
var btnCloseSearch = $('#search-wrap + a');
var topbarTitle = $('#topbar-title');
var searchWrap = $('#search-wrap');
/*--- Actions in small screens ---*/
btnSearchTrigger.click(function() {
offset = $(window).scrollTop();
$('body').addClass('no-scroll');
// $('body').css('top', -offset + 'px');
// $('html,body').addClass('input-focus');
btnSbTrigger.addClass('hidden');
topbarTitle.addClass('hidden');
btnSearchTrigger.addClass('hidden');
searchWrap.addClass('shown flex-grow-1');
btnCancel.addClass('shown');
$('#main').addClass('hidden');
$('#search-result-wrap').addClass('shown');
$('#search-input').focus();
});
btnCancel.click(function() {
btnCancel.removeClass('shown');
$('#search-input').val('');
$('#search-results').empty();
searchWrap.removeClass('shown flex-grow-1');
btnSbTrigger.removeClass('hidden');
topbarTitle.removeClass('hidden');
btnSearchTrigger.removeClass('hidden');
$('#main').removeClass('hidden');
$('#search-result-wrap').removeClass('shown');
$('body').removeClass('no-scroll');
// $('html,body').removeClass('input-focus');
$('html,body').scrollTop(offset);
});
/*--- Actions in large screens. ---*/
var isShown = false;
$('#search-input').on('input', function(){
if (isShown == false) {
offset = $(window).scrollTop();
$('body,html').scrollTop(0);
$('#search-result-wrap').addClass('shown');
$('#main').addClass('hidden');
isShown = true;
}
});
$('#search-input').on('keyup', function(e){
var input = $('#search-input').val();
if (e.keyCode == 8 && input == '' && btnCloseSearch.css('display') == 'none') {
$('#main').removeClass('hidden');
$('#search-result-wrap').removeClass('shown');
$('body,html').scrollTop(offset);
isShown = false;
}
});
});

View File

@@ -0,0 +1,54 @@
/**
* Expand or close the sidebar in mobile screens.
* © 2018-2019 Cotes Chung
* MIT License
*/
$(function(){
var isExpanded = false;
$("#sidebar-trigger").click(function() {
if (isExpanded == false) {
$("#sidebar").addClass("sidebar-expand");
openModal();
isExpanded = true;
}
});
$("#mask").click(function() {
$("#sidebar").removeClass("sidebar-expand");
closeModal();
isExpanded = false;
});
/**
* ModalHelper helpers resolve the modal scrolling issue on mobile devices
* https://github.com/twbs/bootstrap/issues/15852
* requires document.scrollingElement polyfill https://github.com/yangg/scrolling-element
*/
var ModalHelper = (function(bodyCls) {
var scrollTop;
return {
afterOpen: function() {
scrollTop = document.scrollingElement.scrollTop;
document.body.classList.add(bodyCls);
document.body.style.top = -scrollTop + 'px';
},
beforeClose: function() {
document.body.classList.remove(bodyCls);
// scrollTop lost after set position:fixed, restore it back.
document.scrollingElement.scrollTop = scrollTop;
document.body.style.top = '';
}
};
})('no-scroll');
function openModal() {
ModalHelper.afterOpen();
}
function closeModal() {
ModalHelper.beforeClose();
}
});

View File

@@ -0,0 +1,8 @@
/**
* Initial Bootstrap Tooltip.
* © 2019 Cotes Chung
* MIT License
*/
$(function () {
$('[data-toggle="tooltip"]').tooltip({placement: "auto"});
})

View File

@@ -0,0 +1,64 @@
/*
* Hide Header on scroll down
* © 2018-2019 Cotes Chung
* MIT License
*/
$(function() {
var didScroll;
var lastScrollTop = 0;
var delta = 5;
var topbarHeight = $('#topbar').outerHeight();
$(window).scroll(function(event) {
if ($("#topbar-title").is(":hidden")) { // Not in small screens
didScroll = true;
}
});
setInterval(function() {
if (didScroll) {
hasScrolled();
didScroll = false;
}
}, 250);
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').removeClass('topbar-down').addClass('topbar-up');
if ( $('#toc-wrap').length > 0) {
$('#toc-wrap').removeClass('topbar-down');
}
if ( $('.panel-group').length > 0) {
$('.panel-group').removeClass('topbar-down');
}
if ($('#search-input').is(':focus')) {
$('#search-input').blur(); // remove focus
}
} else {
// Scroll Up
if (st + $(window).height() < $(document).height()) {
$('#topbar').removeClass('topbar-up').addClass('topbar-down');
if ( $('#toc-wrap').length > 0) {
$('#toc-wrap').addClass('topbar-down');
}
if ( $('.panel-group').length > 0) {
$('.panel-group').addClass('topbar-down');
}
}
}
lastScrollTop = st;
}
});

View File

@@ -0,0 +1,44 @@
/*
* Topbar title auto change while scrolling in mobile screens.
* © 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);
});
});