Skip to content

Commit

Permalink
fix(all): 重写迷你代码块,修复迷你代码块所导致的例如 TOC跳转、归档无法点击、迷你代码块在代码块中被渲染、分类雷达等问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
LIlGG committed Feb 9, 2022
1 parent 4bf46e9 commit 917a781
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 58 deletions.
116 changes: 59 additions & 57 deletions script/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,36 +337,44 @@ var LIlGGAttachContext = {
},
});

(function () {
$(".toc").css(
"max-height",
$(document).scrollTop() + ($(window).height() - baseTopPadding) + "px"
);
var interval = setInterval(function () {
if(document.readyState == "complete"){
$(".toc").css(
"max-height",
$(document).scrollTop() + ($(window).height() - baseTopPadding) + "px"
);

$(window).scroll(function () {
var s = $(document).scrollTop();
if (s == 0) {
$(".toc").css(
"max-height",
$(document).scrollTop() +
($(window).height() - baseTopPadding) +
"px"
);
} else if (s > offset) {
$(".toc").css(
"max-height",
$(window).height() - maxToppadding + "px"
);
} else {
$(".toc").css(
"max-height",
$(document).scrollTop() +
($(window).height() - baseTopPadding) +
"px"
);
}
});
})();
$(".toc-container").css(
"height",
$(document).scrollTop() + ($(window).height() - baseTopPadding) + "px"
);

$(window).scroll(function () {
var s = $(document).scrollTop();
if (s == 0) {
$(".toc").css(
"max-height",
$(document).scrollTop() +
($(window).height() - baseTopPadding) +
"px"
);
} else if (s > offset) {
$(".toc").css(
"max-height",
$(window).height() - maxToppadding + "px"
);
} else {
$(".toc").css(
"max-height",
$(document).scrollTop() +
($(window).height() - baseTopPadding) +
"px"
);
}
});
clearInterval(interval);
}
},2000);
},
// 文章代码样式
CHS: function () {
Expand Down Expand Up @@ -928,38 +936,42 @@ var LIlGGAttachContext = {

// 内容提示块
MINI_CODE: function() {
if (!!$('.is-homepage')[0]) {
return;
}
const reg = new RegExp("(?<=]).+(?=\\[/)","g")

const noway = new RegExp("(?=\\[noway])(\\S*)(\\[/noway]=?)","g");
const buy = new RegExp("(?=\\[buy])(\\S*)(\\[/buy]=?)","g");
const task = new RegExp("(?=\\[task])(\\S*)(\\[/task]=?)","g");
const warning = new RegExp("(?=\\[warning])(\\S*)(\\[/warning]=?)","g");

var contentDom = document.getElementsByClassName('site-content')[0];
if (!contentDom) {
let $contentDom = $('.site-content p');
if (!$contentDom) {
return;
}

var content = contentDom.outerHTML;
// 获取提示块中的内容提示信息及类型
content = content.replaceAll(noway, (text) => {
return createToast("noway", text.match(reg)[0]);
})

content = content.replaceAll(buy, (text) => {
return createToast("buy", text.match(reg)[0]);
})
$contentDom.each(function () {
var text = $(this).html();
// 获取提示块中的内容提示信息及类型
text = text.replace(noway, (text) => {
return createToast("noway", text.match(reg)[0]);
})

content = content.replaceAll(task, (text) => {
return createToast("task", text.match(reg)[0]);
})
text = text.replace(buy, (text) => {
return createToast("buy", text.match(reg)[0]);
})

content = content.replaceAll(warning, (text) => {
return createToast("warning", text.match(reg)[0]);
})
text = text.replace(task, (text) => {
return createToast("task", text.match(reg)[0]);
})

$(contentDom).replaceWith(content);
text = text.replace(warning, (text) => {
return createToast("warning", text.match(reg)[0]);
})

$(this).html(text)
})
function createToast(type, msg) {
var icon = "";
switch (type) {
Expand Down Expand Up @@ -1219,16 +1231,6 @@ var home = location.href,
);
}
});
// 每次图片加载完成都重新计算高度
if(Poi.toc) {
$imgs.on("load", function() {
if ($("div").hasClass("toc")) {
$(".toc-container").css("height", $(".site-content").outerHeight());
} else {
return;
}
})
}
}

// 标签云
Expand Down
Loading

0 comments on commit 917a781

Please sign in to comment.