添加第三方chat服務 crisp

This commit is contained in:
Jerry
2020-07-22 13:56:54 +08:00
parent 5ee7976c4a
commit 1a2568d645
12 changed files with 166 additions and 130 deletions

View File

@@ -60,8 +60,6 @@ div
if theme.preloader
!=partial('includes/loading/loading-js', {}, {cache:theme.fragment_cache})
!=partial('includes/chat/index', {}, {cache:theme.fragment_cache})
.js-pjax
if is_home() && theme.subtitle.enable
include ./third-party/subtitle.pug
@@ -90,6 +88,7 @@ div
include ./head/aplayer.pug
!=fragment_cache('injectBottom', function(){return injectHtml(theme.inject.bottom)})
!=partial('includes/chat/index', {}, {cache:theme.fragment_cache})
if theme.pjax
!=partial('includes/third-party/pjax', {}, {cache:theme.fragment_cache})

View File

@@ -11,8 +11,6 @@ script.
if (d.head) d.head.appendChild(s);
})(document, window, 'Chatra');
if (!{theme.chat_btn}) {
var chatBtnFn = () => {
var chatBtn = document.getElementById("chat_btn")

View File

@@ -0,0 +1,36 @@
script.
window.$crisp = [];
window.CRISP_WEBSITE_ID = "!{theme.crisp.website_id}";
(function () {
d = document;
s = d.createElement("script");
s.src = "https://client.crisp.chat/l.js";
s.async = 1;
d.getElementsByTagName("head")[0].appendChild(s);
})();
$crisp.push(["safe", true])
if (!{theme.chat_btn}) {
$crisp.push(["do", "chat:hide"])
$crisp.push(["on", "chat:closed", function() {
$crisp.push(["do", "chat:hide"])
}])
var chatBtnFn = () => {
var chatBtn = document.getElementById("chat_btn")
chatBtn.addEventListener("click", function(){
$crisp.push(["do", "chat:show"])
$crisp.push(["do", "chat:open"])
});
}
chatBtnFn()
} else {
if (!{theme.chat_hide_show}) {
function chatBtnHide () {
$crisp.push(["do", "chat:hide"])
}
function chatBtnShow () {
$crisp.push(["do", "chat:show"])
}
}
}

View File

@@ -1,12 +1,29 @@
if theme.chat_btn
script.
((window.gitter = {}).chat = {}).options = {
room: '#{theme.gitter.room}',
activationElement: '#chat_btn'
disableDefaultChat: true,
};
script(src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer)
document.addEventListener('gitter-sidecar-ready', (e) => {
const GitterChat = e.detail.Chat
let chat
function initGitter () {
chat = new GitterChat({
room: '#{theme.gitter.room}',
activationElement: '#chat_btn'
});
}
initGitter()
if (!{theme.pjax}) {
document.addEventListener('pjax:complete', () => {
chat.destroy()
initGitter()
})
}
})
else
script.
((window.gitter = {}).chat = {}).options = {
@@ -22,4 +39,5 @@ else
document.getElementsByClassName('gitter-open-chat-button')[0].style.display= 'block'
}
}
script(src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer)
script(src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer)

View File

@@ -5,4 +5,6 @@ else if theme.tidio && theme.tidio.enable
else if theme.daovoice && theme.daovoice.enable
include ./daovoice.pug
else if theme.gitter && theme.gitter.enable
include ./gitter.pug
include ./gitter.pug
else if theme.crisp && theme.crisp.enable
include ./crisp.pug

View File

@@ -1,5 +1,5 @@
if (theme.google_adsense && theme.google_adsense.enable)
script(async src=theme.google_adsense.js)
script(async src=theme.google_adsense.js data-pjax)
if theme.google_adsense.auto_ads
script.

View File

@@ -22,7 +22,7 @@ section#rightside
if showToc
button#mobile-toc-button.close(type="button" title=_p("rightside.toc"))
i.fas.fa-list-ul
if theme.chat_btn && (theme.chatra.enable || theme.tidio.enable || theme.daovoice.enable || theme.gitter.enable)
if theme.chat_btn
button#chat_btn(type="button" title=_p("rightside.chat_btn"))
i.fas.fa-sms

View File

@@ -1,55 +1,58 @@
script(src=url_for(theme.CDN.pjax))
script.
var pjax = new Pjax({
selectors: [
'title',
'meta[name=description]',
'#config_change',
'#body-wrap',
'#rightside',
'.js-pjax'
],
cacheBust: false,
})
document.addEventListener('pjax:complete', function () {
refreshFn()
$('script[data-pjax]').each(function () {
$(this).parent().append($(this).remove())
$(function () {
var pjax = new Pjax({
selectors: [
'title',
'meta[name=description]',
'#config_change',
'#body-wrap',
'#rightside-config-hide',
'#rightside-config-show',
'.js-pjax'
],
cacheBust: false,
})
GLOBAL_CONFIG.islazyload && lazyLoadInstance.update()
document.addEventListener('pjax:complete', function () {
refreshFn()
typeof chatBtnFn === 'function' && chatBtnFn()
typeof panguInit === 'function' && panguInit()
$('script[data-pjax]').each(function () {
$(this).parent().append($(this).remove())
})
if (typeof gtag === 'function') {
gtag('config', '!{theme.google_analytics}', {'page_path': window.location.pathname});
}
GLOBAL_CONFIG.islazyload && lazyLoadInstance.update()
if (document.getElementsByClassName('aplayer').length){
loadMeting()
}
})
typeof chatBtnFn === 'function' && chatBtnFn()
typeof panguInit === 'function' && panguInit()
document.addEventListener('pjax:send', function () {
if (window.aplayers) {
for (let i = 0; i < window.aplayers.length; i++) {
if (!window.aplayers[i].options.fixed) {
window.aplayers[i].destroy()
if (typeof gtag === 'function') {
gtag('config', '!{theme.google_analytics}', {'page_path': window.location.pathname});
}
if (document.getElementsByClassName('aplayer').length){
typeof loadMeting === 'function' && loadMeting()
}
})
document.addEventListener('pjax:send', function () {
if (window.aplayers) {
for (let i = 0; i < window.aplayers.length; i++) {
if (!window.aplayers[i].options.fixed) {
window.aplayers[i].destroy()
}
}
}
}
typeof typed === 'object' && typed.destroy()
typeof typed === 'object' && typed.destroy()
$(window).off('scroll')
$(window).off('scroll')
//reset readmode
$('body').hasClass('read-mode') && $('body').removeClass('read-mode')
//reset readmode
$('body').hasClass('read-mode') && $('body').removeClass('read-mode')
//reset font-size
$('body').css('font-size') !== originFontSize && $('body').css('font-size', parseFloat(originFontSize))
//reset font-size
$('body').css('font-size') !== originFontSize && $('body').css('font-size', parseFloat(originFontSize))
})
})