我想改一下reacg这个***博客的配置:TinyMCE主题的文章目录没法点击页内跳转。
小菜鸟,思路:去学习BNDong大神
怀疑是这两个和文章目录有关
Cnblogs-Theme-SimpleMemory/src/script/marvin.nav2.js /
$(document).ready(function () {
var b = $('body'),
c = 'cnblogs_post_body',
d = 'sideToolbar',
e = 'sideCatalog',
f = 'sideCatalog-catalog',
g = 'sideCatalogBtn',
h = 'sideToolbar-up',
i = '<div id="sideToolbar"style="display:none;">\<div class="sideCatalogBg"id="sideCatalog">\<div id="sideCatalog-sidebar">\<div class="sideCatalog-sidebar-top"></div>\<div class="sideCatalog-sidebar-bottom"></div>\</div>\<div id="sideCatalog-catalog">\<ul class="nav"style="width:230px;zoom:1">\</ul>\</div>\</div>\<a href="javascript:void(0);"id="sideCatalogBtn"class="sideCatalogBtnDisable"></a>\</div>',
j = '',
k = 200,
l = 0,
m = 0,
n = 0,
o, p = 18,
q = true,
r = false,
s = $('#' + c);
if (s.length === 0) { return };
b.append(i);
o = s.find(':header');
o.each(function () {
var u = $(this),
v = u[0];
if ($.inArray((v.tagName.toLowerCase()), ["h1", "h2"]) === -1) return true;
var lserialNum = u.find('.dev__fe').text(),
rserialNum = u.find('.dev__ux').text(),
titleContent = u.find('.dev__developer').text(),
titleId = u.attr('id');
if (!titleId) {
titleId = (new myTools).randomString(8);
u.attr('id', titleId);
}
if (v.localName === 'h1') {
l++; m = 0; r = true;
if(titleContent.length>26) titleContent=titleContent.substr(0,26) + "...";
titleContent = HTMLEncode(titleContent);
j += '<li h="1" g="'+ lserialNum +'"><a href="#' + titleId + '">' + lserialNum + '.' + rserialNum + ' ' + titleContent + '</a><span class="sideCatalog-dot"></span></li>';
} else if (r && v.localName === 'h2') {
m++; n = 0;
if(q){
if(titleContent.length>30) titleContent = titleContent.substr(0,30) + "...";
titleContent = HTMLEncode(titleContent);
j += '<li h="2" g="'+ lserialNum +'" class="h2Offset ceg'+lserialNum+'"><a href="#' + titleId + '">' + lserialNum + '.' + rserialNum + ' ' + titleContent + '</a></li>';
}
}
});
/**
* @return {string}
*/
function HTMLEncode(html) {
var temp = document.createElement("div");
(temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html);
var output = temp.innerHTML;
temp = null;
return output;
}
$('#' + f + '>ul').html(j);
b.data('spy', 'scroll');
b.data('target', '.sideCatalogBg');
b.scrollspy({
target: '.sideCatalogBg'
});
$sideCatelog = $('#' + e);
$('#' + g).on('click', function () {
if ($(this).hasClass('sideCatalogBtnDisable') && $sideCatelog.css('visibility') === 'visible') {
$sideCatelog.css('visibility', 'hidden');
$(this).removeClass('sideCatalogBtnDisable');
} else {
$sideCatelog.css('visibility', 'visible');
$(this).addClass('sideCatalogBtnDisable');
}
});
$('#' + h).on('click', function () {
$("html,body").animate({
在看代码的时候,还发现了BNdong大神设置了打赏,但是文档里却没有说,不知道为什么,我也没机会去尝试了
// 添加打赏
if (window.cnblogsConfig.reward.enable && (window.cnblogsConfig.reward.alipay || window.cnblogsConfig.reward.wechatpay)) {
var rightDashangHtml = '<div id="rightDashang" clickflg="false"><span class="rightMenuSpan rightDanshanSpan"><div class="ds-pay">' +
(window.cnblogsConfig.reward.alipay ? '<div class="ds-alipay"><img src="'+window.cnblogsConfig.reward.alipay+'"><span>Alipay</span></div>' : '') +
(window.cnblogsConfig.reward.wechatpay ? '<div class="ds-wecat"><img src="'+window.cnblogsConfig.reward.wechatpay+'"><span>WeChat</span></div>' : '') +
'</div></span><i class="iconfont icon-shang"></i></div>';
rightMenu.prepend(rightDashangHtml);
bndongJs.rightMenuMous('#rightDashang', '.rightDanshanSpan');
}
DIV狂魔的目录设置代码
// 设置随笔目录
setCatalog() {
const options = this.defaultOptions.catalog
if (!options.enable) return
if (!this.hasPostTitle) return
if (this.pageName !== 'post') return
if (this.userAgent !== 'pc') return
const $post = $($('#cnblogs_post_body'))
const $catalogContainer = $('<div>')
const $ulContainer = $('<ul>')
const titleReg = /^h[1-3]$/
$catalogContainer.attr('id', 'catalog').append($(`<div class='catListTitle'><h3>目录</h3></div>`))
$post.children().each(function() {
if (titleReg.test(this.tagName.toLowerCase())) {
$(this).append("<a href='#catalog' class='title_back'></a>")
let aEle = $('<a></a>')
let hEle = $('<li></li>')
const text = this.childNodes.length === 3 ? this.childNodes[1].nodeValue : this.childNodes[0].nodeValue
aEle.attr('href', '#' + this.id).text(text)
hEle.attr('class', this.nodeName.toLowerCase() + '-list').append(aEle)
$ulContainer.append(hEle)
}
})
$($catalogContainer.append($ulContainer)).appendTo('#sideBar')
this.setCatalogPosition()
}