style: 4 space indents to the JS files

This commit is contained in:
Cotes Chung 2022-10-25 19:26:44 +08:00
parent 1fd665bf49
commit 339293d0d7
No known key found for this signature in database
GPG key ID: 0D9E54843167A808
21 changed files with 913 additions and 912 deletions

View file

@ -2,10 +2,13 @@ root = true
[*]
charset = utf-8
# 2 space indentation
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
# Unix-style newlines with a newline ending every file
end_of_line = lf
insert_final_newline = true
[*.js]
indent_size = 4

View file

@ -1,6 +1,6 @@
/*
Reference: https://bootsnipp.com/snippets/featured/link-to-top-page
*/
/**
* Reference: https://bootsnipp.com/snippets/featured/link-to-top-page
*/
$(function() {
$(window).scroll(() => {
if ($(this).scrollTop() > 50 &&

View file

@ -1,7 +1,7 @@
/*
/**
* Listener for theme mode toggle
*/
$(function() {
$(function () {
$(".mode-toggle").click((e) => {
const $target = $(e.target);
let $btn = ($target.prop("tagName") === "button".toUpperCase() ?

View file

@ -18,7 +18,9 @@ const ScrollHelper = (function () {
addScrollUpTask: () => {
scrollUpCount += 1;
if (!topbarLocked) { topbarLocked = true; }
if (!topbarLocked) {
topbarLocked = true;
}
},
popScrollUpTask: () => scrollUpCount -= 1,
hasScrollUpTask: () => scrollUpCount > 0,

View file

@ -1,8 +1,8 @@
/*
* This script make #search-result-wrapper switch to unloaded or shown automatically.
*/
/**
* This script make #search-result-wrapper switch to unloaded or shown automatically.
*/
$(function() {
$(function () {
const btnSbTrigger = $("#sidebar-trigger");
const btnSearchTrigger = $("#search-trigger");
const btnCancel = $("#search-cancel");
@ -91,22 +91,22 @@ $(function() {
return btnCancel.hasClass("loaded");
}
btnSearchTrigger.click(function() {
btnSearchTrigger.click(function () {
mobileSearchBar.on();
resultSwitch.on();
input.focus();
});
btnCancel.click(function() {
btnCancel.click(function () {
mobileSearchBar.off();
resultSwitch.off();
});
input.focus(function() {
input.focus(function () {
searchWrapper.addClass("input-focus");
});
input.focusout(function() {
input.focusout(function () {
searchWrapper.removeClass("input-focus");
});

View file

@ -2,8 +2,7 @@
* Expand or close the sidebar in mobile screens.
*/
$(function() {
$(function () {
const sidebarUtil = (function () {
const ATTR_DISPLAY = "sidebar-display";
let isExpanded = false;
@ -26,5 +25,4 @@ $(function() {
$("#sidebar-trigger").click(sidebarUtil.toggle);
$("#mask").click(sidebarUtil.toggle);
});

View file

@ -1,6 +1,6 @@
/**
* Initial Bootstrap Tooltip.
*/
*/
$(function () {
$("[data-toggle=\"tooltip\"]").tooltip();
});

View file

@ -1,8 +1,8 @@
/*
/**
* Hide Header on scroll down
*/
$(function() {
$(function () {
const $searchInput = $("#search-input");
const delta = ScrollHelper.getTopbarHeight();
@ -17,7 +17,7 @@ $(function() {
return;
}
if (st > lastScrollTop ) { // Scroll Down
if (st > lastScrollTop) { // Scroll Down
ScrollHelper.hideTopbar();
if ($searchInput.is(":focus")) {
@ -66,7 +66,7 @@ $(function() {
} else {
// for the browsers that not support `window.screen.orientation` API
$(window).on("orientationchange",() => {
$(window).on("orientationchange", () => {
if ($(window).width() < $(window).height()) { // before rotating, it is still in portrait mode.
handleLandscape();
}
@ -86,5 +86,4 @@ $(function() {
didScroll = false;
}
}, 250);
});

View file

@ -1,8 +1,8 @@
/*
/**
* Top bar title auto change while scrolling up/down in mobile screens.
*/
*/
$(function() {
$(function () {
const titleSelector = "div.post>h1:first-of-type";
const $pageTitle = $(titleSelector);
const $topbarTitle = $("#topbar-title");
@ -60,7 +60,7 @@ $(function() {
observer.observe(document.querySelector(titleSelector));
/* Click title will scroll to top */
$topbarTitle.click(function() {
$topbarTitle.click(function () {
$("body,html").animate({scrollTop: 0}, 800);
});

View file

@ -1,8 +1,8 @@
/*
/**
* Tab 'Categories' expand/close effect.
*/
$(function() {
$(function () {
const childPrefix = "l_";
const parentPrefix = "h_";
const collapse = $(".collapse");
@ -18,7 +18,7 @@ $(function() {
});
/* expand the top category */
collapse.on("show.bs.collapse", function() {
collapse.on("show.bs.collapse", function () {
const parentId = parentPrefix + $(this).attr("id").substring(childPrefix.length);
if (parentId) {
$(`#${parentId} .far.fa-folder`).attr("class", "far fa-folder-open fa-fw");

View file

@ -1,4 +1,4 @@
/*
/**
* Clipboard functions
*
* Dependencies:
@ -6,7 +6,7 @@
* - clipboard.js (https://github.com/zenorocha/clipboard.js)
*/
$(function() {
$(function () {
const btnSelector = '.code-header>button';
const ICON_SUCCESS = 'fas fa-check';
const ATTR_TIMEOUT = 'timeout';

View file

@ -1,13 +1,12 @@
/**
Lazy load images (https://github.com/ApoorvSaxena/lozad.js)
and popup when clicked (https://github.com/dimsemenov/Magnific-Popup)
*/
$(function() {
*/
$(function () {
const IMG_SCOPE = '#main > div.row:first-child > div:first-child';
if ($(`${IMG_SCOPE} img`).length <= 0 ) {
if ($(`${IMG_SCOPE} img`).length <= 0) {
return;
}
@ -19,8 +18,8 @@ $(function() {
/* popup */
$(`${IMG_SCOPE} p > img[data-src],${IMG_SCOPE} img[data-src].preview-img`).each(
function() {
$(`${IMG_SCOPE} p > img[data-src], ${IMG_SCOPE} img[data-src].preview-img`).each(
function () {
let nextTag = $(this).next();
const title = nextTag.prop('tagName') === 'EM' ? nextTag.text() : '';
const src = $(this).attr('data-src'); // created by lozad.js

View file

@ -20,7 +20,7 @@ const LocaleHelper = (function () {
}());
$(function() {
$(function () {
dayjs.locale(LocaleHelper.locale());
dayjs.extend(window.dayjs_plugin_localizedFormat);

View file

@ -1,4 +1,4 @@
/*
/**
* Count page views form GA or local cache file.
*
* Dependencies:
@ -106,7 +106,7 @@ const PvStorage = (function () {
return;
}
for(let i = 0; i < localStorage.length; i++){
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
switch (key) {
case Keys.KEY_PV:
@ -136,7 +136,7 @@ function countUp(min, max, destId) {
function countPV(path, rows) {
let count = 0;
if (typeof rows !== "undefined" ) {
if (typeof rows !== "undefined") {
for (let i = 0; i < rows.length; ++i) {
const gaPath = rows[parseInt(i, 10)][0];
if (gaPath === path) { /* path format see: site.permalink */
@ -172,7 +172,7 @@ function displayPageviews(data) {
const rows = data.rows; /* could be undefined */
if ($("#post-list").length > 0) { /* the Home page */
$(".post-preview").each(function() {
$(".post-preview").each(function () {
const path = $(this).find("a").attr("href");
tacklePV(rows, path, $(this).find(".pageviews"), hasInit);
});
@ -215,7 +215,7 @@ function fetchLocalPageviews(hasCache = false) {
});
}
$(function() {
$(function () {
if ($(".pageviews").length <= 0) {
return;
}

View file

@ -1,13 +1,13 @@
/*
/**
Safari doesn't support CSS `scroll-behavior: smooth`,
so here is a compatible solution for all browser to smooth scrolling
See: <https://css-tricks.com/snippets/jquery/smooth-scrolling/>
Warning: It must be called after all `<a>` tags (e.g., the dynamic TOC) are ready.
*/
*/
$(function() {
$(function () {
const $topbarTitle = $("#topbar-title");
const REM = 16; // in pixels
const ATTR_SCROLL_FOCUS = "scroll-focus";
@ -15,7 +15,7 @@ $(function() {
$("a[href*='#']")
.not("[href='#']")
.not("[href='#0']")
.click(function(event) {
.click(function (event) {
if (this.pathname.replace(/^\//, "") !==
location.pathname.replace(/^\//, "")) {
return;

View file

@ -5,7 +5,6 @@ layout: compress
---
const resource = [
/* --- CSS --- */
'{{ "/assets/css/style.css" | relative_url }}',
@ -16,6 +15,7 @@ const resource = [
/* --- HTML --- */
'{{ "/index.html" | relative_url }}',
'{{ "/404.html" | relative_url }}',
{% for tab in site.tabs %}
'{{ tab.url | relative_url }}',
{% endfor %}
@ -25,7 +25,6 @@ const resource = [
{% for file in cache_list %}
'{{ file.path | relative_url }}'{%- unless forloop.last -%},{%- endunless -%}
{% endfor %}
];
/* The request url with below domain will be cached */

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -32,8 +32,7 @@ if ('serviceWorker' in navigator) {
}
$notification.toast('hide');
});
}
);
});
let refreshing = false;
@ -45,3 +44,4 @@ if ('serviceWorker' in navigator) {
}
});
}

View file

@ -87,3 +87,4 @@ self.addEventListener('fetch', event => {
})
);
});