mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-12 22:17:06 +08:00
✨ disqus/disqusjs/facebook comments 可隨夜間模式按鈕切換而轉換主題
🐛 修復pjax下valine評論顯示不正常的bugs 🐛 修復facebook comments 在手機下寬度不是100%的bugs
This commit is contained in:
@@ -78,13 +78,19 @@ div
|
||||
if theme.busuanzi.site_uv || theme.busuanzi.site_pv || theme.busuanzi.page_pv
|
||||
script(async src=url_for(theme.CDN.busuanzi))
|
||||
|
||||
if theme.pjax && theme.comments && theme.comments.use
|
||||
!=partial('includes/comments/js-load-all', {}, {cache:theme.fragment_cache})
|
||||
else if commentsJsLoad
|
||||
!=partial('includes/comments/js-load-all', {}, {cache:theme.fragment_cache})
|
||||
|
||||
if theme.aplayerInject
|
||||
if theme.pjax
|
||||
include ./head/aplayer.pug
|
||||
else if page.aplayer
|
||||
include ./head/aplayer.pug
|
||||
|
||||
if theme.pjax
|
||||
include ./third-party/pjax.pug
|
||||
|
||||
!=fragment_cache('injectBottom', function(){return injectHtml(theme.inject.bottom)})
|
||||
|
||||
if theme.pjax
|
||||
!=partial('includes/third-party/pjax', {}, {cache:theme.fragment_cache})
|
||||
|
||||
|
||||
@@ -6,11 +6,15 @@ script.
|
||||
this.page.title = '!{ page.title }'
|
||||
};
|
||||
|
||||
if (window.DISQUS) {
|
||||
window.disqusReset = () => {
|
||||
DISQUS.reset({
|
||||
reload: true,
|
||||
config: disqus_config
|
||||
})
|
||||
}
|
||||
|
||||
if (window.DISQUS) {
|
||||
disqusReset()
|
||||
} else {
|
||||
(function() {
|
||||
var d = document, s = d.createElement('script')
|
||||
@@ -34,11 +38,11 @@ script.
|
||||
|
||||
if is_post() && theme.comments.count && defaultComment === 'Disqus'
|
||||
script.
|
||||
function getDisqusCount() {
|
||||
if (window.DISQUSWIDGETS === undefined) {
|
||||
var d = document, s = d.createElement('script');
|
||||
s.src = 'https://!{theme.disqus.shortname}.disqus.com/count.js';
|
||||
s.id = 'dsq-count-scr';
|
||||
(d.head || d.body).appendChild(s);
|
||||
} else {
|
||||
DISQUSWIDGETS.getCount({reset: true});
|
||||
}
|
||||
|
||||
getDisqusCount()
|
||||
@@ -7,7 +7,7 @@ script.
|
||||
document.getElementsByTagName('head')[0].appendChild(ele)
|
||||
}
|
||||
|
||||
function initDiqusjs () {
|
||||
function initDisqusjs () {
|
||||
window.DISQUS = null
|
||||
new DisqusJS({
|
||||
shortname: '!{theme.disqusjs.shortname}',
|
||||
@@ -23,11 +23,13 @@ script.
|
||||
});
|
||||
}
|
||||
|
||||
if (window.disqusjsload) initDiqusjs()
|
||||
window.disqusReset = initDisqusjs
|
||||
|
||||
if (window.disqusJsLoad) initDisqusjs()
|
||||
else {
|
||||
addDisqusjsCSS()
|
||||
$.getScript('!{url_for(theme.CDN.disqusjs)}', initDiqusjs)
|
||||
window.disqusjsload = true
|
||||
$.getScript('!{url_for(theme.CDN.disqusjs)}', initDisqusjs)
|
||||
window.disqusJsLoad = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,10 +45,12 @@ script.
|
||||
|
||||
if is_post() && theme.comments.count && defaultComment === 'Disqusjs'
|
||||
script.
|
||||
function getDisqusCount() {
|
||||
if (window.DISQUSWIDGETS === undefined) {
|
||||
var d = document, s = d.createElement('script');
|
||||
s.src = 'https://!{theme.disqusjs.shortname}.disqus.com/count.js';
|
||||
s.src = 'https://!{theme.disqus.shortname}.disqus.com/count.js';
|
||||
s.id = 'dsq-count-scr';
|
||||
(d.head || d.body).appendChild(s);
|
||||
} else {
|
||||
DISQUSWIDGETS.getCount({reset: true});
|
||||
}
|
||||
getDisqusCount()
|
||||
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
#fb-root
|
||||
script.
|
||||
function loadFBComent () {
|
||||
let ele = document.createElement('script')
|
||||
ele.setAttribute('src','https://connect.facebook.net/!{theme.facebook_comments.lang}/sdk.js#xfbml=1&version=v7.0')
|
||||
ele.setAttribute('async', 'true')
|
||||
ele.setAttribute('defer', 'true')
|
||||
ele.setAttribute('crossorigin', 'anonymous')
|
||||
document.getElementById('fb-root').insertAdjacentElement('afterbegin',ele)
|
||||
|
||||
function loadFBComment () {
|
||||
var themeNow = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light'
|
||||
document.getElementsByClassName('fb-comments')[0].setAttribute('data-colorscheme',themeNow)
|
||||
|
||||
if (typeof FB === 'object') FB.XFBML.parse()
|
||||
else {
|
||||
let ele = document.createElement('script')
|
||||
ele.setAttribute('src','https://connect.facebook.net/!{theme.facebook_comments.lang}/sdk.js#xfbml=1&version=v7.0')
|
||||
ele.setAttribute('async', 'true')
|
||||
ele.setAttribute('defer', 'true')
|
||||
ele.setAttribute('crossorigin', 'anonymous')
|
||||
document.getElementById('fb-root').insertAdjacentElement('afterbegin',ele)
|
||||
}
|
||||
}
|
||||
|
||||
if ('!{defaultComment}' === 'Facebook Comments' || !{theme.comments.load_begin}) {
|
||||
loadFBComent()
|
||||
document.getElementsByClassName('fb-comments').length && loadFBComment()
|
||||
!{theme.pjax} && document.addEventListener('pjax:complete', () =>
|
||||
document.getElementsByClassName('fb-comments').length && loadFBComment()
|
||||
)
|
||||
}
|
||||
else {
|
||||
function loadOtherComment () {
|
||||
loadFBComent()
|
||||
loadFBComment()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
script.
|
||||
function loadGitalk () {
|
||||
function addGitalkSource () {
|
||||
const ele = document.createElement('link')
|
||||
ele.rel = 'stylesheet'
|
||||
ele.href= '!{url_for(theme.CDN.gitalk_css)}'
|
||||
document.getElementsByTagName('head')[0].appendChild(ele)
|
||||
}
|
||||
function addGitalkSource () {
|
||||
const ele = document.createElement('link')
|
||||
ele.rel = 'stylesheet'
|
||||
ele.href= '!{url_for(theme.CDN.gitalk_css)}'
|
||||
document.getElementsByTagName('head')[0].appendChild(ele)
|
||||
}
|
||||
|
||||
function loadGitalk () {
|
||||
function initGitalk () {
|
||||
var gitalk = new Gitalk({
|
||||
clientID: '!{theme.gitalk.client_id}',
|
||||
@@ -30,13 +30,11 @@ script.
|
||||
addGitalkSource()
|
||||
$.getScript('!{url_for(theme.CDN.gitalk)}', initGitalk)
|
||||
}
|
||||
|
||||
function commentCount(n){
|
||||
try {
|
||||
document.getElementsByClassName('gitalk-comment-count')[0].innerHTML= n
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function commentCount(n){
|
||||
if (document.querySelector('#post-meta .gitalk-comment-count')) {
|
||||
document.querySelector('#post-meta .gitalk-comment-count').innerHTML= n
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
hr
|
||||
#post-comment
|
||||
.comment-head
|
||||
.comment-headling
|
||||
.comment-headline
|
||||
i.fas.fa-comments.fa-fw
|
||||
span= ' ' + _p('comment')
|
||||
|
||||
|
||||
7
layout/includes/comments/js-load-all.pug
Normal file
7
layout/includes/comments/js-load-all.pug
Normal file
@@ -0,0 +1,7 @@
|
||||
- let defaultComment = theme.comments.use[0]
|
||||
each name in theme.comments.use
|
||||
case name
|
||||
when 'Valine'
|
||||
include ./valine.pug
|
||||
when 'Facebook Comments'
|
||||
include ./facebook_comments.pug
|
||||
@@ -3,8 +3,6 @@ each name in theme.comments.use
|
||||
case name
|
||||
when 'Disqus'
|
||||
include ./disqus.pug
|
||||
when 'Valine'
|
||||
include ./valine.pug
|
||||
when 'Disqusjs'
|
||||
include ./disqusjs.pug
|
||||
when 'Livere'
|
||||
@@ -13,5 +11,3 @@ each name in theme.comments.use
|
||||
include ./gitalk.pug
|
||||
when 'Utterances'
|
||||
include ./utterances.pug
|
||||
when 'Facebook Comments'
|
||||
include ./facebook_comments.pug
|
||||
@@ -1,5 +1,5 @@
|
||||
script.
|
||||
function loadlivere () {
|
||||
function loadLivere () {
|
||||
(function(d, s) {
|
||||
var j, e = d.getElementsByTagName(s)[0];
|
||||
if (typeof LivereTower === 'function') { return; }
|
||||
@@ -11,13 +11,10 @@ script.
|
||||
}
|
||||
|
||||
if ('!{defaultComment}' === 'Livere' || !{theme.comments.load_begin}) {
|
||||
loadlivere()
|
||||
loadLivere()
|
||||
}
|
||||
else {
|
||||
function loadOtherComment () {
|
||||
loadlivere()
|
||||
loadLivere()
|
||||
}
|
||||
}
|
||||
|
||||
noscript.
|
||||
Please activate JavaScript for write a comment in LiveRe
|
||||
}
|
||||
@@ -13,6 +13,18 @@ script.
|
||||
document.getElementById('utterances-wrap').insertAdjacentElement('afterbegin',ele)
|
||||
}
|
||||
|
||||
function utterancesTheme () {
|
||||
if (document.querySelector('.utterances-frame')) {
|
||||
const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? '#{theme.utterances.dark_theme}' : '#{theme.utterances.light_theme}'
|
||||
const message = {
|
||||
type: 'set-theme',
|
||||
theme: theme
|
||||
};
|
||||
const iframe = document.querySelector('.utterances-frame');
|
||||
iframe.contentWindow.postMessage(message, 'https://utteranc.es');
|
||||
}
|
||||
}
|
||||
|
||||
if ('!{defaultComment}' === 'Utterances' || !{theme.comments.load_begin}) {
|
||||
loadUtterances()
|
||||
}
|
||||
@@ -21,16 +33,4 @@ script.
|
||||
loadUtterances()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if theme.darkmode.enable
|
||||
script.
|
||||
function utterancesTheme () {
|
||||
var theme = document.documentElement.getAttribute('data-theme') === 'dark' ? '#{theme.utterances.dark_theme}' : '#{theme.utterances.light_theme}'
|
||||
const message = {
|
||||
type: 'set-theme',
|
||||
theme: theme
|
||||
};
|
||||
const iframe = document.querySelector('.utterances-frame');
|
||||
iframe.contentWindow.postMessage(message, 'https://utteranc.es');
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ if site.data.valine
|
||||
- emojiMaps = JSON.stringify(site.data.valine)
|
||||
|
||||
script.
|
||||
function loadvaline () {
|
||||
function loadValine () {
|
||||
function requestSetting (from, set) {
|
||||
var from = from
|
||||
var setting = set.split(',').filter(function(item){
|
||||
@@ -18,10 +18,9 @@ script.
|
||||
|
||||
function initValine () {
|
||||
window.valine = new Valine({
|
||||
el:'#vcomment',
|
||||
el: '#vcomment',
|
||||
appId: '#{theme.valine.appId}',
|
||||
appKey: '#{theme.valine.appKey}',
|
||||
path: window.location.pathname,
|
||||
placeholder: '#{theme.valine.placeholder}',
|
||||
avatar: '#{theme.valine.avatar}',
|
||||
meta: guestInfo,
|
||||
@@ -32,20 +31,22 @@ script.
|
||||
emojiCDN: '#{theme.valine.emojiCDN}',
|
||||
emojiMaps: !{emojiMaps},
|
||||
enableQQ: #{theme.valine.enableQQ},
|
||||
requiredFields: requiredFields
|
||||
requiredFields: requiredFields,
|
||||
path: window.location.pathname,
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof window.valine ==='object') initValine()
|
||||
if (typeof Valine === 'function') initValine()
|
||||
else $.getScript('!{url_for(theme.CDN.valine)}', initValine)
|
||||
}
|
||||
|
||||
if ('!{defaultComment}' === 'Valine' || !{theme.comments.load_begin}) {
|
||||
loadvaline()
|
||||
document.querySelector('#vcomment') && loadValine()
|
||||
!{theme.pjax} && document.addEventListener('pjax:complete', () => document.querySelector('#vcomment') && loadValine())
|
||||
}
|
||||
else {
|
||||
function loadOtherComment () {
|
||||
loadvaline()
|
||||
loadValine()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
layout/includes/third-party/pjax.pug
vendored
2
layout/includes/third-party/pjax.pug
vendored
@@ -42,6 +42,8 @@ script.
|
||||
}
|
||||
}
|
||||
|
||||
typeof typed === 'object' && typed.destroy()
|
||||
|
||||
$(window).off('scroll')
|
||||
|
||||
//reset readmode
|
||||
|
||||
Reference in New Issue
Block a user