mirror of https://github.com/IoTcat/kayo.git
parent
5103d83bf5
commit
d9859f299d
15 changed files with 194 additions and 15 deletions
@ -1,11 +1,13 @@ |
||||
{%- if theme.google_analytics -%} |
||||
<!-- Global site tag (gtag.js) - Google Analytics --> |
||||
<script async src="https://www.googletagmanager.com/gtag/js?id={{ theme.google_analytics }}"></script> |
||||
<script async src="https://www.googletagmanager.com/gtag/js?id={{ theme.google_analytics }}" data-pjax></script> |
||||
<script> |
||||
pjax_google_analytics = () => { |
||||
window.dataLayer = window.dataLayer || []; |
||||
function gtag(){dataLayer.push(arguments);} |
||||
gtag('js', new Date()); |
||||
|
||||
gtag('config', '{{ theme.google_analytics }}'); |
||||
} |
||||
</script> |
||||
{%- endif -%} |
||||
|
@ -1,8 +1 @@ |
||||
{%- if !is_home() and !is_archive() -%} |
||||
{%- include "_comments/disqus.swig" -%} |
||||
{%- include "_comments/changyan.swig" -%} |
||||
{%- include "_comments/livere.swig" -%} |
||||
{%- include "_comments/gitalk.swig" -%} |
||||
{%- include "_comments/utterances.swig" -%} |
||||
{%- include "_comments/valine.swig" -%} |
||||
{%- endif -%} |
||||
{%- include "_comments/valine.swig" -%} |
||||
|
@ -0,0 +1,42 @@ |
||||
var loadingBar = document.querySelector(".loading-bar"); |
||||
var progress = document.querySelector(".loading-bar .progress"); |
||||
var timer = null; |
||||
|
||||
|
||||
// Pjax 开始时执行的函数 |
||||
var loadingbarStart = function () { |
||||
// 进度条默认已经加载 20% |
||||
var loadingBarWidth = 20; |
||||
// 进度条的最大增加宽度 |
||||
var MAX_LOADING_WIDTH = 95; |
||||
|
||||
// 显示进度条 |
||||
loadingBar.classList.add("loading"); |
||||
// 初始化进度条的宽度 |
||||
progress.style.width = loadingBarWidth + "%"; |
||||
|
||||
clearInterval(timer); |
||||
timer = setInterval(function () { |
||||
// 进度条的增加速度(可以改为一个随机值,显得更加真实) |
||||
loadingBarWidth += 3; |
||||
|
||||
// 当进度条到达 95% 后停止增加 |
||||
if (loadingBarWidth > MAX_LOADING_WIDTH) { |
||||
loadingBarWidth = MAX_LOADING_WIDTH; |
||||
} |
||||
|
||||
progress.style.width = loadingBarWidth + "%"; |
||||
}, 500); |
||||
}; |
||||
|
||||
|
||||
// Pjax 完成之后执行的函数 |
||||
var loadingbarStop = function () { |
||||
clearInterval(timer); |
||||
progress.style.width = "100%"; |
||||
loadingBar.classList.remove("loading"); |
||||
|
||||
setTimeout(function () { |
||||
progress.style.width = 0; |
||||
}, 400); |
||||
}; |
@ -0,0 +1,63 @@ |
||||
{%- if theme.pjax.enable -%} |
||||
<script src="https://cdn.jsdelivr.net/npm/pjax/pjax.js"></script> |
||||
<script> |
||||
new Pjax({ |
||||
elements: 'a[href]:not([href^="#"]):not([href="javascript:void(0)"])', |
||||
selectors: ["head title, #main", "#footer"], |
||||
}); |
||||
|
||||
|
||||
/* 第一次载入页面加载的函数 */ |
||||
pjax_ini = () => { |
||||
|
||||
/* 关闭侧边栏 */ |
||||
window.slideout.close(); |
||||
|
||||
if(page_obj.comments == "true"){ |
||||
{%- if theme.valine.enable -%} |
||||
pjax_valine(); |
||||
{%- endif -%} |
||||
} |
||||
{%- if theme.google_analytics -%} |
||||
pjax_google_analytics(); |
||||
{%- endif -%} |
||||
}; |
||||
|
||||
/* 第一次 执行 */ |
||||
pjax_ini(); |
||||
|
||||
|
||||
{%- if theme.pjax.loadingbar -%} |
||||
{%- include "loading-bar.swig" -%} |
||||
{%- endif -%} |
||||
|
||||
|
||||
/* Pjax 开始时,重新加载的函数 */ |
||||
document.addEventListener("pjax:send", function () { |
||||
{%- if theme.pjax.loadingbar -%} |
||||
loadingbarStart(); |
||||
{%- endif -%} |
||||
|
||||
}); |
||||
|
||||
|
||||
/* Pjax 完成后,重新加载的函数 */ |
||||
document.addEventListener("pjax:complete", function () { |
||||
/* 重载带data-pjax的script,或者.pjax-reload属性内容的script */ |
||||
$("script[data-pjax], .pjax-reload script").each(function () { |
||||
$(this).parent().append($(this).remove()); |
||||
}); |
||||
pjax_ini(); |
||||
{%- if theme.pjax.loadingbar -%} |
||||
loadingbarStop(); |
||||
{%- endif -%} |
||||
}); |
||||
|
||||
|
||||
/* Pjax 出错,执行的函数 */ |
||||
document.addEventListener("pjax:error", function () { |
||||
|
||||
}); |
||||
|
||||
</script> |
||||
{%- endif -%} |
@ -1 +1,2 @@ |
||||
<script type="text/javascript" src="{{ url_for('js/src') }}/kayo.js?v={{ theme.version }}"></script> |
||||
<script type="text/javascript" src="{{ url_for('js/src') }}/kayo.js?v={{ theme.version }}" data-pjax></script> |
||||
<script type="text/javascript" src="{{ url_for('js/src') }}/kayo-no-pjax.js?v={{ theme.version }}"></script> |
||||
|
@ -0,0 +1,35 @@ |
||||
(function(){ |
||||
|
||||
var $nav = $('#mobile-navbar'); |
||||
var $navIcon = $('.mobile-navbar-icon'); |
||||
|
||||
var slideout = new Slideout({ |
||||
'panel': document.getElementById('mobile-panel'), |
||||
'menu': document.getElementById('mobile-menu'), |
||||
'padding': 180, |
||||
'tolerance': 70 |
||||
}); |
||||
slideout.disableTouch(); |
||||
|
||||
window.slideout = slideout; |
||||
|
||||
$navIcon.click(function () { |
||||
slideout.toggle(); |
||||
}); |
||||
|
||||
slideout.on('beforeopen', function () { |
||||
$nav.addClass('fixed-open'); |
||||
$navIcon.addClass('icon-click').removeClass('icon-out'); |
||||
}); |
||||
|
||||
slideout.on('beforeclose', function () { |
||||
$nav.removeClass('fixed-open'); |
||||
$navIcon.addClass('icon-out').removeClass('icon-click'); |
||||
}); |
||||
|
||||
$('#mobile-panel').on('touchend', function () { |
||||
slideout.isOpen() && $navIcon.click(); |
||||
}); |
||||
|
||||
|
||||
}()) |
Loading…
Reference in new issue