fix(view): fix pjax support for busuanzi #1335
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
问题描述
在使用“卜算子”统计插件时,如果启用了 pjax,则会导致切换页面后,卜算子的显示功能失效。例如,文章详情页面的顶部信息栏显示
0 VISITS
。原因分析
这是因为卜算子的 JS 脚本需要重新运行才能生效。卜算子的 JS 源码概述如下:
可见,必须运行
bszCaller.fetch(...)
语句才可以使得页面中的统计文本正常显示。解决方案
仿照上次 MathJax 问题的解决方案。只需在
pjax:complete
事件触发后,手动运行bszCaller.fetch(...)
语句即可。Problem Description
When using the "Busuanzi" statistics plugin, enabling PJAX causes the plugin's display functionality to fail after page navigation. For example, the top information bar on a post details page might display
0 VISITS
.Cause Analysis
This issue occurs because the JavaScript script for Busuanzi needs to be re-executed to function properly. A summary of Busuanzi's JavaScript source code is as follows:
As shown, the
bszCaller.fetch(...)
statement must be executed to correctly display the statistical text on the page.Solution
Following the approach used for the MathJax issue, the solution is straightforward: manually execute the
bszCaller.fetch(...)
statement after thepjax:complete
event is triggered.