Hide topbar when mobile orientation in landscape mode (resolve #459)

This commit is contained in:
Cotes Chung 2022-01-09 19:09:29 +08:00
parent 9620eddd12
commit 2cef631385
14 changed files with 186 additions and 147 deletions

View file

@ -2,7 +2,7 @@
The Top Bar The Top Bar
--> -->
<div id="topbar-wrapper" class="row justify-content-center topbar-down"> <div id="topbar-wrapper" class="row justify-content-center">
<div id="topbar" class="col-11 d-flex h-100 align-items-center justify-content-between"> <div id="topbar" class="col-11 d-flex h-100 align-items-center justify-content-between">
<span id="breadcrumb"> <span id="breadcrumb">

View file

@ -0,0 +1,36 @@
/**
* A tool for smooth scrolling and topbar switcher
*/
const ScrollHelper = (function () {
const $body = $("body");
const ATTR_TOPBAR_VISIBLE = "topbar-visible";
const topbarHeight = $("#topbar-wrapper").outerHeight();
let scrollUpCount = 0; // the number of times the scroll up was triggered by ToC or anchor
let topbarLocked = false;
let orientationLocked = false;
return {
hideTopbar: () => $body.attr(ATTR_TOPBAR_VISIBLE, false),
showTopbar: () => $body.attr(ATTR_TOPBAR_VISIBLE, true),
// scroll up
addScrollUpTask: () => {
scrollUpCount += 1;
if (!topbarLocked) { topbarLocked = true; }
},
popScrollUpTask: () => scrollUpCount -= 1,
hasScrollUpTask: () => scrollUpCount > 0,
topbarLocked: () => topbarLocked === true,
unlockTopbar: () => topbarLocked = false,
getTopbarHeight: () => topbarHeight,
// orientation change
orientationLocked: () => orientationLocked === true,
lockOrientation: () => orientationLocked = true,
unLockOrientation: () => orientationLocked = false
};
}());

View file

@ -1,70 +0,0 @@
/*
* Hide Header on scroll down
*/
$(function() {
const $topbarWrapper = $("#topbar-wrapper");
const $topbarTitle = $("#topbar-title");
const $panel = $("#panel-wrapper");
const $searchInput = $("#search-input");
const CLASS_TOPBAR_UP = "topbar-up";
const CLASS_TOPBAR_DOWN = "topbar-down";
const ATTR_TOC_SCROLLING_UP = "toc-scrolling-up"; // topbar locked
let didScroll;
let lastScrollTop = 0;
const delta = $topbarWrapper.outerHeight();
const topbarHeight = $topbarWrapper.outerHeight();
function hasScrolled() {
let st = $(this).scrollTop();
/* Make sure they scroll more than delta */
if (Math.abs(lastScrollTop - st) <= delta) {
return;
}
if (st > lastScrollTop ) { // Scroll Down
if (st > topbarHeight) {
$topbarWrapper.removeClass(CLASS_TOPBAR_DOWN).addClass(CLASS_TOPBAR_UP);
$panel.removeClass(CLASS_TOPBAR_DOWN);
if ($searchInput.is(":focus")) {
$searchInput.blur(); /* remove focus */
}
}
} else {// Scroll up
// did not reach the bottom of the document, i.e., still have space to scroll up
if (st + $(window).height() < $(document).height()) {
let tocScrollingUp = $topbarWrapper.attr(ATTR_TOC_SCROLLING_UP);
if (typeof tocScrollingUp !== "undefined") {
if (tocScrollingUp === "false") {
$topbarWrapper.removeAttr(ATTR_TOC_SCROLLING_UP);
}
} else {
$topbarWrapper.removeClass(CLASS_TOPBAR_UP).addClass(CLASS_TOPBAR_DOWN);
$panel.addClass(CLASS_TOPBAR_DOWN);
}
}
}
lastScrollTop = st;
}
$(window).scroll(function(event) {
if ($topbarTitle.is(":hidden")) {
didScroll = true;
}
});
setInterval(function() {
if (didScroll) {
hasScrolled();
didScroll = false;
}
}, 250);
});

View file

@ -0,0 +1,90 @@
/*
* Hide Header on scroll down
*/
$(function() {
const $searchInput = $("#search-input");
const delta = ScrollHelper.getTopbarHeight();
let didScroll;
let lastScrollTop = 0;
function hasScrolled() {
let st = $(this).scrollTop();
/* Make sure they scroll more than delta */
if (Math.abs(lastScrollTop - st) <= delta) {
return;
}
if (st > lastScrollTop ) { // Scroll Down
ScrollHelper.hideTopbar();
if ($searchInput.is(":focus")) {
$searchInput.blur(); /* remove focus */
}
} else { // Scroll up
// has not yet scrolled to the bottom of the screen, that is, there is still space for scrolling
if (st + $(window).height() < $(document).height()) {
if (ScrollHelper.hasScrollUpTask()) {
return;
}
if (ScrollHelper.topbarLocked()) { // avoid redundant scroll up event from smooth scrolling
ScrollHelper.unlockTopbar();
} else {
if (ScrollHelper.orientationLocked()) { // avoid device auto scroll up on orientation change
ScrollHelper.unLockOrientation();
} else {
ScrollHelper.showTopbar();
}
}
}
}
lastScrollTop = st;
} // hasScrolled()
function handleLandscape() {
if ($(window).scrollTop() === 0) {
return;
}
ScrollHelper.lockOrientation();
ScrollHelper.hideTopbar();
}
if (screen.orientation) {
screen.orientation.onchange = () => {
const type = screen.orientation.type;
if (type === "landscape-primary" || type === "landscape-secondary") {
handleLandscape();
}
};
} else {
// for the browsers that not support `window.screen.orientation` API
$(window).on("orientationchange",() => {
if ($(window).width() < $(window).height()) { // before rotating, it is still in portrait mode.
handleLandscape();
}
});
}
$(window).scroll(() => {
if (didScroll) {
return;
}
didScroll = true;
});
setInterval(() => {
if (didScroll) {
hasScrolled();
didScroll = false;
}
}, 250);
});

View file

@ -14,17 +14,22 @@ $(function() {
} }
const defaultTitleText = $topbarTitle.text().trim(); const defaultTitleText = $topbarTitle.text().trim();
let titleText = $pageTitle.text().trim(); let pageTitleText = $pageTitle.text().trim();
let hasScrolled = false; let hasScrolled = false;
let lastScrollTop = 0; let lastScrollTop = 0;
if ($("#page-category").length || $("#page-tag").length) { if ($("#page-category").length || $("#page-tag").length) {
/* The title in Category or Tag page will be "<title> <count_of_posts>" */ /* The title in Category or Tag page will be "<title> <count_of_posts>" */
if (/\s/.test(titleText)) { if (/\s/.test(pageTitleText)) {
titleText = titleText.replace(/[0-9]/g, "").trim(); pageTitleText = pageTitleText.replace(/[0-9]/g, "").trim();
} }
} }
// When the page is scrolled down and then refreshed, the topbar title needs to be initialized
if ($pageTitle.offset().top < $(window).scrollTop()) {
$topbarTitle.text(pageTitleText);
}
let options = { let options = {
rootMargin: '-48px 0px 0px 0px', // 48px equals to the topbar height (3rem) rootMargin: '-48px 0px 0px 0px', // 48px equals to the topbar height (3rem)
threshold: [0, 1] threshold: [0, 1]
@ -43,7 +48,7 @@ $(function() {
if (isScrollDown) { if (isScrollDown) {
if (heading.intersectionRatio === 0) { if (heading.intersectionRatio === 0) {
$topbarTitle.text(titleText); $topbarTitle.text(pageTitleText);
} }
} else { } else {
if (heading.intersectionRatio === 1) { if (heading.intersectionRatio === 1) {

View file

@ -8,21 +8,16 @@
*/ */
$(function() { $(function() {
const $topbarWrapper = $("#topbar-wrapper");
const topbarHeight = $topbarWrapper.outerHeight();
const $topbarTitle = $("#topbar-title"); const $topbarTitle = $("#topbar-title");
const ATTR_TOC_SCROLLING = "toc-scrolling-up";
const SCROLL_MARK = "scroll-focus";
const REM = 16; // in pixels const REM = 16; // in pixels
let tocScrollUpCount = 0; const ATTR_SCROLL_FOCUS = "scroll-focus";
$("a[href*='#']") $("a[href*='#']")
.not("[href='#']") .not("[href='#']")
.not("[href='#0']") .not("[href='#0']")
.click(function(event) { .click(function(event) {
if (this.pathname.replace(/^\//, "") !==
if (this.pathname.replace(/^\//, "") !== location.pathname.replace(/^\//, "")) { location.pathname.replace(/^\//, "")) {
return; return;
} }
@ -36,9 +31,8 @@ $(function() {
let selector = hash.includes(":") ? hash.replace(/\:/g, "\\:") : hash; let selector = hash.includes(":") ? hash.replace(/\:/g, "\\:") : hash;
let $target = $(selector); let $target = $(selector);
let parent = $(this).parent().prop("tagName"); let isMobileViews = $topbarTitle.is(":visible");
let isAnchor = RegExp(/^H\d/).test(parent); let isPortrait = $(window).width() < $(window).height();
let isMobileViews = !$topbarTitle.is(":hidden");
if (typeof $target === "undefined") { if (typeof $target === "undefined") {
return; return;
@ -50,26 +44,20 @@ $(function() {
history.pushState(null, null, hash); history.pushState(null, null, hash);
} }
let curOffset = isAnchor ? $(this).offset().top : $(window).scrollTop(); let curOffset = $(window).scrollTop();
let destOffset = $target.offset().top -= REM / 2; let destOffset = $target.offset().top -= REM / 2;
if (destOffset < curOffset) { // scroll up if (destOffset < curOffset) { // scroll up
if (!isAnchor && !toFootnote) { // trigger by ToC item ScrollHelper.hideTopbar();
if (!isMobileViews) { // on desktop/tablet screens ScrollHelper.addScrollUpTask();
$topbarWrapper.removeClass("topbar-down").addClass("topbar-up");
// Send message to `${JS_ROOT}/commons/topbar-switch.js` if (isMobileViews && isPortrait) {
$topbarWrapper.attr(ATTR_TOC_SCROLLING, true); destOffset -= ScrollHelper.getTopbarHeight();
tocScrollUpCount += 1;
}
} }
if ((isAnchor || toFootnoteRef) && isMobileViews) { } else { // scroll down
destOffset -= topbarHeight; if (isMobileViews && isPortrait) {
} destOffset -= ScrollHelper.getTopbarHeight();
} else {
if (isMobileViews) {
destOffset -= topbarHeight;
} }
} }
@ -79,18 +67,18 @@ $(function() {
$target.focus(); $target.focus();
/* clean up old scroll mark */ /* clean up old scroll mark */
if ($(`[${SCROLL_MARK}=true]`).length) { if ($(`[${ATTR_SCROLL_FOCUS}=true]`).length) {
$(`[${SCROLL_MARK}=true]`).attr(SCROLL_MARK, false); $(`[${ATTR_SCROLL_FOCUS}=true]`).attr(ATTR_SCROLL_FOCUS, false);
} }
/* Clean :target links */ /* Clean :target links */
if ($(":target").length) { /* element that visited by the URL with hash */ if ($(":target").length) { /* element that visited by the URL with hash */
$(":target").attr(SCROLL_MARK, false); $(":target").attr(ATTR_SCROLL_FOCUS, false);
} }
/* set scroll mark to footnotes */ /* set scroll mark to footnotes */
if (toFootnote || toFootnoteRef) { if (toFootnote || toFootnoteRef) {
$target.attr(SCROLL_MARK, true); $target.attr(ATTR_SCROLL_FOCUS, true);
} }
if ($target.is(":focus")) { /* Checking if the target was focused */ if ($target.is(":focus")) { /* Checking if the target was focused */
@ -100,12 +88,8 @@ $(function() {
$target.focus(); /* Set focus again */ $target.focus(); /* Set focus again */
} }
if (typeof $topbarWrapper.attr(ATTR_TOC_SCROLLING) !== "undefined") { if (ScrollHelper.hasScrollUpTask()) {
tocScrollUpCount -= 1; ScrollHelper.popScrollUpTask();
if (tocScrollUpCount <= 0) {
$topbarWrapper.attr(ATTR_TOC_SCROLLING, "false");
}
} }
}); });
}); /* click() */ }); /* click() */

View file

@ -21,7 +21,7 @@ layout: compress
{% include mode-toggle.html %} {% include mode-toggle.html %}
{% endunless %} {% endunless %}
<body data-spy="scroll" data-target="#toc"> <body data-spy="scroll" data-target="#toc" topbar-visible="true">
{% include sidebar.html %} {% include sidebar.html %}

View file

@ -34,7 +34,7 @@ layout: default
</div> <!-- #core-wrapper --> </div> <!-- #core-wrapper -->
<!-- pannel --> <!-- pannel -->
<div id="panel-wrapper" class="col-xl-3 pl-2 text-muted topbar-down"> <div id="panel-wrapper" class="col-xl-3 pl-2 text-muted">
<div class="access"> <div class="access">
{% include update-list.html %} {% include update-list.html %}

View file

@ -247,7 +247,7 @@ img[data-src] {
} }
} }
&.topbar-down > div { [topbar-visible=true] & > div {
top: 6rem; top: 6rem;
} }
} }
@ -570,10 +570,6 @@ img[data-src] {
box-shadow: 0 0 8px 0 var(--btn-box-shadow) !important; box-shadow: 0 0 8px 0 var(--btn-box-shadow) !important;
} }
.topbar-up {
top: -3rem !important; /* same as topbar height. */
}
.no-text-decoration { .no-text-decoration {
@include no-text-decoration; @include no-text-decoration;
} }
@ -876,6 +872,10 @@ $sidebar-display: "sidebar-display";
z-index: 50; z-index: 50;
border-bottom: 1px solid rgba(0, 0, 0, 0.07); border-bottom: 1px solid rgba(0, 0, 0, 0.07);
background-color: var(--topbar-wrapper-bg); background-color: var(--topbar-wrapper-bg);
[topbar-visible=false] & {
top: -$topbar-height; /* same as topbar height. */
}
} }
#topbar { #topbar {
@ -1193,9 +1193,15 @@ $sidebar-display: "sidebar-display";
/* hide sidebar and panel */ /* hide sidebar and panel */
@media all and (max-width: 849px) { @media all and (max-width: 849px) {
%slide { @mixin slide($append: null) {
-webkit-transition: transform 0.4s ease; $basic: transform 0.4s ease;
transition: transform 0.4s ease; @if $append {
-webkit-transition: $basic, $append;
transition: $basic, $append;
} @else {
-webkit-transition: $basic;
transition: $basic;
}
} }
html, html,
@ -1203,15 +1209,6 @@ $sidebar-display: "sidebar-display";
overflow-x: hidden; overflow-x: hidden;
} }
.footnotes ol > li {
padding-top: 3.5rem;
margin-top: -3.2rem;
&:first-child {
margin-top: -3.5rem;
}
}
[#{$sidebar-display}] { [#{$sidebar-display}] {
#sidebar { #sidebar {
transform: translateX(0); transform: translateX(0);
@ -1221,11 +1218,10 @@ $sidebar-display: "sidebar-display";
#main-wrapper { #main-wrapper {
transform: translateX(#{$sidebar-width}); transform: translateX(#{$sidebar-width});
} }
} }
#sidebar { #sidebar {
@extend %slide; @include slide;
transform: translateX(-#{$sidebar-width}); // hide transform: translateX(-#{$sidebar-width}); // hide
-webkit-transform: translateX(-#{$sidebar-width}); -webkit-transform: translateX(-#{$sidebar-width});
@ -1238,7 +1234,7 @@ $sidebar-display: "sidebar-display";
} }
#main-wrapper { #main-wrapper {
@extend %slide; @include slide;
padding-top: $topbar-height; padding-top: $topbar-height;
} }
@ -1253,15 +1249,11 @@ $sidebar-display: "sidebar-display";
} }
#topbar-wrapper { #topbar-wrapper {
@extend %slide; @include slide(top 0.2s ease);
left: 0; left: 0;
} }
.topbar-up {
top: 0 !important;
}
#main > div.row:first-child > div:nth-child(1), #main > div.row:first-child > div:nth-child(1),
#main > div.row:first-child > div:nth-child(2) { #main > div.row:first-child > div:nth-child(2) {
margin-top: 0; margin-top: 0;
@ -1308,6 +1300,12 @@ $sidebar-display: "sidebar-display";
} // max-width: 849px } // max-width: 849px
@media all and (max-width: 849px) and (orientation: portrait) {
[topbar-visible=false] #topbar-wrapper {
top: 0;
}
}
/* Phone & Pad */ /* Phone & Pad */
@media all and (min-width: 577px) and (max-width: 1199px) { @media all and (min-width: 577px) and (max-width: 1199px) {
footer > .d-flex > div { footer > .d-flex > div {
@ -1353,10 +1351,6 @@ $sidebar-display: "sidebar-display";
right: 1.2rem; right: 1.2rem;
} }
.topbar-up {
box-shadow: none !important;
}
#topbar-title { #topbar-title {
text-align: left; text-align: left;
} }

View file

@ -3,4 +3,4 @@
* © 2019 Cotes Chung * © 2019 Cotes Chung
* MIT Licensed * MIT Licensed
*/ */
$(function(){$(window).scroll(()=>{50<$(this).scrollTop()&&"none"===$("#sidebar-trigger").css("display")?$("#back-to-top").fadeIn():$("#back-to-top").fadeOut()}),$("#back-to-top").click(()=>($("body,html").animate({scrollTop:0},800),!1))}),$(function(){$(".mode-toggle").click(e=>{const o=$(e.target);let t=o.prop("tagName")==="button".toUpperCase()?o:o.parent();t.blur(),flipMode()})}),$(function(){const e=$("#sidebar-trigger"),o=$("#search-trigger"),t=$("#search-cancel"),s=$("#search-cleaner"),a=$("#main"),l=$("#topbar-title"),r=$("#search-wrapper"),n=$("#search-result-wrapper"),d=$("#search-results"),i=$("#search-input"),c=$("#search-hints"),u=function(){let e=0;return{block(){e=window.scrollY,$("html,body").scrollTop(0)},release(){$("html,body").scrollTop(e)},getOffset(){return e}}}(),f={on(){e.addClass("unloaded"),l.addClass("unloaded"),o.addClass("unloaded"),r.addClass("d-flex"),t.addClass("loaded")},off(){t.removeClass("loaded"),r.removeClass("d-flex"),e.removeClass("unloaded"),l.removeClass("unloaded"),o.removeClass("unloaded")}},p=function(){let e=!1;return{on(){e||(u.block(),n.removeClass("unloaded"),a.addClass("unloaded"),e=!0)},off(){e&&(d.empty(),c.hasClass("unloaded")&&c.removeClass("unloaded"),n.addClass("unloaded"),s.removeClass("visible"),a.removeClass("unloaded"),u.release(),i.val(""),e=!1)},isVisible(){return e}}}();function h(){return t.hasClass("loaded")}o.click(function(){f.on(),p.on(),i.focus()}),t.click(function(){f.off(),p.off()}),i.focus(function(){r.addClass("input-focus")}),i.focusout(function(){r.removeClass("input-focus")}),i.on("keyup",function(e){8===e.keyCode&&""===i.val()?h()?c.removeClass("unloaded"):p.off():""!==i.val()&&(p.on(),s.hasClass("visible")||s.addClass("visible"),h()&&c.addClass("unloaded"))}),s.on("click",function(){i.val(""),h()?(c.removeClass("unloaded"),d.empty()):p.off(),i.focus(),s.removeClass("visible")})}),$(function(){var e=function(){const e="sidebar-display";let o=!1;const t=$("body");return{toggle(){!1===o?t.attr(e,""):t.removeAttr(e),o=!o}}}();$("#sidebar-trigger").click(e.toggle),$("#mask").click(e.toggle)}),$(function(){$('[data-toggle="tooltip"]').tooltip()}),$(function(){const t=$("#topbar-wrapper"),o=$("#topbar-title"),s=$("#panel-wrapper"),a=$("#search-input"),l="topbar-up",r="topbar-down",n="toc-scrolling-up";let d,i=0;const c=t.outerHeight(),u=t.outerHeight();$(window).scroll(function(e){o.is(":hidden")&&(d=!0)}),setInterval(function(){d&&(function(){var e,o=$(this).scrollTop();Math.abs(i-o)<=c||(o>i?o>u&&(t.removeClass(r).addClass(l),s.removeClass(r),a.is(":focus")&&a.blur()):o+$(window).height()<$(document).height()&&(void 0!==(e=t.attr(n))?"false"===e&&t.removeAttr(n):(t.removeClass(l).addClass(r),s.addClass(r))),i=o)}(),d=!1)},250)}),$(function(){var o="div.post>h1:first-of-type";const t=$(o),r=$("#topbar-title");if(0!==t.length&&!t.hasClass("dynamic-title")&&!r.is(":hidden")){const n=r.text().trim();let s=t.text().trim(),a=!1,l=0;($("#page-category").length||$("#page-tag").length)&&/\s/.test(s)&&(s=s.replace(/[0-9]/g,"").trim());let e=new IntersectionObserver(e=>{var o,t;a?(o=$(window).scrollTop(),t=l<o,l=o,e=e[0],t?0===e.intersectionRatio&&r.text(s):1===e.intersectionRatio&&r.text(n)):a=!0},{rootMargin:"-48px 0px 0px 0px",threshold:[0,1]});e.observe(document.querySelector(o)),r.click(function(){$("body,html").animate({scrollTop:0},800)})}}),$(function(){const e=$(".collapse");e.on("hide.bs.collapse",function(){var e="h_"+$(this).attr("id").substring("l_".length);e&&($(`#${e} .far.fa-folder-open`).attr("class","far fa-folder fa-fw"),$(`#${e} i.fas`).addClass("rotate"),$("#"+e).removeClass("hide-border-bottom"))}),e.on("show.bs.collapse",function(){var e="h_"+$(this).attr("id").substring("l_".length);e&&($(`#${e} .far.fa-folder`).attr("class","far fa-folder-open fa-fw"),$(`#${e} i.fas`).removeClass("rotate"),$("#"+e).addClass("hide-border-bottom"))})}); $(function(){$(window).scroll(()=>{50<$(this).scrollTop()&&"none"===$("#sidebar-trigger").css("display")?$("#back-to-top").fadeIn():$("#back-to-top").fadeOut()}),$("#back-to-top").click(()=>($("body,html").animate({scrollTop:0},800),!1))}),$(function(){$(".mode-toggle").click(o=>{const e=$(o.target);let t=e.prop("tagName")==="button".toUpperCase()?e:e.parent();t.blur(),flipMode()})});const ScrollHelper=function(){const o=$("body"),e="topbar-visible",t=$("#topbar-wrapper").outerHeight();let l=0,a=!1,r=!1;return{hideTopbar:()=>o.attr(e,!1),showTopbar:()=>o.attr(e,!0),addScrollUpTask:()=>{l+=1,a=a||!0},popScrollUpTask:()=>--l,hasScrollUpTask:()=>0<l,topbarLocked:()=>!0===a,unlockTopbar:()=>a=!1,getTopbarHeight:()=>t,orientationLocked:()=>!0===r,lockOrientation:()=>r=!0,unLockOrientation:()=>r=!1}}();$(function(){const o=$("#sidebar-trigger"),e=$("#search-trigger"),t=$("#search-cancel"),l=$("#search-cleaner"),a=$("#main"),r=$("#topbar-title"),s=$("#search-wrapper"),n=$("#search-result-wrapper"),i=$("#search-results"),c=$("#search-input"),d=$("#search-hints"),p=function(){let o=0;return{block(){o=window.scrollY,$("html,body").scrollTop(0)},release(){$("html,body").scrollTop(o)},getOffset(){return o}}}(),f={on(){o.addClass("unloaded"),r.addClass("unloaded"),e.addClass("unloaded"),s.addClass("d-flex"),t.addClass("loaded")},off(){t.removeClass("loaded"),s.removeClass("d-flex"),o.removeClass("unloaded"),r.removeClass("unloaded"),e.removeClass("unloaded")}},u=function(){let o=!1;return{on(){o||(p.block(),n.removeClass("unloaded"),a.addClass("unloaded"),o=!0)},off(){o&&(i.empty(),d.hasClass("unloaded")&&d.removeClass("unloaded"),n.addClass("unloaded"),l.removeClass("visible"),a.removeClass("unloaded"),p.release(),c.val(""),o=!1)},isVisible(){return o}}}();function h(){return t.hasClass("loaded")}e.click(function(){f.on(),u.on(),c.focus()}),t.click(function(){f.off(),u.off()}),c.focus(function(){s.addClass("input-focus")}),c.focusout(function(){s.removeClass("input-focus")}),c.on("keyup",function(o){8===o.keyCode&&""===c.val()?h()?d.removeClass("unloaded"):u.off():""!==c.val()&&(u.on(),l.hasClass("visible")||l.addClass("visible"),h()&&d.addClass("unloaded"))}),l.on("click",function(){c.val(""),h()?(d.removeClass("unloaded"),i.empty()):u.off(),c.focus(),l.removeClass("visible")})}),$(function(){var o=function(){const o="sidebar-display";let e=!1;const t=$("body");return{toggle(){!1===e?t.attr(o,""):t.removeAttr(o),e=!e}}}();$("#sidebar-trigger").click(o.toggle),$("#mask").click(o.toggle)}),$(function(){$('[data-toggle="tooltip"]').tooltip()}),$(function(){const e=$("#search-input"),t=ScrollHelper.getTopbarHeight();let o,l=0;function a(){0!==$(window).scrollTop()&&(ScrollHelper.lockOrientation(),ScrollHelper.hideTopbar())}screen.orientation?screen.orientation.onchange=()=>{var o=screen.orientation.type;"landscape-primary"!==o&&"landscape-secondary"!==o||a()}:$(window).on("orientationchange",()=>{$(window).width()<$(window).height()&&a()}),$(window).scroll(()=>{o=o||!0}),setInterval(()=>{o&&(function(){var o=$(this).scrollTop();if(!(Math.abs(l-o)<=t)){if(o>l)ScrollHelper.hideTopbar(),e.is(":focus")&&e.blur();else if(o+$(window).height()<$(document).height()){if(ScrollHelper.hasScrollUpTask())return;ScrollHelper.topbarLocked()?ScrollHelper.unlockTopbar():ScrollHelper.orientationLocked()?ScrollHelper.unLockOrientation():ScrollHelper.showTopbar()}l=o}}(),o=!1)},250)}),$(function(){var e="div.post>h1:first-of-type";const t=$(e),s=$("#topbar-title");if(0!==t.length&&!t.hasClass("dynamic-title")&&!s.is(":hidden")){const n=s.text().trim();let l=t.text().trim(),a=!1,r=0;($("#page-category").length||$("#page-tag").length)&&/\s/.test(l)&&(l=l.replace(/[0-9]/g,"").trim()),t.offset().top<$(window).scrollTop()&&s.text(l);let o=new IntersectionObserver(o=>{var e,t;a?(e=$(window).scrollTop(),t=r<e,r=e,o=o[0],t?0===o.intersectionRatio&&s.text(l):1===o.intersectionRatio&&s.text(n)):a=!0},{rootMargin:"-48px 0px 0px 0px",threshold:[0,1]});o.observe(document.querySelector(e)),s.click(function(){$("body,html").animate({scrollTop:0},800)})}}),$(function(){const o=$(".collapse");o.on("hide.bs.collapse",function(){var o="h_"+$(this).attr("id").substring("l_".length);o&&($(`#${o} .far.fa-folder-open`).attr("class","far fa-folder fa-fw"),$(`#${o} i.fas`).addClass("rotate"),$("#"+o).removeClass("hide-border-bottom"))}),o.on("show.bs.collapse",function(){var o="h_"+$(this).attr("id").substring("l_".length);o&&($(`#${o} .far.fa-folder`).attr("class","far fa-folder-open fa-fw"),$(`#${o} i.fas`).removeClass("rotate"),$("#"+o).addClass("hide-border-bottom"))})});

View file

@ -3,4 +3,4 @@
* © 2019 Cotes Chung * © 2019 Cotes Chung
* MIT Licensed * MIT Licensed
*/ */
$(function(){$(window).scroll(()=>{50<$(this).scrollTop()&&"none"===$("#sidebar-trigger").css("display")?$("#back-to-top").fadeIn():$("#back-to-top").fadeOut()}),$("#back-to-top").click(()=>($("body,html").animate({scrollTop:0},800),!1))}),$(function(){$(".mode-toggle").click(e=>{const o=$(e.target);let t=o.prop("tagName")==="button".toUpperCase()?o:o.parent();t.blur(),flipMode()})}),$(function(){const e=$("#sidebar-trigger"),o=$("#search-trigger"),t=$("#search-cancel"),s=$("#search-cleaner"),a=$("#main"),l=$("#topbar-title"),n=$("#search-wrapper"),r=$("#search-result-wrapper"),i=$("#search-results"),d=$("#search-input"),c=$("#search-hints"),u=function(){let e=0;return{block(){e=window.scrollY,$("html,body").scrollTop(0)},release(){$("html,body").scrollTop(e)},getOffset(){return e}}}(),p={on(){e.addClass("unloaded"),l.addClass("unloaded"),o.addClass("unloaded"),n.addClass("d-flex"),t.addClass("loaded")},off(){t.removeClass("loaded"),n.removeClass("d-flex"),e.removeClass("unloaded"),l.removeClass("unloaded"),o.removeClass("unloaded")}},f=function(){let e=!1;return{on(){e||(u.block(),r.removeClass("unloaded"),a.addClass("unloaded"),e=!0)},off(){e&&(i.empty(),c.hasClass("unloaded")&&c.removeClass("unloaded"),r.addClass("unloaded"),s.removeClass("visible"),a.removeClass("unloaded"),u.release(),d.val(""),e=!1)},isVisible(){return e}}}();function m(){return t.hasClass("loaded")}o.click(function(){p.on(),f.on(),d.focus()}),t.click(function(){p.off(),f.off()}),d.focus(function(){n.addClass("input-focus")}),d.focusout(function(){n.removeClass("input-focus")}),d.on("keyup",function(e){8===e.keyCode&&""===d.val()?m()?c.removeClass("unloaded"):f.off():""!==d.val()&&(f.on(),s.hasClass("visible")||s.addClass("visible"),m()&&c.addClass("unloaded"))}),s.on("click",function(){d.val(""),m()?(c.removeClass("unloaded"),i.empty()):f.off(),d.focus(),s.removeClass("visible")})}),$(function(){var e=function(){const e="sidebar-display";let o=!1;const t=$("body");return{toggle(){!1===o?t.attr(e,""):t.removeAttr(e),o=!o}}}();$("#sidebar-trigger").click(e.toggle),$("#mask").click(e.toggle)}),$(function(){$('[data-toggle="tooltip"]').tooltip()}),$(function(){const t=$("#topbar-wrapper"),o=$("#topbar-title"),s=$("#panel-wrapper"),a=$("#search-input"),l="topbar-up",n="topbar-down",r="toc-scrolling-up";let i,d=0;const c=t.outerHeight(),u=t.outerHeight();$(window).scroll(function(e){o.is(":hidden")&&(i=!0)}),setInterval(function(){i&&(function(){var e,o=$(this).scrollTop();Math.abs(d-o)<=c||(o>d?o>u&&(t.removeClass(n).addClass(l),s.removeClass(n),a.is(":focus")&&a.blur()):o+$(window).height()<$(document).height()&&(void 0!==(e=t.attr(r))?"false"===e&&t.removeAttr(r):(t.removeClass(l).addClass(n),s.addClass(n))),d=o)}(),i=!1)},250)}),$(function(){var o="div.post>h1:first-of-type";const t=$(o),n=$("#topbar-title");if(0!==t.length&&!t.hasClass("dynamic-title")&&!n.is(":hidden")){const r=n.text().trim();let s=t.text().trim(),a=!1,l=0;($("#page-category").length||$("#page-tag").length)&&/\s/.test(s)&&(s=s.replace(/[0-9]/g,"").trim());let e=new IntersectionObserver(e=>{var o,t;a?(o=$(window).scrollTop(),t=l<o,l=o,e=e[0],t?0===e.intersectionRatio&&n.text(s):1===e.intersectionRatio&&n.text(r)):a=!0},{rootMargin:"-48px 0px 0px 0px",threshold:[0,1]});e.observe(document.querySelector(o)),n.click(function(){$("body,html").animate({scrollTop:0},800)})}}); $(function(){$(window).scroll(()=>{50<$(this).scrollTop()&&"none"===$("#sidebar-trigger").css("display")?$("#back-to-top").fadeIn():$("#back-to-top").fadeOut()}),$("#back-to-top").click(()=>($("body,html").animate({scrollTop:0},800),!1))}),$(function(){$(".mode-toggle").click(e=>{const o=$(e.target);let t=o.prop("tagName")==="button".toUpperCase()?o:o.parent();t.blur(),flipMode()})});const ScrollHelper=function(){const e=$("body"),o="topbar-visible",t=$("#topbar-wrapper").outerHeight();let l=0,r=!1,a=!1;return{hideTopbar:()=>e.attr(o,!1),showTopbar:()=>e.attr(o,!0),addScrollUpTask:()=>{l+=1,r=r||!0},popScrollUpTask:()=>--l,hasScrollUpTask:()=>0<l,topbarLocked:()=>!0===r,unlockTopbar:()=>r=!1,getTopbarHeight:()=>t,orientationLocked:()=>!0===a,lockOrientation:()=>a=!0,unLockOrientation:()=>a=!1}}();$(function(){const e=$("#sidebar-trigger"),o=$("#search-trigger"),t=$("#search-cancel"),l=$("#search-cleaner"),r=$("#main"),a=$("#topbar-title"),n=$("#search-wrapper"),s=$("#search-result-wrapper"),i=$("#search-results"),c=$("#search-input"),d=$("#search-hints"),p=function(){let e=0;return{block(){e=window.scrollY,$("html,body").scrollTop(0)},release(){$("html,body").scrollTop(e)},getOffset(){return e}}}(),u={on(){e.addClass("unloaded"),a.addClass("unloaded"),o.addClass("unloaded"),n.addClass("d-flex"),t.addClass("loaded")},off(){t.removeClass("loaded"),n.removeClass("d-flex"),e.removeClass("unloaded"),a.removeClass("unloaded"),o.removeClass("unloaded")}},f=function(){let e=!1;return{on(){e||(p.block(),s.removeClass("unloaded"),r.addClass("unloaded"),e=!0)},off(){e&&(i.empty(),d.hasClass("unloaded")&&d.removeClass("unloaded"),s.addClass("unloaded"),l.removeClass("visible"),r.removeClass("unloaded"),p.release(),c.val(""),e=!1)},isVisible(){return e}}}();function h(){return t.hasClass("loaded")}o.click(function(){u.on(),f.on(),c.focus()}),t.click(function(){u.off(),f.off()}),c.focus(function(){n.addClass("input-focus")}),c.focusout(function(){n.removeClass("input-focus")}),c.on("keyup",function(e){8===e.keyCode&&""===c.val()?h()?d.removeClass("unloaded"):f.off():""!==c.val()&&(f.on(),l.hasClass("visible")||l.addClass("visible"),h()&&d.addClass("unloaded"))}),l.on("click",function(){c.val(""),h()?(d.removeClass("unloaded"),i.empty()):f.off(),c.focus(),l.removeClass("visible")})}),$(function(){var e=function(){const e="sidebar-display";let o=!1;const t=$("body");return{toggle(){!1===o?t.attr(e,""):t.removeAttr(e),o=!o}}}();$("#sidebar-trigger").click(e.toggle),$("#mask").click(e.toggle)}),$(function(){$('[data-toggle="tooltip"]').tooltip()}),$(function(){const o=$("#search-input"),t=ScrollHelper.getTopbarHeight();let e,l=0;function r(){0!==$(window).scrollTop()&&(ScrollHelper.lockOrientation(),ScrollHelper.hideTopbar())}screen.orientation?screen.orientation.onchange=()=>{var e=screen.orientation.type;"landscape-primary"!==e&&"landscape-secondary"!==e||r()}:$(window).on("orientationchange",()=>{$(window).width()<$(window).height()&&r()}),$(window).scroll(()=>{e=e||!0}),setInterval(()=>{e&&(function(){var e=$(this).scrollTop();if(!(Math.abs(l-e)<=t)){if(e>l)ScrollHelper.hideTopbar(),o.is(":focus")&&o.blur();else if(e+$(window).height()<$(document).height()){if(ScrollHelper.hasScrollUpTask())return;ScrollHelper.topbarLocked()?ScrollHelper.unlockTopbar():ScrollHelper.orientationLocked()?ScrollHelper.unLockOrientation():ScrollHelper.showTopbar()}l=e}}(),e=!1)},250)}),$(function(){var o="div.post>h1:first-of-type";const t=$(o),n=$("#topbar-title");if(0!==t.length&&!t.hasClass("dynamic-title")&&!n.is(":hidden")){const s=n.text().trim();let l=t.text().trim(),r=!1,a=0;($("#page-category").length||$("#page-tag").length)&&/\s/.test(l)&&(l=l.replace(/[0-9]/g,"").trim()),t.offset().top<$(window).scrollTop()&&n.text(l);let e=new IntersectionObserver(e=>{var o,t;r?(o=$(window).scrollTop(),t=a<o,a=o,e=e[0],t?0===e.intersectionRatio&&n.text(l):1===e.intersectionRatio&&n.text(s)):r=!0},{rootMargin:"-48px 0px 0px 0px",threshold:[0,1]});e.observe(document.querySelector(o)),n.click(function(){$("body,html").animate({scrollTop:0},800)})}});

View file

@ -3,4 +3,4 @@
* © 2019 Cotes Chung * © 2019 Cotes Chung
* MIT Licensed * MIT Licensed
*/ */
$(function(){$(window).scroll(()=>{50<$(this).scrollTop()&&"none"===$("#sidebar-trigger").css("display")?$("#back-to-top").fadeIn():$("#back-to-top").fadeOut()}),$("#back-to-top").click(()=>($("body,html").animate({scrollTop:0},800),!1))}),$(function(){$(".mode-toggle").click(t=>{const e=$(t.target);let o=e.prop("tagName")==="button".toUpperCase()?e:e.parent();o.blur(),flipMode()})}),$(function(){const t=$("#sidebar-trigger"),e=$("#search-trigger"),o=$("#search-cancel"),a=$("#search-cleaner"),s=$("#main"),l=$("#topbar-title"),n=$("#search-wrapper"),r=$("#search-result-wrapper"),i=$("#search-results"),d=$("#search-input"),c=$("#search-hints"),u=function(){let t=0;return{block(){t=window.scrollY,$("html,body").scrollTop(0)},release(){$("html,body").scrollTop(t)},getOffset(){return t}}}(),p={on(){t.addClass("unloaded"),l.addClass("unloaded"),e.addClass("unloaded"),n.addClass("d-flex"),o.addClass("loaded")},off(){o.removeClass("loaded"),n.removeClass("d-flex"),t.removeClass("unloaded"),l.removeClass("unloaded"),e.removeClass("unloaded")}},f=function(){let t=!1;return{on(){t||(u.block(),r.removeClass("unloaded"),s.addClass("unloaded"),t=!0)},off(){t&&(i.empty(),c.hasClass("unloaded")&&c.removeClass("unloaded"),r.addClass("unloaded"),a.removeClass("visible"),s.removeClass("unloaded"),u.release(),d.val(""),t=!1)},isVisible(){return t}}}();function m(){return o.hasClass("loaded")}e.click(function(){p.on(),f.on(),d.focus()}),o.click(function(){p.off(),f.off()}),d.focus(function(){n.addClass("input-focus")}),d.focusout(function(){n.removeClass("input-focus")}),d.on("keyup",function(t){8===t.keyCode&&""===d.val()?m()?c.removeClass("unloaded"):f.off():""!==d.val()&&(f.on(),a.hasClass("visible")||a.addClass("visible"),m()&&c.addClass("unloaded"))}),a.on("click",function(){d.val(""),m()?(c.removeClass("unloaded"),i.empty()):f.off(),d.focus(),a.removeClass("visible")})}),$(function(){var t=function(){const t="sidebar-display";let e=!1;const o=$("body");return{toggle(){!1===e?o.attr(t,""):o.removeAttr(t),e=!e}}}();$("#sidebar-trigger").click(t.toggle),$("#mask").click(t.toggle)}),$(function(){$('[data-toggle="tooltip"]').tooltip()}),$(function(){const o=$("#topbar-wrapper"),e=$("#topbar-title"),a=$("#panel-wrapper"),s=$("#search-input"),l="topbar-up",n="topbar-down",r="toc-scrolling-up";let i,d=0;const c=o.outerHeight(),u=o.outerHeight();$(window).scroll(function(t){e.is(":hidden")&&(i=!0)}),setInterval(function(){i&&(function(){var t,e=$(this).scrollTop();Math.abs(d-e)<=c||(e>d?e>u&&(o.removeClass(n).addClass(l),a.removeClass(n),s.is(":focus")&&s.blur()):e+$(window).height()<$(document).height()&&(void 0!==(t=o.attr(r))?"false"===t&&o.removeAttr(r):(o.removeClass(l).addClass(n),a.addClass(n))),d=e)}(),i=!1)},250)}),$(function(){var e="div.post>h1:first-of-type";const o=$(e),n=$("#topbar-title");if(0!==o.length&&!o.hasClass("dynamic-title")&&!n.is(":hidden")){const r=n.text().trim();let a=o.text().trim(),s=!1,l=0;($("#page-category").length||$("#page-tag").length)&&/\s/.test(a)&&(a=a.replace(/[0-9]/g,"").trim());let t=new IntersectionObserver(t=>{var e,o;s?(e=$(window).scrollTop(),o=l<e,l=e,t=t[0],o?0===t.intersectionRatio&&n.text(a):1===t.intersectionRatio&&n.text(r)):s=!0},{rootMargin:"-48px 0px 0px 0px",threshold:[0,1]});t.observe(document.querySelector(e)),n.click(function(){$("body,html").animate({scrollTop:0},800)})}}),$(function(){let o=$(".timeago").length,t=void 0;const s=$("meta[name=day-prompt]").attr("content"),l=$("meta[name=hour-prompt]").attr("content"),n=$("meta[name=minute-prompt]").attr("content"),r=$("meta[name=justnow-prompt]").attr("content");function e(){return $(".timeago").each(function(){var t,e;!1!==$(this)[0].hasAttribute("date")?(e=function(t,e){let o=new Date,a=new Date(t);return a.getFullYear()!==o.getFullYear()||a.getMonth()!==o.getMonth()?e:(t=Math.floor((o-a)/1e3),1<=(e=Math.floor(t/86400))?` ${e} `+s:1<=(e=Math.floor(t/3600))?` ${e} `+l:1<=(t=Math.floor(t/60))?` ${t} `+n:r)}($(this).attr("date"),t=$(this).text()))===t?$(this).removeAttr("date"):$(this).text(e):--o}),0===o&&void 0!==t&&clearInterval(t),o}0!==o&&0<e()&&(t=setInterval(e,6e4))}); $(function(){$(window).scroll(()=>{50<$(this).scrollTop()&&"none"===$("#sidebar-trigger").css("display")?$("#back-to-top").fadeIn():$("#back-to-top").fadeOut()}),$("#back-to-top").click(()=>($("body,html").animate({scrollTop:0},800),!1))}),$(function(){$(".mode-toggle").click(e=>{const t=$(e.target);let o=t.prop("tagName")==="button".toUpperCase()?t:t.parent();o.blur(),flipMode()})});const ScrollHelper=function(){const e=$("body"),t="topbar-visible",o=$("#topbar-wrapper").outerHeight();let a=0,l=!1,r=!1;return{hideTopbar:()=>e.attr(t,!1),showTopbar:()=>e.attr(t,!0),addScrollUpTask:()=>{a+=1,l=l||!0},popScrollUpTask:()=>--a,hasScrollUpTask:()=>0<a,topbarLocked:()=>!0===l,unlockTopbar:()=>l=!1,getTopbarHeight:()=>o,orientationLocked:()=>!0===r,lockOrientation:()=>r=!0,unLockOrientation:()=>r=!1}}();$(function(){const e=$("#sidebar-trigger"),t=$("#search-trigger"),o=$("#search-cancel"),a=$("#search-cleaner"),l=$("#main"),r=$("#topbar-title"),n=$("#search-wrapper"),s=$("#search-result-wrapper"),i=$("#search-results"),c=$("#search-input"),d=$("#search-hints"),p=function(){let e=0;return{block(){e=window.scrollY,$("html,body").scrollTop(0)},release(){$("html,body").scrollTop(e)},getOffset(){return e}}}(),u={on(){e.addClass("unloaded"),r.addClass("unloaded"),t.addClass("unloaded"),n.addClass("d-flex"),o.addClass("loaded")},off(){o.removeClass("loaded"),n.removeClass("d-flex"),e.removeClass("unloaded"),r.removeClass("unloaded"),t.removeClass("unloaded")}},f=function(){let e=!1;return{on(){e||(p.block(),s.removeClass("unloaded"),l.addClass("unloaded"),e=!0)},off(){e&&(i.empty(),d.hasClass("unloaded")&&d.removeClass("unloaded"),s.addClass("unloaded"),a.removeClass("visible"),l.removeClass("unloaded"),p.release(),c.val(""),e=!1)},isVisible(){return e}}}();function h(){return o.hasClass("loaded")}t.click(function(){u.on(),f.on(),c.focus()}),o.click(function(){u.off(),f.off()}),c.focus(function(){n.addClass("input-focus")}),c.focusout(function(){n.removeClass("input-focus")}),c.on("keyup",function(e){8===e.keyCode&&""===c.val()?h()?d.removeClass("unloaded"):f.off():""!==c.val()&&(f.on(),a.hasClass("visible")||a.addClass("visible"),h()&&d.addClass("unloaded"))}),a.on("click",function(){c.val(""),h()?(d.removeClass("unloaded"),i.empty()):f.off(),c.focus(),a.removeClass("visible")})}),$(function(){var e=function(){const e="sidebar-display";let t=!1;const o=$("body");return{toggle(){!1===t?o.attr(e,""):o.removeAttr(e),t=!t}}}();$("#sidebar-trigger").click(e.toggle),$("#mask").click(e.toggle)}),$(function(){$('[data-toggle="tooltip"]').tooltip()}),$(function(){const t=$("#search-input"),o=ScrollHelper.getTopbarHeight();let e,a=0;function l(){0!==$(window).scrollTop()&&(ScrollHelper.lockOrientation(),ScrollHelper.hideTopbar())}screen.orientation?screen.orientation.onchange=()=>{var e=screen.orientation.type;"landscape-primary"!==e&&"landscape-secondary"!==e||l()}:$(window).on("orientationchange",()=>{$(window).width()<$(window).height()&&l()}),$(window).scroll(()=>{e=e||!0}),setInterval(()=>{e&&(function(){var e=$(this).scrollTop();if(!(Math.abs(a-e)<=o)){if(e>a)ScrollHelper.hideTopbar(),t.is(":focus")&&t.blur();else if(e+$(window).height()<$(document).height()){if(ScrollHelper.hasScrollUpTask())return;ScrollHelper.topbarLocked()?ScrollHelper.unlockTopbar():ScrollHelper.orientationLocked()?ScrollHelper.unLockOrientation():ScrollHelper.showTopbar()}a=e}}(),e=!1)},250)}),$(function(){var t="div.post>h1:first-of-type";const o=$(t),n=$("#topbar-title");if(0!==o.length&&!o.hasClass("dynamic-title")&&!n.is(":hidden")){const s=n.text().trim();let a=o.text().trim(),l=!1,r=0;($("#page-category").length||$("#page-tag").length)&&/\s/.test(a)&&(a=a.replace(/[0-9]/g,"").trim()),o.offset().top<$(window).scrollTop()&&n.text(a);let e=new IntersectionObserver(e=>{var t,o;l?(t=$(window).scrollTop(),o=r<t,r=t,e=e[0],o?0===e.intersectionRatio&&n.text(a):1===e.intersectionRatio&&n.text(s)):l=!0},{rootMargin:"-48px 0px 0px 0px",threshold:[0,1]});e.observe(document.querySelector(t)),n.click(function(){$("body,html").animate({scrollTop:0},800)})}}),$(function(){let o=$(".timeago").length,e=void 0;const l=$("meta[name=day-prompt]").attr("content"),r=$("meta[name=hour-prompt]").attr("content"),n=$("meta[name=minute-prompt]").attr("content"),s=$("meta[name=justnow-prompt]").attr("content");function t(){return $(".timeago").each(function(){var e,t;!1!==$(this)[0].hasAttribute("date")?(t=function(e,t){let o=new Date,a=new Date(e);return a.getFullYear()!==o.getFullYear()||a.getMonth()!==o.getMonth()?t:(e=Math.floor((o-a)/1e3),1<=(t=Math.floor(e/86400))?` ${t} `+l:1<=(t=Math.floor(e/3600))?` ${t} `+r:1<=(e=Math.floor(e/60))?` ${e} `+n:s)}($(this).attr("date"),e=$(this).text()))===e?$(this).removeAttr("date"):$(this).text(t):--o}),0===o&&void 0!==e&&clearInterval(e),o}0!==o&&0<t()&&(e=setInterval(t,6e4))});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long