1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2025-12-25 00:53:31 +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

@@ -97,8 +97,7 @@ $(function () {
/* --- Post link sharing --- */
$('#copy-link').click((e) => {
$('#copy-link').on('click',(e) => {
let target = $(e.target);
if (isLocked(target)) {
@@ -106,28 +105,19 @@ $(function () {
}
// Copy URL to clipboard
navigator.clipboard
.writeText(window.location.href)
.then(() => {
const defaultTitle = target.attr(ATTR_TITLE_ORIGIN);
const succeedTitle = target.attr(ATTR_TITLE_SUCCEED);
// Switch tooltip title
target.attr(ATTR_TITLE_ORIGIN, succeedTitle).tooltip('show');
lock(target);
const url = window.location.href;
const $temp = $("<input>");
$("body").append($temp);
$temp.val(url).select();
document.execCommand("copy");
$temp.remove();
// Switch tooltip title
const defaultTitle = target.attr(ATTR_TITLE_ORIGIN);
const succeedTitle = target.attr(ATTR_TITLE_SUCCEED);
target.attr(ATTR_TITLE_ORIGIN, succeedTitle).tooltip('show');
lock(target);
setTimeout(() => {
target.attr(ATTR_TITLE_ORIGIN, defaultTitle);
unlock(target);
}, TIMEOUT);
setTimeout(() => {
target.attr(ATTR_TITLE_ORIGIN, defaultTitle);
unlock(target);
}, TIMEOUT);
});
});
});

View File

@@ -6,7 +6,7 @@
/* A tool for locale datetime */
const LocaleHelper = (function () {
const locale = $('html').attr('lang').substr(0, 2);
const locale = $('html').attr('lang').substring(0, 2);
const attrTimestamp = 'data-ts';
const attrDateFormat = 'data-df';

View File

@@ -15,7 +15,7 @@ $(function () {
$("a[href*='#']")
.not("[href='#']")
.not("[href='#0']")
.click(function (event) {
.on('click', function (event) {
if (this.pathname.replace(/^\//, "") !==
location.pathname.replace(/^\//, "")) {
return;
@@ -64,28 +64,30 @@ $(function () {
$("html").animate({
scrollTop: destOffset
}, 500, () => {
$target.focus();
$target.trigger("focus");
/* clean up old scroll mark */
if ($(`[${ATTR_SCROLL_FOCUS}=true]`).length) {
$(`[${ATTR_SCROLL_FOCUS}=true]`).attr(ATTR_SCROLL_FOCUS, false);
const $scroll_focus = $(`[${ATTR_SCROLL_FOCUS}=true]`);
if ($scroll_focus.length) {
$scroll_focus.attr(ATTR_SCROLL_FOCUS, "false");
}
/* Clean :target links */
if ($(":target").length) { /* element that visited by the URL with hash */
$(":target").attr(ATTR_SCROLL_FOCUS, false);
const $target_links = $(":target");
if ($target_links.length) { /* element that visited by the URL with hash */
$target_links.attr(ATTR_SCROLL_FOCUS, "false");
}
/* set scroll mark to footnotes */
if (toFootnote || toFootnoteRef) {
$target.attr(ATTR_SCROLL_FOCUS, true);
$target.attr(ATTR_SCROLL_FOCUS, "true");
}
if ($target.is(":focus")) { /* Checking if the target was focused */
return false;
} else {
$target.attr("tabindex", "-1"); /* Adding tabindex for elements not focusable */
$target.focus(); /* Set focus again */
$target.trigger("focus"); /* Set focus again */
}
if (ScrollHelper.hasScrollUpTask()) {