-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem occur when using Pjax/Pjax函数重载问题 #649
Comments
请描述你添加pjax所做的修改 |
|
@ojhdt 下面是一个简单的patch用来修复你提到的前两点问题,核心思想是在pjax每次加载结束后重新加载主题所需的JavaScript脚本。如果你发现有其他JavaScript问题,也可以举一反三的修改。至于点击toc没有滚动动画,好像Icarus本身也没有滚动动画这个功能。最后主题中已经提供jQuery 3.x了,你不用再引入2.x版本的jQuery。你可以把pjax放到它后面。
diff --git a/source/js/back-to-top.js b/source/js/back-to-top.js
index 8cf8cc4..b3d3ca9 100644
--- a/source/js/back-to-top.js
+++ b/source/js/back-to-top.js
@@ -1,4 +1,4 @@
-$(document).ready(function () {
+function loadBackToTop() {
var $button = $('#back-to-top');
var $footer = $('footer.footer');
var $mainColumn = $('.column-main');
@@ -153,4 +153,6 @@ $(document).ready(function () {
$('#back-to-top').on('click', function () {
$('body, html').animate({ scrollTop: 0 }, 400);
});
-});
\ No newline at end of file
+}
+$(document).ready(loadBackToTop);
+$(document).on('pjax:end', loadBackToTop);
\ No newline at end of file
diff --git a/source/js/gallery.js b/source/js/gallery.js
index 5747842..5979549 100644
--- a/source/js/gallery.js
+++ b/source/js/gallery.js
@@ -1,4 +1,4 @@
-document.addEventListener('DOMContentLoaded', function () {
+function loadGallery() {
if (typeof ($.fn.lightGallery) === 'function') {
$('.article').lightGallery({ selector: '.gallery-item' });
}
@@ -8,4 +8,6 @@ document.addEventListener('DOMContentLoaded', function () {
}
$('.justified-gallery').justifiedGallery();
}
-});
\ No newline at end of file
+}
+document.addEventListener('DOMContentLoaded', loadGallery);
+$(document).on('pjax:end', function () { setTimeout(loadGallery) });
\ No newline at end of file
diff --git a/source/js/main.js b/source/js/main.js
index 6b36fd9..ad3fa47 100644
--- a/source/js/main.js
+++ b/source/js/main.js
@@ -1,4 +1,4 @@
-(function ($) {
+function loadMain($) {
$('.article img:not(".not-gallery-item")').each(function () {
// wrap images with link and add caption if possible
if ($(this).parent('a').length === 0) {
@@ -186,4 +186,6 @@
link.target = '_blank';
});
}
-})(jQuery);
+}
+loadMain(jQuery);
+$(document).on('pjax:end', function() { loadMain(jQuery) }); |
@ppoffice 很抱歉再次打扰您
另外,在Pjax下的Valine评论读取存在滞后,出现 读取上一篇浏览过的文章的评论 的情况。 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
1 similar comment
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
已并入主线:#1287 。 |
Please make sure you took care of the following things before you submit this issue. Thank you!
I have set up and configured my blog according to the Hexo docs and the Icarus docs;
I have looked up Github issues and found no solutions to my problems.
我尝试为Icarus添加Pjax,在启动成功后出现以下问题:
希望得到解决方案,提供可用重载方法及编辑位置。
The text was updated successfully, but these errors were encountered: