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

refactor: replace the deprecated js api

This commit is contained in:
Cotes Chung
2023-02-15 04:53:40 +08:00
parent a2d01365de
commit c3a840076e
16 changed files with 47 additions and 58 deletions

View File

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

View File

@@ -2,12 +2,12 @@
* Listener for theme mode toggle
*/
$(function () {
$(".mode-toggle").click((e) => {
$(".mode-toggle").on('click',(e) => {
const $target = $(e.target);
let $btn = ($target.prop("tagName") === "button".toUpperCase() ?
$target : $target.parent());
$btn.blur(); // remove the clicking outline
$btn.trigger('blur'); // remove the clicking outline
flipMode();
});
});

View File

@@ -11,8 +11,8 @@ const ScrollHelper = (function () {
let orientationLocked = false;
return {
hideTopbar: () => $body.attr(ATTR_TOPBAR_VISIBLE, false),
showTopbar: () => $body.attr(ATTR_TOPBAR_VISIBLE, true),
hideTopbar: () => $body.attr(ATTR_TOPBAR_VISIBLE, 'false'),
showTopbar: () => $body.attr(ATTR_TOPBAR_VISIBLE, 'true'),
// scroll up

View File

@@ -79,9 +79,6 @@ $(function () {
input.val("");
visible = false;
}
},
isVisible() {
return visible;
}
};
@@ -91,22 +88,22 @@ $(function () {
return btnCancel.hasClass("loaded");
}
btnSearchTrigger.click(function () {
btnSearchTrigger.on('click',function () {
mobileSearchBar.on();
resultSwitch.on();
input.focus();
input.trigger('focus');
});
btnCancel.click(function () {
btnCancel.on('click',function () {
mobileSearchBar.off();
resultSwitch.off();
});
input.focus(function () {
input.on('focus',function () {
searchWrapper.addClass("input-focus");
});
input.focusout(function () {
input.on('focusout', function () {
searchWrapper.removeClass("input-focus");
});

View File

@@ -22,7 +22,7 @@ $(function () {
}());
$("#sidebar-trigger").click(sidebarUtil.toggle);
$("#sidebar-trigger").on('click', sidebarUtil.toggle);
$("#mask").click(sidebarUtil.toggle);
$("#mask").on('click', sidebarUtil.toggle);
});

View File

@@ -21,7 +21,7 @@ $(function () {
ScrollHelper.hideTopbar();
if ($searchInput.is(":focus")) {
$searchInput.blur(); /* remove focus */
$searchInput.trigger('blur'); /* remove focus */
}
} else { // Scroll up
@@ -73,7 +73,7 @@ $(function () {
});
}
$(window).scroll(() => {
$(window).on('scroll',() => {
if (didScroll) {
return;
}

View File

@@ -60,7 +60,7 @@ $(function () {
observer.observe(document.querySelector(titleSelector));
/* Click title will scroll to top */
$topbarTitle.click(function () {
$topbarTitle.on('click', function () {
$("body,html").animate({scrollTop: 0}, 800);
});