This commit is contained in:
Van
2019-03-28 12:14:02 +08:00
parent e3d7be6f23
commit 59450e3218
9 changed files with 524 additions and 292 deletions

View File

@@ -42,25 +42,25 @@ var Skin = {
return
}
if ($(window).scrollTop() > 64) {
$('#headerNav').addClass('header__nav--fixed');
$('.main').css('margin-top', '100px');
$('#headerNav').addClass('header__nav--fixed')
$('.main').css('margin-top', '100px')
} else {
$('#headerNav').removeClass('header__nav--fixed');
$('.main').css('margin-top', '50px');
$('#headerNav').removeClass('header__nav--fixed')
$('.main').css('margin-top', '50px')
}
});
$(window).scroll();
})
$(window).scroll()
Util.initPjax(function () {
Util.parseMarkdown();
Util.parseMarkdown()
if (Util.isArticlePage(location.href)) {
if (!$('#articleSideShare .article__code').qrcode) {
$.ajax({
method: "GET",
method: 'GET',
url: Label.staticServePath + '/js/lib/jquery.qrcode.min.js',
dataType: "script",
cache: true
});
dataType: 'script',
cache: true,
})
}
}
Skin.initToc()
@@ -68,37 +68,34 @@ var Skin = {
Skin.initToc()
},
initTags: function () {
var $tags = $('#tags');
var $tags = $('#tags')
var tagsArray = $tags.find('.tag')
// 根据引用次数添加样式,产生云效果
var max = parseInt(tagsArray.first().data('count'));
var distance = Math.ceil(max / 5);
var max = parseInt(tagsArray.first().data('count'))
var distance = Math.ceil(max / 5)
for (var i = 0; i < tagsArray.length; i++) {
var count = parseInt($(tagsArray[i]).data('count'));
var count = parseInt($(tagsArray[i]).data('count'))
// 算出当前 tag 数目所在的区间,加上 class
for (var j = 0; j < 5; j++) {
if (count > j * distance && count <= (j + 1) * distance) {
tagsArray[i].className = 'tag tag__level' + j;
break;
tagsArray[i].className = 'tag tag__level' + j
break
}
}
}
// 按字母或者中文拼音进行排序
$tags.html(tagsArray.get().sort(function (a, b) {
var valA = $(a).text().toLowerCase();
var valB = $(b).text().toLowerCase();
var valA = $(a).text().toLowerCase()
var valB = $(b).text().toLowerCase()
// 对中英文排序的处理
return valA.localeCompare(valB);
}));
return valA.localeCompare(valB)
}))
},
initArticle: function () {
initArticle1111: function () {
if ($('#articleShare').length === 0) {
return
}
Skin._share('#articleShare')
Skin._share('#articleSideShare')
Skin._share('#articleBottomShare')
var $postSide = $('.post__side')
if ($(window).height() >= $('.post').height()) {
@@ -121,10 +118,11 @@ var Skin = {
// up
$('.header').addClass('header--fixed').css({'top': '0'})
$('.main').css('padding-top', '64px')
if ($(window).height() <= $('.post').height() && scrollTop < bottomTop - $(window).height()) {
if ($(window).height() <= $('.post').height() && scrollTop <
bottomTop - $(window).height()) {
$('.article__toolbar').css({
'bottom': 0,
'opacity': 1
'opacity': 1,
})
}
} else if (beforScrollTop - scrollTop < 0) {
@@ -133,7 +131,7 @@ var Skin = {
$('.main').css('padding-top', '0')
$('.article__toolbar').css({
'bottom': '-44px',
'opacity': 0
'opacity': 0,
})
}
@@ -150,18 +148,18 @@ var Skin = {
if (bottomTop < $(window).height()) {
$postSide.css({
'position': 'absolute',
'top': (bottomTop - 125) + 'px'
'top': (bottomTop - 125) + 'px',
})
} else {
$postSide.css({
'position': 'absolute',
'top': (bottomTop - sideAbsoluteTop) + 'px'
'top': (bottomTop - sideAbsoluteTop) + 'px',
})
}
} else {
$postSide.css({
'position': 'fixed',
'top': '50%'
'top': '50%',
})
}
@@ -170,54 +168,75 @@ var Skin = {
$(window).scroll()
},
_share: function (id) {
var $this = $(id)
var $qrCode = $this.find('.article__code')
var shareURL = $qrCode.data('url')
var avatarURL = $qrCode.data('avatar')
var title = encodeURIComponent($qrCode.data('title') + ' - ' + $qrCode.data('blogtitle')),
url = encodeURIComponent(shareURL)
initArticle: function () {
this._initPage()
page.share()
},
_initPage: function () {
var $articleTocs = $('.vditor-reset [id^=b3_solo_h]')
var $articleToc = $('.article__toc')
var $articleProgress = $('.article__progress')
var urls = {}
urls.tencent = 'http://share.v.t.qq.com/index.php?c=share&a=index&title=' + title +
'&url=' + url + '&pic=' + avatarURL
urls.weibo = 'http://v.t.sina.com.cn/share/share.php?title=' +
title + '&url=' + url + '&pic=' + avatarURL
urls.qqz = 'https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='
+ url + '&sharesource=qzone&title=' + title + '&pics=' + avatarURL
urls.twitter = 'https://twitter.com/intent/tweet?status=' + title + ' ' + url
if ($articleToc.length === 1) {
$('.post__toc').
css('left', $('.article .item__content').offset().left +
$('.article .item__content').outerWidth() - 80)
}
$(window).unbind('scroll').scroll(function (event) {
if ($articleProgress.length === 0) {
return false
}
$this.find('span').click(function () {
var key = $(this).data('type')
$articleProgress.attr('value', parseInt($(window).scrollTop())).
attr('max', parseInt($('body').outerHeight() -
$(window).height()))
if (!key) {
if ($(window).scrollTop() > 236) {
$('.article__top').css('top', 0)
} else {
$('.article__top').css('top', -60)
}
if ($('.article__toc li').length === 0) {
return false
}
if ($(window).scrollTop() > 990 && $(window).scrollTop() <
$('.article').outerHeight() + 100) {
$('.post__toc').show()
} else {
$('.post__toc').hide()
return
}
if (key === 'wechat') {
if ($qrCode.find('canvas').length === 0) {
$qrCode.qrcode({
width: 128,
height: 128,
text: shareURL
});
} else {
$qrCode.slideToggle();
}
return false;
}
// 界面各种图片加载会导致帖子目录定位
var toc = []
$articleTocs.each(function (i) {
toc.push({
id: this.id,
offsetTop: this.offsetTop,
})
})
window.open(urls[key], '_blank', 'top=100,left=200,width=648,height=618')
// 当前目录样式
var scrollTop = $(window).scrollTop()
for (var i = 0, iMax = toc.length; i < iMax; i++) {
if (scrollTop < toc[i].offsetTop) {
$articleToc.find('li').removeClass('current')
var index = i > 0 ? i - 1 : 0
$articleToc.find('a[href="#' + toc[index].id + '"]').
parent().
addClass('current')
break
}
}
if (scrollTop >= toc[toc.length - 1].offsetTop) {
$articleToc.find('li').removeClass('current')
$articleToc.find('li:last').addClass('current')
}
})
$(window).scroll()
},
initToc: function () {
if ($('.article__toc').length !== 0 && $(window).width() > 1000) {
$('.article__toc').animate({
'left': ($('.post').outerWidth() + $('.post').offset().left) + 'px'
}, 600)
} else {
$('.article__toc').hide()
}
}
};
Skin.init();
}
// Skin.init();