This commit is contained in:
119
Bubble/js/common.js
Normal file
119
Bubble/js/common.js
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Solo - A small and beautiful blogging system written in Java.
|
||||
* Copyright (c) 2010-present, b3log.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* @fileoverview util and every page should be used.
|
||||
*
|
||||
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
|
||||
* @version 0.1.1.0, Apr 19, 2019
|
||||
*/
|
||||
|
||||
/**
|
||||
* @description 皮肤脚本
|
||||
* @static
|
||||
*/
|
||||
var Skin = {
|
||||
init: function () {
|
||||
Util.initPjax()
|
||||
},
|
||||
initArticle: function () {
|
||||
page.share()
|
||||
|
||||
var $articleTocs = $('.vditor-reset [id^=b3_solo_h]')
|
||||
var $articleToc = $('.article__toc')
|
||||
var $articleProgress = $('.article__progress')
|
||||
|
||||
if ($articleToc.length === 1) {
|
||||
if ($(window).width() > 876) {
|
||||
$('.post__toc').
|
||||
css('left', $('.article .item__content').offset().left +
|
||||
$('.article .item__content').outerWidth() - 80)
|
||||
} else {
|
||||
$('.post__toc a').click(function () {
|
||||
$('.post__toc').hide()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
$articleToc.find('a').click(function (event) {
|
||||
var id = $(this).attr('href')
|
||||
window.location.hash = id
|
||||
$(window).scrollTop($(id).offset().top - 60)
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
return false
|
||||
})
|
||||
|
||||
$(window).unbind('scroll').scroll(function (event) {
|
||||
if ($articleProgress.length === 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
$articleProgress.attr('value', parseInt($(window).scrollTop())).
|
||||
attr('max', parseInt($('body').outerHeight() -
|
||||
$(window).height()))
|
||||
|
||||
if ($(window).scrollTop() > 236) {
|
||||
$('.article__top').css('top', 0)
|
||||
} else {
|
||||
$('.article__top').css('top', -61)
|
||||
}
|
||||
|
||||
if ($('.article__toc li').length === 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
if ($(window).width() > 876) {
|
||||
if ($(window).scrollTop() > 975 && $(window).scrollTop() <
|
||||
$('.article').outerHeight() + 100) {
|
||||
$('.post__toc').show()
|
||||
} else {
|
||||
$('.post__toc').hide()
|
||||
}
|
||||
}
|
||||
|
||||
// 界面各种图片加载会导致帖子目录定位
|
||||
var toc = []
|
||||
$articleTocs.each(function (i) {
|
||||
toc.push({
|
||||
id: this.id,
|
||||
offsetTop: $(this).offset().top,
|
||||
})
|
||||
})
|
||||
|
||||
// 当前目录样式
|
||||
var scrollTop = $(window).scrollTop()
|
||||
for (var i = 0, iMax = toc.length; i < iMax; i++) {
|
||||
if (scrollTop < toc[i].offsetTop - 61) {
|
||||
$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 - 61) {
|
||||
$articleToc.find('li').removeClass('current')
|
||||
$articleToc.find('li:last').addClass('current')
|
||||
}
|
||||
})
|
||||
|
||||
$(window).scroll()
|
||||
},
|
||||
}
|
||||
Skin.init()
|
1
Bubble/js/common.min.js
vendored
Normal file
1
Bubble/js/common.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
var Skin={init:function(){Util.initPjax()},initArticle:function(){page.share();var l=$(".vditor-reset [id^=b3_solo_h]"),s=$(".article__toc"),c=$(".article__progress");1===s.length&&(876<$(window).width()?$(".post__toc").css("left",$(".article .item__content").offset().left+$(".article .item__content").outerWidth()-80):$(".post__toc a").click(function(){$(".post__toc").hide()})),s.find("a").click(function(t){var o=$(this).attr("href");return window.location.hash=o,$(window).scrollTop($(o).offset().top-60),t.preventDefault(),t.stopPropagation(),!1}),$(window).unbind("scroll").scroll(function(t){if(0===c.length)return!1;if(c.attr("value",parseInt($(window).scrollTop())).attr("max",parseInt($("body").outerHeight()-$(window).height())),236<$(window).scrollTop()?$(".article__top").css("top",0):$(".article__top").css("top",-61),0===$(".article__toc li").length)return!1;876<$(window).width()&&(975<$(window).scrollTop()&&$(window).scrollTop()<$(".article").outerHeight()+100?$(".post__toc").show():$(".post__toc").hide());var o=[];l.each(function(t){o.push({id:this.id,offsetTop:$(this).offset().top})});for(var i=$(window).scrollTop(),e=0,r=o.length;e<r;e++)if(i<o[e].offsetTop-61){s.find("li").removeClass("current");var n=0<e?e-1:0;s.find('a[href="#'+o[n].id+'"]').parent().addClass("current");break}i>=o[o.length-1].offsetTop-61&&(s.find("li").removeClass("current"),s.find("li:last").addClass("current"))}),$(window).scroll()}};Skin.init();
|
Reference in New Issue
Block a user